xw 1 неделя назад
Родитель
Сommit
09d34b3ee8

+ 10 - 7
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreHealthOrderScrmController.java

@@ -438,7 +438,7 @@ public class FsStoreHealthOrderScrmController extends BaseController {
     //订单发货批量导入
     @Log(title = "发货同步导入", businessType = BusinessType.IMPORT)
     @PostMapping("/importDeliveryNoteExpress")
-    public R importDeliveryNoteExpress(@RequestParam("file") MultipartFile file,@RequestParam("miniAppId") String miniAppId,@RequestParam(name = "shipmentType",required = false) Integer shipmentType) {
+    public R importDeliveryNoteExpress(@RequestParam("file") MultipartFile file,@RequestParam(name = "shipmentType",required = false) Integer shipmentType) {
         // 1. 检查文件是否为空
         if (file.isEmpty()) {
             return R.error("上传的文件不能为空");
@@ -465,7 +465,7 @@ public class FsStoreHealthOrderScrmController extends BaseController {
             if(shipmentType == null){
                 shipmentType = 2;
             }
-            return fsStoreOrderService.importDeliveryNoteExpress(dtoList,miniAppId,shipmentType);
+            return fsStoreOrderService.importDeliveryNoteExpress(dtoList,null,shipmentType);
         }catch (Exception e){
             logger.error("发货导入异常", e);
             return R.error("导入失败:" + e.getMessage());
@@ -506,11 +506,14 @@ public class FsStoreHealthOrderScrmController extends BaseController {
         param.setIsHealth("1");
         List<FsStoreOrderDeliveryNoteExportVO> storeOrderDeliveryNoteExportVOList=fsStoreOrderService.getDeliveryNote(param);
         ExcelUtil<FsStoreOrderDeliveryNoteExportVO> util = new ExcelUtil<>(FsStoreOrderDeliveryNoteExportVO.class);
-        //通过商品ID获取关键字
-        String firstKeyword = storeOrderDeliveryNoteExportVOList.stream()
-                .map(FsStoreOrderDeliveryNoteExportVO::getKeyword)
-                .findFirst()
-                .orElse("无订单");
+        //通过商品ID获取关键字,安全处理空列表和null keyword的情况
+        String firstKeyword = "无订单";
+        if (!storeOrderDeliveryNoteExportVOList.isEmpty()) {
+            FsStoreOrderDeliveryNoteExportVO firstItem = storeOrderDeliveryNoteExportVOList.get(0);
+            if (firstItem != null && firstItem.getKeyword() != null && !firstItem.getKeyword().isEmpty()) {
+                firstKeyword = firstItem.getKeyword();
+            }
+        }
         String fileName="077AC"+firstKeyword+new SimpleDateFormat("yyyyMMdd").format(new Date());
         return util.exportExcel(storeOrderDeliveryNoteExportVOList, fileName);
     }

+ 2 - 1
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreOrderScrmService.java

@@ -294,7 +294,8 @@ public interface IFsStoreOrderScrmService
     /**
      * 批量导入更新微信订单发货状态
      * @param voList 订单数据
-     * @param appId 小程序ID
+     * @param appId 小程序ID(自动从订单支付记录中获取)
+     * @param shipmentType 发货类型
      * **/
     R importDeliveryNoteExpress(List<FsStoreOrderDeliveryNoteExportVO> voList,String appId,Integer shipmentType);
 

+ 45 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -4229,7 +4229,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 FsStoreOrderDeliveryNoteExportVO vo = voList.get(i);
                 FsOrderDeliveryNoteDTO dto = new FsOrderDeliveryNoteDTO();
                 int rowNum = i + 2;
-                
+
                 // 基础字段校验
                 if (StringUtils.isEmpty(vo.getOrderNumber())) {
                     result.addFailure(rowNum, "", vo.getDeliveryId(), "系统订单号为空");
@@ -4243,7 +4243,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                     result.addFailure(rowNum, vo.getOrderNumber(), "", "快递单号为空");
                     continue;
                 }
-                
+
                 //处理订单ID信息
                 String originalOrderNumber = vo.getOrderNumber();
                 String processedOrderNumber = extractNumbers(originalOrderNumber);
@@ -4299,6 +4299,30 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         .computeIfAbsent(vo.getId(), k -> new ArrayList<>())
                         .add(vo);
             }
+
+            // 自动从支付记录中获取appId
+            if (appId == null || appId.isEmpty()) {
+                // 从第一个订单的支付记录中获取appId
+                if (!orderCodeOpenIdVoList.isEmpty()) {
+                    FsStoreOrderCodeOpenIdVo firstOrder = orderCodeOpenIdVoList.get(0);
+                    // 通过订单号查询订单ID
+                    FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(firstOrder.getOrderCode());
+                    if (order != null) {
+                        // 查询订单的支付记录
+                        List<FsStorePaymentScrm> paymentList = fsStorePaymentMapper.selectFsStorePaymentByOrderId(order.getId());
+                        if (!paymentList.isEmpty() && paymentList.get(0).getAppId() != null) {
+                            appId = paymentList.get(0).getAppId();
+                            log.info("自动从订单支付记录中获取到appId: {}", appId);
+                        }
+                    }
+                }
+
+                // 如果还是没有获取到appId,返回错误
+                if (appId == null || appId.isEmpty()) {
+                    return R.error("无法获取订单对应的小程序appId,请确保订单已支付");
+                }
+            }
+
             final WxMaService wxService = WxMaConfiguration.getMaService(appId);
             String uploadTime = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"))
                     .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
@@ -5341,6 +5365,25 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         .computeIfAbsent(vo.getId(), k -> new ArrayList<>())
                         .add(vo);
             }
+
+            if (appId == null || appId.isEmpty()) {
+                if (!orderCodeOpenIdVoList.isEmpty()) {
+                    FsStoreOrderCodeOpenIdVo firstOrder = orderCodeOpenIdVoList.get(0);
+                    FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(firstOrder.getId());
+                    if (order != null) {
+                        List<FsStorePaymentScrm> paymentList = fsStorePaymentMapper.selectFsStorePaymentByOrderId(order.getId());
+                        if (!paymentList.isEmpty() && paymentList.get(0).getAppId() != null) {
+                            appId = paymentList.get(0).getAppId();
+                            log.info("自动从订单支付记录中获取到appId: {}", appId);
+                        }
+                    }
+                }
+
+                if (appId == null || appId.isEmpty()) {
+                    return R.error("无法获取订单对应的小程序appId,请确保订单已支付");
+                }
+            }
+
             final WxMaService wxService = WxMaConfiguration.getMaService(appId);
             String uploadTime = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"))
                     .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);

+ 4 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreOrderCodeOpenIdVo.java

@@ -35,4 +35,8 @@ public class FsStoreOrderCodeOpenIdVo implements Serializable {
      * 交易单号
      * **/
     private String outTransId;
+    /**
+     * 订单号
+     * **/
+    private String orderCode;
 }

+ 10 - 3
fs-service/src/main/resources/mapper/hisStore/FsStoreOrderScrmMapper.xml

@@ -956,7 +956,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fu.phone,
         fu.ma_open_id openId,
         ois.json_info,
-        sps.bank_transaction_id outTransId
+        sps.bank_transaction_id outTransId,
+        os.order_code
         FROM
         fs_store_order_scrm os
         INNER JOIN fs_user fu ON os.user_id = fu.user_id
@@ -2046,6 +2047,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="maps.isUpload != null and maps.isUpload == 1">
             AND o.certificates IS NOT NULL
         </if>
+        <if test="maps.appId != null and maps.appId != ''">
+            AND u.app_id LIKE CONCAT('%', #{maps.appId}, '%')
+        </if>
         ${maps.params.dataScope}
         AND o.paid = 1
         GROUP BY o.id
@@ -2062,7 +2066,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND o.paid = 1
           AND o.is_del = 0
     </select>
-    
+
     <!-- 根据商品ID查询用户已购买数量(不区分规格) -->
     <select id="selectUserPurchasedCountByProductId" resultType="java.lang.Integer">
         SELECT IFNULL(SUM(oi.num), 0)
@@ -2074,7 +2078,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND o.paid = 1
           AND o.is_del = 0
     </select>
-    
+
     <select id="selectFsStoreOrderAmountScrmStats" resultType="com.fs.his.vo.FsStoreOrderAmountScrmStatsVo">
         SELECT
         COUNT(*) AS totalOrderCount,
@@ -2223,6 +2227,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="maps.isUpload != null and maps.isUpload == 1">
             AND o.certificates IS NOT NULL
         </if>
+        <if test="maps.appId != null and maps.appId != ''">
+            AND u.app_id LIKE CONCAT('%', #{maps.appId}, '%')
+        </if>
         ${maps.params.dataScope}
         AND o.paid = 1
         GROUP BY o.id