Browse Source

客户分页

24282 2 năm trước cách đây
mục cha
commit
adc78fa900

+ 39 - 35
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -2,6 +2,7 @@ package com.fjhx.customer.service.customer.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -31,7 +32,6 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.system.utils.UserUtil;
-import org.apache.poi.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -70,67 +70,71 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
      */
     @Override
     public Page<CustomerVo> getPage(CustomerSelectDto dto) {
-//        LambdaQueryWrapper<Customer> wrapper = Wrappers.<Customer>lambdaQuery();
-        IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
-        //客户来源查询
-        wrapper.eq("c", Customer::getSource, dto.getSource());
-        //客户类型查询
-        wrapper.eq(Customer::getStatus, dto.getStatus());
-        //国家ID查询
-        wrapper.eq(Customer::getCountryId, dto.getCountryId());
-        //省份ID查询
-        wrapper.eq(Customer::getProvinceId,dto.getProvinceId());
-        //城市ID查询
-        wrapper.eq(Customer::getCityId,dto.getCityId());
-        //客户代码
-        wrapper.like(Customer::getCustomerCode,dto.getCustomerCode());
-        //客户名称
-        wrapper.like(Customer::getName,dto.getName());
 
-        //业务员查询
-        wrapper.eq(Customer::getUserId,dto.getName());
+        IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
 
-        //客户标签查询(多个标签用逗号隔开)
-        if(StringUtils.isNotEmpty(dto.getTag())){
+        // 客户来源查询
+        wrapper.eq("c", Customer::getSource, dto.getSource());
+        // 客户类型查询
+        wrapper.eq("c", Customer::getStatus, dto.getStatus());
+        // 国家ID查询
+        wrapper.eq("c", Customer::getCountryId, dto.getCountryId());
+        // 省份ID查询
+        wrapper.eq("c", Customer::getProvinceId, dto.getProvinceId());
+        // 城市ID查询
+        wrapper.eq("c", Customer::getCityId, dto.getCityId());
+        // 客户代码
+        wrapper.like("c", Customer::getCustomerCode, dto.getCustomerCode());
+        // 客户名称
+        wrapper.like("c", Customer::getName, dto.getName());
+        // 业务员查询
+        wrapper.eq("c", Customer::getUserId, dto.getUserId());
+
+        // 客户标签查询(多个标签用逗号隔开)
+        if (StrUtil.isNotBlank(dto.getTag())) {
             List<String> tagList = Arrays.asList(dto.getTag().split(","));
-            tagList.forEach(tag->wrapper.like(Customer::getTag,tag));
+            tagList.forEach(tag -> wrapper.like("c", Customer::getTag, tag));
         }
 
-        //客户状态(0:公海客户  1:私海客户)(业务员ID为null为公海客户,业务员ID不为null为私海客户)
-        if (ObjectUtil.isNotEmpty(dto.getType())) {
-            //私海客户查询
+        // 客户状态(0:公海客户  1:私海客户)(业务员ID为null为公海客户,业务员ID不为null为私海客户)
+        if (StrUtil.isNotBlank(dto.getType())) {
+            // 私海客户查询
             if (dto.getType().equals("1")) {
                 wrapper.isNotNull("c.user_id");
             } else if (dto.getType().equals("0")) {
-                wrapper.and(wrapper1 -> wrapper1.isNull("c.user_id").or().eq(Customer::getUserId, ""));
+                wrapper.isNull("c.user_id");
             }
         }
 
+        // 置顶条件
+        List<Long> customerIds = customerTopService.listObject(CustomerTop::getCustomerId,
+                q -> q.eq(CustomerTop::getUserId, SecurityUtils.getUserId()));
 
-        //置顶条件
-        List<Long> customerIds = customerTopService.listObject(CustomerTop::getCustomerId, q -> q.eq(CustomerTop::getUserId,
-                SecurityUtils.getUserId()));
         if (ObjectUtil.isNotEmpty(customerIds)) {
             String join = StringUtils.join(customerIds, ",");
             wrapper.orderByDesc("id IN ( " + join + " )");
         }
+
         wrapper.orderByDesc(Customer::getUpdateTime);
         wrapper.orderByDesc(Customer::getCreateTime);
 
         Page<CustomerVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
 
-        //复制城市信息
+        // 复制城市信息
         List<CustomerVo> records = page.getRecords();
         CustomizeAreaUtil.setAreaName(records);
-        //赋值客户跟进记录
+
+        // 赋值客户跟进记录
         for (CustomerVo record : records) {
-            List<CustomerFollowRecords> customerFollowRecordsList = customerFollowRecordsService.list(q ->
-                    q.eq(CustomerFollowRecords::getCustomerId, record.getId())
-                            .orderByDesc(CustomerFollowRecords::getDate).last("limit 3"));
+            List<CustomerFollowRecords> customerFollowRecordsList = customerFollowRecordsService.list(q -> q
+                    .eq(CustomerFollowRecords::getCustomerId, record.getId())
+                    .orderByDesc(CustomerFollowRecords::getDate)
+                    .last("limit 3")
+            );
             record.setCustomerFollowRecordsList(customerFollowRecordsList);
         }
 
-        //赋值是否置顶
+        // 赋值是否置顶
         for (CustomerVo record : records) {
             record.setIsTop(customerIds.contains(record.getId()) ? 1 : 0);
         }