Browse Source

获取询盘最新更新时间,区分后台录入和站点录入,询盘唯一性条件在后台录入时不做更新,增加后台录入时的区分

chenlei1231 3 weeks ago
parent
commit
4516092823

+ 149 - 156
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/api/controller/OpenAPIController.java

@@ -3,12 +3,13 @@ package org.jeecg.modules.adweb.api.controller;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-
 import jakarta.annotation.Resource;
 import jakarta.servlet.http.HttpServletRequest;
-
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import lombok.extern.slf4j.Slf4j;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.api.vo.Result;
@@ -27,180 +28,172 @@ import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
 import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 @RestController
 @RequestMapping("/openapi")
 @Slf4j
 public class OpenAPIController {
 
-    private static final String BEARER_TOKEN_HEADER = "AdWeb-Authorization";
-    private static final String STATIC_BEARER_TOKEN = "Bearer uxl9Wpzh65vXNUyDvynJDjBo";
+  private static final String BEARER_TOKEN_HEADER = "AdWeb-Authorization";
+  private static final String STATIC_BEARER_TOKEN = "Bearer uxl9Wpzh65vXNUyDvynJDjBo";
+
+  @Resource private CommonMapper commonMapper;
 
-    @Resource private CommonMapper commonMapper;
+  @Resource private IAdwebSiteService adwebSiteService;
 
-    @Resource private IAdwebSiteService adwebSiteService;
+  @Resource private IAdwebProductService adwebProductService;
 
-    @Resource private IAdwebProductService adwebProductService;
+  @Resource private IAdwebEnquiryService adwebEnquiryService;
 
-    @Resource private IAdwebEnquiryService adwebEnquiryService;
+  /** 外部api请求获取产品列表 */
+  @IgnoreAuth
+  @PostMapping("/product/list")
+  @ResponseBody
+  public Result<List<ProductInfoVO>> listProducts(
+      @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
+      @RequestBody APIRequestVO apiRequest) {
+    this.validateAuthToken(authToken);
 
-    /** 外部api请求获取产品列表 */
-    @IgnoreAuth
-    @PostMapping("/product/list")
-    @ResponseBody
-    public Result<List<ProductInfoVO>> listProducts(
-            @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
-            @RequestBody APIRequestVO apiRequest) {
-        this.validateAuthToken(authToken);
+    log.info("苏豪通请求产品列表 parameter: {}", apiRequest);
 
-        log.info("苏豪通请求产品列表 parameter: {}", apiRequest);
+    LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
+    adwebSiteQueryWrapper.like(AdwebSite::getDomain, apiRequest.getDomain());
+    List<AdwebSite> adwebSites = adwebSiteService.getBaseMapper().selectList(adwebSiteQueryWrapper);
 
-        LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
-        adwebSiteQueryWrapper.like(AdwebSite::getDomain, apiRequest.getDomain());
-        List<AdwebSite> adwebSites =
-                adwebSiteService.getBaseMapper().selectList(adwebSiteQueryWrapper);
+    if (CollectionUtils.isNotEmpty(adwebSites)) {
+      LambdaQueryWrapper<AdwebProduct> adwebProductQueryWrapper = new LambdaQueryWrapper<>();
+      adwebProductQueryWrapper.eq(AdwebProduct::getSiteCode, adwebSites.get(0).getCode());
+      adwebProductQueryWrapper.ne(AdwebProduct::getActionType, "delete");
+      List<AdwebProduct> adwebProducts = adwebProductService.list(adwebProductQueryWrapper);
 
-        if (CollectionUtils.isNotEmpty(adwebSites)) {
-            LambdaQueryWrapper<AdwebProduct> adwebProductQueryWrapper = new LambdaQueryWrapper<>();
-            adwebProductQueryWrapper.eq(AdwebProduct::getSiteCode, adwebSites.get(0).getCode());
-            adwebProductQueryWrapper.ne(AdwebProduct::getActionType, "delete");
-            List<AdwebProduct> adwebProducts = adwebProductService.list(adwebProductQueryWrapper);
+      return Result.ok(adwebProducts.stream().map(ProductInfoVO::fromAdwebProduct).toList());
+    } else {
+      return Result.error("未找到该站点!");
+    }
+  }
+
+  /** 外部api请求获取询盘列表 */
+  @IgnoreAuth
+  @PostMapping("/enquiry/list")
+  @ResponseBody
+  public Result<EnquiryPageVO> listEnquires(
+      @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
+      @RequestBody APIRequestVO apiRequest) {
+    this.validateAuthToken(authToken);
+
+    log.info("苏豪通请求询盘列表 parameter: {}", apiRequest);
+
+    LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
+    adwebSiteQueryWrapper.like(AdwebSite::getDomain, apiRequest.getDomain());
+    List<AdwebSite> adwebSites = adwebSiteService.getBaseMapper().selectList(adwebSiteQueryWrapper);
+
+    EnquiryPageVO enquiryPage = new EnquiryPageVO();
+    if (CollectionUtils.isNotEmpty(adwebSites)) {
+      Page<AdwebEnquiry> page = new Page<>(apiRequest.getPageNo(), apiRequest.getPageSize());
+
+      LambdaQueryWrapper<AdwebEnquiry> enquiryQueryWrapper = new LambdaQueryWrapper<>();
+      enquiryQueryWrapper.eq(AdwebEnquiry::getSiteCode, adwebSites.get(0).getCode());
+      enquiryQueryWrapper.in(AdwebEnquiry::getUserEffective, "1", "2"); // 获取所有有效询盘
+      IPage<AdwebEnquiry> pageList = adwebEnquiryService.page(page, enquiryQueryWrapper);
+
+      if (pageList != null && CollectionUtils.isNotEmpty(pageList.getRecords())) {
+        // 复制属性到需要返回的新对象
+        List<EnquiryInfoVO> enquiryInfoVOS =
+            pageList.getRecords().stream().map(EnquiryInfoVO::fromAdwebEnquiry).toList();
+
+        enquiryPage.setPages(pageList.getPages());
+        enquiryPage.setSize(pageList.getSize());
+        enquiryPage.setCurrent(pageList.getCurrent());
+        enquiryPage.setTotal(pageList.getTotal());
+        enquiryPage.setRecords(enquiryInfoVOS);
+      }
+    } else {
+      return Result.error("未找到该站点!");
+    }
+
+    return Result.ok(enquiryPage);
+  }
+
+  @IgnoreAuth
+  @PostMapping("/product/getMaxDate")
+  @ResponseBody
+  public Result<?> getMaxDate(
+      @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
+      HttpServletRequest request) {
+    this.validateAuthToken(authToken);
 
-            return Result.ok(adwebProducts.stream().map(ProductInfoVO::fromAdwebProduct).toList());
-        } else {
-            return Result.error("未找到该站点!");
-        }
+    String domain = request.getParameter("siteHost");
+    if (domain == null) {
+      return Result.error("未传递合法的参数!");
     }
 
-    /** 外部api请求获取询盘列表 */
-    @IgnoreAuth
-    @PostMapping("/enquiry/list")
-    @ResponseBody
-    public Result<EnquiryPageVO> listEnquires(
-            @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
-            @RequestBody APIRequestVO apiRequest) {
-        this.validateAuthToken(authToken);
-
-        log.info("苏豪通请求询盘列表 parameter: {}", apiRequest);
-
-        LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
-        adwebSiteQueryWrapper.like(AdwebSite::getDomain, apiRequest.getDomain());
-        List<AdwebSite> adwebSites =
-                adwebSiteService.getBaseMapper().selectList(adwebSiteQueryWrapper);
-
-        EnquiryPageVO enquiryPage = new EnquiryPageVO();
-        if (CollectionUtils.isNotEmpty(adwebSites)) {
-            Page<AdwebEnquiry> page = new Page<>(apiRequest.getPageNo(), apiRequest.getPageSize());
-
-            LambdaQueryWrapper<AdwebEnquiry> enquiryQueryWrapper = new LambdaQueryWrapper<>();
-            enquiryQueryWrapper.eq(AdwebEnquiry::getSiteCode, adwebSites.get(0).getCode());
-            enquiryQueryWrapper.in(AdwebEnquiry::getUserEffective, "1", "2"); // 获取所有有效询盘
-            IPage<AdwebEnquiry> pageList = adwebEnquiryService.page(page, enquiryQueryWrapper);
-
-            if (pageList != null && CollectionUtils.isNotEmpty(pageList.getRecords())) {
-                // 复制属性到需要返回的新对象
-                List<EnquiryInfoVO> enquiryInfoVOS =
-                        pageList.getRecords().stream()
-                                .map(EnquiryInfoVO::fromAdwebEnquiry)
-                                .toList();
-
-                enquiryPage.setPages(pageList.getPages());
-                enquiryPage.setSize(pageList.getSize());
-                enquiryPage.setCurrent(pageList.getCurrent());
-                enquiryPage.setTotal(pageList.getTotal());
-                enquiryPage.setRecords(enquiryInfoVOS);
-            }
-        } else {
-            return Result.error("未找到该站点!");
-        }
-
-        return Result.ok(enquiryPage);
+    log.info("request from domain: {}", domain);
+    // 获取站点
+    LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
+    adwebSiteQueryWrapper.like(AdwebSite::getDomain, domain);
+    AdwebSite adwebsite = adwebSiteService.getOne(adwebSiteQueryWrapper);
+    if (adwebsite == null) {
+      return Result.error("该站点未绑定adweb3系统!");
+    }
+
+    String filterSiteCode = "site_code='%s'".formatted(adwebsite.getCode());
+
+    Date maxDate = commonMapper.getMaxDate("adweb_product", "request_time", filterSiteCode);
+    Long maxTime = null;
+    if (maxDate != null) {
+      maxTime = maxDate.getTime();
     }
 
-    @IgnoreAuth
-    @PostMapping("/product/getMaxDate")
-    @ResponseBody
-    public Result<?> getMaxDate(
-            @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
-            HttpServletRequest request) {
-        this.validateAuthToken(authToken);
-
-        String domain = request.getParameter("siteHost");
-        if (domain == null) {
-            return Result.error("未传递合法的参数!");
-        }
-
-        log.info("request from domain: {}", domain);
-        // 获取站点
-        LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
-        adwebSiteQueryWrapper.like(AdwebSite::getDomain, domain);
-        AdwebSite adwebsite = adwebSiteService.getOne(adwebSiteQueryWrapper);
-        if (adwebsite == null) {
-            return Result.error("该站点未绑定adweb3系统!");
-        }
-
-        String filterSiteCode = "site_code='%s'".formatted(adwebsite.getCode());
-
-        Date maxDate = commonMapper.getMaxDate("adweb_product", "request_time", filterSiteCode);
-        Long maxTime = null;
-        if (maxDate != null) {
-            maxTime = maxDate.getTime();
-        }
-
-        Map<String, Object> result = new HashMap<>();
-
-        result.put("maxTime", maxTime);
-        result.put(
-                "wordpress_setting",
-                adwebsite.getWordpressSetting()); // 指定wordpress 传输的产品类型是来自adwebpro还是woocommerce
-        return Result.ok(result);
+    Map<String, Object> result = new HashMap<>();
+
+    result.put("maxTime", maxTime);
+    result.put(
+        "wordpress_setting",
+        adwebsite.getWordpressSetting()); // 指定wordpress 传输的产品类型是来自adwebpro还是woocommerce
+    return Result.ok(result);
+  }
+
+  @IgnoreAuth
+  @PostMapping("/enquiry/getMaxDate")
+  @ResponseBody
+  public Result<?> getEnquiryMaxDate(
+      @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
+      HttpServletRequest request) {
+    this.validateAuthToken(authToken);
+
+    String domain = request.getParameter("siteHost");
+    if (domain == null) {
+      return Result.error("未传递合法的参数!");
     }
 
-    @IgnoreAuth
-    @PostMapping("/enquiry/getMaxDate")
-    @ResponseBody
-    public Result<?> getEnquiryMaxDate(
-            @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
-            HttpServletRequest request) {
-        this.validateAuthToken(authToken);
-
-        String domain = request.getParameter("siteHost");
-        if (domain == null) {
-            return Result.error("未传递合法的参数!");
-        }
-
-        log.info("EnquiryMaxDate request from domain: {}", domain);
-        // 获取站点
-        LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
-        adwebSiteQueryWrapper.like(AdwebSite::getDomain, domain);
-        AdwebSite adwebsite = adwebSiteService.getOne(adwebSiteQueryWrapper);
-        if (adwebsite == null) {
-            return Result.error("该站点未绑定adweb3系统!");
-        }
-
-        String filterSiteCode = "site_code='%s'".formatted(adwebsite.getCode());
-
-        Date maxDate = commonMapper.getMaxDate("adweb_enquiry", "record_ctime", filterSiteCode);
-        Long maxTime = null;
-        if (maxDate != null) {
-            maxTime = maxDate.getTime();
-        }
-
-        Map<String, Object> result = new HashMap<>();
-
-        result.put("maxTime", maxTime);
-
-        return Result.ok(result);
+    log.info("EnquiryMaxDate request from domain: {}", domain);
+    // 获取站点
+    LambdaQueryWrapper<AdwebSite> adwebSiteQueryWrapper = new LambdaQueryWrapper<>();
+    adwebSiteQueryWrapper.like(AdwebSite::getDomain, domain);
+    AdwebSite adwebsite = adwebSiteService.getOne(adwebSiteQueryWrapper);
+    if (adwebsite == null) {
+      return Result.error("该站点未绑定adweb3系统!");
     }
 
-    private boolean validateAuthToken(String authToken) {
-        if (!StringUtils.equals(STATIC_BEARER_TOKEN, authToken)) {
-            throw new InvalidBearerTokenException("Bearer toke is invalid: " + authToken);
-        }
-        return true;
+    String filterSiteCode =
+        "site_code='%s'".formatted(adwebsite.getCode()) + "AND plugin_name='wpforms'";
+
+    Date maxDate = commonMapper.getMaxDate("adweb_enquiry", "record_ctime", filterSiteCode);
+    Long maxTime = null;
+    if (maxDate != null) {
+      maxTime = maxDate.getTime();
+    }
+
+    Map<String, Object> result = new HashMap<>();
+
+    result.put("maxTime", maxTime);
+
+    return Result.ok(result);
+  }
+
+  private boolean validateAuthToken(String authToken) {
+    if (!StringUtils.equals(STATIC_BEARER_TOKEN, authToken)) {
+      throw new InvalidBearerTokenException("Bearer toke is invalid: " + authToken);
     }
+    return true;
+  }
 }

+ 7 - 5
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/controller/AdwebEnquiryController.java

@@ -280,7 +280,7 @@ public class AdwebEnquiryController extends JeecgController<AdwebEnquiry, IAdweb
   @Operation(summary = "询盘信息存储表单-添加")
   @PostMapping(value = "/add")
   public Result<String> add(@RequestBody EnquiryForm enquiryForm) {
-    String defaultPlugin = "wpforms";
+    String defaultPlugin = "adweb3";
 
     if (StringUtils.isBlank(enquiryForm.getSiteCode())) {
       return Result.error("当前未选择站点");
@@ -836,20 +836,22 @@ public class AdwebEnquiryController extends JeecgController<AdwebEnquiry, IAdweb
       return Result.error("当前站点不存在");
     }
 
+    AdwebSite adwebSite = siteList.get(0);
+
     String jsonString =
         "{\"1\":{\"name\":\"Name\",\"value\":\"chen peiqing\",\"id\":1,\"type\":\"text\"},\"2\":{\"name\":\"Email\",\"value\":\"chenpeiqing.1393599253@live.com\",\"id\":2,\"type\":\"email\"},\"3\":{\"name\":\"Phone\",\"value\":\"13223012703\",\"id\":3,\"type\":\"phone\"},\"4\":{\"name\":\"Message\",\"value\":\"tets\",\"id\":4,\"type\":\"textarea\"},\"5\":{\"name\":\"Customer IP\",\"value\":\"::1\",\"id\":5,\"type\":\"hidden\"},\"6\":{\"name\":\"From Page\",\"value\":\"http:\\/\\/wp063.cpq\\/products\\/occupancy-product-3\\/\",\"id\":6,\"type\":\"hidden\"}}";
 
     JSONObject object = FastJsonUtil.parseObject(jsonString, JSONObject.class);
     EnquiryDTO adwebEnquiry = new EnquiryDTO();
     adwebEnquiry.setForms(object);
-    adwebEnquiry.setFromEmail("chenpeiqing.1393599253@dfd.com");
+    adwebEnquiry.setFromEmail("chenpeiqing.1393599253@live.com");
     adwebEnquiry.setFromIp("107.182.184.127");
     adwebEnquiry.setPluginName("wpforms");
-    adwebEnquiry.setSiteHost("20250219i96eui.v3-site.adwebcloud.com");
-    adwebEnquiry.setRecordCtime(new Date("Tue Feb 25 03:31:37 UTC 2025"));
+    adwebEnquiry.setSiteHost(adwebSite.getDomain().replace("https://", ""));
+    adwebEnquiry.setRecordCtime(new Date());
     adwebEnquiry.setRecordId(siteRecodeId);
     // 模拟mq推送询盘
-    adwebEnquiryService.addEnquiry(adwebEnquiry, adwebEnquiry.getPluginName(), siteList.get(0));
+    adwebEnquiryService.addEnquiry(adwebEnquiry, adwebEnquiry.getPluginName(), adwebSite);
 
     return Result.OK(true);
   }

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

@@ -323,44 +323,47 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
 
     AdwebEnquiry target = adwebEnquiryList.get(0);
 
-    // 获取最近一周的询盘数量,根据域名和record id 生成唯一标识,存入redis,用来过滤之后的询盘mq,防止重复消费
-    // 记录开始时间
-    long startTime = System.currentTimeMillis();
-    String EnquiryRedisUniqueKey = EnquiryUniqueKey + target.getSiteHost();
+    // 管理控制后台添加假询盘时,不做唯一性条件录入
+    if (!"adweb3".equalsIgnoreCase(plugin)) {
+      // 获取最近一周的询盘数量,根据域名和record id 生成唯一标识,存入redis,用来过滤之后的询盘mq,防止重复消费
+      // 记录开始时间
+      long startTime = System.currentTimeMillis();
+      String EnquiryRedisUniqueKey = EnquiryUniqueKey + target.getSiteHost();
 
-    if (adwebRedisUtil.hasKey(EnquiryRedisUniqueKey)) {
-      List<String> enquiryUniqueIds = getListFromRedis(EnquiryRedisUniqueKey);
+      if (adwebRedisUtil.hasKey(EnquiryRedisUniqueKey)) {
+        List<String> enquiryUniqueIds = getListFromRedis(EnquiryRedisUniqueKey);
 
-      // 防止redis 唯一键存储过大,并始终更新
-      enquiryUniqueIds.remove(enquiryUniqueIds.size() - 1); // 移除第一个唯一键
-      enquiryUniqueIds.add(target.getSiteHost() + target.getRecordId()); // 添加最新的唯一键
-
-      adwebRedisUtil.set(EnquiryRedisUniqueKey, 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())
-                .collect(Collectors.toList());
+        // 防止redis 唯一键存储过大,并始终更新
+        enquiryUniqueIds.remove(enquiryUniqueIds.size() - 1); // 移除第一个唯一键
+        enquiryUniqueIds.add(target.getSiteHost() + target.getRecordId()); // 添加最新的唯一键
 
         adwebRedisUtil.set(EnquiryRedisUniqueKey, 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())
+                  .collect(Collectors.toList());
+
+          adwebRedisUtil.set(EnquiryRedisUniqueKey, enquiryUniqueIds, 60 * 60 * 24);
+        }
       }
+      // 记录结束时间
+      long endTime = System.currentTimeMillis();
+      log.info(
+          "站点:{},询盘ID:{} 唯一性条件处理耗时:{} ms",
+          enquiryDto.getSiteHost(),
+          enquiryDto.getRecordId(),
+          endTime - startTime);
     }
-    // 记录结束时间
-    long endTime = System.currentTimeMillis();
-    log.info(
-        "站点:{},询盘ID:{} 唯一性条件处理耗时:{} ms",
-        enquiryDto.getSiteHost(),
-        enquiryDto.getRecordId(),
-        endTime - startTime);
 
     try {
       this.save(target);