电表、水表、温湿度计抄表、拉合闸时,将数值和状态同步到运维系统
This commit is contained in:
parent
e669b38354
commit
6357502c7e
|
|
@ -20,6 +20,8 @@ public class IotElectricityMeterMQDto{
|
|||
private String eleValue;
|
||||
/**阀门状态*/
|
||||
private String relayState;
|
||||
/**上次查表时间*/
|
||||
private String readTime;
|
||||
/**描述*/
|
||||
private String remark;
|
||||
/**区域编码*/
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public class IotWaterMeterMQDto{
|
|||
private String relayState;
|
||||
/**水表电池状态*/
|
||||
private String batteryState;
|
||||
/**上次查表时间*/
|
||||
private String readTime;
|
||||
/**描述*/
|
||||
private String remark;
|
||||
/**区域编码*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.nu.modules.syncLog.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 配置同步日志
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_iot_sync_biz_log")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_iot_sync_biz_log", description="设备同步日志")
|
||||
public class SyncBizLog implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
private String logId;
|
||||
private String orgCode; //机构编码
|
||||
private String orgName; //机构名称
|
||||
private String content;
|
||||
private String syncType;
|
||||
private String status;
|
||||
private String serverType;
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.nu.modules.syncLog.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
|
||||
/**
|
||||
* @Description: 同步日志
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface SyncBizLogMapper extends BaseMapper<SyncBizLog> {
|
||||
void addLog(SyncBizLog syncBizLog);
|
||||
void updateLog(SyncBizLog syncBizLog);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nu.modules.syncLog.mapper.SyncBizLogMapper">
|
||||
<insert id="addLog">
|
||||
insert into nu_iot_sync_biz_log (
|
||||
log_id,
|
||||
org_code,
|
||||
org_name,
|
||||
content,
|
||||
sync_type,
|
||||
status,
|
||||
server_type,
|
||||
create_time
|
||||
)
|
||||
values (
|
||||
#{logId},
|
||||
#{orgCode},
|
||||
#{orgName},
|
||||
#{content},
|
||||
#{syncType},
|
||||
#{status},
|
||||
#{serverType},
|
||||
now()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateLog">
|
||||
UPDATE nu_iot_sync_biz_log
|
||||
SET
|
||||
status = #{status},
|
||||
update_time = now()
|
||||
where log_id = #{logId}
|
||||
</update>
|
||||
|
||||
<select id="findSyncLogPage" parameterType="com.nu.modules.syncLog.entity.SyncBizLog" resultType="com.nu.modules.syncLog.entity.SyncBizLog">
|
||||
select
|
||||
id,
|
||||
log_id as logId,
|
||||
org_code as orgCode,
|
||||
org_name as orgName,
|
||||
content,
|
||||
sync_type as syncType,
|
||||
status,
|
||||
server_type as serverType,
|
||||
create_time as createTime,
|
||||
update_time as updateTime
|
||||
from nu_iot_sync_biz_log
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.nu.modules.syncLog.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
|
||||
/**
|
||||
* @Description: 同步日志
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ISyncBizLogService extends IService<SyncBizLog> {
|
||||
void addLog(SyncBizLog syncBizLog);
|
||||
void updateLog(SyncBizLog syncBizLog);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.nu.modules.syncLog.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.mapper.SyncBizLogMapper;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: 同步日志
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SyncBizLogServiceImpl extends ServiceImpl<SyncBizLogMapper, SyncBizLog> implements ISyncBizLogService {
|
||||
@Override
|
||||
public void addLog(SyncBizLog syncBizLog){
|
||||
baseMapper.addLog(syncBizLog);
|
||||
}
|
||||
@Override
|
||||
public void updateLog(SyncBizLog syncBizLog){
|
||||
baseMapper.updateLog(syncBizLog);
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,12 @@
|
|||
ele_value as eleValue,
|
||||
relay_state as relayState,
|
||||
read_time as readTime,
|
||||
remark
|
||||
remark,
|
||||
nu_id as nuId,
|
||||
nu_name as nuName,
|
||||
depart_id as departId,
|
||||
depart_name as departName,
|
||||
depart_server_url as departServerUrl
|
||||
from nu_iot_tq_electricity_meter
|
||||
where cid = #{cid}
|
||||
and address = #{address}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import java.util.List;
|
|||
public interface IElectricityMeterService extends IService<ElectricityMeter> {
|
||||
IPage<ElectricityMeter> findPage(Page<ElectricityMeter> page, ElectricityMeter electricityMeter);
|
||||
List<ElectricityMeter> findAllList();
|
||||
void updateValue(ElectricityMeter electricityMeter);
|
||||
void updateRelayState(ElectricityMeter electricityMeter);
|
||||
Result<String> eleReset(ElectricityMeter electricityMeter);
|
||||
Result<String> eleControl(ElectricityMeter electricityMeter);
|
||||
Result<String> eleRead(ElectricityMeter electricityMeter);
|
||||
|
|
|
|||
|
|
@ -3,23 +3,31 @@ package com.nu.modules.tq.electricity.service.impl;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nu.dto.IotElectricityMeterMQDto;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||
import com.nu.modules.tq.common.service.ITqApiLogService;
|
||||
import com.nu.modules.tq.utils.HttpTool;
|
||||
import com.nu.modules.tq.utils.SignTool;
|
||||
import com.nu.modules.tq.utils.TqApi;
|
||||
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||
import com.nu.modules.tq.electricity.mapper.ElectricityMeterMapper;
|
||||
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||
import me.zhyd.oauth.utils.UuidUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -31,11 +39,16 @@ import java.util.*;
|
|||
public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMapper, ElectricityMeter> implements IElectricityMeterService {
|
||||
|
||||
@Autowired
|
||||
TqApi tqApi;
|
||||
private TqApi tqApi;
|
||||
|
||||
@Autowired
|
||||
ITqApiLogService logService;
|
||||
private ITqApiLogService logService;
|
||||
|
||||
@Autowired
|
||||
private ISyncBizLogService bizLogService;
|
||||
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
|
|
@ -51,6 +64,16 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
return baseMapper.findAllList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateValue(ElectricityMeter electricityMeter){
|
||||
baseMapper.updateValue(electricityMeter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRelayState(ElectricityMeter electricityMeter){
|
||||
baseMapper.updateRelayState(electricityMeter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零
|
||||
*/
|
||||
|
|
@ -333,7 +356,9 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
em.setCid(cid);
|
||||
em.setAddress(address);
|
||||
em.setEleValue("0");
|
||||
em.setReadTime(DateUtils.formatDateTime());
|
||||
baseMapper.updateValue(em);
|
||||
syncCleanMq(em);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -343,6 +368,31 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零同步到业务系统
|
||||
* @param electricityMeter
|
||||
*/
|
||||
private void syncCleanMq(ElectricityMeter electricityMeter){
|
||||
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||
if(entity!=null) {
|
||||
IotElectricityMeterMQDto iem = new IotElectricityMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iem);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("电表");
|
||||
bizLogService.addLog(log);
|
||||
iem.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotElectricity.eleValue.async", iem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关闸回调通知
|
||||
*/
|
||||
|
|
@ -394,6 +444,7 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
em.setRelayState("1");
|
||||
}
|
||||
baseMapper.updateRelayState(em);
|
||||
syncControlMq(em);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -403,6 +454,31 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关闸同步到业务系统
|
||||
* @param electricityMeter
|
||||
*/
|
||||
private void syncControlMq(ElectricityMeter electricityMeter){
|
||||
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||
if(entity!=null) {
|
||||
IotElectricityMeterMQDto iem = new IotElectricityMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iem);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("电表");
|
||||
bizLogService.addLog(log);
|
||||
iem.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotElectricity.eleControl.async", iem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抄表回调通知
|
||||
*/
|
||||
|
|
@ -450,6 +526,7 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
baseMapper.updateValue(em);
|
||||
tqApiLog.setId(logEntity.getId());
|
||||
logService.update(tqApiLog);
|
||||
syncValueMq(em);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
|
@ -470,6 +547,31 @@ public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMap
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 抄表同步到业务系统
|
||||
* @param electricityMeter
|
||||
*/
|
||||
private void syncValueMq(ElectricityMeter electricityMeter){
|
||||
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||
if(entity!=null) {
|
||||
IotElectricityMeterMQDto iem = new IotElectricityMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iem);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("电表");
|
||||
bizLogService.addLog(log);
|
||||
iem.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotElectricity.eleValue.async", iem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void editHldy(ElectricityMeter electricityMeter) {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ public class WaterMeter implements Serializable {
|
|||
private String nuName;//护理单元
|
||||
private String departId;//机构ID
|
||||
private String departName;//机构名称
|
||||
private String departServerUrl;//机构服务地址
|
||||
/**维修状态*/
|
||||
private String maintainStatus;
|
||||
}
|
||||
|
|
@ -73,7 +73,12 @@
|
|||
relay_state as relayState,
|
||||
battery_state as batteryState,
|
||||
read_time as readTime,
|
||||
remark
|
||||
remark,
|
||||
nu_id as nuId,
|
||||
nu_name as nuName,
|
||||
depart_id as departId,
|
||||
depart_name as departName,
|
||||
depart_server_url as departServerUrl
|
||||
from nu_iot_tq_water_meter
|
||||
where cid = #{cid}
|
||||
and address = #{address}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import java.util.List;
|
|||
public interface IWaterMeterService extends IService<WaterMeter> {
|
||||
IPage<WaterMeter> findPage(Page<WaterMeter> page, WaterMeter waterMeter);
|
||||
List<WaterMeter> findAllList();
|
||||
void updateValue(WaterMeter waterMeter);
|
||||
void updateRelayState(WaterMeter waterMeter);
|
||||
Result<String> waterReset(WaterMeter waterMeter);
|
||||
Result<String> waterControl(WaterMeter waterMeter);
|
||||
Result<String> waterRead(WaterMeter waterMeter);
|
||||
|
|
|
|||
|
|
@ -3,11 +3,15 @@ package com.nu.modules.tq.water.service.impl;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nu.dto.IotWaterMeterMQDto;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
import com.nu.modules.tplink.camera.entity.CameraInfo;
|
||||
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||
import com.nu.modules.tq.common.service.ITqApiLogService;
|
||||
|
|
@ -17,8 +21,12 @@ import com.nu.modules.tq.utils.TqApi;
|
|||
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||
import com.nu.modules.tq.water.mapper.WaterMeterMapper;
|
||||
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.utils.UuidUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -30,12 +38,16 @@ import java.util.*;
|
|||
public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMeter> implements IWaterMeterService {
|
||||
|
||||
@Autowired
|
||||
TqApi tqApi;
|
||||
private TqApi tqApi;
|
||||
|
||||
@Autowired
|
||||
ITqApiLogService logService;
|
||||
private ITqApiLogService logService;
|
||||
|
||||
@Autowired
|
||||
private ISyncBizLogService bizLogService;
|
||||
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
|
|
@ -51,6 +63,16 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
return baseMapper.findAllList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateValue(WaterMeter updateValue){
|
||||
baseMapper.updateValue(updateValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRelayState(WaterMeter updateValue){
|
||||
baseMapper.updateRelayState(updateValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零
|
||||
*/
|
||||
|
|
@ -334,7 +356,9 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
wm.setCid(cid);
|
||||
wm.setAddress(address);
|
||||
wm.setWaterValue("0");
|
||||
wm.setReadTime(DateUtils.formatDateTime());
|
||||
baseMapper.updateValue(wm);
|
||||
syncCleanMq(wm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -344,6 +368,31 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零同步到业务系统
|
||||
* @param waterMeter
|
||||
*/
|
||||
private void syncCleanMq(WaterMeter waterMeter){
|
||||
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||
if(entity!=null) {
|
||||
IotWaterMeterMQDto iwm = new IotWaterMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iwm);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("水表");
|
||||
bizLogService.addLog(log);
|
||||
iwm.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotWater.waterValue.async", iwm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关阀回调通知
|
||||
*/
|
||||
|
|
@ -395,6 +444,7 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
wm.setRelayState("0");
|
||||
}
|
||||
baseMapper.updateRelayState(wm);
|
||||
syncControlMq(wm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -404,6 +454,31 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关阀同步到业务系统
|
||||
* @param waterMeter
|
||||
*/
|
||||
private void syncControlMq(WaterMeter waterMeter){
|
||||
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||
if(entity!=null) {
|
||||
IotWaterMeterMQDto iwm = new IotWaterMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iwm);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("水表");
|
||||
bizLogService.addLog(log);
|
||||
iwm.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotWater.waterControl.async", iwm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抄表回调通知
|
||||
*/
|
||||
|
|
@ -460,6 +535,7 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
baseMapper.updateValue(wm);
|
||||
tqApiLog.setId(logEntity.getId());
|
||||
logService.update(tqApiLog);
|
||||
syncValueMq(wm);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
|
@ -480,6 +556,31 @@ public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMe
|
|||
return "SUCCESS";
|
||||
}
|
||||
|
||||
/**
|
||||
* 抄表同步到业务系统
|
||||
* @param waterMeter
|
||||
*/
|
||||
private void syncValueMq(WaterMeter waterMeter){
|
||||
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||
if(entity!=null) {
|
||||
IotWaterMeterMQDto iwm = new IotWaterMeterMQDto();
|
||||
BeanUtils.copyProperties(entity, iwm);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("水表");
|
||||
bizLogService.addLog(log);
|
||||
iwm.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotWater.waterValue.async", iwm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void baoxiu(WaterMeter waterMeter) {
|
||||
waterMeter.setMaintainStatus("1");
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ public interface HumidDeviceMapper extends BaseMapper<HumidDevice> {
|
|||
int updateValue(HumidDevice humidDevice);
|
||||
int insertLog(HumidDevice humidDevice);
|
||||
IPage<HumidDevice> findLogPage(Page<HumidDevice> page, @Param("params") HumidDevice humidDevice);
|
||||
HumidDevice getHumidInfo(HumidDevice humidDevice);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,4 +338,43 @@
|
|||
order by id desc
|
||||
</select>
|
||||
|
||||
<select id="getHumidInfo" parameterType="com.nu.modules.yiweilian.humid.entity.HumidDevice" resultType="com.nu.modules.yiweilian.humid.entity.HumidDevice">
|
||||
select
|
||||
id,
|
||||
sn,
|
||||
device_name as deviceName,
|
||||
device_types as deviceTypes,
|
||||
reporting_interval as reportingInterval,
|
||||
record_interval as recordInterval,
|
||||
history_report_time as historyReportTime,
|
||||
history_interval as historyInterval,
|
||||
temperature_high as temperatureHigh,
|
||||
temperature_low as temperatureLow,
|
||||
temperature_buffer as temperatureBuffer,
|
||||
humidity_high as humidityHigh,
|
||||
humidity_low as humidityLow,
|
||||
humidity_buffer as humidityBuffer,
|
||||
iz_outages as izOutages,
|
||||
iz_low_battery as izLowBattery,
|
||||
iz_online as izOnline,
|
||||
time_code as timeCode,
|
||||
temperature,
|
||||
humidity,
|
||||
status,
|
||||
reporting_time as reportingTime,
|
||||
electricity,
|
||||
nu_id as nuId,
|
||||
nu_name as nuName,
|
||||
depart_id as departId,
|
||||
depart_name as departName,
|
||||
depart_server_url as departServerUrl,
|
||||
old_depart_id as oldDepartId,
|
||||
old_depart_name as oldDepartName,
|
||||
old_server_url as oldServerUrl,
|
||||
sync_type,
|
||||
del_flag as delFlag
|
||||
from nu_iot_yiweilian_humid_device a
|
||||
where sn = #{sn}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nu.modules.yiweilian.humid.entity.HumidDevice;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
|
||||
public interface IHumidDeviceService extends IService<HumidDevice> {
|
||||
|
|
@ -12,6 +13,7 @@ public interface IHumidDeviceService extends IService<HumidDevice> {
|
|||
String updateDeviceParameters(HumidDevice humidDevice,String type);
|
||||
String updateDeviceRealTime(HumidDevice humidDevice);
|
||||
Result<String> updateDevice(HumidDevice humidDevice);
|
||||
void updateValue(HumidDevice humidDevice);
|
||||
Result<String> deleteDevice(HumidDevice humidDevice);
|
||||
Result getDeviceParameters(HumidDevice humidDevice);
|
||||
IPage<HumidDevice> findLogPage(Page<HumidDevice> page, HumidDevice humidDevice);
|
||||
|
|
|
|||
|
|
@ -3,20 +3,27 @@ package com.nu.modules.yiweilian.humid.service.impl;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nu.dto.IotHumidDeviceMQDto;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||
import com.nu.modules.yiweilian.humid.entity.HumidDevice;
|
||||
import com.nu.modules.yiweilian.humid.mapper.HumidDeviceMapper;
|
||||
import com.nu.modules.yiweilian.humid.service.IHumidDeviceService;
|
||||
import com.nu.modules.yiweilian.utils.YiweilianApi;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.utils.UuidUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -33,7 +40,11 @@ public class HumidDeviceServiceImpl extends ServiceImpl<HumidDeviceMapper, Humid
|
|||
@Autowired
|
||||
YiweilianApi yiweilianApi;
|
||||
|
||||
@Autowired
|
||||
private ISyncBizLogService logService;
|
||||
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
|
|
@ -256,6 +267,7 @@ public class HumidDeviceServiceImpl extends ServiceImpl<HumidDeviceMapper, Humid
|
|||
dh.setOptBy(sysUser.getUsername());
|
||||
}
|
||||
baseMapper.insertLog(dh);
|
||||
syncStatusMq(dh);
|
||||
}
|
||||
}else{
|
||||
errorMsg += humidDevice.getSn()+"温湿度设备丢失,请联系管理员";
|
||||
|
|
@ -273,6 +285,7 @@ public class HumidDeviceServiceImpl extends ServiceImpl<HumidDeviceMapper, Humid
|
|||
}
|
||||
baseMapper.insertLog(dh);
|
||||
baseMapper.updateValue(dh);
|
||||
syncStatusMq(dh);
|
||||
}
|
||||
if((page+1)*limit<count){
|
||||
Map<String, Object> params = getParmas(page+1,limit,humidDevice);
|
||||
|
|
@ -284,6 +297,31 @@ public class HumidDeviceServiceImpl extends ServiceImpl<HumidDeviceMapper, Humid
|
|||
return errorMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步到运维系统
|
||||
* @param humidDevice
|
||||
*/
|
||||
private void syncStatusMq(HumidDevice humidDevice){
|
||||
HumidDevice entity = baseMapper.getHumidInfo(humidDevice);
|
||||
if(entity!=null){
|
||||
IotHumidDeviceMQDto ihd = new IotHumidDeviceMQDto();
|
||||
BeanUtils.copyProperties(entity, ihd);
|
||||
String json = JSON.toJSONString(entity);
|
||||
String logId = UuidUtils.getUUID();
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(logId);
|
||||
log.setOrgCode(entity.getDepartServerUrl());
|
||||
log.setOrgName(entity.getDepartName());
|
||||
log.setContent(json);
|
||||
log.setSyncType("更新");
|
||||
log.setStatus("同步中");
|
||||
log.setServerType("温湿度计");
|
||||
logService.addLog(log);
|
||||
ihd.setLogId(logId);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "hldy.iotHumid.status.async", ihd);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getUpdateParmas(HumidDevice humidDevice){
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("sn", humidDevice.getSn());
|
||||
|
|
@ -327,6 +365,15 @@ public class HumidDeviceServiceImpl extends ServiceImpl<HumidDeviceMapper, Humid
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新温湿度值
|
||||
* @param humidDevice
|
||||
*/
|
||||
@Override
|
||||
public void updateValue(HumidDevice humidDevice){
|
||||
baseMapper.updateValue(humidDevice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -26,4 +26,18 @@ public class DynamicQueueNameProvider {
|
|||
return getSyncDeviceQueueName();
|
||||
}
|
||||
|
||||
public String getSyncDeviceValuesResultQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".bizIotDeviceValues.result.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncDeviceValuesResultKeyName() {
|
||||
return getSyncDeviceValuesResultQueueName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.nu.mq.device.listener;
|
||||
|
||||
import com.nu.dto.StatusMQDto;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class IotDeviceValuesMQListener {
|
||||
|
||||
@Autowired
|
||||
private ISyncBizLogService logService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotDeviceAsyncDQNP.getSyncDeviceValuesResultQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotDeviceAsyncDQNP.getSyncDeviceValuesResultKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
|
||||
public void handleMessage(StatusMQDto dto) {
|
||||
SyncBizLog log = new SyncBizLog();
|
||||
log.setLogId(dto.getPrimaryKey());
|
||||
log.setStatus(dto.getMessage());
|
||||
logService.updateLog(log);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.nu.mq.tq.listenter;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("iotTqAsyncDQNP")
|
||||
public class DynamicQueueNameProvider {
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
public String getSyncEleValueQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".ywIotElectricity.eleValue.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncEleValueKeyName() {
|
||||
return getSyncEleValueQueueName();
|
||||
}
|
||||
|
||||
public String getSyncEleControlQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".ywIotElectricity.eleControl.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncEleControlKeyName() {
|
||||
return getSyncEleControlQueueName();
|
||||
}
|
||||
|
||||
public String getSyncWaterValueQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".ywIotWater.waterValue.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncWaterValueKeyName() {
|
||||
return getSyncWaterValueQueueName();
|
||||
}
|
||||
|
||||
public String getSyncWaterControlQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".ywIotWater.waterControl.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncWaterControlKeyName() {
|
||||
return getSyncWaterControlQueueName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
package com.nu.mq.tq.listenter;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.nu.dto.IotElectricityMeterMQDto;
|
||||
import com.nu.dto.IotWaterMeterMQDto;
|
||||
import com.nu.dto.StatusMQDto;
|
||||
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class IotSyncTqMQListener {
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Autowired
|
||||
private IElectricityMeterService electricityMeterService;
|
||||
|
||||
@Autowired
|
||||
private IWaterMeterService waterMeterService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotTqAsyncDQNP.getSyncEleValueQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotTqAsyncDQNP.getSyncEleValueKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void handleEleValue_unify(IotElectricityMeterMQDto dto) {
|
||||
saveSyncEleValue(dto);
|
||||
}
|
||||
|
||||
private void saveSyncEleValue(IotElectricityMeterMQDto dto) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
try {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("电表");
|
||||
QueryWrapper<ElectricityMeter> emQw = new QueryWrapper<>();
|
||||
emQw.eq("cid",dto.getCid());
|
||||
emQw.eq("address",dto.getAddress());
|
||||
ElectricityMeter entity = electricityMeterService.getOne(emQw);
|
||||
if(entity!=null){
|
||||
entity.setEleValue(dto.getEleValue());
|
||||
entity.setReadTime(dto.getReadTime());
|
||||
electricityMeterService.updateValue(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("电表");
|
||||
e.printStackTrace();
|
||||
}
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "ywIotDeviceValues.result.async", statusMQDto);
|
||||
}
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotTqAsyncDQNP.getSyncEleControlQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotTqAsyncDQNP.getSyncEleControlKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void handleEleControl_unify(IotElectricityMeterMQDto dto) {
|
||||
saveSyncEleControl(dto);
|
||||
}
|
||||
|
||||
private void saveSyncEleControl(IotElectricityMeterMQDto dto) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
try {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("电表");
|
||||
QueryWrapper<ElectricityMeter> emQw = new QueryWrapper<>();
|
||||
emQw.eq("cid",dto.getCid());
|
||||
emQw.eq("address",dto.getAddress());
|
||||
ElectricityMeter entity = electricityMeterService.getOne(emQw);
|
||||
if(entity!=null){
|
||||
entity.setRelayState(dto.getRelayState());
|
||||
electricityMeterService.updateRelayState(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("电表");
|
||||
e.printStackTrace();
|
||||
}
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "ywIotDeviceValues.result.async", statusMQDto);
|
||||
}
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotTqAsyncDQNP.getSyncWaterValueQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotTqAsyncDQNP.getSyncWaterValueKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void handleWaterValue_unify(IotWaterMeterMQDto dto) {
|
||||
saveSyncWaterValue(dto);
|
||||
}
|
||||
|
||||
private void saveSyncWaterValue(IotWaterMeterMQDto dto) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
try {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("水表");
|
||||
QueryWrapper<WaterMeter> emQw = new QueryWrapper<>();
|
||||
emQw.eq("cid",dto.getCid());
|
||||
emQw.eq("address",dto.getAddress());
|
||||
WaterMeter entity = waterMeterService.getOne(emQw);
|
||||
if(entity!=null){
|
||||
entity.setWaterValue(dto.getWaterValue());
|
||||
entity.setReadTime(dto.getReadTime());
|
||||
waterMeterService.updateValue(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("水表");
|
||||
e.printStackTrace();
|
||||
}
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "ywIotDeviceValues.result.async", statusMQDto);
|
||||
}
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotTqAsyncDQNP.getSyncWaterControlQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotTqAsyncDQNP.getSyncWaterControlKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void handleWaterControl_unify(IotWaterMeterMQDto dto) {
|
||||
saveSyncWaterControl(dto);
|
||||
}
|
||||
|
||||
private void saveSyncWaterControl(IotWaterMeterMQDto dto) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
try {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("水表");
|
||||
QueryWrapper<WaterMeter> emQw = new QueryWrapper<>();
|
||||
emQw.eq("cid",dto.getCid());
|
||||
emQw.eq("address",dto.getAddress());
|
||||
WaterMeter entity = waterMeterService.getOne(emQw);
|
||||
if(entity!=null){
|
||||
entity.setRelayState(dto.getRelayState());
|
||||
waterMeterService.updateRelayState(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
statusMQDto.setAsyncId(dto.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(dto.getLogId());
|
||||
statusMQDto.setNote("水表");
|
||||
e.printStackTrace();
|
||||
}
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "ywIotDeviceValues.result.async", statusMQDto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.nu.mq.yiweilian.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("iotYiweilianAsyncDQNP")
|
||||
public class DynamicQueueNameProvider {
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
public String getSyncDeviceQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".ywIotHumid.status.async";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncDeviceKeyName() {
|
||||
return getSyncDeviceQueueName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.nu.mq.yiweilian.listener;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.nu.dto.*;
|
||||
import com.nu.modules.yiweilian.humid.entity.HumidDevice;
|
||||
import com.nu.modules.yiweilian.humid.service.IHumidDeviceService;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class IotSyncHumidMQListener {
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Autowired
|
||||
private IHumidDeviceService humidDeviceService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotYiweilianAsyncDQNP.getSyncDeviceQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotDeviceValues", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotYiweilianAsyncDQNP.getSyncDeviceKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void handleMessage_unify(IotHumidDeviceMQDto dto) {
|
||||
saveSyncInfo(dto);
|
||||
}
|
||||
|
||||
private void saveSyncInfo(IotHumidDeviceMQDto iotHumidDeviceMQDto) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
try {
|
||||
statusMQDto.setAsyncId(iotHumidDeviceMQDto.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(iotHumidDeviceMQDto.getLogId());
|
||||
statusMQDto.setNote("温湿度计");
|
||||
QueryWrapper<HumidDevice> humidQw = new QueryWrapper<>();
|
||||
humidQw.eq("sn",iotHumidDeviceMQDto.getSn());
|
||||
HumidDevice entity = humidDeviceService.getOne(humidQw);
|
||||
if(entity!=null){
|
||||
entity.setStatus(iotHumidDeviceMQDto.getStatus());
|
||||
entity.setElectricity(iotHumidDeviceMQDto.getElectricity());
|
||||
entity.setTemperature(iotHumidDeviceMQDto.getTemperature());
|
||||
entity.setHumidity(iotHumidDeviceMQDto.getHumidity());
|
||||
entity.setReportingTime(iotHumidDeviceMQDto.getReportingTime());
|
||||
humidDeviceService.updateValue(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
statusMQDto.setAsyncId(iotHumidDeviceMQDto.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(iotHumidDeviceMQDto.getLogId());
|
||||
statusMQDto.setNote("温湿度计");
|
||||
e.printStackTrace();
|
||||
}
|
||||
rabbitMQUtil.sendToExchange("hldy.iotDeviceValues", "ywIotDeviceValues.result.async", statusMQDto);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue