Procházet zdrojové kódy

导出数据问题调整

yfh před 3 týdny
rodič
revize
c67f7d09b1

+ 11 - 20
fs-company/src/main/java/com/fs/hisStore/controller/FsIntegralOrderController.java

@@ -1,6 +1,9 @@
 package com.fs.hisStore.controller;
 
+import cn.hutool.core.lang.TypeReference;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
@@ -10,9 +13,11 @@ import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.his.domain.FsIntegralGoods;
 import com.fs.his.domain.FsIntegralOrder;
 import com.fs.his.dto.ExpressInfoDTO;
 import com.fs.his.enums.ShipperCodeEnum;
+import com.fs.his.mapper.FsIntegralGoodsMapper;
 import com.fs.his.param.FsIntegralOrderCreateParam;
 import com.fs.his.param.FsIntegralOrderParam;
 import com.fs.his.service.IFsExpressService;
@@ -26,7 +31,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.List;
+import java.util.*;
 
 import static com.fs.his.utils.PhoneUtil.decryptAutoPhoneMk;
 import static com.fs.his.utils.PhoneUtil.decryptPhone;
@@ -45,6 +50,9 @@ public class FsIntegralOrderController extends BaseController
     private IFsIntegralOrderService fsIntegralOrderService;
     @Autowired
     private IFsExpressService expressService;
+
+    @Autowired
+    private FsIntegralGoodsMapper fsIntegralGoodsMapper;
     /**
      * 查询积分商品订单列表
      */
@@ -66,25 +74,8 @@ public class FsIntegralOrderController extends BaseController
     @PreAuthorize("@ss.hasPermi('his:integralOrder:export')")
     @Log(title = "积分商品订单", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
-    public AjaxResult export(FsIntegralOrder fsIntegralOrder)
-    {
-        List<FsIntegralOrder> list = fsIntegralOrderService.selectFsIntegralOrderList(fsIntegralOrder);
-        for (FsIntegralOrder vo : list) {
-            //商品名称以及原价赋值
-            String itemJson = vo.getItemJson();
-            if(StringUtils.isNotBlank(itemJson)){
-                JSONObject jsonObject = JSONObject.parseObject(itemJson);
-                vo.setGoodsName(jsonObject.getString("goodsName"));
-                vo.setOtPrice(jsonObject.getBigDecimal("otPrice"));
-            }
-            if (vo.getUserPhone()!=null&&!vo.getUserPhone().equals("")){
-                if(vo.getUserPhone().chars().allMatch(Character::isDigit)){continue;}
-//                vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
-                vo.setUserPhone(PhoneUtil.decryptPhone(vo.getUserPhone()));
-            }
-        }
-        ExcelUtil<FsIntegralOrder> util = new ExcelUtil<FsIntegralOrder>(FsIntegralOrder.class);
-        return util.exportExcel(list, "积分商品订单数据");
+    public AjaxResult export(FsIntegralOrder fsIntegralOrder) {
+        return fsIntegralOrderService.export(fsIntegralOrder);
     }
     /**
      * 发货

+ 3 - 0
fs-service/src/main/java/com/fs/his/service/IFsIntegralOrderService.java

@@ -1,5 +1,6 @@
 package com.fs.his.service;
 
+import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.his.domain.FsIntegralOrder;
 import com.fs.his.enums.PaymentMethodEnum;
@@ -100,4 +101,6 @@ public interface IFsIntegralOrderService
      * 支付回调
      */
     R payConfirm(String orderSn, String payCode, String tradeNo, String payType, int type,String bankTransactionId,String bankSerialNo);
+
+    AjaxResult export(FsIntegralOrder fsIntegralOrder);
 }

+ 82 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralOrderServiceImpl.java

@@ -10,12 +10,14 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fs.common.constant.FsConstants;
+import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyUserMapper;
 import com.fs.core.utils.OrderCodeUtils;
@@ -29,6 +31,7 @@ import com.fs.his.service.IFsIntegralCartService;
 import com.fs.his.service.IFsIntegralOrderService;
 import com.fs.his.service.IFsStorePaymentService;
 import com.fs.his.service.IFsUserIntegralLogsService;
+import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsIntegralOrderListUVO;
 import com.fs.his.vo.FsIntegralOrderListVO;
 import com.fs.his.vo.FsIntegralOrderPVO;
@@ -41,6 +44,7 @@ import com.fs.ybPay.dto.OrderQueryDTO;
 import com.fs.ybPay.service.IPayService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -596,4 +600,82 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         return R.ok();
     }
 
+    @Override
+    public AjaxResult export(FsIntegralOrder fsIntegralOrder) {
+        List<FsIntegralOrder> list = fsIntegralOrderMapper.selectFsIntegralOrderList(fsIntegralOrder);
+
+        // 使用Set避免重复数据
+        Set<FsIntegralOrder> fsIntegralOrderSet = new LinkedHashSet<>();
+
+        for (FsIntegralOrder order : list) {
+            // 处理手机号脱敏
+            processPhoneNumber(order);
+
+            // 处理商品信息
+            processGoodsInfo(order, fsIntegralOrderSet);
+        }
+
+        ExcelUtil<FsIntegralOrder> util = new ExcelUtil<>(FsIntegralOrder.class);
+        return util.exportExcel(new ArrayList<>(fsIntegralOrderSet), "积分商品订单数据");
+    }
+
+    /**
+     * 处理手机号脱敏
+     */
+    private void processPhoneNumber(FsIntegralOrder order) {
+        String userPhone = order.getUserPhone();
+        if (StringUtils.isNotBlank(userPhone) && !userPhone.chars().allMatch(Character::isDigit)) {
+            order.setUserPhone(PhoneUtil.decryptPhone(userPhone));
+        }
+    }
+
+    /**
+     * 处理商品信息
+     */
+    private void processGoodsInfo(FsIntegralOrder order, Set<FsIntegralOrder> resultSet) {
+        String itemJson = order.getItemJson();
+        if (StringUtils.isBlank(itemJson)) {
+            return;
+        }
+
+        try {
+            // 判断是否为数组格式
+            if (itemJson.startsWith("[") && itemJson.endsWith("]")) {
+                // 数组格式 - 多个商品
+                List<FsIntegralGoods> goodsList = JSONUtil.toBean(itemJson,
+                        new TypeReference<List<FsIntegralGoods>>(){}, true);
+
+                for (FsIntegralGoods goods : goodsList) {
+                    if (ObjectUtil.isNotEmpty(goods)) {
+                        FsIntegralOrder newOrder = cloneOrder(order);
+                        newOrder.setGoodsName(goods.getGoodsName());
+                        newOrder.setOtPrice(goods.getOtPrice());
+                        resultSet.add(newOrder);
+                    }
+                }
+            } else {
+                // 单商品格式
+                FsIntegralGoods goods = JSONUtil.toBean(itemJson, FsIntegralGoods.class);
+                if (ObjectUtil.isNotEmpty(goods)) {
+                    order.setGoodsName(goods.getGoodsName());
+                    order.setOtPrice(goods.getOtPrice());
+                    resultSet.add(order);
+                }
+            }
+        } catch (Exception e) {
+            // JSON解析异常处理,可以根据需要记录日志
+            log.warn("解析商品JSON数据失败,orderId: {}, json: {}", order.getOrderId(), itemJson);
+        }
+    }
+
+    /**
+     * 克隆订单对象(用于多商品情况)
+     */
+    private FsIntegralOrder cloneOrder(FsIntegralOrder original) {
+        // 这里需要根据实际情况实现对象的深拷贝或浅拷贝
+        // 以下是简单示例,实际项目中可能需要使用BeanUtils或序列化方式
+        FsIntegralOrder cloned = new FsIntegralOrder();
+        BeanUtils.copyProperties(original, cloned);
+        return cloned;
+    }
 }