瀏覽代碼

客户添加 联系人名称/邮箱 搜索

yzc 1 年之前
父節點
當前提交
6ba69c99c5

+ 28 - 15
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -21,7 +21,6 @@ import com.fjhx.customer.entity.customer.po.CustomerUser;
 import com.fjhx.customer.entity.customer.vo.CustomerFollowRecordsVo;
 import com.fjhx.customer.entity.customer.vo.CustomerVo;
 import com.fjhx.customer.mapper.customer.CustomerMapper;
-import com.fjhx.customer.service.customer.CustomerFollowRecordsService;
 import com.fjhx.customer.service.customer.CustomerService;
 import com.fjhx.customer.service.customer.CustomerTopService;
 import com.fjhx.customer.service.customer.CustomerUserService;
@@ -33,7 +32,6 @@ import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
-import com.ruoyi.common.utils.wrapper.SqlField;
 import com.ruoyi.system.utils.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -60,9 +58,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
     private CustomerUserService customerUserService;
 
     @Autowired
-    private CustomerFollowRecordsService customerFollowRecordsService;
-
-    @Autowired
     private CustomerTopService customerTopService;
 
     @Autowired
@@ -77,7 +72,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
         wrapper.like(Customer::getName, dto.getKeyword());
         wrapper.eq("c", Customer::getUserId, dto.getUserId());
-        wrapper.groupBy("c.id");
         Page<CustomerVo> page = baseMapper.getPage(dto.getPage(), wrapper);
         CustomizeAreaUtil.setAreaName(page.getRecords());
         return page;
@@ -111,16 +105,36 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         // 业务员查询
         wrapper.eq("c", Customer::getUserId, dto.getUserId());
         // 关键字
-        wrapper.keyword(dto.getKeyword(),
-                new SqlField("c", Customer::getName),
-                new SqlField("c", Customer::getCode),
-                new SqlField("cu", CustomerUser::getName),
-                new SqlField("cu", CustomerUser::getEmail)
-        );
+        if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
+            List<Long> cuIds = customerUserService.listObject(CustomerUser::getCustomerId, q -> q
+                    .like(CustomerUser::getName, dto.getKeyword()).or()
+                    .like(CustomerUser::getEmail, dto.getKeyword())
+                    .groupBy(CustomerUser::getCustomerId)
+            );
+            wrapper.and(q -> q
+                    .like("c", Customer::getName, dto.getKeyword()).or()
+                    .like(Customer::getCode, dto.getKeyword()).or()
+                    .in(Customer::getId, cuIds)
+            );
+        }
         //客户联系人过滤
-        wrapper.eq("cu", CustomerUser::getName, dto.getContactName());
+        if (ObjectUtil.isNotEmpty(dto.getContactName())) {
+            List<Long> cuIds = customerUserService.listObject(CustomerUser::getCustomerId, q -> q
+                    .like(CustomerUser::getName, dto.getContactName())
+                    .groupBy(CustomerUser::getCustomerId)
+            );
+            cuIds.add(null);
+            wrapper.in("c", Customer::getId, cuIds);
+        }
         //客户联系人邮箱
-        wrapper.eq("cu", CustomerUser::getEmail, dto.getContactEmail());
+        if (ObjectUtil.isNotEmpty(dto.getContactEmail())) {
+            List<Long> cuIds = customerUserService.listObject(CustomerUser::getCustomerId, q -> q
+                    .like(CustomerUser::getEmail, dto.getContactEmail())
+                    .groupBy(CustomerUser::getCustomerId)
+            );
+            cuIds.add(null);
+            wrapper.in("c", Customer::getId, cuIds);
+        }
 
         // 客户标签查询(多个标签用逗号隔开)
         if (StrUtil.isNotBlank(dto.getTag())) {
@@ -150,7 +164,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         wrapper.orderByDesc("c", Customer::getUpdateTime);
         wrapper.orderByDesc("c", Customer::getCreateTime);
 
-        wrapper.groupBy("c.id");
         Page<CustomerVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
 
         // 复制城市信息

+ 0 - 1
hx-customer/src/main/resources/mapper/customer/CustomerMapper.xml

@@ -47,7 +47,6 @@
             c.update_time,
             c.tag
         from customer c
-	        LEFT JOIN customer_user cu ON cu.customer_id = c.id
             ${ew.customSqlSegment}
     </select>