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 index 66e89c07..f2ed25e0 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java @@ -1,6 +1,7 @@ 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; @@ -21,4 +22,12 @@ public interface MiddleDatabaseMapper * @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/service/IMiddleDatabaseService.java b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java index a49f416a..8da12edf 100644 --- a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java +++ b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java @@ -2,8 +2,11 @@ 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接口 * @@ -21,4 +24,12 @@ public interface IMiddleDatabaseService */ boolean insertMiddleDatabaseDeviceData(MdDeviceData mdDeviceData); + /** + * 更新中间库设备 + * + * @param listDevice 设备列表 + * @return 结果 + */ + boolean updateMiddleDatabaseDevice(List listDevice); + } 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 index 84fd9287..616c2c63 100644 --- 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 @@ -1,27 +1,15 @@ package com.zc.business.service.impl; -import com.alibaba.fastjson.JSON; import com.ruoyi.common.annotation.DataSource; -import com.ruoyi.common.constant.HttpStatus; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.DataSourceType; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.zc.business.controller.DcDeviceController; -import com.zc.business.domain.DcBoardPublish; -import com.zc.business.domain.DcBoardReleaseLog; +import com.zc.business.domain.DcDevice; import com.zc.business.domain.MdDeviceData; -import com.zc.business.mapper.DcBoardReleaseLogMapper; import com.zc.business.mapper.MiddleDatabaseMapper; -import com.zc.business.service.IDcBoardService; import com.zc.business.service.IMiddleDatabaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * 中间库Service业务层处理 @@ -36,9 +24,6 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { @Autowired private MiddleDatabaseMapper middleDatabaseMapper; - @Autowired - private DcDeviceController deviceController; - /** * 中间库新增设备数据 @@ -52,4 +37,21 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { { 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/MiddleDatabaseMapper.xml b/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml index b8f1b77b..ed10eb0f 100644 --- a/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml +++ b/zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml @@ -33,4 +33,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + update device set dev_status = #{deviceState} where dev_no = #{iotDeviceId} + +