|
|
|
@ -10,11 +10,9 @@ import com.psdc.entity.vo.ModelVo; |
|
|
|
|
import com.psdc.enums.ControlKeyEnum; |
|
|
|
|
import com.psdc.exception.ControlException; |
|
|
|
|
import com.psdc.mapper.*; |
|
|
|
|
import com.psdc.mqtt.MyMQTTClient; |
|
|
|
|
import com.psdc.service.IPsdcDeviceService; |
|
|
|
|
import com.psdc.utils.SecurityUtils; |
|
|
|
|
import com.psdc.utils.poi.ExcelUtil; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -57,6 +55,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
* @param deviceId 主键 |
|
|
|
|
* @return 实例对象 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public PsdcDevice queryById(Integer deviceId) { |
|
|
|
|
return psdcDeviceMapper.queryById(deviceId); |
|
|
|
|
} |
|
|
|
@ -67,6 +66,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
* |
|
|
|
|
* @return 设备列表 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<PsdcDevice> queryByUserId(Integer parent) { |
|
|
|
|
return psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId(), parent); |
|
|
|
|
} |
|
|
|
@ -81,6 +81,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
return psdcDeviceMapper.queryByUserId(null, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DeviceStatusVo> queryDeviceStatus() { |
|
|
|
|
Date data = new Date(); |
|
|
|
|
List<PsdcDevice> psdcDevices = psdcDeviceMapper.selDevicesByUserId(SecurityUtils.getUserId()); |
|
|
|
@ -151,6 +152,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
|
* @return 实例对象 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Integer insert(PsdcDevice psdcDevice) { |
|
|
|
|
psdcDevice.setDeviceStatus(1); // 未激活
|
|
|
|
|
psdcDevice.setDeviceRunstatus(2); // 关闭
|
|
|
|
@ -180,6 +182,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
* @param psdcDevice 实例对象 |
|
|
|
|
* @return 实例对象 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Integer update(PsdcDevice psdcDevice) { |
|
|
|
|
return psdcDeviceMapper.update(psdcDevice); |
|
|
|
|
} |
|
|
|
@ -190,6 +193,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
* @param deviceIds 主键 |
|
|
|
|
* @return 是否成功 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean deleteById(Long[] deviceIds) { |
|
|
|
|
int total = psdcDeviceMapper.deleteById(deviceIds); |
|
|
|
|
return total > 0; |
|
|
|
@ -384,6 +388,57 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DeviceStatusVo> queryControlDeviceList() { |
|
|
|
|
Date data = new Date(); |
|
|
|
|
List<PsdcDevice> psdcDevices = psdcDeviceMapper.selDevicesByUserId(SecurityUtils.getUserId()); |
|
|
|
|
List<DeviceStatusVo> deviceStatusVoList = new ArrayList<>(); |
|
|
|
|
for (PsdcDevice pd : psdcDevices) { |
|
|
|
|
String deviceModel = pd.getDeviceModel(); |
|
|
|
|
if ("温度传感器".equals(deviceModel)){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if ("总电表".equals(deviceModel)){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
DeviceStatusVo deviceStatusVo = new DeviceStatusVo(); |
|
|
|
|
BeanUtils.copyProperties(pd, deviceStatusVo); |
|
|
|
|
List<Map> ary = new ArrayList<>(); |
|
|
|
|
for (ModelVo mv : psdcModelMapper.selDevIsControlByModelName(deviceModel)) { |
|
|
|
|
Integer deviceId = pd.getDeviceId(); |
|
|
|
|
PsdcThermometerDataRes thermometerDataRes = thermometerRtdataMapper.selTempByDevId(deviceId, sdf.format(data)); |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
Double tempValue = 0.0; |
|
|
|
|
map.put("controlElement", mv.getRelationField()); |
|
|
|
|
map.put("controlRemark", mv.getIoDesc()); |
|
|
|
|
if (null != thermometerDataRes) { |
|
|
|
|
switch (mv.getRelationField()) { |
|
|
|
|
case "intemp": |
|
|
|
|
tempValue = thermometerDataRes.getThermometerValueIn(); |
|
|
|
|
break; |
|
|
|
|
case "outtemp": |
|
|
|
|
tempValue = thermometerDataRes.getThermometerValueOut(); |
|
|
|
|
break; |
|
|
|
|
case "temp": |
|
|
|
|
tempValue = thermometerDataRes.getThermometerValue(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
map.put("tempValue", tempValue); |
|
|
|
|
ary.add(map); |
|
|
|
|
} |
|
|
|
|
if (pd.getDeviceRunstatus() != null && pd.getDeviceRunstatus() == 1) { |
|
|
|
|
deviceStatusVo.setDeviceRunstatus(true); |
|
|
|
|
} else { |
|
|
|
|
deviceStatusVo.setDeviceRunstatus(false); |
|
|
|
|
} |
|
|
|
|
deviceStatusVo.setControl_elements(ary); |
|
|
|
|
deviceStatusVoList.add(deviceStatusVo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return deviceStatusVoList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String coverStr(String s, int i) { |
|
|
|
|
switch (s) { |
|
|
|
|
case "s": |
|
|
|
|