客户数据概览后台

master
wyj2080 6 years ago
parent 0acd3161f8
commit cdb15a30dd

@ -0,0 +1,58 @@
package com.kiisoo.ic.customer.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.customer.entity.CustomerViewVO;
import com.kiisoo.ic.customer.service.CustomerViewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
/**
* @Description:
* @Author: wangyinjia
* @Date: 2020/4/9
* @Company: kiisoo
* @Version: 1.0
*/
@Slf4j
@Controller
@RequestMapping("/customer/view")
public class CustomerViewController extends BaseController {
/**
* service
*/
@Autowired
private CustomerViewService customerViewService;
/**
* main
* @param userId id
* @param regionId id
* @param shopId id
* @param sellerId id
* @param sevenDayStartTime
* @param sevenDayEndTime
* @return VO
*/
@ResponseBody
@RequestMapping(value = "/main", method = RequestMethod.GET)
public Map<String,Object> getMainData(@RequestParam("userId")Long userId, Long regionId, Long shopId, Long sellerId,
@RequestParam("sevenDayStartTime")String sevenDayStartTime, @RequestParam("sevenDayEndTime")String sevenDayEndTime){
try{
CustomerViewVO result = customerViewService.selectCustomerViewMain(userId, regionId, shopId, sellerId, sevenDayStartTime, sevenDayEndTime);
return data(result);
}catch (Exception e){
log.error("查询客户数据概览出错", e);
return fail();
}
}
}

@ -0,0 +1,38 @@
package com.kiisoo.ic.customer.entity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @Description: VO
* @Author: wangyinjia
* @Date: 2020/4/9
* @Company: kiisoo
* @Version: 1.0
*/
@Data
public class CustomerViewVO {
/**未关联的客户*/
private Long customer;
/**已关联人数*/
private Long common;
/**未关联的会员*/
private Long vip;
/**近七天新增客户list*/
List<OpCustomer> sevenDayCustomerList;
/**近七天新增会员list*/
List<OpVip> sevenDayVipList;
/**
*
*/
public CustomerViewVO(){
customer = 0L;
common = 0L;
vip = 0L;
sevenDayCustomerList = new ArrayList<>();
sevenDayVipList = new ArrayList<>();
}
}

@ -98,4 +98,10 @@ public class OpCustomer {
*/
private String updateBy;
/**
*
*/
@TableField(exist = false)
private Date registerTime;
}

@ -1,6 +1,7 @@
package com.kiisoo.ic.customer.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -56,6 +57,11 @@ public class OpVip {
*/
private String mail;
/**
*
*/
private Date registerTime;
/**
*
*/
@ -76,4 +82,8 @@ public class OpVip {
*/
private String updateBy;
/**注册店铺id*/
@TableField(exist = false)
private Long shopId;
}

@ -34,4 +34,11 @@ public interface OpCustomerDOMapper extends BaseMapper<OpCustomer> {
* @return
*/
List<OpCustomerDTO> selectCustomerInfoBySellerId(@Param("sellerId") long sellerId, @Param("startDate") Date startDate,@Param("endDate") Date endDate);
/**
* list
*/
List<OpCustomer> selectCustomerList(@Param("shopIds") List<Long> shopIds, @Param("sellerId") Long sellerId, @Param("memberId") Long memberId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}

@ -2,13 +2,19 @@ package com.kiisoo.ic.customer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kiisoo.ic.customer.entity.OpVip;
import com.kiisoo.ic.customer.entity.OpVipAttr;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
/**
* vip
*/
@Repository
public interface OpVipDOMapper extends BaseMapper<OpVip> {
/**
* list
*/
List<OpVip> selectVipList(@Param("shopIds") List<Long> shopIds, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}

@ -0,0 +1,193 @@
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 regionId id
* @param shopId id
* @param sellerId id
* @param sevenDayStartTime
* @param sevenDayEndTime
* @return VO
*/
public CustomerViewVO selectCustomerViewMain(Long userId, Long regionId, Long shopId, Long sellerId, String sevenDayStartTime, String sevenDayEndTime){
CustomerViewVO customerViewVO = new CustomerViewVO();
//shopIds
List<Long> shopIds = getShopIds(userId, regionId, shopId);
//客户list
List<OpCustomer> customerList = opCustomerDOMapper.selectCustomerList(shopIds, sellerId, null, null, null);
//会员list
List<OpVip> vipList = opVipDOMapper.selectVipList(shopIds, null, null);
//设置客户关联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 - common);
//未关联会员数
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;
}
}
}

@ -52,4 +52,30 @@
GROUP BY t2.id
order by t2.id asc
</select>
<!--客户list-->
<select id="selectCustomerList" resultType="com.kiisoo.ic.customer.entity.OpCustomer">
select t1.id as id, t1.`name` as name,t1.phone as phone, t2.create_time as registerTime
from op_customer t1, op_seller_customer_relation t2
where t1.id=t2.customer_id
<if test="memberId != null">
and t1.member_id = #{memberId}
</if>
<if test="shopIds != null and shopIds.size > 0">
and t2.store_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
</if>
<if test="sellerId != null">
and t2.user_id=#{sellerId}
</if>
<if test="startDate != null">
and t2.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null">
and t2.create_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>
</mapper>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kiisoo.ic.customer.mapper.OpVipDOMapper">
<!--会员list-->
<select id="selectVipList" resultType="com.kiisoo.ic.customer.entity.OpVip">
select t1.id as id, t1.register_time as registerTime, t1.phone as phone, t2.register_store_id as shopId
from op_vip t1,op_vip_attr t2
where t1.id = t2.vip_id
<if test="shopIds != null and shopIds.size > 0">
and t2.register_store_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
</if>
<if test="startDate != null">
and t1.register_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null">
and t1.register_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>
</mapper>
Loading…
Cancel
Save