首页接口

master
jiangyunjie 6 years ago
parent 2ae3ef9b6d
commit 0edba6660d

@ -59,6 +59,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/store/emp/download/store/code", "anon");
filterChainDefinitionMap.put("/store/emp/download/store/seller/code", "anon");
filterChainDefinitionMap.put("/department/sync", "anon");
filterChainDefinitionMap.put("/store/promotion/data/**", "anon");
// 配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/logout", "logout");
// 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了

@ -58,6 +58,16 @@ public class Constants {
*/
public static final Integer STORE_SELLER_CUS_RELATION_TYPE_VALID = 1;
/**
*
*/
public static final String WX_USER_ROLE_SHOP_MANAGER = "DZ-DIANZHANG";
/**
*
*/
public static final String WX_USER_ROLE_STAFF = "DG-DAOGOU";
// 店铺人员类型 1 店长 4 导购
public static final long TYPE_SELLER = 4;
public static final long TYPE_MANAGER = 1;

@ -49,7 +49,7 @@ public class StorePromotionDataController extends BaseController {
*/
@RequestMapping(value = "list",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> listStorePromotionDate(@RequestParam("userId") Long userId,
public Map<String,Object> listStorePromotionData(@RequestParam("userId") Long userId,
@RequestParam(value = "storeId", required = false) Long storeId,
@RequestParam(value = "regionId", required = false) Long regionId,
@RequestParam(value = "sellerId", required = false) Long sellerId,
@ -59,7 +59,7 @@ public class StorePromotionDataController extends BaseController {
@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = "15") int pageSize){
try {
PageInfo<StorePromotionDataDO> storePromotionDataDOS = storePromotionDataService.listStorePromotionDate(userId, storeId,
PageInfo<StorePromotionDataDO> storePromotionDataDOS = storePromotionDataService.listStorePromotionData(userId, storeId,
regionId, sellerId, startDate, endDate, type, pageNum, pageSize);
return data(storePromotionDataDOS);
}catch (Exception e){
@ -67,4 +67,30 @@ public class StorePromotionDataController extends BaseController {
return fail();
}
}
/**
* 广
* @param userId
* @param roleCode
* @param startDate
* @param endDate
* @return
*/
@RequestMapping(value = "list/wx",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> listStorePromotionDataWx(@RequestParam("userId") Long userId,
@RequestParam("roleCode") String roleCode,
@RequestParam(value = "startDate", required = false) Date startDate,
@RequestParam(value = "endDate", required = false) Date endDate,
@RequestParam(value = "lastStartDate", required = false) Date lastStartDate,
@RequestParam(value = "lastEndDate", required = false) Date lastEndDate){
try {
StorePromotionDataDO storePromotionDataDOS = storePromotionDataService.listStorePromotionDataWx(userId, roleCode, startDate, endDate, lastStartDate,
lastEndDate);
return data(storePromotionDataDOS);
}catch (Exception e){
log.error("查询门店推广数据列表",e);
return fail();
}
}
}

@ -0,0 +1,33 @@
package com.kiisoo.ic.store.entity;
import lombok.Data;
/**
* @Description: wx
* @Author: JYJ
* @Date: 2020/4/20 10:15
* @Version: v1.0
*/
@Data
public class StaffDO {
/**
*
*/
private Long id;
/**
*
*/
private String staffName;
/**
*
*/
private Integer cusNum;
/**
*
*/
private Integer newCusNum;
}

@ -4,6 +4,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @Description:
@ -103,4 +104,24 @@ public class StorePromotionDataDO {
*
*/
private Date maxDate;
/**
*
*/
private List<StaffDO> staffDOList;
/**
*
*/
private Integer newCusNumLast;
/**
*
*/
private Integer rankNo;
/**
*
*/
private Integer differFromChampion;
}

@ -1,5 +1,6 @@
package com.kiisoo.ic.store.mapper;
import com.kiisoo.ic.store.entity.StaffDO;
import com.kiisoo.ic.store.entity.StorePromotionDataDO;
import com.kiisoo.ic.store.entity.WxCusInfoRespDO;
import org.apache.ibatis.annotations.Param;
@ -132,4 +133,62 @@ public interface StorePromotionDataDOMapper {
*/
List<StorePromotionDataDO> selectWxCusInfoByStoreId(@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
/**
*
* @param userId
* @param storeId
* @param startDate
* @param endDate
* @param type Type 1.()2.
* @return
*/
Integer selectWxSumCusNumByCondition(@Param("userId") Long userId,
@Param("storeId") Long storeId,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
@Param("type") Integer type);
/**
* id
* @param userId
* @return
*/
Long selectStoreIdByUserId(@Param("userId") Long userId);
/**
*
* @param storeId
* @param startDate
* @param endDate
* @return
*/
List<StaffDO> selectWxStaffDOList(@Param("storeId") Long storeId,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
/**
*
* @param storeId
* @return
*/
List<StaffDO> selectWxValidStaffNameList(@Param("storeId") Long storeId);
/**
*
* @param startDate
* @param endDate
* @return
*/
List<StorePromotionDataDO> selectStoreRankNo(@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
/**
*
* @param startDate
* @param endDate
* @return
*/
List<StorePromotionDataDO> selectStaffRankNo(@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
}

@ -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;
}
}

@ -11,7 +11,7 @@
poi_store t1
LEFT JOIN op_seller_customer_relation t4 on t1.id = t4.store_id
<if test="startDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
@ -89,7 +89,7 @@
poi_store t1
LEFT JOIN op_seller_customer_relation t4 on t1.id = t4.store_id
<if test="startDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
@ -169,7 +169,7 @@
poi_store_staff t1
LEFT JOIN op_seller_customer_relation t2 ON t1.id = t2.user_id
<if test="startDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
@ -239,6 +239,9 @@
<if test="storeId != null">
and t1.store_id = #{storeId}
</if>
<if test="sellerId != null">
and t1.id = #{sellerId}
</if>
<if test="regionId != null">
and t4.region_id = #{regionId}
</if>
@ -285,4 +288,103 @@
AND stat_time &lt;= #{endDate}
group by store_id
</select>
<select id="selectWxSumCusNumByCondition" resultType="java.lang.Integer">
SELECT count(customer_id) from op_seller_customer_relation
where 1 = 1
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="storeId != null">
AND store_id = #{storeId}
</if>
<if test="startDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
</if>
<if test="type != null">
AND `type` = #{type}
</if>
<if test="userId != null">
group by user_id
</if>
<if test="storeId != null">
group by store_id
</if>
</select>
<select id="selectStoreIdByUserId" resultType="java.lang.Long">
SELECT store_id FROM poi_store_staff WHERE user_id = #{userId} and type = 1 and status = 1 and deleted = 0
</select>
<select id="selectWxStaffDOList" resultType="com.kiisoo.ic.store.entity.StaffDO">
SELECT
user_id AS id,
count( customer_id ) AS cusNum
FROM
`op_seller_customer_relation`
WHERE
store_id = #{storeId}
<if test="startDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
</if>
GROUP BY
user_id
</select>
<select id="selectWxValidStaffNameList" resultType="com.kiisoo.ic.store.entity.StaffDO">
SELECT
DISTINCT
t1.user_id as id,
t2.NAME AS staffName
FROM
poi_store_staff t1,
privilage_user t2
WHERE
t1.user_id = t2.id
AND t1.type = 4
AND t1.STATUS = 1
AND t1.deleted = 0
AND t2.STATUS = 1
</select>
<select id="selectStoreRankNo" resultType="com.kiisoo.ic.store.entity.StorePromotionDataDO">
SELECT
a.storeId,
a.newCusNum,
@rank := @rank + 1 AS rankNo
FROM
( SELECT count( customer_id ) AS newCusNum, store_id AS storeId FROM
`op_seller_customer_relation`
<if test="startDate != null">
WHERE DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
</if>
GROUP BY store_id ORDER BY newCusNum DESC ) a,
( SELECT @rank := 0 ) b
</select>
<select id="selectStaffRankNo" resultType="com.kiisoo.ic.store.entity.StorePromotionDataDO">
SELECT
a.userId,
a.newCusNum,
@rank := @rank + 1 AS rankNo
FROM
( SELECT count( customer_id ) AS newCusNum, user_id AS userId FROM
`op_seller_customer_relation`
<if test="startDate != null">
WHERE DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
</if>
GROUP BY user_id ORDER BY newCusNum DESC ) a,
( SELECT @rank := 0 ) b
</select>
</mapper>

Loading…
Cancel
Save