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

生日积分定时任务,修改执行时间

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
ae5d205a37
3 измененных файлов: 45 добавлений и 22 удалений
  1. +14
    -10
      mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java
  2. +2
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java
  3. +29
    -11
      mallinkService/src/main/java/com/iformall/utils/CreditUtil.java

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

@@ -208,7 +208,7 @@ public class CouponSendSchedule {
/** /**
* 生日券发放 * 生日券发放
*/ */
@Scheduled(cron = "0 0 11 * * ?") // 测试每天6点发券
@Scheduled(cron = "0 0 15 * * ?") // 测试每天6点发券
public void birthdayCouponSendSchedule() { public void birthdayCouponSendSchedule() {
logger.info("生日发券: 任务开始"); logger.info("生日发券: 任务开始");
List<WxMall> mallList = wxMallMapper.findList(new WxMall()); List<WxMall> mallList = wxMallMapper.findList(new WxMall());
@@ -274,6 +274,13 @@ public class CouponSendSchedule {
if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) {
beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS);
} }
//提前n天发送生日券,不满足跳过不执行,没有发送的进行补发
int diffBithday = DateUtils.birthdaysBetween(cu.getBirthdate());
if (diffBithday < 0 || diffBithday > beforeDays) {
logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(), beforeDays);
continue;
}

Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("tenantId", cs.getTenantId()); params.put("tenantId", cs.getTenantId());
params.put("cUserId", cu.getId()); params.put("cUserId", cu.getId());
@@ -289,12 +296,7 @@ public class CouponSendSchedule {
logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName()); logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName());
continue; continue;
} }
//提前n天发送生日券,不满足跳过不执行,没有发送的进行补发
int diffBithday = DateUtils.birthdaysBetween(cu.getBirthdate());
if (diffBithday < 0 || diffBithday > beforeDays) {
logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(), beforeDays);
continue;
}

if (cs.getRemainInventory() <= 0) { if (cs.getRemainInventory() <= 0) {
logger.info("生日发券: [title={},id={}]卡券库存不足!", cs.getTitle(), cs.getCouponId()); logger.info("生日发券: [title={},id={}]卡券库存不足!", cs.getTitle(), cs.getCouponId());
continue; continue;
@@ -319,8 +321,10 @@ public class CouponSendSchedule {
sendSMS(cu, mall); sendSMS(cu, mall);
// 记录积分倍率日期 // 记录积分倍率日期
try { try {
cu.setScoreDate(cu.getBirthdate());
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(cu);
WxCUserBasicInfo toUpdate = new WxCUserBasicInfo() ;
toUpdate.setId(cu.getId());
toUpdate.setScoreDate(cu.getBirthdate());
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdate);
} catch (Exception e) { } catch (Exception e) {
logger.error("定时发券:记录积分倍率日期失败 {}", e.getMessage()); logger.error("定时发券:记录积分倍率日期失败 {}", e.getMessage());
} }
@@ -353,7 +357,7 @@ public class CouponSendSchedule {
wxMsgRecord.setTenantId(cUserBasicInfo.getTenantId()); wxMsgRecord.setTenantId(cUserBasicInfo.getTenantId());
Map<String, String> dynamicContentMap = new HashMap<>(); Map<String, String> dynamicContentMap = new HashMap<>();


int birthdayScale = CreditUtil.getScoreScale(cUserBasicInfo.getTenantId(), wxScoreRulesService);
int birthdayScale = CreditUtil.getBirthdayScoreScale(cUserBasicInfo.getTenantId(), wxScoreRulesService);
if (birthdayScale > WxScoreRules.DEFAULT_SCALE) { if (birthdayScale > WxScoreRules.DEFAULT_SCALE) {
float creditScale = new BigDecimal(birthdayScale).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).floatValue(); float creditScale = new BigDecimal(birthdayScale).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).floatValue();
dynamicContentMap.put("creditScale", String.valueOf(creditScale)); dynamicContentMap.put("creditScale", String.valueOf(creditScale));


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

@@ -2,6 +2,7 @@ package com.iformall.domain.po;


import cn.afterturn.easypoi.excel.annotation.Excel; import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@@ -23,7 +24,7 @@ public class WxCUserBasicInfo extends BaseEntity {
@Id @Id
protected Long id; protected Long id;


@Transient
@JsonIgnore
protected Date scoreDate; protected Date scoreDate;


@Transient @Transient


+ 29
- 11
mallinkService/src/main/java/com/iformall/utils/CreditUtil.java Просмотреть файл

@@ -1,14 +1,10 @@
package com.iformall.utils; package com.iformall.utils;


import com.iformall.domain.po.*; import com.iformall.domain.po.*;
import com.iformall.mapper.WxLevelConfigMapper;
import com.iformall.service.WxCouponActionLogService;
import com.iformall.service.WxCouponOrderService;
import com.iformall.service.WxScoreRulesService; import com.iformall.service.WxScoreRulesService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;


import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects; import java.util.Objects;


@Slf4j @Slf4j
@@ -29,10 +25,10 @@ public class CreditUtil {
return 0; return 0;
} }
// 获取等级积分倍率:默认为1.0, // 获取等级积分倍率:默认为1.0,
int levelScale = calLevelScale(wxCUser, scaleFromDb);
int levelScale = getLevelScale(wxCUser, scaleFromDb);


// 获取生日积分倍率: // 获取生日积分倍率:
int birthdayScale = calBirthdayScale(wxCUserBasicInfo, wxScoreRulesService);
int birthdayScale = getBirthdayScale(wxCUserBasicInfo, wxScoreRulesService);


int creditNew = new BigDecimal(creditOrigin) int creditNew = new BigDecimal(creditOrigin)
.multiply(new BigDecimal(levelScale)) .multiply(new BigDecimal(levelScale))
@@ -44,7 +40,13 @@ public class CreditUtil {
return creditNew; return creditNew;
} }


public static int calLevelScale(WxCUser wxCUser, Integer scaleFromDb) {
/**
* 根据会员信息获取等级积分倍率
* @param wxCUser
* @param scaleFromDb
* @return
*/
private static int getLevelScale(WxCUser wxCUser, Integer scaleFromDb) {
int levelScale = WxLevelConfig.DEFAULT_SCALE; int levelScale = WxLevelConfig.DEFAULT_SCALE;
Integer score = wxCUser.getScore(); Integer score = wxCUser.getScore();
//积分不为空时进行计算 //积分不为空时进行计算
@@ -60,18 +62,34 @@ public class CreditUtil {
return levelScale; return levelScale;
} }


public static int calBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) {
/**
* 根据会员信息获取倍率
* @param wxCUserBasicInfo
* @param wxScoreRulesService
* @return
*/
private static int getBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) {
int birthdayScale = WxScoreRules.DEFAULT_SCALE; int birthdayScale = WxScoreRules.DEFAULT_SCALE;
//判断是否生日当天,一年一天有效 //判断是否生日当天,一年一天有效
//发过生日券的用户
if (Objects.nonNull(wxCUserBasicInfo.getScoreDate()) && DateUtils.birthdaysBetween(wxCUserBasicInfo.getScoreDate()) == 0) { if (Objects.nonNull(wxCUserBasicInfo.getScoreDate()) && DateUtils.birthdaysBetween(wxCUserBasicInfo.getScoreDate()) == 0) {
birthdayScale = getScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService);
birthdayScale = getBirthdayScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService);
//没有发过生日券的用户
} else if(Objects.nonNull(wxCUserBasicInfo.getBirthdate()) && DateUtils.birthdaysBetween(wxCUserBasicInfo.getBirthdate()) == 0) {
birthdayScale = getBirthdayScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService);
} else { } else {
log.info("积分倍率计算:未设置生日或生日条件未匹配={}", wxCUserBasicInfo.getScoreDate()); log.info("积分倍率计算:未设置生日或生日条件未匹配={}", wxCUserBasicInfo.getScoreDate());
} }
return birthdayScale;
return birthdayScale ;
} }


public static int getScoreScale(String tenantId, WxScoreRulesService wxScoreRulesService) {
/**
* 获取生日积分倍率
* @param tenantId
* @param wxScoreRulesService
* @return
*/
public static int getBirthdayScoreScale(String tenantId, WxScoreRulesService wxScoreRulesService) {
int birthdayScale = WxScoreRules.DEFAULT_SCALE; int birthdayScale = WxScoreRules.DEFAULT_SCALE;
WxScoreRules rules = wxScoreRulesService.getCreditRules(tenantId); WxScoreRules rules = wxScoreRulesService.getCreditRules(tenantId);
if (Objects.nonNull(rules) && Objects.nonNull(rules.getScale())) { if (Objects.nonNull(rules) && Objects.nonNull(rules.getScale())) {


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