Forráskód Böngészése

客户添加统计

yzc 1 éve
szülő
commit
3dd6bddc5a

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

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

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/entity/customer/dto/CustomerSelectDto.java

@@ -39,7 +39,7 @@ public class CustomerSelectDto extends BaseSelectDto {
     private String keyword;
 
     /**
-     *统计类型(1:来源统计  2,类型统计  3:业务员统计)
+     * 统计类型(1:来源统计  2,类型统计  3:业务员统计 4:客户标签
      */
     private Integer statisticsType;
 

+ 5 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/customer/po/Customer.java

@@ -139,4 +139,9 @@ public class Customer extends BasePo {
      */
     private Date allocationTime;
 
+    /**
+     * 最后一次跟进时间
+     */
+    private Date lastFollowTime;
+
 }

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

@@ -80,4 +80,9 @@ public interface CustomerService extends BaseService<Customer> {
      */
     List<Long> getAuthIdList();
 
+    /**
+     * 客户跟进统计
+     */
+    Map<String, Object> followStatistics(CustomerSelectDto customerDto);
+
 }

+ 34 - 3
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerFollowRecordsServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.customer.entity.customer.dto.CustomerFollowRecordsDto;
 import com.fjhx.customer.entity.customer.dto.CustomerFollowRecordsSelectDto;
+import com.fjhx.customer.entity.customer.po.Customer;
 import com.fjhx.customer.entity.customer.po.CustomerFollowRecords;
 import com.fjhx.customer.entity.customer.vo.CustomerFollowRecordsVo;
 import com.fjhx.customer.mapper.customer.CustomerFollowRecordsMapper;
@@ -75,11 +76,11 @@ public class CustomerFollowRecordsServiceImpl extends ServiceImpl<CustomerFollow
     }
 
     @Override
-    public List<CustomerFollowRecordsVo> followList(Long customerId){
-        if(ObjectUtil.isEmpty(customerId)){
+    public List<CustomerFollowRecordsVo> followList(Long customerId) {
+        if (ObjectUtil.isEmpty(customerId)) {
             throw new ServiceException("客户id不能为空");
         }
-        List<CustomerFollowRecords> customerFollowRecords = list(q->q.eq(CustomerFollowRecords::getCustomerId,customerId)
+        List<CustomerFollowRecords> customerFollowRecords = list(q -> q.eq(CustomerFollowRecords::getCustomerId, customerId)
                 .orderByDesc(CustomerFollowRecords::getDate));
         List<CustomerFollowRecordsVo> customerFollowRecordsVos = BeanUtil.copyToList(customerFollowRecords, CustomerFollowRecordsVo.class);
         //赋值文件列表信息
@@ -107,6 +108,9 @@ public class CustomerFollowRecordsServiceImpl extends ServiceImpl<CustomerFollow
     public void add(CustomerFollowRecordsDto customerFollowRecordsDto) {
         this.save(customerFollowRecordsDto);
         ObsFileUtil.saveFile(customerFollowRecordsDto.getFileList(), customerFollowRecordsDto.getId());
+
+        //更新最后一次跟进时间
+        updateLastFollowTime(customerFollowRecordsDto.getCustomerId());
     }
 
     @DSTransactional
@@ -114,6 +118,9 @@ public class CustomerFollowRecordsServiceImpl extends ServiceImpl<CustomerFollow
     public void edit(CustomerFollowRecordsDto customerFollowRecordsDto) {
         this.updateById(customerFollowRecordsDto);
         ObsFileUtil.editFile(customerFollowRecordsDto.getFileList(), customerFollowRecordsDto.getId());
+
+        //更新最后一次跟进时间
+        updateLastFollowTime(customerFollowRecordsDto.getCustomerId());
     }
 
     @DSTransactional
@@ -121,6 +128,30 @@ public class CustomerFollowRecordsServiceImpl extends ServiceImpl<CustomerFollow
     public void delete(Long id) {
         this.removeById(id);
         ObsFileUtil.removeFile(id);
+
+        //更新最后一次跟进时间
+        CustomerFollowRecords customerFollowRecords = this.getById(id);
+        if (ObjectUtil.isNotEmpty(customerFollowRecords)) {
+            updateLastFollowTime(customerFollowRecords.getCustomerId());
+        }
+    }
+
+    /**
+     * 更新客户最后一次跟进时间
+     */
+    private synchronized void updateLastFollowTime(Long customerId) {
+        //获取跟进时间最新的一条
+        CustomerFollowRecords customerFollowRecords = this.getOne(q -> q
+                .eq(CustomerFollowRecords::getCustomerId, customerId)
+                .orderByDesc(CustomerFollowRecords::getDate)
+                .orderByDesc(CustomerFollowRecords::getId)
+        );
+        if (ObjectUtil.isNotEmpty(customerFollowRecords)) {
+            customerService.update(q -> q
+                    .eq(Customer::getId, customerId)
+                    .set(Customer::getLastFollowTime, customerFollowRecords.getDate())
+            );
+        }
     }
 
 }

+ 47 - 9
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -372,10 +372,12 @@ 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);
 
-
         UserUtil.assignmentNickName(customerList, Customer::getUserId, Customer::setUserName);
 
         Integer countAmount = customerList.stream().map(Customer::getCount).reduce(Integer::sum).orElse(0);
@@ -384,6 +386,50 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         return map;
     }
 
+    @Override
+    public Map<String, Object> followStatistics(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", ""));
+            }
+        }
+
+        // 客户最后一次跟进时间范围计数
+        QueryWrapper<Customer> clone = query.clone();
+        clone.select("count(1) as count");
+        clone.gt("DATEDIFF( NOW(), last_follow_time )", 7);
+        clone.le("DATEDIFF( NOW(), last_follow_time )", 30);
+        Customer customer = baseMapper.selectOne(clone);
+
+        QueryWrapper<Customer> clone1 = query.clone();
+        clone1.select("count(1) as count");
+        clone1.gt("DATEDIFF( NOW(), last_follow_time )", 30);
+        clone1.le("DATEDIFF( NOW(), last_follow_time )", 180);
+        Customer customer1 = baseMapper.selectOne(clone1);
+
+        QueryWrapper<Customer> clone2 = query.clone();
+        clone2.select("count(1) as count");
+        clone2.gt("DATEDIFF( NOW(), last_follow_time )", 180);
+        clone2.or().isNull("last_follow_time");
+        Customer customer2 = baseMapper.selectOne(clone2);
+
+        //返回最终结果
+        Map<String, Object> map = new HashMap<>();
+        map.put("7", customer.getCount());
+        map.put("30", customer1.getCount());
+        map.put("180", customer2.getCount());
+        return map;
+    }
+
     /**
      * 客户分配
      */
@@ -398,14 +444,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         return listObject(Customer::getId, q -> q.in(Customer::getUserId, authUserIdList));
     }
 
-    // 根据字典编码获取字典的数据
-    private List<DictTenantDataVo> getDict(String code) {
-        DictTenantDataSelectDto dto = new DictTenantDataSelectDto();
-        dto.setDictCode(code);
-        List<DictTenantDataVo> dictTenantDataServiceList = dictTenantDataService.getList(dto);
-        return dictTenantDataServiceList;
-    }
-
     @Override
     public CustomerCodeAndCountryId getCustomerCodeAndCountryId(Long customerId) {
         if (customerId == null) {

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -2388,7 +2388,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 .in("cp.product_id", pIds)
                 .orderByDesc("c.create_time")
                 .orderByDesc("c.id")
-                .last("LIMIT 3")
+                .last("LIMIT 20")
         );
         Map<Long, List<ContractProductVo>> contractProductMap =
                 contractProductList.stream().collect(Collectors.groupingBy(ContractProduct::getProductId));

+ 13 - 9
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -516,15 +516,19 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         List<Long> productIds = dto.getProductIds();
 
         //产品在该供应商近20条采购价格
-        List<EhsdPurchaseProductVo> supplyPurchaseProductList = baseMapper.getProductPriceInfo(IWrapper.getWrapper()
-                .in("epp.product_id", productIds)
-                .eq(EhsdPurchase::getSellCorporationId, dto.getSellCorporationId())
-                .orderByDesc(EhsdPurchase::getCreateTime)
-                .orderByDesc(EhsdPurchase::getId)
-                .last("LIMIT 20")
-        );
-        Map<Long, List<EhsdPurchaseProductVo>> supplyPurchaseProductMap =
-                supplyPurchaseProductList.stream().collect(Collectors.groupingBy(EhsdPurchaseProductVo::getProductId));
+        Map<Long, List<EhsdPurchaseProductVo>> supplyPurchaseProductMap = new HashMap<>();
+        Long sellCorporationId = dto.getSellCorporationId();
+        if (ObjectUtils.isNotEmpty(sellCorporationId)) {
+            List<EhsdPurchaseProductVo> supplyPurchaseProductList = baseMapper.getProductPriceInfo(IWrapper.getWrapper()
+                    .in("epp.product_id", productIds)
+                    .eq(EhsdPurchase::getSellCorporationId, sellCorporationId)
+                    .orderByDesc(EhsdPurchase::getCreateTime)
+                    .orderByDesc(EhsdPurchase::getId)
+                    .last("LIMIT 20")
+            );
+            supplyPurchaseProductMap =
+                    supplyPurchaseProductList.stream().collect(Collectors.groupingBy(EhsdPurchaseProductVo::getProductId));
+        }
         //产品近20条采购价格
         List<EhsdPurchaseProductVo> purchaseProductList = baseMapper.getProductPriceInfo(IWrapper.getWrapper()
                 .in("epp.product_id", productIds)