liuyaowen 1 год назад
Родитель
Сommit
7b0605157a

+ 9 - 3
src/main/java/com/yunfeiyun/agmp/iotm/device/service/impl/IotDeviceServiceImpl.java

@@ -2,10 +2,13 @@ package com.yunfeiyun.agmp.iotm.device.service.impl;
 
 import java.util.List;
 
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iotm.device.mapper.IotDeviceMapper;
 import com.yunfeiyun.agmp.iotm.device.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iotm.mq.provider.IotMqProviderService;
 import com.yunfeiyun.agmp.iotm.mq.service.AgmpTosMsgService;
+import com.yunfeiyun.agmp.iotm.mq.service.SendToIotsMsgService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -24,6 +27,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     private IotDeviceMapper iotDeviceMapper;
     @Resource
     private AgmpTosMsgService agmpTosMsgService;
+    @Resource
+    private SendToIotsMsgService sendToIotsMsgService;
 
     /**
      * 查询设备基础
@@ -58,9 +63,10 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     @Override
     public int insertIotDevice(IotDevice iotDevice) {
         iotDevice.setDevBid(iotDevice.getUUId());
-        iotDevice.setTid(iotDevice.getTid());
+        iotDevice.setTid(SecurityUtils.getTid());
         int result =  iotDeviceMapper.insertIotDevice(iotDevice);
         agmpTosMsgService.sendIotDeviceInsertMsg(iotDevice);
+        sendToIotsMsgService.sendIotDeviceInsertMsg(iotDevice);
         return result;
     }
 
@@ -73,7 +79,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     @Override
     public int updateIotDevice(IotDevice iotDevice) {
         int result = iotDeviceMapper.updateIotDevice(iotDevice);
-        agmpTosMsgService.sendIotDeviceInsertMsg(iotDevice);
+        agmpTosMsgService.sendIotDeviceUpdateMsg(iotDevice);
         return result;
     }
 
@@ -82,7 +88,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     /**
      * 删除设备基础信息
      * 
-     * @param id 设备基础主键
+     * @param devBid 设备基础主键
      * @return 结果
      */
     @Override

+ 37 - 0
src/main/java/com/yunfeiyun/agmp/iotm/mq/provider/IotMqProviderService.java

@@ -0,0 +1,37 @@
+package com.yunfeiyun.agmp.iotm.mq.provider;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.consts.MqTosConsts;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.model.SynGlobalTenantInfoDto;
+import com.yunfeiyun.agmp.common.utils.JSONUtils;
+import com.yunfeiyun.agmp.iot.common.constant.mq.IotActionEnums;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@ConditionalOnBean(name = "iotMqConfig")
+public class IotMqProviderService {
+    @Autowired
+    @Qualifier("iotRabbitTemplate")
+    private RabbitTemplate iotRabbitTemplate;
+
+
+    /**
+     * 往TOS发送
+     *
+     * @param
+     */
+    public void sendToIots(IotActionEnums iotActionEnums, Object data, String desc) {
+        SynGlobalTenantInfoDto synGlobalTenantInfoDto = new SynGlobalTenantInfoDto();
+        synGlobalTenantInfoDto.setAction(iotActionEnums.getCode());
+        synGlobalTenantInfoDto.setDesc(desc);
+        synGlobalTenantInfoDto.setData(JSONObject.from(data));
+        iotRabbitTemplate.convertAndSend(MqTosConsts.ExchangeConsts.AGMP_TO_TOS_MSG_EXCHANGE, "", JSONUtils.toJSONString(synGlobalTenantInfoDto));
+    }
+
+}

+ 6 - 9
src/main/java/com/yunfeiyun/agmp/iotm/mq/service/AgmpTosMsgService.java

@@ -26,10 +26,9 @@ public class AgmpTosMsgService {
     private TosMqProviderService mqService;
 
     /**
-     * 门户修改菜单,同步到tos ok
+     * 物联网新增设备,同步到tos ok
      *
-     * @param tid
-     * @param data
+     * @param iotDevice
      */
     public void sendIotDeviceInsertMsg(IotDevice iotDevice) {
         mqService.sendToTos( TosActionEnums.IOT_DEVICE_CREATE, iotDevice, "【AGMP】to【Tos】物联网新增设备,同步到tos");
@@ -37,10 +36,9 @@ public class AgmpTosMsgService {
     }
 
     /**
-     * 门户修改平台信息,同步到tos  ok
+     * 物联网编辑设备,同步到tos  ok
      *
-     * @param tid
-     * @param data
+     * @param iotDevice
      */
     public void sendIotDeviceUpdateMsg(IotDevice iotDevice) {
         mqService.sendToTos( TosActionEnums.IOT_DEVICE_UPDATE, iotDevice, "【AGMP】to【Tos】物联网编辑设备,同步到tos");
@@ -48,10 +46,9 @@ public class AgmpTosMsgService {
     }
 
     /**
-     * 门户修改账号中心信息,同步tos  ok
+     * 物联网删除设备,同步tos  ok
      *
-     * @param tid
-     * @param data
+     * @param iotDevice
      */
     public void sendIotDeviceDeleteMsg(IotDevice iotDevice) {
         mqService.sendToTos( TosActionEnums.IOT_DEVICE_DELETE, iotDevice, "【AGMP】to【Tos】物联网删除设备,同步到tos");

+ 50 - 0
src/main/java/com/yunfeiyun/agmp/iotm/mq/service/SendToIotsMsgService.java

@@ -0,0 +1,50 @@
+package com.yunfeiyun.agmp.iotm.mq.service;
+
+
+import com.yunfeiyun.agmp.iot.common.constant.mq.IotActionEnums;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iotm.mq.provider.IotMqProviderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.stereotype.Service;
+
+/**
+ * 往Iots发送
+ *
+ * @author liuyaowen
+ */
+@Service
+@ConditionalOnBean(name = "iotMqConfig")
+public class SendToIotsMsgService {
+    @Autowired
+    private IotMqProviderService mqService;
+
+    /**
+     * 物联网新增设备,同步到iots ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceInsertMsg(IotDevice iotDevice) {
+        mqService.sendToIots( IotActionEnums.IOT_DEVICE_CREATE, iotDevice, "【Iotm】to【Iots】物联网新增设备,同步到Iotm");
+
+    }
+
+    /**
+     * 物联网编辑设备,同步到iots  ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceUpdateMsg(IotDevice iotDevice) {
+        mqService.sendToIots( IotActionEnums.IOT_DEVICE_UPDATE, iotDevice, "【Iotm】to【Iots】物联网编辑设备,同步到Iotm");
+
+    }
+
+    /**
+     * 物联网删除设备,同步iots  ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceDeleteMsg(IotDevice iotDevice) {
+        mqService.sendToIots( IotActionEnums.IOT_DEVICE_DELETE, iotDevice, "【Iotm】to【Iots】物联网删除设备,同步到Iotm");
+    }
+}