|
@@ -21,13 +21,14 @@ import org.dromara.customer.domain.bo.*;
|
|
|
import org.dromara.customer.domain.vo.*;
|
|
import org.dromara.customer.domain.vo.*;
|
|
|
import org.dromara.customer.mapper.*;
|
|
import org.dromara.customer.mapper.*;
|
|
|
import org.dromara.customer.service.ICustomerInfoService;
|
|
import org.dromara.customer.service.ICustomerInfoService;
|
|
|
-import org.dromara.system.api.RemoteDeptService;
|
|
|
|
|
|
|
+import org.dromara.system.api.*;
|
|
|
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.math.BigDecimal;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -41,6 +42,16 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
@Service
|
|
|
public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, CustomerInfo> implements ICustomerInfoService {
|
|
public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, CustomerInfo> implements ICustomerInfoService {
|
|
|
|
|
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteComPostService remoteComPostService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteComStaffService remoteComStaffService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteComDeptService remoteComDeptService;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteComCompanyService remoteComCompanyService;
|
|
|
|
|
+
|
|
|
private final CustomerInfoMapper baseMapper;
|
|
private final CustomerInfoMapper baseMapper;
|
|
|
private final CustomerBusinessInfoMapper customerBusinessInfoMapper;
|
|
private final CustomerBusinessInfoMapper customerBusinessInfoMapper;
|
|
|
private final CustomerInvoiceInfoMapper customerInvoiceInfoMapper;
|
|
private final CustomerInvoiceInfoMapper customerInvoiceInfoMapper;
|
|
@@ -52,9 +63,6 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
private final CustomerContractMapper customerContractMapper;
|
|
private final CustomerContractMapper customerContractMapper;
|
|
|
private final CustomerDeptMapper customerDeptMapper;
|
|
private final CustomerDeptMapper customerDeptMapper;
|
|
|
|
|
|
|
|
- @DubboReference
|
|
|
|
|
- private RemoteDeptService remoteDeptService;
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询客户信息
|
|
* 查询客户信息
|
|
@@ -128,25 +136,101 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
LambdaQueryWrapper<CustomerInfo> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<CustomerInfo> lqw = buildQueryWrapper(bo);
|
|
|
Page<CustomerInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
Page<CustomerInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
List<CustomerInfoVo> records = result.getRecords();
|
|
List<CustomerInfoVo> records = result.getRecords();
|
|
|
- if (CollUtil.isNotEmpty(records)) {
|
|
|
|
|
- Set<Long> industryIds = records.stream()
|
|
|
|
|
- .map(CustomerInfoVo::getIndustryCategoryId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
- List<IndustryCategoryVo> industryList = industryCategoryMapper.selectVoByIds(industryIds);
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
|
|
+ return TableDataInfo.build(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // === 1. 补充行业分类名称 ===
|
|
|
|
|
+ Set<Long> industryIds = records.stream()
|
|
|
|
|
+ .map(CustomerInfoVo::getIndustryCategoryId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
+ if (!industryIds.isEmpty()) {
|
|
|
|
|
+ List<IndustryCategoryVo> industryList = industryCategoryMapper.selectVoByIds(industryIds);
|
|
|
Map<Long, String> industryMap = industryList.stream()
|
|
Map<Long, String> industryMap = industryList.stream()
|
|
|
.collect(Collectors.toMap(
|
|
.collect(Collectors.toMap(
|
|
|
IndustryCategoryVo::getId,
|
|
IndustryCategoryVo::getId,
|
|
|
IndustryCategoryVo::getIndustryCategoryName,
|
|
IndustryCategoryVo::getIndustryCategoryName,
|
|
|
- (existing, replacement) -> existing
|
|
|
|
|
|
|
+ (e, r) -> e
|
|
|
));
|
|
));
|
|
|
|
|
+ records.forEach(vo -> vo.setIndustryCategory(industryMap.get(vo.getIndustryCategoryId())));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // === 2. 提取客户ID,查询销售信息 ===
|
|
|
|
|
+ Set<Long> infoIds = records.stream()
|
|
|
|
|
+ .map(CustomerInfoVo::getId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toCollection(() -> new HashSet<>(records.size())));
|
|
|
|
|
|
|
|
- records.forEach(vo -> {
|
|
|
|
|
- vo.setIndustryCategory(industryMap.get(vo.getIndustryCategoryId()));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ Set<Long> companyIds = records.stream()
|
|
|
|
|
+ .map(CustomerInfoVo::getBelongCompanyId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toCollection(() -> new HashSet<>(records.size())));
|
|
|
|
|
+
|
|
|
|
|
+ if (infoIds.isEmpty()) {
|
|
|
|
|
+ return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (companyIds.isEmpty()) {
|
|
|
|
|
+ return TableDataInfo.build(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<CustomerSalesInfoVo> salesInfoVos = customerSalesInfoMapper.selectVoList(
|
|
|
|
|
+ new LambdaQueryWrapper<CustomerSalesInfo>()
|
|
|
|
|
+ .in(CustomerSalesInfo::getCustomerId, infoIds)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isEmpty(salesInfoVos)) {
|
|
|
|
|
+ // 即使没有销售信息,也要返回客户列表(只是销售字段为空)
|
|
|
|
|
+ return TableDataInfo.build(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // === 3. 构建 customerId -> CustomerSalesInfoVo 映射
|
|
|
|
|
+ Map<Long, CustomerSalesInfoVo> salesInfoMap = salesInfoVos.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ CustomerSalesInfoVo::getCustomerId,
|
|
|
|
|
+ Function.identity(),
|
|
|
|
|
+ (existing, replacement) -> existing // 若有重复,保留第一个
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ // === 4. 收集人员和部门ID ===
|
|
|
|
|
+ Set<Long> staffIds = new HashSet<>();
|
|
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (CustomerSalesInfoVo vo : salesInfoVos) {
|
|
|
|
|
+ if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
|
|
+ if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
|
|
+ if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // === 5. 远程调用获取名称 ===
|
|
|
|
|
+ Map<Long, String> companyMap = companyIds.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : remoteComCompanyService.selectCompanyNameByIds(companyIds);
|
|
|
|
|
+ Map<Long, String> staffMap = staffIds.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : remoteComStaffService.selectStaffNameByIds(staffIds);
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, String> deptMap = deptIds.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : remoteComDeptService.selectDeptNameByIds(deptIds);
|
|
|
|
|
+
|
|
|
|
|
+ // === 6. 回填人员和部门名称到 salesInfoVo ===
|
|
|
|
|
+ for (CustomerSalesInfoVo vo : salesInfoVos) {
|
|
|
|
|
+ vo.setSalesPerson(staffMap.get(vo.getSalesPersonId()));
|
|
|
|
|
+ vo.setServiceStaff(staffMap.get(vo.getServiceStaffId()));
|
|
|
|
|
+ vo.setBelongingDepartment(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // === 7. 将销售信息回填到客户VO ===
|
|
|
|
|
+ for (CustomerInfoVo customerVo : records) {
|
|
|
|
|
+ customerVo.setCompanyName(companyMap.get(customerVo.getBelongCompanyId()));
|
|
|
|
|
+ CustomerSalesInfoVo salesVo = salesInfoMap.get(customerVo.getId());
|
|
|
|
|
+ customerVo.setCustomerSalesInfoVo(salesVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return TableDataInfo.build(result);
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -198,8 +282,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
vo.setCustomerId(customer.getId());
|
|
vo.setCustomerId(customer.getId());
|
|
|
vo.setCustomerNo(customer.getCustomerNo());
|
|
vo.setCustomerNo(customer.getCustomerNo());
|
|
|
|
|
|
|
|
- // ⚠️ 确认这里字段是否存在!
|
|
|
|
|
- vo.setCustomerName(customer.getBusinessCustomerName()); // 或 customer.getShortName()
|
|
|
|
|
|
|
+ vo.setCustomerName(customer.getBusinessCustomerName());
|
|
|
|
|
|
|
|
vo.setIndustryCategoryId(customer.getIndustryCategoryId());
|
|
vo.setIndustryCategoryId(customer.getIndustryCategoryId());
|
|
|
vo.setIndustryCategory(industryCategoryMap.getOrDefault(customer.getIndustryCategoryId(), ""));
|
|
vo.setIndustryCategory(industryCategoryMap.getOrDefault(customer.getIndustryCategoryId(), ""));
|
|
@@ -325,7 +408,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
String platform = PlatformContext.getPlatform();
|
|
String platform = PlatformContext.getPlatform();
|
|
|
- RemoteDeptVo deptVo = remoteDeptService.selectParentDeptByPlatformCode(platform);
|
|
|
|
|
|
|
+// RemoteDeptVo deptVo = remoteDeptService.selectParentDeptByPlatformCode(platform);
|
|
|
|
|
|
|
|
boolean isNew = bo.getId() == null || bo.getId() <= 0;
|
|
boolean isNew = bo.getId() == null || bo.getId() <= 0;
|
|
|
|
|
|