diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 67911e37..ee545626 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -21,6 +21,7 @@ import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDoor; import com.zc.business.domain.DcEvent; +import com.zc.business.domain.DcSmokeRecord; import com.zc.business.enums.UniversalEnum; import com.zc.business.interfaces.OperationLog; import com.zc.business.request.DeviceGetPropertiesOperateRequest; @@ -79,6 +80,7 @@ private VideoController videoController; private ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE); private static final String DOORSTATUS = "doorStatus";//redis策略缓存的key + private static final String SOMKEVALUE = "smokeValue";//redis策略缓存的key /* @Value("${iot.address}") private String iotAddress; @@ -1736,7 +1738,7 @@ private VideoController videoController; return batchInvokedFunction2(jsonObject); } //一体机柜调用机箱门数据 - //@PostMapping("/integratedCabinetAir") + @PostMapping("/integratedCabinetAir") @Scheduled(cron = "20 * * * * ?") @Transactional() public AjaxResult chassisDoor() throws IOException, HttpException { @@ -1791,6 +1793,50 @@ private VideoController videoController; } } } + for (DcDevice device : dcDeviceList){ + AjaxResult result = getDeviceLatestProperty(device.getIotDeviceId(), "SmokeAlarm"); + if (!result.get("code").toString().equals("200")){ + continue; + } + JSONObject data = (JSONObject) result.get("data");//属性全部值 + if (data==null){ + continue; + } + String value = data.get("value").toString();//属性值 + if (Integer.parseInt(value)>=400){ + String cacheMapValue = redisCache.getCacheMapValue(SOMKEVALUE, device.getIotDeviceId());//查询缓存 + if (cacheMapValue==null||"".equals(cacheMapValue)){//缓存不存在,加入数据加入缓存 + DcSmokeRecord dcSmokeRecord = new DcSmokeRecord(); + dcSmokeRecord.setDeviceName(device.getDeviceName()); + dcSmokeRecord.setDeviceType(device.getDeviceType()); + dcSmokeRecord.setDirection(device.getDirection()); + dcSmokeRecord.setStakeMark(device.getStakeMark()); + dcSmokeRecord.setSmokeValue(value); + dcSmokeRecord.setCreateTime(DateUtils.getNowDate()); + dcSmokeRecord.setIotDeviceId(device.getIotDeviceId()); + dcDeviceService.insertSmokeRecord(dcSmokeRecord); + redisCache.setCacheMapValue(SOMKEVALUE,device.getIotDeviceId(),value); + }else { + if (Integer.parseInt(value)==Integer.parseInt(cacheMapValue)){ //最新值与之前的缓存值一样,不予处理 + continue; + } + //如果缓存存在,并且与当前值不一样,而且当前值大于400,烟感值缓存替换、数据替换 + redisCache.delCacheMapValue(SOMKEVALUE,device.getIotDeviceId()); + redisCache.setCacheMapValue(SOMKEVALUE,device.getIotDeviceId(),value); + DcSmokeRecord dcSmokeRecord = new DcSmokeRecord(); + dcSmokeRecord.setIotDeviceId(device.getIotDeviceId()); + dcSmokeRecord.setSmokeValue(value); + dcSmokeRecord.setUpdateTime(DateUtils.getNowDate()); + dcDeviceService.updateSmokeValue(dcSmokeRecord);//修改数据值 + } + }else { + String cacheMapValue = redisCache.getCacheMapValue(SOMKEVALUE, device.getIotDeviceId());//查询缓存 + if (cacheMapValue==null||"".equals(cacheMapValue)){ + continue; + } + redisCache.delCacheMapValue(SOMKEVALUE,device.getIotDeviceId()); + } + } return AjaxResult.success(); } //设备箱机箱门状态采集 @@ -1855,7 +1901,19 @@ private VideoController videoController; } return AjaxResult.success(); } - + //查询机柜烟感记录 + @GetMapping("/dcSmokeRecordList") + public TableDataInfo selectSmokeList( DcSmokeRecord dcSmokeRecord){ + startPage(); + Map redisCacheCacheMap = redisCache.getCacheMap(SOMKEVALUE); + if (redisCacheCacheMap==null){ + return getDataTable(Collections.emptyList()); + } + Set strings = redisCacheCacheMap.keySet(); + List list = dcDeviceService.selectSmokeList(strings); + return getDataTable(list); + } + //查询机柜门锁记录 @GetMapping("/dcDoorList") public TableDataInfo selectEnergyCircuit( DcDoor dcDoor){ startPage(); diff --git a/zc-business/src/main/java/com/zc/business/domain/DcSmokeRecord.java b/zc-business/src/main/java/com/zc/business/domain/DcSmokeRecord.java new file mode 100644 index 00000000..294f79a3 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcSmokeRecord.java @@ -0,0 +1,130 @@ +package com.zc.business.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * @author 王思祥 + * @ClassName DcSmokeRecord + */ + +public class DcSmokeRecord extends BaseEntity { + /** 预警编号 */ + private Long id; + + /** 所在桩号 */ + @Excel(name = "所在桩号") + private String stakeMark; + + /** 方向:1-上行2-中3-下行 */ + @Excel(name = "方向",readConverterExp = "1=菏泽方向,3=济南方向,2=双向") + private String direction; + + private String deviceName; + private String deviceType; + + private String iotDeviceId; + private String endStakeMark; + + private String startTime; + + private String endTime; + + private String smokeValue; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getStakeMark() { + return stakeMark; + } + + public void setStakeMark(String stakeMark) { + this.stakeMark = stakeMark; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getIotDeviceId() { + return iotDeviceId; + } + + public void setIotDeviceId(String iotDeviceId) { + this.iotDeviceId = iotDeviceId; + } + + public String getEndStakeMark() { + return endStakeMark; + } + + public void setEndStakeMark(String endStakeMark) { + this.endStakeMark = endStakeMark; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getSmokeValue() { + return smokeValue; + } + + public void setSmokeValue(String smokeValue) { + this.smokeValue = smokeValue; + } + + @Override + public String toString() { + return "DcSmokeRecord{" + + "id=" + id + + ", stakeMark='" + stakeMark + '\'' + + ", direction='" + direction + '\'' + + ", deviceName='" + deviceName + '\'' + + ", deviceType='" + deviceType + '\'' + + ", iotDeviceId='" + iotDeviceId + '\'' + + ", endStakeMark='" + endStakeMark + '\'' + + ", startTime='" + startTime + '\'' + + ", endTime='" + endTime + '\'' + + ", smokeValue='" + smokeValue + '\'' + + '}'; + } +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java index 07f601d5..40a828ed 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java @@ -3,6 +3,7 @@ package com.zc.business.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDoor; +import com.zc.business.domain.DcSmokeRecord; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -53,4 +54,10 @@ public interface DcDeviceMapper extends BaseMapper { List selectDcDoorList(DcDoor dcDoor); //查询状态为开的设备 List selectDcDoorOpen(@Param("iotIds")Set strings); + //查询机柜烟感异常数据 + List selectSmokeList(@Param("iotIds")Set strings); + //新增机柜烟感记录 + Integer insertSmokeRecord(DcSmokeRecord dcSmokeRecord); + //修改机柜烟感值 + Integer updateSmokeValue(DcSmokeRecord dcSmokeRecord); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java index 19f87669..70c2b672 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java @@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDoor; import com.zc.business.domain.DcEvent; +import com.zc.business.domain.DcSmokeRecord; import com.zc.business.domain.DcStakeMark; import com.zc.common.core.httpclient.exception.HttpException; import io.swagger.v3.oas.models.security.SecurityScheme; @@ -141,4 +142,10 @@ public interface IDcDeviceService extends IService { List selectDcDoorList(DcDoor dcDoor); //查询状态为开的设备 List selectDcDoorOpen(Set strings); + //查询机柜烟感异常数据 + List selectSmokeList(Set strings); + //新增机柜烟感记录 + Integer insertSmokeRecord(DcSmokeRecord dcSmokeRecord); + //修改机柜烟感值 + Integer updateSmokeValue(DcSmokeRecord dcSmokeRecord); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index c837d3a4..fc249546 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -14,6 +14,7 @@ import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDoor; import com.zc.business.domain.DcEvent; import com.zc.business.domain.DcProduct; +import com.zc.business.domain.DcSmokeRecord; import com.zc.business.domain.DcStakeMark; import com.zc.business.domain.MdDevice; import com.zc.business.enums.UniversalEnum; @@ -686,6 +687,21 @@ public class DcDeviceServiceImpl extends ServiceImpl i public List selectDcDoorOpen(Set strings) { return dcDeviceMapper.selectDcDoorOpen(strings); } + //查询机柜烟感异常数据 + @Override + public List selectSmokeList(Set strings) { + return dcDeviceMapper.selectSmokeList(strings); + } + //新增机柜烟感记录 + @Override + public Integer insertSmokeRecord(DcSmokeRecord dcSmokeRecord) { + return dcDeviceMapper.insertSmokeRecord(dcSmokeRecord); + } + + @Override + public Integer updateSmokeValue(DcSmokeRecord dcSmokeRecord) { + return dcDeviceMapper.updateSmokeValue(dcSmokeRecord); + } } diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index 82c59493..2aa72857 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -93,6 +93,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{iotDeviceId}, + + insert into dc_smoke_record + + id, + stake_mark, + direction, + device_type, + device_name, + smoke_value, + create_time, + iot_device_id, + + + #{id}, + #{stakeMark}, + #{direction}, + #{deviceType}, + #{deviceName}, + #{smokeValue}, + #{createTime}, + #{iotDeviceId}, + + select t1.id, t1.iot_device_id, t1.group_id, t1.product_id, t1.stake_mark, t1.direction, t1.device_name, t1.device_code, t1.device_type,t1.installation_Date,t1.production_date,t1.durable_years,t1.installation_site, @@ -252,4 +276,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ) b ON a.iot_device_id = b.iot_device_id AND a.create_time = b.latest_time ORDER BY a.create_time DESC + + + UPDATE dc_smoke_record + SET smoke_value =#{smokeValue},update_time=#{updateTime} + WHERE id = ( + SELECT id FROM ( + SELECT id + FROM dc_smoke_record + WHERE iot_device_id = #{iotDeviceId} + ORDER BY create_time DESC + LIMIT 1 + ) AS latest_record + ); +