From faf27967a7f94a4ed03a179ec2670031576f4502 Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期五, 07 三月 2025 18:41:41 +0800
Subject: [PATCH] 迭代版本:2.28

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java |   80 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 1 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
index 4ff898f..fa00bec 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
@@ -34,6 +34,7 @@
 import com.ruoyi.system.api.feignClient.SysUserClient;
 import com.ruoyi.system.api.model.LoginUser;
 import io.swagger.annotations.*;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -545,11 +546,55 @@
     @GetMapping("/exportExpress")
     public void exportExpress(HttpServletResponse response, OrderPageList orderPage) {
 
+        //搜索条件,用户姓名
+        if (StringUtils.isNotEmpty(orderPage.getUserName())) {
+            List<AppUser> data = appUserClient.getAppUserByNameNoFilter(orderPage.getUserName()).getData();
+            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(collect)) {
+                return;
+            }
+            if (null != orderPage.getAppUserIds()) {
+                List<Long> appUserIds = orderPage.getAppUserIds();
+                appUserIds.addAll(collect);
+                orderPage.setAppUserIds(appUserIds);
+            } else {
+                orderPage.setAppUserIds(collect);
+            }
+        }
+        //搜索条件,用户电话
+        if (StringUtils.isNotEmpty(orderPage.getPhone())) {
+            List<AppUser> data = appUserClient.getAppUserByPhoneNoFilter(orderPage.getPhone()).getData();
+            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(collect)) {
+                return;
+            }
+
+            if (null != orderPage.getAppUserIds()) {
+                List<Long> appUserIds = orderPage.getAppUserIds();
+                if (!containsAny(appUserIds, collect)) {
+                    return;
+                }
+                appUserIds.addAll(collect);
+                orderPage.setAppUserIds(appUserIds);
+            } else {
+                orderPage.setAppUserIds(collect);
+            }
+        }
+        if (null != orderPage.getAppUserIds()) {
+            orderPage.setAppUserIds(orderPage.getAppUserIds().stream().distinct().collect(Collectors.toList()));
+        }
+
+//        UserAddress userAddress = JSON.parseObject(order.getAddressJson(), UserAddress.class);
+//        orderInfo.setRecipient(userAddress.getRecieveName() + "-" + userAddress.getRecievePhone());
+//        userAddress.setRecieveAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress());
+//        orderInfo.setAddress(userAddress.getRecieveAddress());
+
+
         List<OrderExport> orderExportList = orderMapper.getOrderExportList(orderPage);
         orderExportList.forEach(orderExport -> {
             Long appUserId = orderExport.getAppUserId();
             AppUser appUserById = appUserClient.getAppUserById(appUserId);
-            if (null != appUserById){
+            if (null != appUserById) {
                 orderExport.setUserName(appUserById.getName());
                 orderExport.setPhone(appUserById.getPhone());
             }
@@ -567,6 +612,16 @@
                 orderExport.setExpressNum(jsonObject.getString("num"));
                 orderExport.setExpressName(ExpressCompanyMap.getCompanyNameByCode(jsonObject.getString("com")));
             }
+            String addressJson = orderExport.getAddressJson();
+            if (StringUtils.isNotEmpty(addressJson)) {
+                UserAddress userAddress = JSON.parseObject(addressJson, UserAddress.class);
+                orderExport.setAddress(
+                                userAddress.getProvince() +
+                                userAddress.getCity() +
+                                userAddress.getDistrict() +
+                                userAddress.getRecieveAddress()
+                );
+            }
 
 
         });
@@ -577,6 +632,29 @@
 
 
     /**
+     * 判断 list1 是否包含 list2 中的至少一个元素
+     *
+     * @param list1 第一个列表
+     * @param list2 第二个列表
+     * @return 如果 list1 包含 list2 中的至少一个元素,返回 true;否则返回 false
+     */
+    private boolean containsAny(List<Long> list1, List<Long> list2) {
+        // 将 list1 转换为 HashSet 以提高查询效率
+        Set<Long> set1 = new HashSet<>(list1);
+
+        // 遍历 list2,检查是否有元素存在于 set1 中
+        for (Long element : list2) {
+            if (set1.contains(element)) {
+                return true;
+            }
+        }
+
+        // 如果没有找到共同元素,返回 false
+        return false;
+    }
+
+
+    /**
      * 获取用户订单数量
      *
      * @param appUserId

--
Gitblit v1.7.1