|
|
@@ -1,49 +1,42 @@
|
|
|
package com.tuoren.web.rabbit;
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.lang.TypeReference;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.rabbitmq.client.AMQP;
|
|
|
-import com.rabbitmq.client.Channel;
|
|
|
+import com.tuoren.common.api.CommonResult;
|
|
|
+import com.tuoren.common.api.ResultCode;
|
|
|
+import com.tuoren.common.constant.CommonConstant;
|
|
|
import com.tuoren.common.utils.ConstastUtils;
|
|
|
+import com.tuoren.common.utils.LocalDateTimeUtil;
|
|
|
import com.tuoren.web.layer.d0.PumpRemovePushRabbitDTO;
|
|
|
import com.tuoren.web.layer.d0.PumpRemoveUserPushRabbitDTO;
|
|
|
import com.tuoren.web.layer.entity.*;
|
|
|
+import com.tuoren.web.layer.mapper.BusConstantMapper;
|
|
|
import com.tuoren.web.layer.service.*;
|
|
|
-
|
|
|
import com.tuoren.web.push.PushInfo;
|
|
|
-import com.tuoren.web.utils.DataUtils;
|
|
|
+import com.tuoren.web.rabbit.dto.BusConstantDTO;
|
|
|
+import com.tuoren.web.rabbit.helper.BusConstantHelper;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
-import org.springframework.amqp.core.Exchange;
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
-import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.tuoren.common.api.CommonResult;
|
|
|
-import com.tuoren.common.api.ResultCode;
|
|
|
-import com.tuoren.common.constant.CommonConstant;
|
|
|
-import com.tuoren.common.utils.LocalDateTimeUtil;
|
|
|
-
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -73,6 +66,11 @@ public class RabbitHandle {
|
|
|
|
|
|
private final IBusWordService iBusWordService;
|
|
|
|
|
|
+ private final IBusConstantService iBusConstantService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BusConstantMapper busConstantMapper;
|
|
|
+
|
|
|
PushInfo pushInfo;
|
|
|
/**
|
|
|
* @Description 监听呼吸队列
|
|
|
@@ -265,6 +263,51 @@ public class RabbitHandle {
|
|
|
log.info("======phoneAnalgesicScoreQueueHandle======:"+message);
|
|
|
System.out.println(message);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @description: 监听常量队列
|
|
|
+ * @author wangzl
|
|
|
+ * @date 2025/9/2
|
|
|
+ */
|
|
|
+ @RabbitListener(queuesToDeclare = @Queue(CommonConstant.QUEUE_CONSTANT))
|
|
|
+ public void constantHandle(byte[] bytes) {
|
|
|
+ String message = byteToString(bytes);
|
|
|
+ log.info("======constantHandle 常量队列消息======:"+message);
|
|
|
+ BusConstantDTO constantDTO = JSONObject.parseObject(message, BusConstantDTO.class);
|
|
|
+
|
|
|
+ List<BusConstantEntity> busConstantEntities = BusConstantHelper.dealConstant(constantDTO);
|
|
|
+ if(CollectionUtil.isNotEmpty(busConstantEntities)){
|
|
|
+ List<String> md5s = busConstantEntities.stream().map(BusConstantEntity::getMd5).collect(Collectors.toList());
|
|
|
+ //先查询md5存在的
|
|
|
+ List<BusConstantEntity> list = iBusConstantService.list(new LambdaQueryWrapper<BusConstantEntity>()
|
|
|
+ .in(BusConstantEntity::getMd5,md5s));
|
|
|
+ //去掉已经存储的数据
|
|
|
+ List<BusConstantEntity> collect = busConstantEntities.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ // 查找是否有匹配的已删除记录
|
|
|
+ Optional<BusConstantEntity> deletedEntity = list.stream()
|
|
|
+ .filter(entity -> entity.getMd5().equals(item.getMd5()) &&
|
|
|
+ Boolean.TRUE.equals(entity.getIsDelete()))
|
|
|
+ .findFirst();
|
|
|
+ if (deletedEntity.isPresent()) {
|
|
|
+ // 恢复已删除记录
|
|
|
+ item.setId(deletedEntity.get().getId());
|
|
|
+ item.setIsDelete(false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 检查是否已存在且未删除
|
|
|
+ boolean exists = list.stream()
|
|
|
+ .anyMatch(entity -> entity.getMd5().equals(item.getMd5()) &&
|
|
|
+ !Boolean.TRUE.equals(entity.getIsDelete()));
|
|
|
+ // 只有在不存在或已删除时才保留
|
|
|
+ return !exists;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ log.info("保存的常量数据个数:{}", collect.size());
|
|
|
+ if(CollectionUtil.isNotEmpty(collect)){
|
|
|
+ iBusConstantService.saveOrUpdateBatch(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private Boolean existHospital(String hospital) {
|
|
|
QueryWrapper<BusHospitalEntity> wrapper = new QueryWrapper<>();
|