|
|
|
@@ -1,11 +1,15 @@ |
|
|
|
package com.iformall.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
|
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxDevice; |
|
|
|
import com.iformall.enums.EnumDeviceStatus; |
|
|
|
import com.iformall.enums.EnumDeviceType; |
|
|
|
import com.iformall.mapper.WxDeviceMapper; |
|
|
|
import com.iformall.service.WxDeviceService; |
|
|
|
import org.slf4j.Logger; |
|
|
|
@@ -24,6 +28,14 @@ public class WxDeviceServiceImpl implements WxDeviceService { |
|
|
|
@Autowired |
|
|
|
WxDeviceMapper wxDeviceMapper; |
|
|
|
|
|
|
|
final String DEVICE_DEFAULT_CONFIG_SCREEN_AD = "{" + |
|
|
|
"\"heartBeatIntervel\":300000," + //5MIN |
|
|
|
"\"dataRefreshIntervel\":3600000," + //1HOUR |
|
|
|
"\"pageChangeInterval\":10000," + //10SEC |
|
|
|
"\"animationTheme\":0" + |
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxDevice> listAsPage(WxDevice record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxDeviceMapper.findList(record)); |
|
|
|
@@ -34,20 +46,60 @@ public class WxDeviceServiceImpl implements WxDeviceService { |
|
|
|
return wxDeviceMapper.selectByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getDefaultConfig(int type) { |
|
|
|
|
|
|
|
if (type == EnumDeviceType.SCREEN.getCode()) { |
|
|
|
return DEVICE_DEFAULT_CONFIG_SCREEN_AD; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkConfig(int type, String config) { |
|
|
|
JSONObject jConfig; |
|
|
|
try { |
|
|
|
jConfig = JSONObject.parseObject(config); |
|
|
|
} catch (Exception e) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (type == EnumDeviceType.SCREEN.getCode()) { |
|
|
|
Integer heartBeatIntervel = jConfig.getInteger("heartBeatIntervel"); |
|
|
|
Integer dataRefreshIntervel = jConfig.getInteger("dataRefreshIntervel"); |
|
|
|
Integer pageChangeInterval = jConfig.getInteger("pageChangeInterval"); |
|
|
|
Integer animationTheme = jConfig.getInteger("animationTheme"); |
|
|
|
if (heartBeatIntervel == null || |
|
|
|
dataRefreshIntervel == null || |
|
|
|
pageChangeInterval == null || |
|
|
|
animationTheme == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveOrUpdate(WxDevice record) { |
|
|
|
public ResultData saveOrUpdate(WxDevice record) { |
|
|
|
if (record.getId() == null) { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setCreateDate(new Date()); |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
record.setConfig(getDefaultConfig(record.getType())); |
|
|
|
wxDeviceMapper.insertSelective(record); |
|
|
|
} else { |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
if (record.getConfig() != null) { |
|
|
|
if (!checkConfig(record.getType(),record.getConfig())) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
wxDeviceMapper.updateByPrimaryKeySelective(record); |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteById(Long id) { |
|
|
|
wxDeviceMapper.deleteByPrimaryKey(id); |
|
|
|
|