瀏覽代碼

客户标签统计更换接口

yzc 1 年之前
父節點
當前提交
fa849d93ad

+ 8 - 0
hx-customer/src/main/java/com/fjhx/customer/controller/customer/CustomerController.java

@@ -123,4 +123,12 @@ public class CustomerController {
         return customerService.followStatistics(customerDto);
     }
 
+    /**
+     * 客户标签统计
+     */
+    @PostMapping("/tagStatistics")
+    public Map<String, Object> tagStatistics(@RequestBody CustomerSelectDto customerDto) {
+        return customerService.tagStatistics(customerDto);
+    }
+
 }

+ 6 - 0
hx-customer/src/main/java/com/fjhx/customer/service/customer/CustomerService.java

@@ -85,4 +85,10 @@ public interface CustomerService extends BaseService<Customer> {
      */
     Map<String, Object> followStatistics(CustomerSelectDto customerDto);
 
+    /**
+     * 客户标签统计
+     */
+    Map<String, Object> tagStatistics(CustomerSelectDto customerDto);
+
+
 }

+ 48 - 3
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -390,9 +390,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         } else if (customerDto.getStatisticsType() == 3) {// 业务员统计
             query.groupBy("user_id");
             query.select("count(*) count,user_id");
-        } else if (customerDto.getStatisticsType() == 4) {// 客户标签统计
-            query.groupBy("SUBSTRING_INDEX( IFNULL(tag,''), ',', - 1 )");
-            query.select("count(*) count,SUBSTRING_INDEX( IFNULL(tag,''), ',', - 1 ) as tag");
         }
         List<Customer> customerList = baseMapper.selectList(query);
 
@@ -451,6 +448,54 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         return map;
     }
 
+    @Override
+    public Map<String, Object> tagStatistics(CustomerSelectDto customerDto) {
+        if (ObjectUtil.isEmpty(customerDto) && ObjectUtil.isEmpty(customerDto.getStatisticsType())) {
+            throw new ServiceException("参数异常:统计类型不能为null");
+        }
+        QueryWrapper<Customer> query = Wrappers.query();
+        if (ObjectUtil.isNotEmpty(customerDto.getType())) {
+            // 私海客户查询
+            if (customerDto.getType().equals("1")) {
+                query.isNotNull("user_id");
+                // 私海客户需要添加权限(自己查自己)
+                query.eq("user_id", SecurityUtils.getUserId());
+            } else if (customerDto.getType().equals("0")) {// 公海客户
+                query.and(wrapper1 -> wrapper1.isNull("user_id").or().eq("user_id", ""));
+            }
+        }
+
+        //将标签合在一起
+        query.select("GROUP_CONCAT(IFNULL(tag,'')) as tag");
+        Customer customer = baseMapper.selectOne(query);
+
+        Integer sumCount = 0;
+        Map<String, Integer> map = new HashMap<>();
+        if (ObjectUtil.isNotEmpty(customer)) {
+            String tags = customer.getTag();
+            String[] split = tags.split(",");
+            for (String tag : split) {
+                Integer count = map.getOrDefault(tag, 0);
+                map.put(tag, ++count);
+                sumCount++;
+            }
+        }
+
+        List<Customer> arr = new ArrayList<>();
+        for (Map.Entry<String, Integer> entry : map.entrySet()) {
+            Customer customer1 = new Customer();
+            customer1.setTag(entry.getKey());
+            customer1.setCount(entry.getValue());
+            arr.add(customer1);
+        }
+
+        Map<String, Object> reData = new HashMap<>();
+        reData.put("countAmount", sumCount);
+        reData.put("customerList", arr);
+
+        return reData;
+    }
+
     /**
      * 客户分配
      */