Просмотр исходного кода

[需求][1000115]:返回每个会员等级的人数

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
9b9226bfbe
7 измененных файлов: 106 добавлений и 33 удалений
  1. +1
    -1
      mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java
  2. +41
    -10
      mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java
  3. +11
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxLevelConfig.java
  4. +11
    -8
      mallinkService/src/main/java/com/iformall/mapper/WxCouponActionLogMapper.java
  5. +3
    -3
      mallinkService/src/main/java/com/iformall/service/impl/MarkingDataReportServiceImpl.java
  6. +19
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxLevelConfigServiceImpl.java
  7. +20
    -9
      mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml

+ 1
- 1
mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java Просмотреть файл

@@ -96,7 +96,7 @@ public class WxMerchantBUserController extends BaseController {


return new ResultData(resultMap); return new ResultData(resultMap);
} }


/** /**
* 用户登录 * 用户登录


+ 41
- 10
mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java Просмотреть файл

@@ -1,11 +1,13 @@
package com.iformall.schedule; package com.iformall.schedule;


import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.iformall.common.ErrorCode;
import com.iformall.domain.dto.WxCUserBasicInfoDto; import com.iformall.domain.dto.WxCUserBasicInfoDto;
import com.iformall.domain.po.*; import com.iformall.domain.po.*;
import com.iformall.domain.vo.WxCouponSendVo; import com.iformall.domain.vo.WxCouponSendVo;
import com.iformall.enums.EnumCouponSendSendType; import com.iformall.enums.EnumCouponSendSendType;
import com.iformall.enums.EnumCouponSendStatus; import com.iformall.enums.EnumCouponSendStatus;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.*; import com.iformall.mapper.*;
import com.iformall.service.WxCouponActionLogService; import com.iformall.service.WxCouponActionLogService;
import com.iformall.service.WxCouponSendService; import com.iformall.service.WxCouponSendService;
@@ -18,9 +20,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;


import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;


@Component @Component
@@ -43,6 +47,9 @@ public class CouponSendSchedule {
@Autowired @Autowired
private WxCouponSendMapper wxCouponSendMapper; private WxCouponSendMapper wxCouponSendMapper;


@Autowired
private WxCouponActionLogMapper wxCouponActionLogMapper;

@Autowired @Autowired
private WxOrderService wxOrderService; private WxOrderService wxOrderService;


@@ -61,6 +68,17 @@ public class CouponSendSchedule {
return; return;
} }


Date startTime = Date.from(LocalDateTime.now()
.with(TemporalAdjusters.firstDayOfMonth())
.with(LocalTime.MIN)
.atZone(ZoneId.systemDefault())
.toInstant());
Date endTime = Date.from(LocalDateTime.now()
.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX)
.atZone(ZoneId.systemDefault())
.toInstant());

mallList.stream().forEach(mall-> { mallList.stream().forEach(mall-> {


WxLevelConfig wxLevelConfig = new WxLevelConfig(); WxLevelConfig wxLevelConfig = new WxLevelConfig();
@@ -95,8 +113,8 @@ public class CouponSendSchedule {
List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend); List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend);
couponSendList.stream().forEach(cs->{ couponSendList.stream().forEach(cs->{
if (cs.getRemainInventory() < sendCount){ if (cs.getRemainInventory() < sendCount){
logger.error("定时发券:库存不足 levelId="+ l.getId() +"couponId="+ cs.getCouponId());
return; //下一个券
logger.error("定时发券:库存不足 levelId="+ l.getId() +" couponId="+ cs.getCouponId());
return; //下一个券
} }
WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto();
wxCUserBasicInfoDto.setTenantId(l.getTenantId()); wxCUserBasicInfoDto.setTenantId(l.getTenantId());
@@ -106,11 +124,23 @@ public class CouponSendSchedule {


wxCUserBasicInfoList.stream().forEach(cu->{ wxCUserBasicInfoList.stream().forEach(cu->{
if (cs.getRemainInventory() < sendCount){ if (cs.getRemainInventory() < sendCount){
logger.error("定时发券:库存不足 levelId="+ l.getId() +"couponId="+ cs.getCouponId()+"userId="+cu.getId());
logger.error("定时发券:库存不足 levelId="+ l.getId() +" couponId="+ cs.getCouponId()+"userId="+cu.getId());
return; //下一个券 return; //下一个券
} }


for (int count = 0; count<sendCount; count++) {
Map params = new HashMap<String, Object>();
params.put("tenantId", cs.getTenantId());
params.put("cUserId", cu.getId());
params.put("couponId", cs.getCouponId());
params.put("startTime", startTime);
params.put("endTime", endTime );
int sentCount = wxCouponActionLogMapper.getCountByUserAndCouponAndDate(params);

logger.info("定时发券:给["+ cu.getNickName() +
"]已发送券[" + cs.getTitle() + "] " +
sentCount +"张,还需发"+ (sendCount-sentCount) +"张");

for (int count = 0; count<sendCount-sentCount; count++) {
// 发放免费券 // 发放免费券
try { try {
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId());
@@ -122,9 +152,10 @@ public class CouponSendSchedule {


logger.info("定时发券:商场[" + mall.getName() + logger.info("定时发券:商场[" + mall.getName() +
"]会员等级[" + l.getLevel() + "]会员等级[" + l.getLevel() +
"]发送券" + cs.getTitle() +
"]给[" + cu.getNickName() +
"] 电话:" + cu.getPhone() + "id:" + cu.getId());
"]发送券[" + cs.getTitle() +
"]给:" + cu.getNickName() +
" 电话-" + cu.getPhone() +
" id-" + cu.getId());
} }
}); });
}); });


+ 11
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxLevelConfig.java Просмотреть файл

@@ -70,6 +70,9 @@ public class WxLevelConfig implements Serializable {
@Transient @Transient
protected Long count; protected Long count;


@Transient
protected Long userCount;

public String getTenantId() { public String getTenantId() {
return tenantId; return tenantId;
} }
@@ -135,6 +138,14 @@ public class WxLevelConfig implements Serializable {
this.capability = capability; this.capability = capability;
} }


public Long getUserCount() {
return userCount;
}

public void setUserCount(Long userCount) {
this.userCount = userCount;
}

public static enum Field public static enum Field
{ {
Id_ASC("`id` ASC"),Id_DESC("`id` DESC") Id_ASC("`id` ASC"),Id_DESC("`id` DESC")


+ 11
- 8
mallinkService/src/main/java/com/iformall/mapper/WxCouponActionLogMapper.java Просмотреть файл

@@ -10,14 +10,6 @@ import com.iformall.domain.po.WxCouponActionLog;
public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog, String> { public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog, String> {


List<WxCouponActionLog> findList(WxCouponActionLog wxCouponActionLog); List<WxCouponActionLog> findList(WxCouponActionLog wxCouponActionLog);
/**
* 查询场景投放发券数
* @param tenantId
* @param startTime
* @param endTime
* @return
*/
int findCountByDateLimit(@Param("tenantId")String tenantId,@Param("startTime") Date startTime,@Param("endTime")Date endTime);


List<MarkingSceneDataReportVo> sceneDataMap(HashMap<String,Object> params); List<MarkingSceneDataReportVo> sceneDataMap(HashMap<String,Object> params);


@@ -27,6 +19,15 @@ public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog,


List<MarkingSceneDataReportVo> sceneDataJoinCouponOrderList(HashMap<String,Object> params); List<MarkingSceneDataReportVo> sceneDataJoinCouponOrderList(HashMap<String,Object> params);


/**
* 查询场景投放发券数
* @param tenantId
* @param startTime
* @param endTime
* @return
*/
int getCountByDateLimit(@Param("tenantId")String tenantId,@Param("startTime") Date startTime,@Param("endTime")Date endTime);



int getCountByChannelId(@Param("tenantId")String tenantId,@Param("channelType") int channelType,@Param("channelId")Long channelId); int getCountByChannelId(@Param("tenantId")String tenantId,@Param("channelType") int channelType,@Param("channelId")Long channelId);


@@ -44,4 +45,6 @@ public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog,
*/ */
int getCountByUserAndCoupon(Map<String,Object> params); int getCountByUserAndCoupon(Map<String,Object> params);



int getCountByUserAndCouponAndDate(Map<String,Object> params);
} }

+ 3
- 3
mallinkService/src/main/java/com/iformall/service/impl/MarkingDataReportServiceImpl.java Просмотреть файл

@@ -128,9 +128,9 @@ public class MarkingDataReportServiceImpl implements MarkingDataReportService {
@Override @Override
public Map<String, Object> getSceneData(String tenantId) { public Map<String, Object> getSceneData(String tenantId) {
//今日营销投放券数 //今日营销投放券数
int todaySceneCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId, addDay(0), addDay(1));
int yesterdayCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId, addDay(-1), addDay(0));
int lastWeekCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId, addDay(-7), addDay(-6));
int todaySceneCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(0), addDay(1));
int yesterdayCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-1), addDay(0));
int lastWeekCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-7), addDay(-6));


NumberFormat nf = NumberFormat.getPercentInstance(); NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点


+ 19
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxLevelConfigServiceImpl.java Просмотреть файл

@@ -3,9 +3,11 @@ package com.iformall.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.iformall.domain.dto.WxCUserBasicInfoDto;
import com.iformall.domain.po.WxLevelConfig; import com.iformall.domain.po.WxLevelConfig;
import com.iformall.domain.po.WxLevelMerchant; import com.iformall.domain.po.WxLevelMerchant;
import com.iformall.domain.vo.WxLevelMerchantCVo; import com.iformall.domain.vo.WxLevelMerchantCVo;
import com.iformall.mapper.WxCUserBasicInfoMapper;
import com.iformall.mapper.WxLevelConfigMapper; import com.iformall.mapper.WxLevelConfigMapper;
import com.iformall.mapper.WxLevelMerchantMapper; import com.iformall.mapper.WxLevelMerchantMapper;
import com.iformall.service.WxLevelConfigService; import com.iformall.service.WxLevelConfigService;
@@ -28,17 +30,32 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService {
@Autowired @Autowired
WxLevelMerchantMapper wxLevelMerchantapper; WxLevelMerchantMapper wxLevelMerchantapper;


@Autowired
WxCUserBasicInfoMapper wxCUserBasicInfoMapper;

@Override @Override
public PageInfo<WxLevelConfig> listAsPage(WxLevelConfig record, Integer pageIndex, Integer pageSize) { public PageInfo<WxLevelConfig> listAsPage(WxLevelConfig record, Integer pageIndex, Integer pageSize) {
PageInfo<WxLevelConfig> page = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxLevelConfigMapper.findList(record)); PageInfo<WxLevelConfig> page = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxLevelConfigMapper.findList(record));
page.getList().stream().forEach(l->{

for (int i=0;i<page.getList().size();i++)
{
WxLevelConfig l = page.getList().get(i);
if (l.getCapability()!= null){ if (l.getCapability()!= null){
JSONObject jo = JSONObject.parseObject(l.getCapability()); JSONObject jo = JSONObject.parseObject(l.getCapability());
l.setCount(jo.getLong(CAPABILITY_SEND_CAR_COUPON)); l.setCount(jo.getLong(CAPABILITY_SEND_CAR_COUPON));
}else { }else {
l.setCount(0L); l.setCount(0L);
} }
});

WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto();
dto.setTenantId(l.getTenantId());
dto.setLevelStartScore(l.getPoints());
if (i + 1<page.getList().size())
dto.setLevelEndScore(page.getList().get(i+1).getPoints());

l.setUserCount(wxCUserBasicInfoMapper.findCountByScore(dto));

}
return page; return page;
} }




+ 20
- 9
mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml Просмотреть файл

@@ -72,15 +72,6 @@
<include refid="dynamicWhereConditions" /> <include refid="dynamicWhereConditions" />
</select> </select>


<select id="findCountByDateLimit" resultType="java.lang.Integer">
select COUNT(*) FROM wx_coupon_action_log
where tenant_id = #{tenantId}
and `channel_type` != 0
and `channel_type` != 1
and `create_time` &gt;= #{startTime}
and `create_time` &lt;= #{endTime}
</select>

<select id="sceneDataMap" resultType="com.iformall.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap"> <select id="sceneDataMap" resultType="com.iformall.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap">
select DATE_FORMAT(create_time,'%m/%d') as xTime, select DATE_FORMAT(create_time,'%m/%d') as xTime,
(select Count(*) from wx_coupon_action_log c (select Count(*) from wx_coupon_action_log c
@@ -155,6 +146,15 @@
</select> </select>




<select id="getCountByDateLimit" resultType="java.lang.Integer">
select COUNT(*) FROM wx_coupon_action_log
where tenant_id = #{tenantId}
and `channel_type` != 0
and `channel_type` != 1
and `create_time` &gt;= #{startTime}
and `create_time` &lt;= #{endTime}
</select>

<select id="getCountByChannelId" resultType="java.lang.Integer"> <select id="getCountByChannelId" resultType="java.lang.Integer">
select COUNT(*) FROM wx_coupon_action_log select COUNT(*) FROM wx_coupon_action_log
where tenant_id = #{tenantId} where tenant_id = #{tenantId}
@@ -181,4 +181,15 @@
AND date(a.create_time) between date_sub(curdate(),interval #{dayNum} day) and curdate() AND date(a.create_time) between date_sub(curdate(),interval #{dayNum} day) and curdate()
</select> </select>


<select id="getCountByUserAndCouponAndDate" resultType="java.lang.Integer" parameterType="hashmap">
select COUNT(*)
FROM wx_coupon_action_log a, wx_coupon_order o
WHERE a.coupon_order_id = o.id
AND a.tenant_id = #{tenantId}
AND o.c_user_id = #{cUserId}
AND a.coupon_id = #{couponId}
and a.create_time &gt;= #{startTime}
and a.create_time &lt;= #{endTime}
</select>

</mapper> </mapper>

Загрузка…
Отмена
Сохранить