|
|
|
|
@ -2,9 +2,12 @@ package com.mh.user.job;
|
|
|
|
|
|
|
|
|
|
import com.mh.user.constants.Constant; |
|
|
|
|
import com.mh.user.entity.CollectionParamsManageEntity; |
|
|
|
|
import com.mh.user.entity.DeviceInstallEntity; |
|
|
|
|
import com.mh.user.entity.GatewayManageEntity; |
|
|
|
|
import com.mh.user.mapper.CollectionParamsManageMapper; |
|
|
|
|
import com.mh.user.mapper.DeviceInstallMapper; |
|
|
|
|
import com.mh.user.mapper.GatewayManageMapper; |
|
|
|
|
import com.mh.user.mapper.NowDataMapper; |
|
|
|
|
import com.mh.user.s7.S7ConnectorUtil; |
|
|
|
|
import com.mh.user.utils.DateUtil; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
@ -34,11 +37,15 @@ public class S7PlcCollectionJob {
|
|
|
|
|
|
|
|
|
|
// 缓存S7连接器,避免频繁创建连接
|
|
|
|
|
private static final Map<String, S7ConnectorUtil> connectorCache = new ConcurrentHashMap<>(); |
|
|
|
|
private final DeviceInstallMapper deviceInstallMapper; |
|
|
|
|
private final NowDataMapper nowDataMapper; |
|
|
|
|
|
|
|
|
|
public S7PlcCollectionJob(GatewayManageMapper gatewayManageMapper, |
|
|
|
|
CollectionParamsManageMapper collectionParamsManageMapper) { |
|
|
|
|
CollectionParamsManageMapper collectionParamsManageMapper, DeviceInstallMapper deviceInstallMapper, NowDataMapper nowDataMapper, NowDataMapper nowDataMapper1) { |
|
|
|
|
this.gatewayManageMapper = gatewayManageMapper; |
|
|
|
|
this.collectionParamsManageMapper = collectionParamsManageMapper; |
|
|
|
|
this.deviceInstallMapper = deviceInstallMapper; |
|
|
|
|
this.nowDataMapper = nowDataMapper1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -132,6 +139,22 @@ public class S7PlcCollectionJob {
|
|
|
|
|
param.getRegisterAddr(), param.getOtherName(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 遍历完全之后更新回水状态,因为有多箱和单箱电磁阀
|
|
|
|
|
// params遍历得出多少个buildingId分组
|
|
|
|
|
List<Long> buildingIds = params.stream().map(CollectionParamsManageEntity::getBuildingId).distinct().collect(Collectors.toList()); |
|
|
|
|
for (Long buildingId : buildingIds) { |
|
|
|
|
List<Map<String, Object>> backWaterStates = collectionParamsManageMapper.selectBackWaterState(buildingId); |
|
|
|
|
// map值有cur_value,cur_time,通过stream判断cur_time是否是当前时间,然后cur_value如果存在一天记录等于1的,back_water_state=运行,否则back_water_state=不运行
|
|
|
|
|
backWaterStates.forEach(backWaterState -> { |
|
|
|
|
if (backWaterState.get("cur_time").toString().substring(0, 10).equals(dateStr.substring(0, 10))) { |
|
|
|
|
if (backWaterState.get("cur_value").equals(1)) { |
|
|
|
|
nowDataMapper.updateBackWaterState(buildingId, "运行"); |
|
|
|
|
} else { |
|
|
|
|
nowDataMapper.updateBackWaterState(buildingId, "不运行"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -148,8 +171,29 @@ public class S7PlcCollectionJob {
|
|
|
|
|
|
|
|
|
|
// 读取数据
|
|
|
|
|
Object value = connector.readData(registerAddr); |
|
|
|
|
|
|
|
|
|
DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDeviceById(param.getDeviceInstallId()); |
|
|
|
|
|
|
|
|
|
if (value == null) { |
|
|
|
|
log.warn("读取数据为空: registerAddr={}", registerAddr); |
|
|
|
|
// 更新deviceInstall离线
|
|
|
|
|
deviceInstallMapper.updateNotOnlineById(param.getDeviceInstallId()); |
|
|
|
|
// 更新now_data离线
|
|
|
|
|
nowDataMapper.updateRunState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
"2", deviceInstallEntity.getDeviceName()); |
|
|
|
|
// 在判断设备类型,如果是供水泵,up_water_state=运行
|
|
|
|
|
// 如果是补水电磁阀开,use_water_state=运行,
|
|
|
|
|
// 如果是单箱电磁阀或者多箱电磁阀开,back_water_state=运行
|
|
|
|
|
if (deviceInstallEntity.getDeviceType().equals("供水泵")) { |
|
|
|
|
nowDataMapper.updateUpWaterState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
"2", deviceInstallEntity.getDeviceName()); |
|
|
|
|
} else if (deviceInstallEntity.getDeviceType().equals("补水电磁阀")) { |
|
|
|
|
nowDataMapper.updateUseWaterState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
"2", deviceInstallEntity.getDeviceName()); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -185,6 +229,87 @@ public class S7PlcCollectionJob {
|
|
|
|
|
param.getBuildingId() != null ? param.getBuildingId().toString() : null |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 在同步更新device_install表
|
|
|
|
|
deviceInstallMapper.updateLastValueByOtherParam(param.getDeviceInstallId(), curValue.toString()); |
|
|
|
|
|
|
|
|
|
if (deviceInstallEntity != null) { |
|
|
|
|
// 更新设备安装表中的now_date字段,根据param.getParamTypeId()的值进行判断 // 在对now_date进行更新
|
|
|
|
|
// 查询当前点位是否是运行状态、压力、液位、液位设置、回水温度、故障状态
|
|
|
|
|
switch(param.getParamTypeId()) { |
|
|
|
|
case 2: // 运行状态
|
|
|
|
|
nowDataMapper.updateRunState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
String.valueOf(curValue.intValue()), deviceInstallEntity.getDeviceName()); |
|
|
|
|
// 在判断设备类型,如果是供水泵,up_water_state=运行
|
|
|
|
|
// 如果是补水电磁阀开,use_water_state=运行,
|
|
|
|
|
// 如果是单箱电磁阀或者多箱电磁阀开,back_water_state=运行
|
|
|
|
|
if (deviceInstallEntity.getDeviceType().equals("供水泵")) { |
|
|
|
|
nowDataMapper.updateUpWaterState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
String.valueOf(curValue.intValue()), deviceInstallEntity.getDeviceName()); |
|
|
|
|
} else if (deviceInstallEntity.getDeviceType().equals("补水电磁阀")) { |
|
|
|
|
nowDataMapper.updateUseWaterState(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
String.valueOf(curValue.intValue()), deviceInstallEntity.getDeviceName()); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 5: // 压力
|
|
|
|
|
nowDataMapper.updatePressure(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
curValue.toString(), deviceInstallEntity.getDeviceName()); |
|
|
|
|
break; |
|
|
|
|
case 31: // 液位
|
|
|
|
|
if (param.getOtherName().contains("单箱") && deviceInstallEntity.getIsSingleBox() == 1) { |
|
|
|
|
// 更新单箱液位
|
|
|
|
|
nowDataMapper.updateBoxLevel(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
curValue.toString(), |
|
|
|
|
deviceInstallEntity.getDeviceName(), 1); |
|
|
|
|
} else { |
|
|
|
|
// 获取多箱的液位
|
|
|
|
|
nowDataMapper.updateBoxLevel(deviceInstallEntity.getBuildingId(), |
|
|
|
|
null, |
|
|
|
|
curValue.toString(), |
|
|
|
|
null, 0); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 39: // 液位设置
|
|
|
|
|
if (param.getOtherName().contains("单箱") && deviceInstallEntity.getIsSingleBox() == 1) { |
|
|
|
|
// 更新单箱液位
|
|
|
|
|
nowDataMapper.updateBoxLevelSet(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
curValue.toString(), |
|
|
|
|
deviceInstallEntity.getDeviceName(), 1); |
|
|
|
|
} else { |
|
|
|
|
// 获取多箱的液位
|
|
|
|
|
nowDataMapper.updateBoxLevelSet(deviceInstallEntity.getBuildingId(), |
|
|
|
|
null, |
|
|
|
|
curValue.toString(), |
|
|
|
|
null, 0); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 32: // 压力设置
|
|
|
|
|
nowDataMapper.updatePressureSet(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
curValue.toString(), deviceInstallEntity.getDeviceName()); |
|
|
|
|
break; |
|
|
|
|
case 12: // 回水温度
|
|
|
|
|
break; |
|
|
|
|
case 3: // 故障状态
|
|
|
|
|
nowDataMapper.updatePressureSet(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
curValue.intValue() == 0 ? "正常" : "故障", deviceInstallEntity.getDeviceName()); |
|
|
|
|
break; |
|
|
|
|
case 41: // 回水阀控制模式:0单箱,1多箱
|
|
|
|
|
nowDataMapper.updateBackControlModel(deviceInstallEntity.getBuildingId(), |
|
|
|
|
deviceInstallEntity.getDeviceAddr(), |
|
|
|
|
String.valueOf(curValue.intValue()), deviceInstallEntity.getDeviceName()); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// 根据deviceInstall查询对应的deviceInstall表数据
|
|
|
|
|
// 根据查询出来的deviceInstall表数据,根据device_addr和device_name值进行更新
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.debug("采集成功: registerAddr={}, value={}, otherName={}", |
|
|
|
|
registerAddr, curValue, param.getOtherName()); |
|
|
|
|
} |
|
|
|
|
|