xiewj hace 11 meses
padre
commit
01a4e60d70

+ 5 - 0
pom.xml

@@ -146,6 +146,11 @@
             <artifactId>jasypt-spring-boot-starter</artifactId>
             <version>3.0.5</version>
         </dependency>
+        <dependency>
+            <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-utils-rabbitmq</artifactId>
+            <version>3.0.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 18 - 0
src/main/java/com/fdkankan/site/entity/dto/RelicsCooperationQueueDTO.java

@@ -0,0 +1,18 @@
+package com.fdkankan.site.entity.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+
+/**
+ * @author Xiewj
+ * @date 2024/9/4
+ */
+@Data
+public class RelicsCooperationQueueDTO {
+
+    private List<String> numList;
+    private String contractorAccount;
+    private String command;
+}

+ 80 - 0
src/main/java/com/fdkankan/site/listener/SceneCooperationListener.java

@@ -0,0 +1,80 @@
+package com.fdkankan.site.listener;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.fdkankan.site.entity.User;
+import com.fdkankan.site.entity.dto.RelicsCooperationQueueDTO;
+import com.fdkankan.site.service.IProjectNumService;
+import com.fdkankan.site.service.IProjectService;
+import com.fdkankan.site.service.IUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+import com.rabbitmq.client.Channel;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+/**
+ * 消息监听器
+ *
+ * @author Xiewj
+ * @version 1.0
+ * @since 2023/08/07
+ */
+@Component
+@Slf4j
+public class SceneCooperationListener {
+    @Autowired
+    private IProjectService projectService;
+    @Autowired
+    private IUserService userService;
+    @Autowired
+    private IProjectNumService projectNumService;
+    /**
+     *  迁移
+     *
+     * @param channel
+     * @param message
+     * @throws Exception the io exception  这里异常需要处理
+     */
+    @RabbitListener(
+            queuesToDeclare = @Queue("${queue.manage-collaborate-msg-notice}"),concurrency = "1"
+    )
+    public void cooperationSceneQueue(Channel channel, Message message) throws IOException {
+            if (ObjectUtils.isEmpty(message.getBody())) {
+                log.error("消息内容为空,退出构建,当前服务器id:{}" );
+                return;
+            }
+        String traceId = System.currentTimeMillis()+"";
+        MDC.put("TRACE_ID", traceId);
+        long deliveryTag = message.getMessageProperties().getDeliveryTag();
+        try {
+            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+            String messageId = message.getMessageProperties().getMessageId();
+            log.info("场景cooperationScene开始,id:{},deliveryTag:{},消息体:{}", messageId,deliveryTag,msg);
+            RelicsCooperationQueueDTO param = JSONObject.parseObject(JSON.parse(msg).toString(), RelicsCooperationQueueDTO.class);
+            if (ObjectUtil.isNotNull(param)&&param.getCommand().equalsIgnoreCase("unCollaborate")){
+                User byUserName = userService.findByUserName(param.getContractorAccount());
+                if (ObjectUtil.isNotNull(byUserName)){
+                    Integer userId = byUserName.getUserId();
+                    projectNumService.removeByNumListAndUserId(userId,param.getNumList());
+                }
+
+            }
+
+        }catch (Exception e){
+            log.error("场景cooperationScene报错{}",e.getMessage());
+            e.printStackTrace();
+        }
+        channel.basicAck(deliveryTag, false);
+    }
+}

+ 2 - 0
src/main/java/com/fdkankan/site/service/IProjectNumService.java

@@ -42,4 +42,6 @@ public interface IProjectNumService extends IService<ProjectNum> {
 
     List<ProjectNum> getByNum(String num);
     ProjectNum getByNumAndProjectId(String num,Integer projectId);
+
+    void removeByNumListAndUserId(Integer userId, List<String> numList);
 }

+ 13 - 0
src/main/java/com/fdkankan/site/service/impl/ProjectNumServiceImpl.java

@@ -1,5 +1,7 @@
 package com.fdkankan.site.service.impl;
 
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.site.common.util.JwtUtil;
@@ -151,4 +153,15 @@ public class ProjectNumServiceImpl extends ServiceImpl<IProjectNumMapper, Projec
         wrapper.eq(ProjectNum::getProjectId,projectId);
         return this.getOne(wrapper);
     }
+
+    @Override
+    public void removeByNumListAndUserId(Integer userId, List<String> numList) {
+        if(ArrayUtil.isEmpty(numList) || ObjectUtil.isNull(userId)){
+            return;
+        }
+        LambdaQueryWrapper<ProjectNum> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(ProjectNum::getNum,numList);
+        wrapper.eq(ProjectNum::getCreateBy,userId);
+        this.remove(wrapper);
+    }
 }

+ 1 - 0
src/main/java/com/fdkankan/site/service/impl/SceneServiceImpl.java

@@ -147,6 +147,7 @@ public class SceneServiceImpl implements ISceneService {
         //获取四维(看看,看见)场景数据
         FdkkResponse fdkkResponse = null;
         if (param.getNumList() == null || param.getNumList().size() <= 0) {
+            param.setStatus(-2);
             fdkkResponse = fdKKClient.sceneList(param, token);
         } else {
             param.setStatus(2);

+ 15 - 1
src/main/resources/application-jp-prod.yaml

@@ -27,6 +27,18 @@ spring:
         max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
     lettuce:
       shutdown-timeout: 0ms
+  rabbitmq:
+    host: 127.0.0.1
+    port: 5672
+    username: admin
+    password: admin1231
+    virtual-host: 4dkankan
+    connection-timeout: 0
+    listener:
+      simple:
+        prefetch: 1
+        max-concurrency: 2
+        acknowledge-mode: manual #开启消费者手动确认
 
 4dkk:
   fdService:
@@ -54,4 +66,6 @@ filestorage:
     access-key-secret: JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
     bucket: 4dkankan
     bucket-custom-domain:
-      4dkankan: https://4dkk.4dage.com/
+      4dkankan: https://4dkk.4dage.com/
+queue:
+  manage-collaborate-msg-notice: manage-collaborate-msg-notice

+ 14 - 1
src/main/resources/application-jp-test.yaml

@@ -28,7 +28,18 @@ spring:
         max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
     lettuce:
       shutdown-timeout: 0ms
-
+  rabbitmq:
+    host: 127.0.0.1
+    port: 5672
+    username: admin
+    password: admin1231
+    virtual-host: 4dkankan
+    connection-timeout: 0
+    listener:
+      simple:
+        prefetch: 1
+        max-concurrency: 2
+        acknowledge-mode: manual #开启消费者手动确认
 4dkk:
   fdService:
     #官网生产环境:https://www.4dkankan.com      http://test.4dkankan.com
@@ -60,3 +71,5 @@ filestorage:
     bucket: geosign-4dkk
     bucket-custom-domain:
       geosign-4dkk: https://oss.4dkankan.jp
+queue:
+  manage-collaborate-msg-notice: manage-collaborate-msg-notice