|
|
@@ -25,8 +25,11 @@ import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -107,8 +110,9 @@ public class CustomerTradeServiceImpl
|
|
|
wrapper.like(CustomerEntity::getCustomerName, dto.getCustomerName());
|
|
|
}
|
|
|
|
|
|
- // 模糊筛选:blurry(覆盖公司名称 + 联系人姓名)
|
|
|
- // 思路:分别查 customer_company / liaison 两张表取 customerId,做并集后再 IN customer 表
|
|
|
+ // 模糊筛选:blurry(覆盖公司名称 + 联系人姓名 + 客户名称)
|
|
|
+ // 思路:查 customer_company / liaison 取 customerId 并集,与「customerName LIKE」组成 OR 组,
|
|
|
+ // 整个 OR 组与其他条件走 AND:SQL = <其他> AND (customerName LIKE ? OR customer.id IN (B∪C))
|
|
|
if (!StringUtils.isEmpty(dto.getBlurry())) {
|
|
|
String blurry = dto.getBlurry().trim();
|
|
|
|
|
|
@@ -116,28 +120,30 @@ public class CustomerTradeServiceImpl
|
|
|
new LambdaQueryWrapper<CustomerCompanyEntity>()
|
|
|
.eq(CustomerCompanyEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
|
|
|
.like(CustomerCompanyEntity::getName, blurry)
|
|
|
- ).stream().map(CustomerCompanyEntity::getCustomerId).collect(Collectors.toList());
|
|
|
+ ).stream().map(CustomerCompanyEntity::getCustomerId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
List<Long> liaisonCustomerIds = liaisonTradeService.list(
|
|
|
new LambdaQueryWrapper<LiaisonEntity>()
|
|
|
.eq(LiaisonEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
|
|
|
.eq(LiaisonEntity::getHasPrimaryLialison, 1)
|
|
|
.like(LiaisonEntity::getName, blurry)
|
|
|
- ).stream().map(LiaisonEntity::getCustomerId).collect(Collectors.toList());
|
|
|
+ ).stream().map(LiaisonEntity::getCustomerId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
- // 合并两个集合,去重
|
|
|
- List<Long> blurCustomerIds = new ArrayList<>();
|
|
|
- blurCustomerIds.addAll(companyCustomerIds);
|
|
|
- blurCustomerIds.addAll(liaisonCustomerIds);
|
|
|
- blurCustomerIds = blurCustomerIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ // 合并两个集合去重
|
|
|
+ Set<Long> blurCustomerIdSet = new HashSet<>();
|
|
|
+ blurCustomerIdSet.addAll(companyCustomerIds);
|
|
|
+ blurCustomerIdSet.addAll(liaisonCustomerIds);
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(blurCustomerIds)) {
|
|
|
- // 无匹配公司也无匹配联系人,直接返回空
|
|
|
- Page<CustomerVO> emptyPage = new Page<>(dto.getPageIndex(), dto.getPageSize());
|
|
|
- emptyPage.setRecords(new ArrayList<>());
|
|
|
- return emptyPage;
|
|
|
- }
|
|
|
- wrapper.in(CustomerEntity::getId, blurCustomerIds);
|
|
|
+ // OR 组:(customerName LIKE blurry) OR (id IN 并集)
|
|
|
+ // 当 blurCustomerIdSet 为空时跳过 .in(),仅保留 .like() 作为 OR 组里唯一条件
|
|
|
+ // 注意:本项目 MP 版本 < 3.5.0,and() 只有 Function 重载,lambda 必须 return
|
|
|
+ wrapper.and(w -> {
|
|
|
+ w.like(CustomerEntity::getCustomerName, blurry);
|
|
|
+ if (!blurCustomerIdSet.isEmpty()) {
|
|
|
+ w.or().in(CustomerEntity::getId, blurCustomerIdSet);
|
|
|
+ }
|
|
|
+ return w;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// 精确筛选:联系人手机/邮箱
|