Bläddra i källkod

处理来自管理后台的修改相机出库信息通知

lyhzzz 1 år sedan
förälder
incheckning
3ea16821f6

+ 53 - 0
src/main/java/com/fdkankan/agent/mq/consumer/CameraUpdateAgentConsumer.java

@@ -0,0 +1,53 @@
+package com.fdkankan.agent.mq.consumer;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.agent.mq.vo.CameraUpdateAgentVo;
+import com.fdkankan.agent.service.IAgentNewCameraService;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * 场景封存解封 mq
+ */
+@Slf4j
+@Component
+public class CameraUpdateAgentConsumer {
+
+
+    @Autowired
+    IAgentNewCameraService agentNewCameraService;
+
+    @RabbitListener(
+            queuesToDeclare = @Queue("${queue.scene.pay-status:camera-update-agent}")
+            ,concurrency = "1"
+    )
+    public void consumerQueue(Channel channel, Message message)  {
+        try {
+            String messageId = message.getMessageProperties().getMessageId();
+            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+            log.info("camera-update-agent-mq--messageId:{},msg:{}",messageId,msg);
+
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+            CameraUpdateAgentVo vo = JSONObject.parseObject(msg, CameraUpdateAgentVo.class);
+            if(vo == null){
+                return;
+            }
+            if(vo.getCameraIds() != null && !vo.getCameraIds().isEmpty()){
+                agentNewCameraService.delByCameraIds(vo.getCameraIds());
+            }
+        }catch (Exception e){
+            log.info("camera-update-agent----消费失败",e);
+        }finally {
+
+        }
+
+    }
+
+}

+ 10 - 0
src/main/java/com/fdkankan/agent/mq/vo/CameraUpdateAgentVo.java

@@ -0,0 +1,10 @@
+package com.fdkankan.agent.mq.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CameraUpdateAgentVo {
+    private List<Long> cameraIds;
+}

+ 2 - 0
src/main/java/com/fdkankan/agent/service/IAgentNewCameraService.java

@@ -24,4 +24,6 @@ public interface IAgentNewCameraService extends IService<AgentNewCamera> {
     HashMap<Long, AgentNewCamera> getMapByCameraIds(List<Long> voCameraIds);
 
     Integer giveCameraBatch(List<Long> cameraIds, Integer agentId, Integer subAgentId);
+
+    void delByCameraIds(List<Long> cameraIds);
 }

+ 2 - 0
src/main/java/com/fdkankan/agent/service/ICameraDetailService.java

@@ -26,4 +26,6 @@ public interface ICameraDetailService extends IService<CameraDetail> {
     List<CameraDetail> getListByCompanyId(Integer companyId);
 
     List<CameraDetail> getListByAgentId(Integer agentId);
+
+    List<CameraDetail> getByCameraIds(List<Long> cameraIds);
 }

+ 36 - 0
src/main/java/com/fdkankan/agent/service/impl/AgentNewCameraServiceImpl.java

@@ -16,8 +16,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -102,4 +104,38 @@ public class AgentNewCameraServiceImpl extends ServiceImpl<IAgentNewCameraMapper
         list.forEach(e -> map.put(e.getCameraId(),e));
         return map;
     }
+
+    @Override
+    public void delByCameraIds(List<Long> cameraIds) {
+        List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
+        if(cameraDetails == null || cameraDetails.isEmpty()){
+            return;
+        }
+        List<AgentNewCamera> agentNewCameraList = this.getByCameraIds(cameraIds);
+        if(agentNewCameraList == null || agentNewCameraList.isEmpty()){
+            return;
+        }
+        HashMap<Long,CameraDetail> cameraMap = new HashMap<>();
+        cameraDetails.forEach(e -> cameraMap.put(e.getCameraId(),e));
+
+        List<Integer> rmList = new ArrayList<>();
+        for (AgentNewCamera agentNewCamera : agentNewCameraList) {
+            CameraDetail cameraDetail = cameraMap.get(agentNewCamera.getCameraId());
+            if(cameraDetail !=null && (cameraDetail.getAgentId() == null || !cameraDetail.getAgentId().equals(agentNewCamera.getAgentId()))){
+                rmList.add(agentNewCamera.getId());
+            }
+        }
+        if(!rmList.isEmpty()){
+            this.removeByIds(rmList);
+        }
+    }
+
+    private List<AgentNewCamera> getByCameraIds(List<Long> cameraIds) {
+        if(cameraIds.isEmpty()){
+            return null;
+        }
+        LambdaQueryWrapper<AgentNewCamera> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(AgentNewCamera::getCameraId,cameraIds);
+        return this.list(wrapper);
+    }
 }

+ 10 - 0
src/main/java/com/fdkankan/agent/service/impl/CameraDetailServiceImpl.java

@@ -122,4 +122,14 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
         wrapper.eq(CameraDetail::getAgentId,agentId);
         return this.list(wrapper);
     }
+
+    @Override
+    public List<CameraDetail> getByCameraIds(List<Long> cameraIds) {
+        if(cameraIds.isEmpty()){
+            return null;
+        }
+        LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(CameraDetail::getCameraId, cameraIds);
+        return this.list(wrapper);
+    }
 }