|
@@ -1,8 +1,6 @@
|
|
|
package org.dromara.customer.service.impl;
|
|
package org.dromara.customer.service.impl;
|
|
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
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.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -10,23 +8,23 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.common.core.context.PlatformContext;
|
|
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.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.customer.domain.CustomerDept;
|
|
import org.dromara.customer.domain.CustomerDept;
|
|
|
-import org.dromara.customer.domain.CustomerInfo;
|
|
|
|
|
import org.dromara.customer.domain.bo.CustomerDeptBo;
|
|
import org.dromara.customer.domain.bo.CustomerDeptBo;
|
|
|
import org.dromara.customer.domain.vo.CustomerDeptTreeVo;
|
|
import org.dromara.customer.domain.vo.CustomerDeptTreeVo;
|
|
|
import org.dromara.customer.domain.vo.CustomerDeptVo;
|
|
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.CustomerDeptMapper;
|
|
|
|
|
+import org.dromara.customer.mapper.CustomerShippingAddressMapper;
|
|
|
import org.dromara.customer.service.ICustomerDeptService;
|
|
import org.dromara.customer.service.ICustomerDeptService;
|
|
|
import org.dromara.system.api.RemoteDeptService;
|
|
import org.dromara.system.api.RemoteDeptService;
|
|
|
import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
|
import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,6 +45,8 @@ public class CustomerDeptServiceImpl extends ServiceImpl<CustomerDeptMapper, Cus
|
|
|
|
|
|
|
|
private final CustomerDeptMapper baseMapper;
|
|
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()
|
|
Map<Long, RemoteDeptVo> deptMap = sysDepts.stream()
|
|
|
.collect(Collectors.toMap(RemoteDeptVo::getDeptId, d -> d));
|
|
.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()
|
|
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(
|
|
.sorted(Comparator.comparing(
|
|
|
CustomerDeptTreeVo::getOrderNum,
|
|
CustomerDeptTreeVo::getOrderNum,
|
|
|
- Comparator.nullsLast(Comparator.naturalOrder()) // ✅ 安全处理 null
|
|
|
|
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder())
|
|
|
))
|
|
))
|
|
|
.collect(Collectors.toList());
|
|
.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) {
|
|
private LambdaQueryWrapper<CustomerDept> buildQueryWrapper(CustomerDeptBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<CustomerDept> lqw = Wrappers.lambdaQuery();
|
|
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.getMonthLimit() != null, CustomerDept::getMonthLimit, bo.getMonthLimit());
|
|
|
lqw.eq(bo.getMonthUsedBudget() != null, CustomerDept::getMonthUsedBudget, bo.getMonthUsedBudget());
|
|
lqw.eq(bo.getMonthUsedBudget() != null, CustomerDept::getMonthUsedBudget, bo.getMonthUsedBudget());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getBindStatus()), CustomerDept::getBindStatus, bo.getBindStatus());
|
|
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.getDeptManage()), CustomerDept::getDeptManage, bo.getDeptManage());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getIsLimit()), CustomerDept::getIsLimit, bo.getIsLimit());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getIsLimit()), CustomerDept::getIsLimit, bo.getIsLimit());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getSelectYear()), CustomerDept::getSelectYear, bo.getSelectYear());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getSelectYear()), CustomerDept::getSelectYear, bo.getSelectYear());
|