|
|
|
@ -7,6 +7,7 @@ import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.kiisoo.ic.config.WxCpConfiguration;
|
|
|
|
|
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
|
|
|
|
import com.kiisoo.ic.store.constant.Constants;
|
|
|
|
|
import com.kiisoo.ic.store.entity.StaffDO;
|
|
|
|
|
import com.kiisoo.ic.store.entity.StorePromotionDataDO;
|
|
|
|
|
import com.kiisoo.ic.store.entity.WxCusInfoReqDO;
|
|
|
|
|
import com.kiisoo.ic.store.entity.WxCusInfoRespDO;
|
|
|
|
@ -14,16 +15,14 @@ import com.kiisoo.ic.store.mapper.StorePromotionDataDOMapper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -61,7 +60,7 @@ public class StorePromotionDataService {
|
|
|
|
|
* @param pageSize
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public PageInfo<StorePromotionDataDO> listStorePromotionDate(Long userId, Long storeId, Long regionId, Long sellerId,
|
|
|
|
|
public PageInfo<StorePromotionDataDO> listStorePromotionData(Long userId, Long storeId, Long regionId, Long sellerId,
|
|
|
|
|
Date startDate, Date endDate, String type, int pageNum, int pageSize) {
|
|
|
|
|
//用户权限下的店铺
|
|
|
|
|
List<Long> storeIds = privilageDomainService.listUserDatePermission(userId);
|
|
|
|
@ -275,4 +274,103 @@ public class StorePromotionDataService {
|
|
|
|
|
String[] behavior_data = JSONObject.parseObject(parseObject.getString("behavior_data"), String[].class);
|
|
|
|
|
return JSONObject.parseObject(behavior_data[0], WxCusInfoRespDO.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询门店推广数据列表 手机端
|
|
|
|
|
* @param userId
|
|
|
|
|
* @param roleCode
|
|
|
|
|
* @param startDate
|
|
|
|
|
* @param endDate
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public StorePromotionDataDO listStorePromotionDataWx(Long userId, String roleCode,
|
|
|
|
|
Date startDate, Date endDate, Date lastStartDate, Date lastEndDate) {
|
|
|
|
|
StorePromotionDataDO storePromotionDataDO = new StorePromotionDataDO();
|
|
|
|
|
Integer cusNum = null;
|
|
|
|
|
Integer newCusNum = null;
|
|
|
|
|
Integer newCusNumLast = null;
|
|
|
|
|
Integer rankNo = null;
|
|
|
|
|
Integer differFromChampion = null;
|
|
|
|
|
switch (roleCode) {
|
|
|
|
|
// 店长
|
|
|
|
|
case Constants.WX_USER_ROLE_SHOP_MANAGER:
|
|
|
|
|
Long storeId = storePromotionDataDOMapper.selectStoreIdByUserId(userId);
|
|
|
|
|
cusNum = storePromotionDataDOMapper.selectWxSumCusNumByCondition(null, storeId, null, null, Constants.STORE_SELLER_CUS_RELATION_TYPE_VALID);
|
|
|
|
|
newCusNum = storePromotionDataDOMapper.selectWxSumCusNumByCondition(null, storeId, startDate, endDate, Constants.STORE_SELLER_CUS_RELATION_TYPE_VALID);
|
|
|
|
|
newCusNumLast = storePromotionDataDOMapper.selectWxSumCusNumByCondition(null, storeId, lastStartDate, lastEndDate, Constants.STORE_SELLER_CUS_RELATION_TYPE_VALID);
|
|
|
|
|
// 店铺排名
|
|
|
|
|
List<StorePromotionDataDO> storeRankNoList = storePromotionDataDOMapper.selectStoreRankNo(startDate, endDate);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(storeRankNoList)) {
|
|
|
|
|
for (int i = 0; i < storeRankNoList.size(); i++) {
|
|
|
|
|
if (storeRankNoList.get(i).getStoreId().equals(storeId)) {
|
|
|
|
|
rankNo = storeRankNoList.get(i).getRankNo();
|
|
|
|
|
Integer curNewCusNum = storeRankNoList.get(i).getNewCusNum();
|
|
|
|
|
Integer championNewCusNum = storeRankNoList.get(0).getNewCusNum();
|
|
|
|
|
differFromChampion = championNewCusNum - curNewCusNum;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 导购列表
|
|
|
|
|
List<StaffDO> staffDOList = storePromotionDataDOMapper.selectWxValidStaffNameList(storeId);
|
|
|
|
|
// 导购新增客户数列表
|
|
|
|
|
List<StaffDO> staffNewCusNumList = storePromotionDataDOMapper.selectWxStaffDOList(storeId, startDate, endDate);
|
|
|
|
|
Map<Long, Integer> staffNewCusNumMap = staffNewCusNumList.stream().collect(Collectors.toMap(StaffDO::getId, StaffDO::getCusNum, (k1, k2) -> k1));
|
|
|
|
|
// 导购总客户数
|
|
|
|
|
List<StaffDO> staffCusNumList = storePromotionDataDOMapper.selectWxStaffDOList(storeId, null, null);
|
|
|
|
|
Map<Long, Integer> staffCusNumMap = staffCusNumList.stream().collect(Collectors.toMap(StaffDO::getId, StaffDO::getCusNum, (k1, k2) -> k1));
|
|
|
|
|
staffDOList.forEach(storeDO ->{
|
|
|
|
|
Long id = storeDO.getId();
|
|
|
|
|
if (null != staffCusNumMap && staffCusNumMap.get(id) != null) {
|
|
|
|
|
storeDO.setCusNum(staffCusNumMap.get(id));
|
|
|
|
|
}
|
|
|
|
|
if (null != staffNewCusNumMap && staffNewCusNumMap.get(id) != null) {
|
|
|
|
|
storeDO.setNewCusNum(staffNewCusNumMap.get(id));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (CollectionUtils.isNotEmpty(staffDOList)) {
|
|
|
|
|
// 总客户数降序
|
|
|
|
|
staffDOList.stream().sorted(Comparator.comparing(StaffDO::getCusNum, Comparator.nullsLast(Integer::compareTo))).findFirst().get();
|
|
|
|
|
storePromotionDataDO.setStaffDOList(staffDOList);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// 导购
|
|
|
|
|
case Constants.WX_USER_ROLE_STAFF:
|
|
|
|
|
cusNum = storePromotionDataDOMapper.selectWxSumCusNumByCondition(userId, null, null, null, null);
|
|
|
|
|
newCusNum = storePromotionDataDOMapper.selectWxSumCusNumByCondition(userId, null, startDate, endDate, null);
|
|
|
|
|
newCusNumLast = storePromotionDataDOMapper.selectWxSumCusNumByCondition(userId, null, lastStartDate, lastEndDate, null);
|
|
|
|
|
// 店铺排名
|
|
|
|
|
List<StorePromotionDataDO> staffRankNoList = storePromotionDataDOMapper.selectStaffRankNo(startDate, endDate);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(staffRankNoList)) {
|
|
|
|
|
for (int i = 0; i < staffRankNoList.size(); i++) {
|
|
|
|
|
if (staffRankNoList.get(i).getUserId().equals(userId)) {
|
|
|
|
|
rankNo = staffRankNoList.get(i).getRankNo();
|
|
|
|
|
Integer curNewCusNum = staffRankNoList.get(i).getNewCusNum();
|
|
|
|
|
Integer championNewCusNum = staffRankNoList.get(0).getNewCusNum();
|
|
|
|
|
differFromChampion = championNewCusNum - curNewCusNum;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (null != cusNum) {
|
|
|
|
|
storePromotionDataDO.setCusNum(cusNum);
|
|
|
|
|
}
|
|
|
|
|
if (null != newCusNum) {
|
|
|
|
|
storePromotionDataDO.setNewCusNum(newCusNum);
|
|
|
|
|
}
|
|
|
|
|
if (null != newCusNumLast) {
|
|
|
|
|
storePromotionDataDO.setNewCusNumLast(newCusNumLast);
|
|
|
|
|
}
|
|
|
|
|
if (null != rankNo) {
|
|
|
|
|
storePromotionDataDO.setRankNo(rankNo);
|
|
|
|
|
}
|
|
|
|
|
if (null != differFromChampion) {
|
|
|
|
|
storePromotionDataDO.setDifferFromChampion(differFromChampion);
|
|
|
|
|
}
|
|
|
|
|
return storePromotionDataDO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|