Browse Source

阶段提交:测报灯的代码初步提交

yf_zn 1 year ago
parent
commit
4a5a3bd96b

+ 1 - 7
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/CqCbdDeviceImpl.java

@@ -43,13 +43,6 @@ public class CqCbdDeviceImpl implements ICbdDevice {
 
     private static final String SERVICE_NAME = ServiceNameConst.SERVICE_YF_CBD;
 
-
-    /**
-     * 测试设备编号(云飞测报灯)
-     */
-    public final static String DEVICE_CODE_CBD_TEST = "861551058867599";
-
-
     @Autowired
     private MqttManager mqttManager;
 
@@ -129,6 +122,7 @@ public class CqCbdDeviceImpl implements ICbdDevice {
         }
         String topic = IotMqttConstant.YFCbdTopic.TOPIC_CBD_CMD_PREFIX + cmdModel.getIotDevice().getDevCode();
         log.info("!!!!!!!!!!【看这里:临时测试】这里的connectionId写死了,对接业务时候换掉,取出来真实的");
+        //String connectionId = cmdModel.getIotDevice().getDevconnBid();
         mqttManager.publishMsg(connectionId, topic, mqttMsgContent);
 
         log.info("【CBD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}",connectionId,topic, mqttMsgContent);

+ 61 - 1
src/main/java/com/yunfeiyun/agmp/iots/mq/listener/IotmChannelAwareMessageListener.java

@@ -1,9 +1,19 @@
 package com.yunfeiyun.agmp.iots.mq.listener;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.rabbitmq.client.Channel;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.enums.TosActionEnums;
+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.domain.reqvo.IotCbdrecogAgainReqVo;
+import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
+import com.yunfeiyun.agmp.iots.core.cmd.core.CmdDispatcherService;
+import com.yunfeiyun.agmp.iots.device.serviceImp.IotCbdImgService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.Message;
 import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.stereotype.Component;
 
@@ -16,6 +26,11 @@ import java.io.IOException;
 @Slf4j
 @ConditionalOnBean(name = "agmpMqConfig")
 public class IotmChannelAwareMessageListener implements ChannelAwareMessageListener {
+    @Autowired
+    private CmdDispatcherService cmdDispatcherService;
+
+    @Autowired
+    private IotCbdImgService iotCbdImgService;
 
     @Override
     public void onMessage(Message message, Channel channel) throws Exception {
@@ -24,11 +39,56 @@ public class IotmChannelAwareMessageListener implements ChannelAwareMessageListe
             byte[] body = message.getBody();
             String content = new String(body);
             log.info("【SAAS:】收到AGMP消息:{}", content);
+            SynGlobalTenantInfoDto synGlobalTenantInfoDto = JSONUtils.toObject(content, SynGlobalTenantInfoDto.class);
+            //根据不同的action进行相应业务处理
+            String action = synGlobalTenantInfoDto.getAction();
+            IotActionEnums iotActionEnums = IotActionEnums.getAction(action);
+            if (iotActionEnums != null) {
+                switch (iotActionEnums) {
+                    //控制指令
+                    case CMD_TASK:
+                        CmdGroupModel cmdGroupModel = JSONUtils.toObject(synGlobalTenantInfoDto.getData().toString(), CmdGroupModel.class);
+                        cmdDispatcherService.handleCmd(cmdGroupModel);
+                        break;
+                    //控制指令结果
+                    case CMD_TASK_RESULT:
+                        break;
+                    //设备创建
+                    case IOT_DEVICE_CREATE:
+                        break;
+                    //设备更新
+                    case IOT_DEVICE_UPDATE:
+                        break;
+                    //设备删除
+                    case IOT_DEVICE_DELETE:
+                        break;
+                    //设备连接信息创建
+                    case DEVICE_COON_CREATE:
+                        break;
+                    //设备连接信息更新
+                    case DEVICE_COON_UPDATE:
+                        break;
+                    //设备连接信息删除
+                    case DEVICE_COON_DELETE:
+                        break;
+                    //更新所有设备信息
+                    case DEVICE_ALL_SYN:
+                        break;
+                    //测报灯重新识别
+                    case DEVICE_CBD_AGAIN_RECORD:
+                        iotCbdImgService.iotmAgainRecog(synGlobalTenantInfoDto.getData().toString());
+                        break;
+                    default:
+                        break;
+                }
+            } else {
+                log.error("【SAAS:】收到Tos:所有租户处理的消息:action 为空,忽略消息");
+            }
             // 手动确认消息
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
         } catch (IOException e) {
             // 处理异常,例如重新入队或拒绝消息
-            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
+            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
         }
     }
 }