物联设备同步推送
This commit is contained in:
parent
105f22962c
commit
f45a861d1d
|
|
@ -0,0 +1,33 @@
|
|||
package com.nu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class DevicePreviewMqDto {
|
||||
private Integer id;
|
||||
private String orgCode;
|
||||
private String departName;
|
||||
private String nuId;
|
||||
private String nuName;
|
||||
private String batchNo;
|
||||
private String dimension;
|
||||
private String sn;
|
||||
private String deviceName;
|
||||
private String deviceType;
|
||||
private String deviceModel;
|
||||
private String factory;
|
||||
private String deviceStatus;
|
||||
private Date createTime;//更新时间
|
||||
private String createBy;//创建人
|
||||
private Date updateTime;//更新时间
|
||||
private String updateBy;//更新人
|
||||
private String izSync;//是否同步
|
||||
private Date syncTime;//同步时间
|
||||
private String syncBy;//同步人
|
||||
// private Integer purchaseQuantity;
|
||||
private String logId;//日志ID
|
||||
private String remarks;//备注
|
||||
private Integer ywId;//运维ID
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.nu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class IotSyncPreviewMQDto {
|
||||
private List<DevicePreviewMqDto> previewList;
|
||||
}
|
||||
|
|
@ -108,12 +108,12 @@ public class DeviceManagerController extends JeecgController<DeviceManager, IDev
|
|||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param DeviceManager
|
||||
* @param deviceManager
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody DeviceManager DeviceManager) {
|
||||
service.updateById(DeviceManager);
|
||||
public Result<String> edit(@RequestBody DeviceManager deviceManager) {
|
||||
service.updateManager(deviceManager);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,4 +32,5 @@ public class DeviceBindLog implements Serializable {
|
|||
private Date optDate;
|
||||
private String optType;
|
||||
private String remarks;
|
||||
private Integer ywId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ public class DeviceManager implements Serializable {
|
|||
private String nuId;
|
||||
@TableField(exist = false)
|
||||
private String nuName;
|
||||
private String batchNo;//批次号
|
||||
@Excel(name = "设备名称", width = 15)
|
||||
private String deviceName;
|
||||
@Excel(name = "设备类型", width = 15, dicCode = "tplink_device_type")
|
||||
@Dict(dicCode = "tplink_device_type")
|
||||
private String deviceType;
|
||||
|
|
@ -48,5 +51,6 @@ public class DeviceManager implements Serializable {
|
|||
@TableField(exist = false)
|
||||
private String onlineStatus;//在线状态
|
||||
private String deviceStatus;//设备状态
|
||||
private Integer ywId;//运维ID
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
a.nu_id,
|
||||
c.nu_name,
|
||||
a.dimension,
|
||||
a.device_name,
|
||||
a.device_type,
|
||||
a.device_model,
|
||||
a.factory,
|
||||
|
|
@ -16,7 +17,8 @@
|
|||
a.update_time,
|
||||
a.remarks,
|
||||
a.device_status,
|
||||
ifnull(t.online_status,'待集成') as online_status
|
||||
ifnull(t.online_status,'待集成') as online_status,
|
||||
a.yw_id
|
||||
from nu_iot_device_preview a
|
||||
left join nu_base_info c on a.nu_id = c.nu_id
|
||||
left join (
|
||||
|
|
@ -37,6 +39,7 @@
|
|||
from nu_iot_yiweilian_humid_device
|
||||
) t on a.sn = t.sn
|
||||
where a.sn is not null
|
||||
and ifnull(a.device_status,'') != '损坏'
|
||||
<if test="params.nuName != null and params.nuName != ''">
|
||||
AND c.nu_name LIKE concat('%',#{params.nuName},'%')
|
||||
</if>
|
||||
|
|
@ -53,6 +56,7 @@
|
|||
select
|
||||
a.id,
|
||||
a.dimension,
|
||||
a.device_name,
|
||||
a.device_type,
|
||||
a.device_model,
|
||||
a.factory,
|
||||
|
|
@ -60,16 +64,16 @@
|
|||
a.create_time,
|
||||
a.update_time,
|
||||
a.remarks,
|
||||
a.device_status
|
||||
a.device_status,
|
||||
a.yw_id
|
||||
from nu_iot_device_preview a
|
||||
<where>
|
||||
where ifnull(a.device_status,'') != '损坏'
|
||||
<if test="params.dimension != null and params.dimension != ''">
|
||||
AND a.dimension = #{params.dimension}
|
||||
</if>
|
||||
<if test="params.deviceType != null and params.deviceType != ''">
|
||||
AND a.device_type = #{params.deviceType}
|
||||
</if>
|
||||
</where>
|
||||
order by a.dimension,a.device_type,a.device_model,a.sn
|
||||
</select>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public interface IDeviceManagerService extends IService<DeviceManager> {
|
|||
IPage<DeviceManager> findPage(Page<DeviceManager> page, DeviceManager deviceManager);
|
||||
IPage<DeviceManager> findAllPage(Page<DeviceManager> page, DeviceManager deviceManager);
|
||||
IPage<DeviceBindLog> findBingLogPage(Page<DeviceBindLog> page, DeviceBindLog deviceBindLog);
|
||||
void updateManager(DeviceManager deviceManager);
|
||||
void addLog(DeviceBindLog deviceBindLog);
|
||||
List<DeviceManager> queryNuList(DeviceManager deviceManager);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.nu.modules.manager.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.DevicePreviewMqDto;
|
||||
import com.nu.dto.ElderTagTypeMQDto;
|
||||
import com.nu.modules.manager.entity.DeviceBindLog;
|
||||
import com.nu.modules.manager.entity.DeviceManager;
|
||||
import com.nu.modules.manager.mapper.DeviceManagerMapper;
|
||||
|
|
@ -12,7 +14,11 @@ import com.nu.modules.tplink.camera.entity.CameraInfo;
|
|||
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||
import com.nu.modules.yiweilian.humid.entity.HumidDevice;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -28,6 +34,12 @@ import java.util.Map;
|
|||
@Slf4j
|
||||
public class DeviceManagerServiceImpl extends ServiceImpl<DeviceManagerMapper, DeviceManager> implements IDeviceManagerService {
|
||||
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Override
|
||||
public IPage<DeviceManager> findPage(Page<DeviceManager> page, DeviceManager deviceManager){
|
||||
return baseMapper.findPage(page,deviceManager);
|
||||
|
|
@ -43,6 +55,15 @@ public class DeviceManagerServiceImpl extends ServiceImpl<DeviceManagerMapper, D
|
|||
return baseMapper.findBingLogPage(page,deviceBindLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateManager(DeviceManager deviceManager){
|
||||
baseMapper.updateById(deviceManager);
|
||||
//同步给运维平台
|
||||
DevicePreviewMqDto dto = new DevicePreviewMqDto();
|
||||
BeanUtils.copyProperties(deviceManager, dto);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotsyncbiz", "iotsyncbiz.editpreviewsn", dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLog(DeviceBindLog deviceBindLog){
|
||||
baseMapper.addLog(deviceBindLog);
|
||||
|
|
@ -53,7 +74,14 @@ public class DeviceManagerServiceImpl extends ServiceImpl<DeviceManagerMapper, D
|
|||
deviceManager.setNuId(deviceBindLog.getNuId());
|
||||
}
|
||||
baseMapper.updateById(deviceManager);
|
||||
//需同步到运维
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
//同步给运维平台
|
||||
DevicePreviewMqDto dto = new DevicePreviewMqDto();
|
||||
BeanUtils.copyProperties(deviceBindLog, dto);
|
||||
dto.setOrgCode(orgCode);
|
||||
dto.setDeviceStatus(deviceBindLog.getOptType());
|
||||
rabbitMQUtil.sendToExchange("hldy.iotsyncbiz", "iotsyncbiz.bindpreview", dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -82,4 +82,19 @@ public class DynamicQueueNameProvider {
|
|||
return getSyncDeviceValuesResultQueueName();
|
||||
}
|
||||
|
||||
|
||||
public String getSyncDeviceAddQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".iotsyncbiz.addpreview";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncDeviceAddKeyName() {
|
||||
return getSyncDeviceAddQueueName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
package com.nu.mq.device.listener;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.nu.dto.*;
|
||||
import com.nu.modules.manager.entity.DeviceManager;
|
||||
import com.nu.modules.manager.service.IDeviceManagerService;
|
||||
import com.nu.modules.nubaseinfo.api.INuBaseInfoApi;
|
||||
import com.nu.modules.tplink.camera.entity.CameraCapability;
|
||||
import com.nu.modules.tplink.camera.entity.CameraInfo;
|
||||
import com.nu.modules.tplink.camera.service.ICameraCapabilityService;
|
||||
import com.nu.modules.tplink.camera.service.ICameraInfoService;
|
||||
import com.nu.modules.tq.common.entity.TqDeviceInfo;
|
||||
import com.nu.modules.tq.common.service.ITqDeviceInfoService;
|
||||
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||
import com.nu.modules.tq.utils.MqttMessageHandler;
|
||||
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||
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.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class IotSyncPreviewMQListener {
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
@Autowired
|
||||
private IDeviceManagerService deviceManagerService;
|
||||
|
||||
@Autowired
|
||||
private ICameraInfoService cameraInfoService;
|
||||
|
||||
@Autowired
|
||||
private ICameraCapabilityService cameraCapabilityService;
|
||||
|
||||
@Autowired
|
||||
private IElectricityMeterService electricityMeterService;
|
||||
|
||||
@Autowired
|
||||
private IWaterMeterService waterMeterService;
|
||||
|
||||
@Autowired
|
||||
private ITqDeviceInfoService collectorService;
|
||||
|
||||
@Autowired
|
||||
private IHumidDeviceService humidDeviceService;
|
||||
|
||||
@Autowired
|
||||
private MqttMessageHandler mqttMessageHandler;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(name = "#{iotDeviceAsyncDQNP.getSyncDeviceAddQueueName()}"),
|
||||
exchange = @Exchange(name = "hldy.iotsyncbiz", type = ExchangeTypes.DIRECT),
|
||||
key = "#{iotDeviceAsyncDQNP.getSyncDeviceAddKeyName()}"
|
||||
),
|
||||
errorHandler = "iotDeviceMQErrorHandler"
|
||||
)
|
||||
public void addPreviewSync_unify(IotSyncPreviewMQDto dto) {
|
||||
List<StatusMQDto> statusList = new ArrayList<>();
|
||||
List<DevicePreviewMqDto> previewList = dto.getPreviewList();
|
||||
if(previewList!=null&&previewList.size()>0){
|
||||
for(int i=0;i<previewList.size();i++){
|
||||
DevicePreviewMqDto preview = previewList.get(i);
|
||||
try {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setAsyncId(preview.getId().toString());
|
||||
statusMQDto.setMessage("成功");
|
||||
statusMQDto.setPrimaryKey(preview.getLogId());
|
||||
statusMQDto.setCode(preview.getBatchNo());
|
||||
QueryWrapper<DeviceManager> dmQw = new QueryWrapper<>();
|
||||
dmQw.eq("yw_id",preview.getYwId());
|
||||
DeviceManager entity = deviceManagerService.getOne(dmQw);
|
||||
if(entity==null){
|
||||
DeviceManager dm = new DeviceManager();
|
||||
BeanUtils.copyProperties(preview, dm);
|
||||
dm.setId(null);
|
||||
dm.setCreateTime(new Date());
|
||||
deviceManagerService.save(dm);
|
||||
statusList.add(statusMQDto);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setAsyncId(preview.getId().toString());
|
||||
statusMQDto.setMessage("失败");
|
||||
statusMQDto.setPrimaryKey(preview.getLogId());
|
||||
statusList.add(statusMQDto);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
StatusListMQDto statusListMQDto = new StatusListMQDto();
|
||||
statusListMQDto.setStatusList(statusList);
|
||||
rabbitMQUtil.sendToExchange("hldy.iotsyncbiz", "iotsyncbiz.addpreview.result", statusListMQDto);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue