Jelajahi Sumber

Merge remote-tracking branch 'origin/master' into master

zxf 12 jam lalu
induk
melakukan
002aa2f48f

+ 16 - 0
jd-logistics-api/jd-logistics-api-system/src/main/java/com/ruoyi/system/api/RemoteMonthQRCodeConsumeService.java

@@ -0,0 +1,16 @@
+package com.ruoyi.system.api;
+import com.ruoyi.common.core.constant.ServiceNameConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.Map;
+
+@FeignClient(contextId = "remoteMonthQRCodeConsumeService", value = ServiceNameConstants.SYSTEM_SERVICE)
+public interface RemoteMonthQRCodeConsumeService {
+
+    @PostMapping("/front/qrcode/consume")
+    public R<String> consume();
+}

+ 17 - 0
jd-logistics-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java

@@ -188,4 +188,21 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+
+    /**
+     * 计算开始时间和结束时间相差的分钟数
+     * 
+     * @param startDate 开始时间
+     * @param endDate 结束时间
+     * @return 相差的分钟数
+     */
+    public static long differentMinutes(Date startDate, Date endDate)
+    {
+        if (startDate == null || endDate == null)
+        {
+            throw new IllegalArgumentException("开始时间和结束时间不能为空");
+        }
+        long diffInMillis = Math.abs(endDate.getTime() - startDate.getTime());
+        return diffInMillis / (1000 * 60);
+    }
 }

+ 23 - 0
jd-logistics-modules/jd-logistics-job/src/main/java/com/ruoyi/job/task/MonthQRCodeConsumeTask.java

@@ -0,0 +1,23 @@
+package com.ruoyi.job.task;
+
+import com.ruoyi.system.api.RemoteMonthQRCodeConsumeService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 二维码消费查询定时任务
+ */
+@Slf4j
+@Component("monthQRCodeConsumeTask")
+public class MonthQRCodeConsumeTask {
+
+    @Autowired
+    private RemoteMonthQRCodeConsumeService remoteMonthQRCodeConsumeService;
+
+    public void doTask() {
+        log.info("二维码消费查询定时任务开始");
+        remoteMonthQRCodeConsumeService.consume();
+        log.info("二维码消费查询定时任务结束");
+    }
+}

+ 9 - 10
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/front/controller/MonthQRCodeController.java

@@ -1,19 +1,18 @@
 package com.ruoyi.front.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderByMonthSettleQRV1.CommonMonthSettleQRQueryResponse;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.security.annotation.InnerAuth;
-import com.ruoyi.logistics.domain.BizWaybillOrder;
-import com.ruoyi.logistics.response.CommonOrderInfoResponse;
 import com.ruoyi.logistics.service.IMonthQRCodeTaskService;
 import com.ruoyi.logistics.service.LogisticsOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * WX-月结二维码生成
@@ -22,7 +21,7 @@ import org.springframework.web.bind.annotation.*;
  * @date 2026-02-04
  */
 @RestController
-@RequestMapping("/callback/qrcode")
+@RequestMapping("/front/qrcode")
 public class MonthQRCodeController extends BaseController {
 
     @Autowired
@@ -34,14 +33,14 @@ public class MonthQRCodeController extends BaseController {
     @RequestMapping
     public AjaxResult qrcode(@RequestParam("source") Integer source, @RequestParam("waybillCode") String waybillCode) {
         try{
-//            JSONObject jsonObject = logisticsOrderService.getQRCode(source);
+            JSONObject jsonObject = logisticsOrderService.getQRCode(source);
 //            JSONObject jsonObject = logisticsOrderService.queryOrderDetailByWaybillCode(source, waybillCode);
-            JSONObject jsonObject = logisticsOrderService.queryOrderByQRCode(source, waybillCode);
+//            JSONObject jsonObject = logisticsOrderService.queryOrderByQRCode(source, waybillCode);
 
 
-            CommonMonthSettleQRQueryResponse response = (CommonMonthSettleQRQueryResponse) jsonObject.get("msg");
+//            CommonMonthSettleQRQueryResponse response = (CommonMonthSettleQRQueryResponse) jsonObject.get("msg");
             // 返回完整的二维码信息,包括图片数据
-            return AjaxResult.success(response);
+            return AjaxResult.success(jsonObject);
         } catch (ServiceException e) {
             return AjaxResult.error("获取二维码失败! 原因:"+e.getMessage());
         } catch (Exception e) {

+ 33 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/dto/MonthQRCodeDTO.java

@@ -2,16 +2,49 @@ package com.ruoyi.logistics.dto;
 
 import lombok.Data;
 
+import java.util.Date;
+import java.util.List;
+
 @Data
 public class MonthQRCodeDTO {
 
+    /**
+     * 二维码ID
+     */
     private Long qrcodeId;
 
+    /**
+     * 二维码内容
+     */
     private String qrCodeContent;
 
+    /**
+     * 用户ID
+     */
     private Long userId;
 
+    /**
+     * 供应商ID
+     */
     private Long deptId;
 
+    /**
+     * 二维码来源
+     */
     private Integer source;
+
+    /**
+     * 已处理运单号
+     */
+    private List<String> processWaybillCodes;
+
+    /**
+     * 二维码处理次数
+     */
+    private Integer processNum;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
 }

+ 88 - 51
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/MonthQRCodeTaskServiceImpl.java

@@ -5,7 +5,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetActualFeeInfoV1.CommonActualFeeInfoDetailResponse;
 import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetActualFeeInfoV1.CommonActualFeeResponse;
 import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderByMonthSettleQRV1.CommonMonthSettleQRQueryResponse;
+import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderByMonthSettleQRV1.WaybillQRVerifyInfo;
 import com.lop.open.api.sdk.domain.ECAP.CommonQueryOrderApi.commonGetOrderInfoV1.addedProducts;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.redis.service.RedisIdGenerator;
@@ -20,7 +22,9 @@ import com.ruoyi.logistics.mapper.BizWaybillOrderMapper;
 import com.ruoyi.logistics.response.CommonOrderInfoResponse;
 import com.ruoyi.logistics.service.*;
 import com.ruoyi.system.api.domain.SysDept;
+import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.system.mapper.SysUserMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -52,6 +56,9 @@ public class MonthQRCodeTaskServiceImpl implements IMonthQRCodeTaskService {
     @Autowired
     private SysDeptMapper sysDeptMapper;
 
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
 
     @Autowired
     private RedisIdGenerator redisIdGenerator;
@@ -59,74 +66,104 @@ public class MonthQRCodeTaskServiceImpl implements IMonthQRCodeTaskService {
     @Override
     public void consumeQRCode() {
         Collection<String> keys = redisService.keys(RedisCacheConstants.MONTH_QRCODE_CACHE_KEY + "*");
+        if (keys == null || keys.size() == 0) {
+            return;
+        }
 
-        keys.forEach(key -> {
+        for (String key : keys) {
             MonthQRCodeDTO monthQRCodeDTO = redisService.getCacheObject(key);
+            if (DateUtils.differentMinutes(monthQRCodeDTO.getCreateTime(), DateUtils.getNowDate()) < 5) {
+                continue;
+            }
 
+            SysUser sysUser = sysUserMapper.selectUserById(monthQRCodeDTO.getUserId());
             SysDept sysDept = sysDeptMapper.selectDeptById(monthQRCodeDTO.getDeptId());
 
-            JSONObject waybillCode = logisticsOrderService.queryOrderByQRCode(1, monthQRCodeDTO.getQrCodeContent());
-
-            CommonMonthSettleQRQueryResponse response = JSON.parseObject(waybillCode.getString("msg"), CommonMonthSettleQRQueryResponse.class);
-
-            if (response.getWaybillQRVerifyInfoList() != null && response.getWaybillQRVerifyInfoList().size() > 0) {
-                log.info("用户:{} 扫描了二维码:{}", monthQRCodeDTO.getUserId(), monthQRCodeDTO.getQrCodeContent());
-
-                response.getWaybillQRVerifyInfoList().forEach(waybillQRVerifyInfo -> {
-                    JSONObject orderDetail = logisticsOrderService.queryOrderDetailByWaybillCode(1, waybillQRVerifyInfo.getWaybillCode());
-                    JSONObject orderFeeInfo = logisticsOrderService.queryOrderFeeInfoByWaybillCode(1, waybillQRVerifyInfo.getWaybillCode());
-
-                    CommonOrderInfoResponse orderInfo = (CommonOrderInfoResponse) orderDetail.get("msg");
-                    CommonActualFeeResponse actualFee = JSON.parseObject(orderFeeInfo.getString("msg"), CommonActualFeeResponse.class);
+            if (1 == monthQRCodeDTO.getSource()) {
+                this.jdQRCodeConsume(monthQRCodeDTO, sysUser, sysDept, key);
+            }
+        }
+    }
 
-                    BizWaybillOrder bizWaybillOrder = new BizWaybillOrder();
-                    bizWaybillOrder.setWaybillNo(redisIdGenerator.generateUniqueId("RJSD"));
-                    bizWaybillOrder.setExternalWaybillNo(orderInfo.getWaybillCode());
-                    bizWaybillOrder.setOrderType(1);
+    private void jdQRCodeConsume(MonthQRCodeDTO monthQRCodeDTO, SysUser sysUser, SysDept sysDept, String key) {
+        JSONObject waybillCode = logisticsOrderService.queryOrderByQRCode(1, monthQRCodeDTO.getQrCodeContent());
+        if(!waybillCode.getBooleanValue("success")){
+            log.info("根据二维码查询运单号失败{}", waybillCode.getString("msg"));
+            return;
+        }
+
+        CommonMonthSettleQRQueryResponse response = JSON.parseObject(waybillCode.getString("msg"), CommonMonthSettleQRQueryResponse.class);
+
+        if (response.getWaybillQRVerifyInfoList() != null && response.getWaybillQRVerifyInfoList().size() > 0) {
+
+            for (WaybillQRVerifyInfo waybillQRVerifyInfo : response.getWaybillQRVerifyInfoList()) {
+                // 判断订单是否已经处理过
+                if (monthQRCodeDTO.getProcessWaybillCodes().contains(waybillQRVerifyInfo.getWaybillCode())) {
+                    continue;
+                }
+                monthQRCodeDTO.getProcessWaybillCodes().add(waybillQRVerifyInfo.getWaybillCode());
+
+                JSONObject orderDetail = logisticsOrderService.queryOrderDetailByWaybillCode(1, waybillQRVerifyInfo.getWaybillCode());
+                if(!waybillCode.getBooleanValue("success")){
+                    log.info("根据运单号查询运单详情失败{}", waybillCode.getString("msg"));
+                    continue;
+                }
+                JSONObject orderFeeInfo = logisticsOrderService.queryOrderFeeInfoByWaybillCode(1, waybillQRVerifyInfo.getWaybillCode());
+                if(!waybillCode.getBooleanValue("success")){
+                    log.info("根据运单号查询运单费用失败{}", waybillCode.getString("msg"));
+                    continue;
+                }
+
+                CommonOrderInfoResponse orderInfo = (CommonOrderInfoResponse) orderDetail.get("msg");
+                CommonActualFeeResponse actualFee = JSON.parseObject(orderFeeInfo.getString("msg"), CommonActualFeeResponse.class);
+
+                BizWaybillOrder bizWaybillOrder = new BizWaybillOrder();
+                bizWaybillOrder.setWaybillNo(redisIdGenerator.generateUniqueId("RJSD"));
+                bizWaybillOrder.setExternalWaybillNo(orderInfo.getWaybillCode());
+                bizWaybillOrder.setOrderType(1);
 //                    bizWaybillOrder.setSenderName(orderInfo.gets());
 //                    bizWaybillOrder.setSenderPhone(orderInfo.getSenderPhone());
-                    bizWaybillOrder.setSenderProvince(orderInfo.getSenderContact().getProvince());
-                    bizWaybillOrder.setSenderCity(orderInfo.getSenderContact().getCity());
-                    bizWaybillOrder.setSenderCounty(orderInfo.getSenderContact().getCounty());
-                    bizWaybillOrder.setSenderAddress(orderInfo.getSenderContact().getTown());
-//                    bizWaybillOrder.setReceiverName(orderInfo.getReceiverName());
-//                    bizWaybillOrder.setReceiverPhone(orderInfo.getReceiverPhone());
-                    bizWaybillOrder.setReceiverProvince(orderInfo.getReceiverContact().getProvince());
-                    bizWaybillOrder.setReceiverCity(orderInfo.getReceiverContact().getCity());
-                    bizWaybillOrder.setReceiverCounty(orderInfo.getReceiverContact().getCounty());
-                    bizWaybillOrder.setReceiverAddress(orderInfo.getReceiverContact().getTown());
-                    bizWaybillOrder.setGoodsName(orderInfo.getCargoes().get(0).getName());
-                    bizWaybillOrder.setGoodsWeight(new BigDecimal(orderInfo.getCargoes().get(0).getWeight()));
-                    bizWaybillOrder.setGoodsVolume(new BigDecimal(orderInfo.getCargoes().get(0).getVolume()));
-                    bizWaybillOrder.setGoodsQty(orderInfo.getCargoes().get(0).getQuantity().longValue());
-                    bizWaybillOrder.setOrderStatus(1);
-                    bizWaybillOrder.setPickupType(1);
-                    bizWaybillOrder.setSendStartTime(new Date(orderInfo.getShipmentInfo().getPickupStartTime()));
-                    bizWaybillOrder.setSendEndTime(new Date(orderInfo.getShipmentInfo().getPickupEndTime()));
+                bizWaybillOrder.setSenderProvince(orderInfo.getSenderContact().getProvince());
+                bizWaybillOrder.setSenderCity(orderInfo.getSenderContact().getCity());
+                bizWaybillOrder.setSenderCounty(orderInfo.getSenderContact().getCounty());
+                bizWaybillOrder.setSenderAddress(orderInfo.getSenderContact().getTown());
+                bizWaybillOrder.setReceiverName(sysUser.getNickName());
+                bizWaybillOrder.setReceiverPhone(sysUser.getPhonenumber());
+                bizWaybillOrder.setReceiverProvince(orderInfo.getReceiverContact().getProvince());
+                bizWaybillOrder.setReceiverCity(orderInfo.getReceiverContact().getCity());
+                bizWaybillOrder.setReceiverCounty(orderInfo.getReceiverContact().getCounty());
+                bizWaybillOrder.setReceiverAddress(orderInfo.getReceiverContact().getTown());
+                bizWaybillOrder.setGoodsName(orderInfo.getCargoes().get(0).getName());
+                bizWaybillOrder.setGoodsWeight(new BigDecimal(orderInfo.getCargoes().get(0).getWeight()));
+                bizWaybillOrder.setGoodsVolume(new BigDecimal(orderInfo.getCargoes().get(0).getVolume()));
+                bizWaybillOrder.setGoodsQty(orderInfo.getCargoes().get(0).getQuantity().longValue());
+                bizWaybillOrder.setOrderStatus(6);
+                bizWaybillOrder.setPickupType(orderInfo.getShipmentInfo().getPickupType());
+                bizWaybillOrder.setSendStartTime(new Date(orderInfo.getShipmentInfo().getPickupStartTime()));
+                bizWaybillOrder.setSendEndTime(new Date(orderInfo.getShipmentInfo().getPickupEndTime()));
 //                    bizWaybillOrder.setPickupTime(new Date(orderInfo.getShipmentInfo().geta()));
 //                    bizWaybillOrder.setDeliveryTime(waybillQRVerifyInfo.getDeliveryTime());
 //                    bizWaybillOrder.setSignTime(waybillQRVerifyInfo.getSignTime());
-                    bizWaybillOrder.setProductCode(orderInfo.getProducts().getProductCode());
-                    bizWaybillOrder.setAddedService(assembleAddedService(orderInfo.getProducts().getAddedProducts()));
-                    bizWaybillOrder.setCreateTime(DateUtils.getNowDate());
-                    bizWaybillOrder.setUserId(monthQRCodeDTO.getUserId());
-                    bizWaybillOrder.setDeptId(monthQRCodeDTO.getDeptId());
+                bizWaybillOrder.setProductCode(orderInfo.getProducts().getProductCode());
+                bizWaybillOrder.setAddedService(assembleJDAddedService(orderInfo.getProducts().getAddedProducts()));
+                bizWaybillOrder.setCreateTime(DateUtils.getNowDate());
+                bizWaybillOrder.setUserId(monthQRCodeDTO.getUserId());
+                bizWaybillOrder.setDeptId(monthQRCodeDTO.getDeptId());
 
-                    bizWaybillOrderMapper.insertBizWaybillOrder(bizWaybillOrder);
+                bizWaybillOrderMapper.insertBizWaybillOrder(bizWaybillOrder);
 
-                    List<BizWaybillCostDetails> details = assembleCostDetails(sysDept, bizWaybillOrder, actualFee.getCommonActualFeeInfoDetails());
+                List<BizWaybillCostDetails> details = assembleJDCostDetails(sysDept, bizWaybillOrder, actualFee.getCommonActualFeeInfoDetails());
 
-                    details.forEach(detail -> {
-                        bizWaybillCostDetailsMapper.insertBizWaybillCostDetails(detail);
-                    });
+                details.forEach(detail -> {
+                    bizWaybillCostDetailsMapper.insertBizWaybillCostDetails(detail);
                 });
-
-
             }
-        });
+
+            redisService.setCacheObject(key, monthQRCodeDTO);
+        }
     }
 
-    private List<BizWaybillCostDetails> assembleCostDetails(SysDept sysDept, BizWaybillOrder bizWaybillOrder, List<CommonActualFeeInfoDetailResponse> commonActualFeeInfoDetails) {
+    private List<BizWaybillCostDetails> assembleJDCostDetails(SysDept sysDept, BizWaybillOrder bizWaybillOrder, List<CommonActualFeeInfoDetailResponse> commonActualFeeInfoDetails) {
         List<BizWaybillCostDetails> details = new ArrayList<>();
         commonActualFeeInfoDetails.forEach(item -> {
             BizWaybillCostDetails costDetail = new BizWaybillCostDetails();
@@ -150,7 +187,7 @@ public class MonthQRCodeTaskServiceImpl implements IMonthQRCodeTaskService {
         return details;
     }
 
-    private String assembleAddedService(List<addedProducts> addedProducts) {
+    private String assembleJDAddedService(List<addedProducts> addedProducts) {
         JSONObject addedService = new JSONObject();
 
         addedService.put("isPack", null);