diff --git a/zc-business/src/main/java/com/zc/business/domain/MdDeviceData.java b/zc-business/src/main/java/com/zc/business/domain/MdDeviceData.java new file mode 100644 index 00000000..71b467ed --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/MdDeviceData.java @@ -0,0 +1,194 @@ +package com.zc.business.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; + +/** + * @Description 中间库设备数据 + * + * @author liuwenge + * @date 2024/2/20 17:30 + */ +public class MdDeviceData { + + /** 主键 */ + private Long id; + + /** 设备编号 */ + @Excel(name = "设备编号") + private String devNo; + + /** 设备类型 */ + @Excel(name = "设备类型") + private String devType; + + /** 时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date timeStamp; + + /** 自定义字段 */ + @Excel(name = "自定义字段") + private String expands; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date creationTime; + + /** 创建人 */ + @Excel(name = "创建人") + private String creatorUserId; + + /** 最后修改时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "最后修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date lastModificationTime; + + /** 最后修改人 */ + @Excel(name = "最后修改人") + private Long lastModifierUserId; + + /** 是否删除 */ + @Excel(name = "是否删除") + private Integer isDeleted; + + /** 删除人 */ + @Excel(name = "删除人") + private Long deleterUserId; + + /** 删除时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "删除时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date deletionTime; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setDevNo(String devNo) + { + this.devNo = devNo; + } + + public String getDevNo() + { + return devNo; + } + + public String getDevType() { + return devType; + } + + public void setDevType(String devType) { + this.devType = devType; + } + + public void setTimeStamp(Date timeStamp) + { + this.timeStamp = timeStamp; + } + + public Date getTimeStamp() + { + return timeStamp; + } + public void setExpands(String expands) + { + this.expands = expands; + } + + public String getExpands() + { + return expands; + } + public void setCreationTime(Date creationTime) + { + this.creationTime = creationTime; + } + + public Date getCreationTime() + { + return creationTime; + } + public void setCreatorUserId(String creatorUserId) + { + this.creatorUserId = creatorUserId; + } + + public String getCreatorUserId() + { + return creatorUserId; + } + public void setLastModificationTime(Date lastModificationTime) + { + this.lastModificationTime = lastModificationTime; + } + + public Date getLastModificationTime() + { + return lastModificationTime; + } + public void setLastModifierUserId(Long lastModifierUserId) + { + this.lastModifierUserId = lastModifierUserId; + } + + public Long getLastModifierUserId() + { + return lastModifierUserId; + } + public void setIsDeleted(Integer isDeleted) + { + this.isDeleted = isDeleted; + } + + public Integer getIsDeleted() + { + return isDeleted; + } + public void setDeleterUserId(Long deleterUserId) + { + this.deleterUserId = deleterUserId; + } + + public Long getDeleterUserId() + { + return deleterUserId; + } + public void setDeletionTime(Date deletionTime) + { + this.deletionTime = deletionTime; + } + + public Date getDeletionTime() + { + return deletionTime; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("devNo", getDevNo()) + .append("timeStamp", getTimeStamp()) + .append("expands", getExpands()) + .append("creationTime", getCreationTime()) + .append("creatorUserId", getCreatorUserId()) + .append("lastModificationTime", getLastModificationTime()) + .append("lastModifierUserId", getLastModifierUserId()) + .append("isDeleted", getIsDeleted()) + .append("deleterUserId", getDeleterUserId()) + .append("deletionTime", getDeletionTime()) + .toString(); + } + +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java index b98086ce..7788b60e 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java @@ -2,6 +2,7 @@ package com.zc.business.mapper; import java.util.List; import com.zc.business.domain.DcMeteorologicalDetectorData; +import com.zc.business.domain.MdDeviceData; /** * 气象检测器数据Mapper接口 @@ -43,22 +44,6 @@ public interface DcMeteorologicalDetectorDataMapper */ int updateDcMeteorologicalDetectorData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData); - /** - * 中间库新增气象检测器数据 - * - * @param dcMeteorologicalDetectorData 气象检测器数据 - * @return 结果 - */ - Boolean insertIntermediateWarehouseData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData); - - /** - * 中间库修改气象检测器数据 - * - * @param dcMeteorologicalDetectorData 气象检测器数据 - * @return 结果 - */ - Boolean updateIntermediateWarehouseData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData); - /** * 删除气象检测器数据 * diff --git a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java new file mode 100644 index 00000000..f2ed25e0 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java @@ -0,0 +1,33 @@ +package com.zc.business.mapper; + +import com.zc.business.domain.DcBoardReleaseLog; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.MdDeviceData; + +import java.util.List; + +/** + * 中间库Mapper接口 + * + * @author ruoyi + * @date 2024-01-05 + */ +public interface MiddleDatabaseMapper +{ + + /** + * 中间库新增设备数据 + * + * @param mdDeviceData 气象检测器数据 + * @return 结果 + */ + Boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData); + + /** + * 更新中间库设备 + * + * @param dcDevice 设备 + * @return 结果 + */ + boolean updateMiddleDatabaseDevice(DcDevice dcDevice); +} diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index e96500e0..9ab3e5c4 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -13,6 +13,7 @@ import com.zc.business.enums.WarningStateEnum; import com.zc.business.enums.WarningSubclassEnum; import com.zc.business.service.IDcDeviceService; import com.zc.business.service.IDcWarningService; +import com.zc.business.service.IMiddleDatabaseService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -42,6 +43,9 @@ public class DeviceMessageHandler { @Resource private IDcWarningService dcWarningService; + @Resource + private IMiddleDatabaseService middleDatabaseService; + @Resource private RedisCache redisCache; @@ -65,6 +69,9 @@ public class DeviceMessageHandler { // 批量更新设备状态 dcDeviceService.batchUpdate(dcDevices); + + // 批量更新中间库设备状态 + middleDatabaseService.updateMiddleDatabaseDevice(dcDevices); } /** diff --git a/zc-business/src/main/java/com/zc/business/message/device/listener/DevicePropertyReportListener.java b/zc-business/src/main/java/com/zc/business/message/device/listener/DevicePropertyReportListener.java index 110da462..172dadf8 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/listener/DevicePropertyReportListener.java +++ b/zc-business/src/main/java/com/zc/business/message/device/listener/DevicePropertyReportListener.java @@ -1,11 +1,14 @@ package com.zc.business.message.device.listener; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonObject; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcMeteorologicalDetectorData; +import com.zc.business.domain.MdDeviceData; import com.zc.business.enums.IotProductEnum; import com.zc.business.service.IDcMeteorologicalDetectorDataService; +import com.zc.business.service.IMiddleDatabaseService; import com.zc.common.core.redis.stream.RedisStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +20,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,6 +40,8 @@ public class DevicePropertyReportListener implements StreamListener message) { @@ -53,8 +59,31 @@ public class DevicePropertyReportListener implements StreamListener expands = new HashMap<>(); + expands.put("rainFall",meteorologicalDetectorData.getRainfall()); //雨量 + expands.put("windSpeed",meteorologicalDetectorData.getWindSpeed()); //风速 + expands.put("windDirection",meteorologicalDetectorData.getWindDirection()); //风向 + expands.put("temperature",meteorologicalDetectorData.getTemperature()); //大气温度 + expands.put("humidity",meteorologicalDetectorData.getHumidity()); //大气湿度 + expands.put("airPressure",meteorologicalDetectorData.getAtmosphericPressure()); //数字气压 + expands.put("wet",meteorologicalDetectorData.getWetSlipperyCoefficient()); //湿滑 + expands.put("rainXingTai",meteorologicalDetectorData.getPrecipitationType()); //雨量降水形态 + expands.put("visibility",meteorologicalDetectorData.getVisibility()); //能见度 + expands.put("pathContactLu",meteorologicalDetectorData.getRoadSurfaceTemperature()); //路面温度 + expands.put("pathContactBing",meteorologicalDetectorData.getFreezingPointTemperature()); //冰点温度 + expands.put("pathContactYan",meteorologicalDetectorData.getSalinityValue()); //路面盐度 + expands.put("pathContactZhuang",meteorologicalDetectorData.getRemoteRoadSurfaceStatus()); //路面状况 + + mdDeviceData.setExpands(JSONObject.toJSONString(expands)); + + middleDatabaseService.insertMiddleDatabaseDeviceData(mdDeviceData); } else if (IotProductEnum.ONE_STOP_PRODUCT.value().equals(productId)){ //交调 diff --git a/zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java b/zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java index 481967f4..4832955c 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java @@ -2,6 +2,7 @@ package com.zc.business.service; import java.util.List; import com.zc.business.domain.DcMeteorologicalDetectorData; +import com.zc.business.domain.MdDeviceData; /** * 气象检测器数据Service接口 @@ -35,14 +36,6 @@ public interface IDcMeteorologicalDetectorDataService */ int insertDcMeteorologicalDetectorData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData); - /** - * 中间库新增气象检测器数据 - * - * @param dcMeteorologicalDetectorData 气象检测器数据 - * @return 结果 - */ - boolean insertIntermediateWarehouseData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData); - /** * 修改气象检测器数据 * diff --git a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java new file mode 100644 index 00000000..8da12edf --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java @@ -0,0 +1,35 @@ +package com.zc.business.service; + +import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcBoardPublish; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.MdDeviceData; + +import java.util.List; + +/** + * 中间库Service接口 + * + * @author ruoyi + * @date 2024-01-03 + */ +public interface IMiddleDatabaseService +{ + + /** + * 中间库新增设备数据 + * + * @param mdDeviceData 气象检测器数据 + * @return 结果 + */ + boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData); + + /** + * 更新中间库设备 + * + * @param listDevice 设备列表 + * @return 结果 + */ + boolean updateMiddleDatabaseDevice(List listDevice); + +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java index c1d3d4da..56ed60eb 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java @@ -5,6 +5,7 @@ import java.util.List; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.enums.DataSourceType; import com.zc.business.domain.DcDevice; +import com.zc.business.domain.MdDeviceData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.zc.business.mapper.DcMeteorologicalDetectorDataMapper; @@ -59,22 +60,6 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica return dcMeteorologicalDetectorDataMapper.insertDcMeteorologicalDetectorData(dcMeteorologicalDetectorData); } - /** - * 中间库新增气象检测器数据 - * - * @param dcMeteorologicalDetectorData 气象检测器数据 - * @return 结果 - */ - @DataSource(value = DataSourceType.SLAVE)//切换数据源 - @Override - public boolean insertIntermediateWarehouseData(DcMeteorologicalDetectorData dcMeteorologicalDetectorData) - { - if (!dcMeteorologicalDetectorDataMapper.updateIntermediateWarehouseData(dcMeteorologicalDetectorData)){ - return dcMeteorologicalDetectorDataMapper.insertIntermediateWarehouseData(dcMeteorologicalDetectorData); - } - return false; - } - /** * 修改气象检测器数据 * diff --git a/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java new file mode 100644 index 00000000..616c2c63 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java @@ -0,0 +1,57 @@ +package com.zc.business.service.impl; + +import com.ruoyi.common.annotation.DataSource; +import com.ruoyi.common.enums.DataSourceType; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.MdDeviceData; +import com.zc.business.mapper.MiddleDatabaseMapper; +import com.zc.business.service.IMiddleDatabaseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 中间库Service业务层处理 + * + * @author ruoyi + * @date 2024-01-03 + */ +@Service +public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { + + + @Autowired + private MiddleDatabaseMapper middleDatabaseMapper; + + + /** + * 中间库新增设备数据 + * + * @param mdDeviceData 气象检测器数据 + * @return 结果 + */ + @DataSource(value = DataSourceType.SLAVE)//切换数据源 + @Override + public boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData) + { + return middleDatabaseMapper.insertMiddleDatabaseDeviceData(mdDeviceData); + } + + + /** + * 更新中间库设备 + * + * @param listDevice 设备列表 + * @return 结果 + */ + @DataSource(value = DataSourceType.SLAVE)//切换数据源 + @Override + public boolean updateMiddleDatabaseDevice(List listDevice) + { + for (DcDevice dcDevice : listDevice) { + middleDatabaseMapper.updateMiddleDatabaseDevice(dcDevice); + } + return true; + } +} diff --git a/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml index 673e82f7..88e7f843 100644 --- a/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml @@ -146,44 +146,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} - - insert into meteorological_detector_data - - device_id, - temperature, - humidity, - precipitation_type, - rainfall, - road_surface_status, - water_film_thickness, - update_time - - - #{iotDeviceId}, - #{temperature}, - #{humidity}, - #{precipitationType}, - #{rainfall}, - #{roadSurfaceStatus}, - #{waterFilmThickness}, - current_date - - - - - update meteorological_detector_data - - temperature = #{temperature}, - humidity = #{humidity}, - precipitation_type = #{precipitationType}, - rainfall = #{rainfall}, - road_surface_status = #{roadSurfaceStatus}, - water_film_thickness = #{waterFilmThickness}, - update_time = current_date - - where device_id = #{iotDeviceId} - - delete from dc_meteorological_detector_data where id = #{id} diff --git a/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml b/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml new file mode 100644 index 00000000..ed10eb0f --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml @@ -0,0 +1,40 @@ + + + + + + insert into device_data + + devNo, + devType, + `timeStamp`, + expands, + CreatorUserId, + LastModificationTime, + LastModifierUserId, + IsDeleted, + DeleterUserId, + DeletionTime, + CreationTime + + + #{devNo}, + #{devType}, + #{timeStamp}, + #{expands}, + #{creatorUserId}, + #{lastModificationTime}, + #{isDeleted}, + #{deleterUserId}, + #{deletionTime}, + current_date + + + + + update device set dev_status = #{deviceState} where dev_no = #{iotDeviceId} + + +