|
|
|
|
package com.kiisoo.ic.customer.service;
|
|
|
|
|
|
|
|
|
|
import com.kiisoo.ic.customer.entity.CustomerViewVO;
|
|
|
|
|
import com.kiisoo.ic.customer.entity.OpCustomer;
|
|
|
|
|
import com.kiisoo.ic.customer.entity.OpVip;
|
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
|
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
|
|
|
|
|
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
|
|
|
|
import com.kiisoo.ic.store.entity.PoiStore;
|
|
|
|
|
import com.kiisoo.ic.store.service.PoiStoreService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 客户数据概览service
|
|
|
|
|
* @Author: wangyinjia
|
|
|
|
|
* @Date: 2020/4/9
|
|
|
|
|
* @Company: kiisoo
|
|
|
|
|
* @Version: 1.0
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class CustomerViewService {
|
|
|
|
|
|
|
|
|
|
/**零*/
|
|
|
|
|
static final Long ZERO_L= 0L;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户权限mapper
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageDomainService privilageDomainService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 店铺mapper
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private PoiStoreService poiStoreService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 客户mapper
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private OpCustomerDOMapper opCustomerDOMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* vip mapper
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private OpVipDOMapper opVipDOMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 客户概览main
|
|
|
|
|
* @param userId 用户id
|
|
|
|
|
* @param organizationId 零售公司id
|
|
|
|
|
* @param shopId 店铺id
|
|
|
|
|
* @param sevenDayStartTime 近七天开始时间
|
|
|
|
|
* @param sevenDayEndTime 近七天结束时间
|
|
|
|
|
* @return 客户概览VO
|
|
|
|
|
*/
|
|
|
|
|
public CustomerViewVO selectCustomerViewMain(Long userId, Long organizationId, Long shopId, String sevenDayStartTime, String sevenDayEndTime){
|
|
|
|
|
CustomerViewVO customerViewVO = new CustomerViewVO();
|
|
|
|
|
//shopIds
|
|
|
|
|
// List<Long> shopIds = getShopIds(userId, regionId, shopId);
|
|
|
|
|
List<Long> shopIds = new ArrayList<>();
|
|
|
|
|
//客户list
|
|
|
|
|
List<OpCustomer> customerList = opCustomerDOMapper.selectCustomerList(shopIds, null, null, null, null);
|
|
|
|
|
//会员list
|
|
|
|
|
List<OpVip> vipList = opVipDOMapper.selectVipList(shopIds, null, null);
|
|
|
|
|
|
|
|
|
|
//5大块客户数
|
|
|
|
|
|
|
|
|
|
//设置客户,关联,vip人数
|
|
|
|
|
setCustomerAndVipSize(customerList, vipList, customerViewVO);
|
|
|
|
|
//近七天新增list
|
|
|
|
|
List<OpCustomer> sevenDayCustomerList = customerList.stream().filter(customerDO -> filterSevenDayCustomer(customerDO, sevenDayStartTime, sevenDayEndTime)).collect(Collectors.toList());
|
|
|
|
|
List<OpVip> sevenDayVipList = vipList.stream().filter(vipDO -> filterSevenDayVip(vipDO, sevenDayStartTime, sevenDayEndTime)).collect(Collectors.toList());
|
|
|
|
|
customerViewVO.setSevenDayCustomerList(sevenDayCustomerList);
|
|
|
|
|
customerViewVO.setSevenDayVipList(sevenDayVipList);
|
|
|
|
|
return customerViewVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* shopIds
|
|
|
|
|
* @param userId 用户id
|
|
|
|
|
* @param regionId 区域id
|
|
|
|
|
* @param shopId 店铺id
|
|
|
|
|
* @return shopIds
|
|
|
|
|
*/
|
|
|
|
|
List<Long> getShopIds(Long userId, Long regionId, Long shopId){
|
|
|
|
|
List<Long> shopIds = new ArrayList<>();
|
|
|
|
|
//单店
|
|
|
|
|
if(shopId != null){
|
|
|
|
|
shopIds.add(shopId);
|
|
|
|
|
return shopIds;
|
|
|
|
|
}
|
|
|
|
|
//单区域
|
|
|
|
|
if(regionId != null){
|
|
|
|
|
List<PoiStore> shopList = poiStoreService.getRegionShop(regionId);
|
|
|
|
|
shopIds = shopList.stream().map(PoiStore::getId).collect(Collectors.toList());
|
|
|
|
|
return shopIds;
|
|
|
|
|
}
|
|
|
|
|
//所有shopIds
|
|
|
|
|
shopIds = privilageDomainService.listUserDatePermission(userId);
|
|
|
|
|
return shopIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 客户,关联,vip人数
|
|
|
|
|
* @param customerList 客户List
|
|
|
|
|
* @param vipList vipList
|
|
|
|
|
* @param customerViewVO 客户概览VO
|
|
|
|
|
*/
|
|
|
|
|
public void setCustomerAndVipSize(List<OpCustomer> customerList, List<OpVip> vipList, CustomerViewVO customerViewVO){
|
|
|
|
|
//关联人数(手机号确定)
|
|
|
|
|
List<String> customerPhoneList = customerList.stream().map(OpCustomer::getPhone).distinct().collect(Collectors.toList());
|
|
|
|
|
List<String> vipPhoneList = vipList.stream().map(OpVip::getPhone).distinct().collect(Collectors.toList());
|
|
|
|
|
AtomicLong commonInt = new AtomicLong(0);
|
|
|
|
|
customerPhoneList.forEach(customerPhone -> {
|
|
|
|
|
if(vipPhoneList.contains(customerPhone)){
|
|
|
|
|
commonInt.incrementAndGet();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Long common = commonInt.get();
|
|
|
|
|
customerViewVO.setCommon(common);
|
|
|
|
|
//未关联的客户数
|
|
|
|
|
Long customer = customerList.stream().filter(customerDO -> ZERO_L.equals(customerDO.getMemberId())).map(OpCustomer::getPhone).distinct().count();
|
|
|
|
|
customerViewVO.setCustomer(customer);
|
|
|
|
|
//未关联会员数
|
|
|
|
|
Long vip = vipList.stream().map(OpVip::getPhone).distinct().count();
|
|
|
|
|
customerViewVO.setVip(vip - common);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 过滤客户list
|
|
|
|
|
* @param customerDO 客户DO
|
|
|
|
|
* @param sevenDayStartTime 开始时间
|
|
|
|
|
* @param sevenDayEndTime 结束时间
|
|
|
|
|
* @return 客户list
|
|
|
|
|
*/
|
|
|
|
|
Boolean filterSevenDayCustomer(OpCustomer customerDO, String sevenDayStartTime, String sevenDayEndTime){
|
|
|
|
|
try {
|
|
|
|
|
if(customerDO.getRegisterTime() != null){
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Long start = sdf.parse(sevenDayStartTime).getTime();
|
|
|
|
|
Long end = sdf.parse(sevenDayEndTime).getTime();
|
|
|
|
|
if(customerDO.getRegisterTime().getTime() >= start && customerDO.getRegisterTime().getTime() <= end){
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("过滤近7天客户出错", e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 过滤会员list
|
|
|
|
|
* @param vipDO 会员DO
|
|
|
|
|
* @param sevenDayStartTime 开始时间
|
|
|
|
|
* @param sevenDayEndTime 结束时间
|
|
|
|
|
* @return 会员list
|
|
|
|
|
*/
|
|
|
|
|
Boolean filterSevenDayVip(OpVip vipDO, String sevenDayStartTime, String sevenDayEndTime){
|
|
|
|
|
try {
|
|
|
|
|
if(vipDO.getRegisterTime() != null){
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Long start = sdf.parse(sevenDayStartTime).getTime();
|
|
|
|
|
Long end = sdf.parse(sevenDayEndTime).getTime();
|
|
|
|
|
if(vipDO.getRegisterTime().getTime() >= start && vipDO.getRegisterTime().getTime() <= end){
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("过滤近7天会员出错", e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|