优化自动生成秒杀活动

This commit is contained in:
paulGao 2022-02-18 20:26:35 +08:00
parent cd374f2d98
commit f555f6423a
2 changed files with 6 additions and 5 deletions

View File

@ -62,14 +62,16 @@ public class PromotionEverydayExecute implements EveryDayExecute {
/**
* 添加秒杀活动
* 从系统设置中获取秒杀活动的配置
* 添加30天后的秒杀活动
* 添加天后的秒杀活动
*/
private void addSeckill() {
Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
log.info("生成秒杀活动设置:{}", seckillSetting);
for (int i = 1; i <= SeckillService.PRE_CREATION; i++) {
Seckill seckill = new Seckill(i, seckillSetting.getHours(), seckillSetting.getSeckillRule());
seckillService.savePromotions(seckill);
boolean result = seckillService.savePromotions(seckill);
log.info("生成秒杀活动参数:{},结果:{}", seckill, result);
}
}
}

View File

@ -1,6 +1,5 @@
package cn.lili.modules.promotion.entity.dos;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.lili.modules.promotion.entity.vos.SeckillVO;
@ -59,8 +58,8 @@ public class Seckill extends BasePromotions {
public Seckill(int day, String hours, String seckillRule) {
//默认创建*天后的秒杀活动
DateTime dateTime = DateUtil.beginOfDay(DateUtil.offset(new DateTime(), DateField.DAY_OF_YEAR, day));
this.applyEndTime = dateTime;
DateTime dateTime = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), day));
this.applyEndTime = DateUtil.offsetHour(new Date(), Integer.parseInt(hours) - 1);
this.hours = hours;
this.seckillRule = seckillRule;
this.goodsNum = 0;