Explorar o código

新增项目启动时加载类型缓存信息以及,tos平台与iotm同步厂家,类型,型号时,数据同步更新缓存

liuyaowen hai 1 ano
pai
achega
73adb16d5c

+ 11 - 7
src/main/java/com/yunfeiyun/agmp/iotm/device/service/impl/IotDeviceServiceImpl.java

@@ -7,8 +7,9 @@ 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.service.AgmpTosMsgService;
+import com.yunfeiyun.agmp.iotm.mq.service.SendToTosMsgService;
 
+import com.yunfeiyun.agmp.iotm.mq.service.SendToIotsMsgService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -26,8 +27,9 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     @Autowired
     private IotDeviceMapper iotDeviceMapper;
     @Resource
-    private AgmpTosMsgService agmpTosMsgService;
-
+    private SendToTosMsgService sendToTosMsgService;
+    @Resource
+    private SendToIotsMsgService sendToIotsMsgService;
 
     /**
      * 查询设备基础
@@ -63,8 +65,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService
         iotDevice.setDevBid(iotDevice.getUUId());
         iotDevice.setTid(SecurityUtils.getTid());
         int result =  iotDeviceMapper.insertIotDevice(iotDevice);
-        agmpTosMsgService.sendIotDeviceInsertMsg(iotDevice);
-
+        sendToTosMsgService.sendIotDeviceInsertMsg(iotDevice);
+        sendToIotsMsgService.sendIotDeviceInsertMsg(iotDevice);
         return result;
     }
 
@@ -77,7 +79,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     @Override
     public int updateIotDevice(IotDevice iotDevice) {
         int result = iotDeviceMapper.updateIotDevice(iotDevice);
-        agmpTosMsgService.sendIotDeviceUpdateMsg(iotDevice);
+        sendToTosMsgService.sendIotDeviceUpdateMsg(iotDevice);
+        sendToIotsMsgService.sendIotDeviceUpdateMsg(iotDevice);
         return result;
     }
 
@@ -96,7 +99,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService
            return 0;
         }
         int result = iotDeviceMapper.deleteIotDeviceByDevBid(devBid);
-        agmpTosMsgService.sendIotDeviceDeleteMsg(iotDevice);
+        sendToTosMsgService.sendIotDeviceDeleteMsg(iotDevice);
+        sendToIotsMsgService.sendIotDeviceDeleteMsg(iotDevice);
         return result;
     }
 }

+ 26 - 5
src/main/java/com/yunfeiyun/agmp/iotm/device/service/impl/TosDevicetypeServiceImpl.java

@@ -1,6 +1,9 @@
 package com.yunfeiyun.agmp.iotm.device.service.impl;
 
 
+import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
+import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
+import com.yunfeiyun.agmp.common.utils.DictUtils;
 import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
 import com.yunfeiyun.agmp.iotm.device.domain.resvo.IotDevicetypeListResVo;
 import com.yunfeiyun.agmp.iotm.device.domain.resvo.TosDevicetypeResVo;
@@ -10,6 +13,8 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,7 +30,16 @@ public class TosDevicetypeServiceImpl implements ITosDevicetypeService
 {
     @Autowired
     private TosDevicetypeMapper tosDevicetypeMapper;
-
+    @Resource
+    private RedisCacheManager redisCacheManager;
+
+    @PostConstruct
+    public void init(){
+        List<TosDevicetype> tosDevicetypeList = tosDevicetypeMapper.selectTosDevicetypeList(null);
+        for(TosDevicetype tosDevicetype : tosDevicetypeList){
+            redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode(),tosDevicetype);
+        }
+    }
 
     /**
      * 查询设备类型
@@ -57,7 +71,9 @@ public class TosDevicetypeServiceImpl implements ITosDevicetypeService
      */
     @Override
     public int insertTosDevicetypeByTosMsg(TosDevicetype tosDevicetype){
-        return tosDevicetypeMapper.insertTosDevicetype(tosDevicetype);
+        int result = tosDevicetypeMapper.insertTosDevicetype(tosDevicetype);
+        redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode(),tosDevicetype);
+        return result;
     }
 
     /**
@@ -68,7 +84,9 @@ public class TosDevicetypeServiceImpl implements ITosDevicetypeService
      */
     @Override
     public int updateTosDevicetypeByTosMsg(TosDevicetype tosDevicetype){
-        return tosDevicetypeMapper.updateTosDevicetype(tosDevicetype);
+        int result = tosDevicetypeMapper.updateTosDevicetype(tosDevicetype);
+        redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode(),tosDevicetype);
+        return result;
     }
 
 
@@ -86,10 +104,13 @@ public class TosDevicetypeServiceImpl implements ITosDevicetypeService
 
     @Override
     public int deleteTosDevicetypeByTosMsg(TosDevicetype tosDevicetype) {
+        int result = 0;
         if(null == tosDevicetype){
-           return 0;
+           return result;
         }
-        return tosDevicetypeMapper.deleteTosDevicetypeByDevtypeBid(tosDevicetype.getDevtypeBid());
+        result = tosDevicetypeMapper.deleteTosDevicetypeByDevtypeBid(tosDevicetype.getDevtypeBid());
+        redisCacheManager.deleteObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode());
+        return result;
     }
 
     @Override

+ 4 - 5
src/main/java/com/yunfeiyun/agmp/iotm/mq/bussiness/AgmpMqBusConfig.java

@@ -1,10 +1,9 @@
 package com.yunfeiyun.agmp.iotm.mq.bussiness;
 
-import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.consts.MqAgmpConsts;
 import com.yunfeiyun.agmp.iot.common.constant.mq.IotMqExchange;
 import com.yunfeiyun.agmp.iot.common.constant.mq.IotMqQueue;
 
-import com.yunfeiyun.agmp.iotm.mq.listener.AgmpChannelAwareMessageListener;
+import com.yunfeiyun.agmp.iotm.mq.listener.IotsChannelAwareMessageListener;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.*;
 import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
@@ -50,7 +49,7 @@ public class AgmpMqBusConfig {
      */
     @Bean("agmpQueue")
     public Queue agmpQueue() {
-        return QueueBuilder.durable(IotMqQueue.IOTM_TO_IOTS_CMD_QUEUE).build();
+        return QueueBuilder.durable(IotMqQueue.IOTS_TO_IOTM_CMD_QUEUE).build();
     }
 
     /**
@@ -60,7 +59,7 @@ public class AgmpMqBusConfig {
      */
     @Bean("agmpExchange")
     public FanoutExchange agmpExchange() {
-        return new FanoutExchange(IotMqExchange.IOTM_TO_IOTS_EXCHANGE);
+        return new FanoutExchange(IotMqExchange.IOTS_TO_IOTM_EXCHANGE);
     }
 
     /**
@@ -84,7 +83,7 @@ public class AgmpMqBusConfig {
     @Bean("agmpSimpleMessageListenerContainer")
     public SimpleMessageListenerContainer agmpSimpleMessageListenerContainer(
             @Qualifier("agmpConnectionFactory") CachingConnectionFactory connectionFactory,
-            AgmpChannelAwareMessageListener listener) {
+            IotsChannelAwareMessageListener listener) {
         SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
         container.setQueues(agmpQueue());
         container.setMessageListener(listener);

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/mq/listener/AgmpChannelAwareMessageListener.java

@@ -15,7 +15,7 @@ import java.io.IOException;
 @Component
 @Slf4j
 @ConditionalOnBean(name = "agmpMqConfig")
-public class AgmpChannelAwareMessageListener implements ChannelAwareMessageListener {
+public class IotsChannelAwareMessageListener implements ChannelAwareMessageListener {
 
     @Override
     public void onMessage(Message message, Channel channel) throws Exception {

+ 46 - 0
src/main/java/com/yunfeiyun/agmp/iotm/mq/provider/IotsMqProviderService.java

@@ -0,0 +1,46 @@
+package com.yunfeiyun.agmp.iotm.mq.provider;
+
+import com.alibaba.fastjson2.JSONObject;
+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 com.yunfeiyun.agmp.iot.common.constant.mq.IotMqExchange;
+import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
+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 = "agmpMqConfig")
+public class IotsMqProviderService {
+    @Autowired
+    @Qualifier("agmpRabbitTemplate")
+    private RabbitTemplate iotRabbitTemplate;
+
+
+    /**
+     * 往Iots发送基础信息
+     *
+     * @param
+     */
+    public void sendBaseDataToIots(IotActionEnums iotActionEnums, Object data, String desc) {
+        SynGlobalTenantInfoDto synGlobalTenantInfoDto = new SynGlobalTenantInfoDto();
+        synGlobalTenantInfoDto.setAction(iotActionEnums.getCode());
+        synGlobalTenantInfoDto.setDesc(desc);
+        synGlobalTenantInfoDto.setData(JSONObject.from(data));
+        iotRabbitTemplate.convertAndSend(IotMqExchange.IOTM_TO_IOTS_EXCHANGE, "", JSONUtils.toJSONString(synGlobalTenantInfoDto));
+    }
+    /**
+     * 往Iots发送指令信息
+     * */
+    public void sendCmdToIots(CmdGroupModel cmdGroupModel, String desc){
+        SynGlobalTenantInfoDto synGlobalTenantInfoDto = new SynGlobalTenantInfoDto();
+        synGlobalTenantInfoDto.setAction(IotActionEnums.CMD_TASK.getCode());
+        synGlobalTenantInfoDto.setDesc(desc);
+        synGlobalTenantInfoDto.setData(JSONObject.from(cmdGroupModel));
+    }
+}

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

@@ -0,0 +1,78 @@
+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.iot.common.domain.IotDeviceconn;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevicetype;
+import com.yunfeiyun.agmp.iotm.mq.provider.IotsMqProviderService;
+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 = "agmpMqConfig")
+public class SendToIotsMsgService {
+    @Autowired
+    private IotsMqProviderService mqService;
+
+    /**
+     * 物联网新增设备,同步到iots ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceInsertMsg(IotDevice iotDevice) {
+        mqService.sendBaseDataToIots( IotActionEnums.IOT_DEVICE_CREATE, iotDevice, "【Iotm】to【Iots】物联网新增设备,同步到Iotm");
+
+    }
+
+    /**
+     * 物联网编辑设备,同步到iots  ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceUpdateMsg(IotDevice iotDevice) {
+        mqService.sendBaseDataToIots( IotActionEnums.IOT_DEVICE_UPDATE, iotDevice, "【Iotm】to【Iots】物联网编辑设备,同步到Iotm");
+
+    }
+
+    /**
+     * 物联网删除设备,同步iots  ok
+     *
+     * @param iotDevice
+     */
+    public void sendIotDeviceDeleteMsg(IotDevice iotDevice) {
+        mqService.sendBaseDataToIots( IotActionEnums.IOT_DEVICE_DELETE, iotDevice, "【Iotm】to【Iots】物联网删除设备,同步到Iotm");
+    }
+    /**
+     * 物联网新增设备型号,同步到iots ok
+     *
+     * @param iotDeviceconn
+     */
+    public void sendIotDeviceconnInsertMsg(IotDeviceconn iotDeviceconn) {
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_CREATE, iotDeviceconn, "【Iotm】to【Iots】物联网新增设备,同步到Iotm");
+    }
+
+    /**
+     * 物联网编辑设备型号,同步到iots  ok
+     *
+     * @param iotDeviceconn
+     */
+    public void sendIotDeviceconnUpdateMsg(IotDeviceconn iotDeviceconn) {
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_UPDATE, iotDeviceconn, "【Iotm】to【Iots】物联网编辑设备,同步到Iotm");
+    }
+
+    /**
+     * 物联网删除设备型号,同步iots  ok
+     *
+     * @param iotDeviceconn
+     */
+    public void sendIotDeviceconnDeleteMsg(IotDeviceconn iotDeviceconn) {
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_DELETE, iotDeviceconn, "【Iotm】to【Iots】物联网删除设备,同步到Iotm");
+    }
+}

+ 1 - 2
src/main/java/com/yunfeiyun/agmp/iotm/mq/service/AgmpTosMsgService.java

@@ -1,6 +1,5 @@
 package com.yunfeiyun.agmp.iotm.mq.service;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.enums.TosActionEnums;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iotm.mq.provider.TosMqProviderService;
@@ -20,7 +19,7 @@ import org.springframework.stereotype.Service;
  */
 @Service
 @ConditionalOnBean(name = "tosMqConfig")
-public class AgmpTosMsgService {
+public class SendToTosMsgService {
 
     @Autowired
     private TosMqProviderService mqService;