Browse Source

redis消息订阅 修改中间库设备状态

develop
lau572 9 months ago
parent
commit
d7008022ba
  1. 9
      zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java
  2. 7
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  3. 11
      zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java
  4. 34
      zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java
  5. 4
      zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

9
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);
}

7
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);
}
/**

11
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<DcDevice> listDevice);
}

34
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<DcDevice> listDevice)
{
for (DcDevice dcDevice : listDevice) {
middleDatabaseMapper.updateMiddleDatabaseDevice(dcDevice);
}
return true;
}
}

4
zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

@ -33,4 +33,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<update id="updateMiddleDatabaseDevice">
update device set dev_status = #{deviceState} where dev_no = #{iotDeviceId}
</update>
</mapper>

Loading…
Cancel
Save