Browse Source

Merge branch 'cpq-dev' of wangfan/adweb3-server into master

chenpeiqing 4 months ago
parent
commit
1a6c4e371f

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/AdwebEnquiryMapper.java

@@ -4,6 +4,7 @@ import cn.hutool.core.lang.Pair;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO;
 import org.jeecg.modules.adweb.enquiry.dto.param.EnquirySearchDto;
 import org.jeecg.modules.adweb.enquiry.dto.result.EnquiryListDto;
 import org.jeecg.modules.adweb.enquiry.entity.AdwebEnquiry;
@@ -83,4 +84,6 @@ public interface AdwebEnquiryMapper extends BaseMapper<AdwebEnquiry> {
      * @return List<Pair < String, Long>> -- MyBatis COUNT()方法默认类型为Long
      */
     List<Pair<String, Long>> getEnquiryPeriodicCounts(String siteCode);
+
+    List<EnquiryDTO> getEnquiryList(String siteCode, String startTime, String endTime);
 }

+ 18 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/xml/AdwebEnquiryMapper.xml

@@ -359,4 +359,22 @@
         tp.period;
     </select>
 
+    <select id="getEnquiryList" resultType="org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO">
+        SELECT
+        id,
+        site_host,
+        site_code,
+        record_id
+        FROM
+        adweb_enquiry
+        WHERE
+        site_code = #{siteCode}
+        <if test="startTime != null">
+            AND record_ctime &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND record_ctime &lt;= #{endTime}
+        </if>
+    </select>
+
 </mapper>

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/service/IAdwebEnquiryService.java

@@ -36,4 +36,6 @@ public interface IAdwebEnquiryService extends IService<AdwebEnquiry> {
     boolean updateUserEffective(EffectiveEnquiryParamDto effectiveEnquiryParamDto);
 
     void specialSendEmail(AdwebEnquiry adwebEnquiry, AdwebSite adwebSite);
+
+    List<EnquiryDTO> enquiryList(String siteCode, String startTime, String endTime);
 }

+ 43 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/service/impl/AdwebEnquiryServiceImpl.java

@@ -147,6 +147,9 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
 
     private static final byte[] siteRedisKey = EnquiryConstants.ENQUIRY_SITE.getBytes();
 
+    // 询盘唯一键 redis key
+    public static final String EnquiryUniqueKey = "ENQUIRY_UNIQUE_KEY::";
+
     // Email Redis key
     private static final String EmailTenMinKey = "JUDGE_WASTE_ENQUIRY_EMAIL_BY_10_MIN::";
     private static final String EmailOneDayKey = "JUDGE_WASTE_ENQUIRY_EMAIL_BY_ONE_DAY::";
@@ -273,6 +276,29 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
         judgeBlacklist(adwebEnquiryList);
 
         AdwebEnquiry target = adwebEnquiryList.get(0);
+
+        //获取最近一周的询盘数量,根据域名和record id 生成唯一标识,存入redis,用来过滤之后的询盘mq,防止重复消费
+
+        if (adwebRedisUtil.hasKey(EnquiryUniqueKey + target.getSiteHost())) {
+            List<String> enquiryUniqueIds = (List<String>) adwebRedisUtil.get(EnquiryUniqueKey + target.getSiteHost());
+
+            // 防止redis 唯一键存储过大,并始终更新
+            enquiryUniqueIds.remove(enquiryUniqueIds.size() - 1); // 移除第一个唯一键
+            enquiryUniqueIds.add(target.getSiteHost() + ">>>" + target.getRecordId()); // 添加最新的唯一键
+
+            adwebRedisUtil.set(EnquiryUniqueKey + target.getSiteHost(), enquiryUniqueIds, 60 * 60 * 24);
+
+        } else {
+            Date start = DateUtil.addDays(new Date(), -7);
+            List<EnquiryDTO> enquiryList = this.enquiryList(target.getSiteCode(), DateUtil.formatDate(start, DateUtil.DATE_TIME_FORMAT), DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT));
+
+            if (enquiryList != null) {
+                List<String> enquiryUniqueIds = enquiryList.stream().map(enquiry -> enquiry.getSiteHost() + ">>>" + enquiry.getRecordId()).toList();
+                adwebRedisUtil.set(EnquiryUniqueKey + target.getSiteHost(), enquiryUniqueIds, 60 * 60 * 24);
+            }
+        }
+
+
         try {
             this.save(target);
             adwebEnquiryFormService.save(form);
@@ -1937,4 +1963,21 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
         }
         return true;
     }
+
+    /**
+     * @param siteCode
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    @Override
+    public List<EnquiryDTO> enquiryList(String siteCode, String startTime, String endTime) {
+        List<EnquiryDTO> enquiryList = adwebEnquiryMapper.getEnquiryList(siteCode, startTime, endTime);
+
+        if (enquiryList.isEmpty()) {
+            return null;
+        }
+
+        return enquiryList;
+    }
 }

+ 26 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mq/EnquiryReceiver.java

@@ -2,12 +2,12 @@ package org.jeecg.modules.mq;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.rabbitmq.client.Channel;
-
+import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
-
 import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler;
 import org.jeecg.boot.starter.rabbitmq.listenter.MqListener;
 import org.jeecg.common.annotation.RabbitComponent;
+import org.jeecg.modules.adweb.common.util.AdwebRedisUtil;
 import org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO;
 import org.jeecg.modules.adweb.enquiry.service.IAdwebEnquiryService;
 import org.jeecg.modules.adweb.site.entity.AdwebSite;
@@ -18,8 +18,11 @@ import org.springframework.amqp.support.AmqpHeaders;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.messaging.handler.annotation.Header;
 
+import java.io.IOException;
 import java.util.List;
 
+import static org.jeecg.modules.adweb.enquiry.service.impl.AdwebEnquiryServiceImpl.EnquiryUniqueKey;
+
 /**
  * Rabbit MQ - 询盘消息接收
  *
@@ -29,9 +32,14 @@ import java.util.List;
 @RabbitComponent(value = "enquiryReceiver")
 public class EnquiryReceiver extends BaseRabbiMqHandler<EnquiryDTO> {
 
-    @Autowired private IAdwebSiteService adwebSiteService;
+    @Autowired
+    private IAdwebSiteService adwebSiteService;
+
+    @Autowired
+    private IAdwebEnquiryService adwebEnquiryService;
 
-    @Autowired private IAdwebEnquiryService adwebEnquiryService;
+    @Resource
+    private AdwebRedisUtil adwebRedisUtil;
 
     @RabbitHandler
     // ackMode需要设置为MANUAL - BaseRabbiMqHandler.onMessage()有channel.basicAck()操作
@@ -50,6 +58,20 @@ public class EnquiryReceiver extends BaseRabbiMqHandler<EnquiryDTO> {
                         // 业务处理
                         log.info("收到MQ消息 {}", enquiry);
 
+                        if (adwebRedisUtil.hasKey(EnquiryUniqueKey + enquiry.getSiteHost())) {
+                            // 消息内容唯一性判断
+                            List<String> enquiryUniqueIds = (List<String>) adwebRedisUtil.get(EnquiryUniqueKey + enquiry.getSiteHost());
+                            // 如果该消息内容原数据中已存在,则将该重复消息踢出队列
+                            if (enquiryUniqueIds.contains(enquiry.getSiteHost() + ">>>" + enquiry.getRecordId())) {
+                                try {
+                                    channel.basicAck(deliveryTag, false);
+                                } catch (IOException e) {
+                                    throw new RuntimeException(e);
+                                }
+                            }
+                        }
+
+
                         // 查看发布当前消息的站点是否是 adweb3 平台中绑定的是否是有效站点, 如果不是则直接确认消息,不做业务处理
                         List<AdwebSite> adwebSites =
                                 adwebSiteService.list(

+ 1 - 1
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -192,7 +192,7 @@ spring:
     port: 5672
     publisher-confirm-type: correlated
     publisher-returns: true
-    virtual-host: /adweb3-dev
+    virtual-host: /adweb3-test
 #mybatis plus 设置
 mybatis-plus:
   mapper-locations: classpath*:org/jeecg/**/xml/*Mapper.xml

+ 1 - 1
jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml

@@ -191,7 +191,7 @@ spring:
     port: 5672
     publisher-confirm-type: correlated
     publisher-returns: true
-    virtual-host: /adweb3-dev
+    virtual-host: /adweb3-test
 #mybatis plus 设置
 mybatis-plus:
   mapper-locations: classpath*:org/jeecg/**/xml/*Mapper.xml