|
@@ -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)&¶m.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);
|
|
|
|
+ }
|
|
|
|
+}
|