|
|
@ -13,16 +13,21 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private PsdcDeviceMapper psdcDeviceMapper; |
|
|
|
private PsdcDeviceMapper psdcDeviceMapper; |
|
|
@ -36,21 +41,21 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
* @param deviceId 主键 |
|
|
|
* @param deviceId 主键 |
|
|
|
* @return 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PsdcDevice queryById(Integer deviceId){ |
|
|
|
public PsdcDevice queryById(Integer deviceId) { |
|
|
|
return psdcDeviceMapper.queryById(deviceId); |
|
|
|
return psdcDeviceMapper.queryById(deviceId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 根据用户id查询设备列表 |
|
|
|
* 根据用户id查询设备列表 |
|
|
|
|
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<PsdcDevice> queryByUserId(){ |
|
|
|
public List<PsdcDevice> queryByUserId() { |
|
|
|
return psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); |
|
|
|
return psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<DeviceStatusVo> queryDeviceStatus(){ |
|
|
|
public List<DeviceStatusVo> queryDeviceStatus() { |
|
|
|
List<PsdcDevice> psdcDevices = psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); |
|
|
|
List<PsdcDevice> psdcDevices = psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); |
|
|
|
return psdcDevices.stream().map(psdcDevice -> { |
|
|
|
return psdcDevices.stream().map(psdcDevice -> { |
|
|
|
DeviceStatusVo deviceStatusVo = new DeviceStatusVo(); |
|
|
|
DeviceStatusVo deviceStatusVo = new DeviceStatusVo(); |
|
|
@ -70,13 +75,20 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Integer insert(PsdcDevice psdcDevice){ |
|
|
|
public Integer insert(PsdcDevice psdcDevice) { |
|
|
|
return psdcDeviceMapper.insert(psdcDevice); |
|
|
|
return psdcDeviceMapper.insert(psdcDevice); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<PsdcDevice> queryAllByLimit(PsdcDevice psdcDevice) { |
|
|
|
public List<PsdcDevice> queryAllByLimit(PsdcDevice psdcDevice) { |
|
|
|
return psdcDeviceMapper.queryAllByLimit(psdcDevice); |
|
|
|
List<PsdcDevice> list = psdcDeviceMapper.queryAllByLimit(psdcDevice); |
|
|
|
|
|
|
|
for (PsdcDevice dev : list){ |
|
|
|
|
|
|
|
dev.setDevType(s("t", dev.getDeviceType())); |
|
|
|
|
|
|
|
dev.setDevStatus(s("s", dev.getDeviceStatus())); |
|
|
|
|
|
|
|
dev.setDevRunstatus(s("r", dev.getDeviceRunstatus())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -85,7 +97,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Integer update(PsdcDevice psdcDevice){ |
|
|
|
public Integer update(PsdcDevice psdcDevice) { |
|
|
|
return psdcDeviceMapper.update(psdcDevice); |
|
|
|
return psdcDeviceMapper.update(psdcDevice); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -95,42 +107,59 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
* @param deviceIds 主键 |
|
|
|
* @param deviceIds 主键 |
|
|
|
* @return 是否成功 |
|
|
|
* @return 是否成功 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean deleteById(Long[] deviceIds){ |
|
|
|
public boolean deleteById(Long[] deviceIds) { |
|
|
|
int total = psdcDeviceMapper.deleteById(deviceIds); |
|
|
|
int total = psdcDeviceMapper.deleteById(deviceIds); |
|
|
|
return total > 0; |
|
|
|
return total > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(propagation = REQUIRES_NEW) |
|
|
|
|
|
|
|
public boolean daoruDevicesData(MultipartFile file) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
//需要将上传文件转成Stream流
|
|
|
|
|
|
|
|
InputStream in = file.getInputStream(); |
|
|
|
|
|
|
|
// EasyExcel.read(in, PsdcDevice.class, new DevicesDataListener(psdcDeviceMapper)).sheet().sheetNo(0).doRead();
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
log.info("Sorry,导入设备数据失败!+ 错误原因: {}", e.getMessage()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 更新设备状态 |
|
|
|
* 更新设备状态 |
|
|
|
|
|
|
|
* |
|
|
|
* @param deviceId |
|
|
|
* @param deviceId |
|
|
|
* @param runStatus |
|
|
|
* @param runStatus |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int updateDeviceRunStatus(Integer deviceId, Integer runStatus) { |
|
|
|
public int updateDeviceRunStatus(Integer deviceId, Integer runStatus) { |
|
|
|
return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId,runStatus); |
|
|
|
return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId, runStatus); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 控制设备启动停止 |
|
|
|
* 控制设备启动停止 |
|
|
|
|
|
|
|
* |
|
|
|
* @param deviceId |
|
|
|
* @param deviceId |
|
|
|
* @param runStatus |
|
|
|
* @param runStatus |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus,String controlBy,Integer controlMethod) { |
|
|
|
public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus, String controlBy, Integer controlMethod) { |
|
|
|
|
|
|
|
|
|
|
|
String value = ""; |
|
|
|
String value = ""; |
|
|
|
if(runStatus == 1){ |
|
|
|
if (runStatus == 1) { |
|
|
|
value = "启动"; |
|
|
|
value = "启动"; |
|
|
|
} else if ( runStatus == 2 ) { |
|
|
|
} else if (runStatus == 2) { |
|
|
|
value = "停止"; |
|
|
|
value = "停止"; |
|
|
|
} |
|
|
|
} |
|
|
|
log.info("设备id:{}",deviceId); |
|
|
|
log.info("设备id:{}", deviceId); |
|
|
|
|
|
|
|
|
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
if(psdcDevice == null){ |
|
|
|
if (psdcDevice == null) { |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设备启停",value,controlMethod,3,"未找到该设备",controlBy)); |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, null, null, "设备启停", value, controlMethod, 3, "未找到该设备", controlBy)); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -138,27 +167,27 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,3,"手动控制,等待终端响应超时",controlBy));
|
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,3,"手动控制,等待终端响应超时",controlBy));
|
|
|
|
|
|
|
|
|
|
|
|
//发送成功
|
|
|
|
//发送成功
|
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,2,"手动控制,控制成功",controlBy)); |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, psdcDevice.getDeviceName(), psdcDevice.getDeviceSn(), "设备启停", value, controlMethod, 2, "手动控制,控制成功", controlBy)); |
|
|
|
return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId,runStatus); |
|
|
|
return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId, runStatus); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int setTemperature(Integer deviceId, List<HashMap> data, String controlBy,Integer controlMethod) { |
|
|
|
public int setTemperature(Integer deviceId, List<HashMap> data, String controlBy, Integer controlMethod) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("设备id:{}",deviceId); |
|
|
|
log.info("设备id:{}", deviceId); |
|
|
|
log.info("控制指令:{}",data); |
|
|
|
log.info("控制指令:{}", data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
if(psdcDevice == null){ |
|
|
|
if (psdcDevice == null) { |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设定温度",null,controlMethod,3,"未找到该设备",controlBy)); |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, null, null, "设定温度", null, controlMethod, 3, "未找到该设备", controlBy)); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AtomicInteger atomicInteger = new AtomicInteger(0); |
|
|
|
AtomicInteger atomicInteger = new AtomicInteger(0); |
|
|
|
|
|
|
|
|
|
|
|
for (Map map: data) { |
|
|
|
for (Map map : data) { |
|
|
|
|
|
|
|
|
|
|
|
String controlKey = map.get("controlKey").toString(); |
|
|
|
String controlKey = map.get("controlKey").toString(); |
|
|
|
String controlValue = map.get("controlValue").toString(); |
|
|
|
String controlValue = map.get("controlValue").toString(); |
|
|
@ -168,7 +197,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy));
|
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy));
|
|
|
|
//发送成功
|
|
|
|
//发送成功
|
|
|
|
|
|
|
|
|
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy)); |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, psdcDevice.getDeviceName(), psdcDevice.getDeviceSn(), controlContext, controlValue, controlMethod, 2, "控制成功", controlBy)); |
|
|
|
atomicInteger.incrementAndGet(); |
|
|
|
atomicInteger.incrementAndGet(); |
|
|
|
} |
|
|
|
} |
|
|
|
return atomicInteger.get(); |
|
|
|
return atomicInteger.get(); |
|
|
@ -176,6 +205,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 单条控制指令 |
|
|
|
* 单条控制指令 |
|
|
|
|
|
|
|
* |
|
|
|
* @param deviceId |
|
|
|
* @param deviceId |
|
|
|
* @param key |
|
|
|
* @param key |
|
|
|
* @param value |
|
|
|
* @param value |
|
|
@ -184,17 +214,17 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int setTemperature(Integer deviceId, String key,String value, String controlBy,Integer controlMethod) { |
|
|
|
public int setTemperature(Integer deviceId, String key, String value, String controlBy, Integer controlMethod) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("设备id:{}",deviceId); |
|
|
|
log.info("设备id:{}", deviceId); |
|
|
|
log.info("控制指令:{}",key); |
|
|
|
log.info("控制指令:{}", key); |
|
|
|
log.info("控制内容:{}",value); |
|
|
|
log.info("控制内容:{}", value); |
|
|
|
String controlContext = ControlKeyEnum.getControlContext(key); |
|
|
|
String controlContext = ControlKeyEnum.getControlContext(key); |
|
|
|
|
|
|
|
|
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); |
|
|
|
if(psdcDevice == null){ |
|
|
|
if (psdcDevice == null) { |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,controlContext,null,controlMethod,3,"未找到该设备",controlBy)); |
|
|
|
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, null, null, controlContext, null, controlMethod, 3, "未找到该设备", controlBy)); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
throw new ControlException("控制失败,未找到该设备"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -204,7 +234,39 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ |
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,3,"等待终端响应超时",controlBy));
|
|
|
|
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,3,"等待终端响应超时",controlBy));
|
|
|
|
//发送成功
|
|
|
|
//发送成功
|
|
|
|
|
|
|
|
|
|
|
|
return psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,2,"控制成功",controlBy)); |
|
|
|
return psdcControlLogMapper.insert(new PsdcControlLog(deviceId, psdcDevice.getDeviceName(), psdcDevice.getDeviceSn(), controlContext, value, controlMethod, 2, "控制成功", controlBy)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String s(String s, int i) { |
|
|
|
|
|
|
|
switch (s) { |
|
|
|
|
|
|
|
case "s": |
|
|
|
|
|
|
|
switch (i) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
return "未激活"; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
return "禁用"; |
|
|
|
|
|
|
|
case 3: |
|
|
|
|
|
|
|
return "在线"; |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
return "离线"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case "t": |
|
|
|
|
|
|
|
switch (i) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
return "监测设备"; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
return "运行设备"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case "r": |
|
|
|
|
|
|
|
switch (i) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
return "开启"; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
return "关闭"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |