浏览代码

Merge branch 'hurx'

hurx 2 月之前
父节点
当前提交
90f8502786

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/CustomerDept.java

@@ -61,7 +61,7 @@ public class CustomerDept extends TenantEntity {
     /**
      * 绑定地址
      */
-    private String bindAddress;
+    private Long bindAddress;
 
     /**
      * 部门负责人

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/bo/CustomerDeptBo.java

@@ -85,7 +85,7 @@ public class CustomerDeptBo extends BaseEntity {
     /**
      * 绑定地址
      */
-    private String bindAddress;
+    private Long bindAddress;
 
     /**
      * 部门负责人

+ 2 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/vo/CustomerDeptTreeVo.java

@@ -17,7 +17,8 @@ public class CustomerDeptTreeVo implements Serializable {
     private BigDecimal yearlyBudget;
     private BigDecimal usedBudget;
     private BigDecimal monthLimit;
-    private String bindAddress;
+    private Long bindAddress;
+    private String bindAddressStr;
     private String bindStatus;
     private String status;      // 来自 sys_dept(启用/停用)
 

+ 3 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/vo/CustomerDeptVo.java

@@ -98,7 +98,9 @@ public class CustomerDeptVo implements Serializable {
      * 绑定地址
      */
     @ExcelProperty(value = "绑定地址")
-    private String bindAddress;
+    private Long bindAddress;
+
+    private String bindAddressStr;
 
     /**
      * 部门负责人

+ 53 - 26
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerDeptServiceImpl.java

@@ -1,8 +1,6 @@
 package org.dromara.customer.service.impl;
 
-import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.lang.tree.Tree;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -10,23 +8,23 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.common.core.context.PlatformContext;
-import org.dromara.common.core.enums.IsDefault;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.customer.domain.CustomerDept;
-import org.dromara.customer.domain.CustomerInfo;
 import org.dromara.customer.domain.bo.CustomerDeptBo;
 import org.dromara.customer.domain.vo.CustomerDeptTreeVo;
 import org.dromara.customer.domain.vo.CustomerDeptVo;
+import org.dromara.customer.domain.vo.CustomerShippingAddressVo;
 import org.dromara.customer.mapper.CustomerDeptMapper;
+import org.dromara.customer.mapper.CustomerShippingAddressMapper;
 import org.dromara.customer.service.ICustomerDeptService;
 import org.dromara.system.api.RemoteDeptService;
 import org.dromara.system.api.domain.vo.RemoteDeptVo;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.math.BigDecimal;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -47,6 +45,8 @@ public class CustomerDeptServiceImpl extends ServiceImpl<CustomerDeptMapper, Cus
 
     private final CustomerDeptMapper baseMapper;
 
+    private final CustomerShippingAddressMapper customerShippingAddressMapper;
+
     /**
      * 查询客户部门信息
      *
@@ -133,33 +133,61 @@ public class CustomerDeptServiceImpl extends ServiceImpl<CustomerDeptMapper, Cus
         Map<Long, RemoteDeptVo> deptMap = sysDepts.stream()
             .collect(Collectors.toMap(RemoteDeptVo::getDeptId, d -> d));
 
-        // 3. 合并 + 安全排序
+        // 1. 提前批量获取所有需要的地址信息
+        Set<Long> bindAddressIds = customerDepts.stream()
+            .map(CustomerDept::getBindAddress)
+            .filter(Objects::nonNull)
+            .collect(Collectors.toSet());
+
+        final Map<Long, CustomerShippingAddressVo> addressVoMap = !bindAddressIds.isEmpty()
+            ? customerShippingAddressMapper.selectVoByIds(new ArrayList<>(bindAddressIds))
+            .stream()
+            .collect(Collectors.toMap(CustomerShippingAddressVo::getId, Function.identity(), (a, b) -> a))
+            : new HashMap<>();
+
+        Map<Long, CustomerDept> customerDeptsMap = customerDepts.stream()
+            .collect(Collectors.toMap(CustomerDept::getDeptId, Function.identity()));
+
+        // 2. 构建结果并排序
         return customerDepts.stream()
-            .filter(cd -> deptMap.containsKey(cd.getDeptId()))
-            .map(cd -> {
-                RemoteDeptVo sys = deptMap.get(cd.getDeptId());
-                CustomerDeptTreeVo vo = new CustomerDeptTreeVo();
-                vo.setDeptId(sys.getDeptId());
-                vo.setParentId(sys.getParentId());
-                vo.setDeptName(sys.getDeptName());
-                vo.setOrderNum(sys.getOrderNum()); // 可能为 null!
-                vo.setStatus(sys.getStatus());
-
-                vo.setYearlyBudget(cd.getYearlyBudget());
-                vo.setUsedBudget(cd.getUsedBudget());
-                vo.setMonthLimit(cd.getMonthLimit());
-                vo.setBindAddress(cd.getBindAddress());
-                vo.setBindStatus(cd.getBindStatus());
-
-                return vo;
-            })
+            .map(cd -> deptMap.get(cd.getDeptId())) // 直接 get,null 表示不匹配
+            .filter(Objects::nonNull) // 过滤掉 deptMap 中不存在的
+            .map(sys -> buildCustomerDeptTreeVo(sys, customerDeptsMap.get(sys.getDeptId()), addressVoMap)) // 假设你有 customerDepts 按 deptId 的 map
             .sorted(Comparator.comparing(
                 CustomerDeptTreeVo::getOrderNum,
-                Comparator.nullsLast(Comparator.naturalOrder()) // ✅ 安全处理 null
+                Comparator.nullsLast(Comparator.naturalOrder())
             ))
             .collect(Collectors.toList());
     }
 
+    private CustomerDeptTreeVo buildCustomerDeptTreeVo(RemoteDeptVo sys, CustomerDept cd, Map<Long, CustomerShippingAddressVo> addressVoMap) {
+        CustomerDeptTreeVo vo = new CustomerDeptTreeVo();
+
+        // 部门信息
+        vo.setDeptId(sys.getDeptId());
+        vo.setParentId(sys.getParentId());
+        vo.setDeptName(sys.getDeptName());
+        vo.setOrderNum(sys.getOrderNum());
+        vo.setStatus(sys.getStatus());
+
+        // 客户部门绑定信息
+        vo.setYearlyBudget(cd.getYearlyBudget());
+        vo.setUsedBudget(cd.getUsedBudget());
+        vo.setMonthLimit(cd.getMonthLimit());
+        vo.setBindAddress(cd.getBindAddress());
+        vo.setBindStatus(cd.getBindStatus());
+
+        // 地址拼接(安全处理 null)
+        CustomerShippingAddressVo addressVo = addressVoMap.get(cd.getBindAddress());
+        if (addressVo != null) {
+            String provinceCity = Optional.ofNullable(addressVo.getProvincialCityCountry()).orElse("");
+            String detailAddr = Optional.ofNullable(addressVo.getAddress()).orElse("");
+            vo.setBindAddressStr((provinceCity + " " + detailAddr).trim());
+        }
+
+        return vo;
+    }
+
     private LambdaQueryWrapper<CustomerDept> buildQueryWrapper(CustomerDeptBo bo) {
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<CustomerDept> lqw = Wrappers.lambdaQuery();
@@ -170,7 +198,6 @@ public class CustomerDeptServiceImpl extends ServiceImpl<CustomerDeptMapper, Cus
         lqw.eq(bo.getMonthLimit() != null, CustomerDept::getMonthLimit, bo.getMonthLimit());
         lqw.eq(bo.getMonthUsedBudget() != null, CustomerDept::getMonthUsedBudget, bo.getMonthUsedBudget());
         lqw.eq(StringUtils.isNotBlank(bo.getBindStatus()), CustomerDept::getBindStatus, bo.getBindStatus());
-        lqw.eq(StringUtils.isNotBlank(bo.getBindAddress()), CustomerDept::getBindAddress, bo.getBindAddress());
         lqw.eq(StringUtils.isNotBlank(bo.getDeptManage()), CustomerDept::getDeptManage, bo.getDeptManage());
         lqw.eq(StringUtils.isNotBlank(bo.getIsLimit()), CustomerDept::getIsLimit, bo.getIsLimit());
         lqw.eq(StringUtils.isNotBlank(bo.getSelectYear()), CustomerDept::getSelectYear, bo.getSelectYear());

+ 5 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerShippingAddressServiceImpl.java

@@ -12,6 +12,7 @@ import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.redis.utils.SequenceUtils;
 import org.dromara.customer.domain.CustomerShippingAddress;
 import org.dromara.customer.domain.bo.CustomerShippingAddressBo;
 import org.dromara.customer.domain.vo.CustomerShippingAddressVo;
@@ -20,6 +21,7 @@ import org.dromara.customer.service.ICustomerShippingAddressService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.Duration;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +37,8 @@ import java.util.Map;
 @Service
 public class CustomerShippingAddressServiceImpl extends ServiceImpl<CustomerShippingAddressMapper, CustomerShippingAddress> implements ICustomerShippingAddressService {
 
+    private static final String SHOPPING_ADDRESS_NO_KEY = "customer_shipping_address:shipping_address_no";
+
     private final CustomerShippingAddressMapper baseMapper;
 
     /**
@@ -107,6 +111,7 @@ public class CustomerShippingAddressServiceImpl extends ServiceImpl<CustomerShip
      */
     @Override
     public Boolean insertByBo(CustomerShippingAddressBo bo) {
+        bo.setShippingAddressNo(SequenceUtils.nextPaddedIdStr(SHOPPING_ADDRESS_NO_KEY, Duration.ofDays(3650), 4));
         CustomerShippingAddress add = MapstructUtils.convert(bo, CustomerShippingAddress.class);
         validEntityBeforeSave(add);
         boolean flag = baseMapper.insert(add) > 0;