秒杀活动自动创建调整为7天

This commit is contained in:
Chopper 2021-08-31 17:42:27 +08:00
parent c12dd02f8a
commit e9075a94f3
4 changed files with 12 additions and 18 deletions

View File

@ -217,7 +217,7 @@ public class PromotionEverydayExecute implements EveryDayExecute {
private void addSeckill() {
Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
Seckill seckill = new Seckill(30, seckillSetting.getHours(), seckillSetting.getSeckillRule());
Seckill seckill = new Seckill(SeckillService.PRE_CREATION, seckillSetting.getHours(), seckillSetting.getSeckillRule());
seckillService.saveSeckill(seckill);
}

View File

@ -15,6 +15,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface SeckillService extends IService<Seckill> {
/**
* 预创建活动数量
*/
public static final Integer PRE_CREATION = 7;
/**
* 从mysql中根据条件获取秒杀活动分页列表

View File

@ -60,10 +60,7 @@ import java.util.stream.Collectors;
@Transactional(rollbackFor = Exception.class)
public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> implements SeckillService {
/**
* 预创建活动数量
*/
private final Integer preCreation = 30;
/**
* 延时任务
*/
@ -143,7 +140,8 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
for (int i = 1; i <= preCreation; i++) {
for (int i = 1; i <= PRE_CREATION; i++) {
Seckill seckill = new Seckill(i, seckillSetting.getHours(), seckillSetting.getSeckillRule());
this.saveSeckill(seckill);
}
@ -158,7 +156,7 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
seckillVO.setSeckillApplyStatus(SeckillApplyStatusEnum.NOT_APPLY.name());
seckillVO.setSeckillApplyList(null);
//检查秒杀活动参数
checkSeckillParam(seckillVO, seckill.getStoreId());
checkSeckillParam(seckillVO);
//保存到MYSQL中
boolean result = this.save(seckillVO);
//保存到MONGO中
@ -189,13 +187,11 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
if (PromotionStatusEnum.START.name().equals(seckillVO.getPromotionStatus())) {
throw new ServiceException(ResultCode.PROMOTION_UPDATE_ERROR);
}
//检查秒杀活动参数
this.checkSeckillParam(seckillVO, seckillVO.getStoreId());
//更新到MYSQL中
boolean result = this.updateById(seckillVO);
//保存到MONGO中
this.mongoTemplate.save(seckillVO);
//如果编辑后活动时间不一致则编辑延时任务
if (seckill.getStartTime().getTime() != seckillVO.getStartTime().getTime()) {
PromotionMessage promotionMessage = new PromotionMessage(seckillVO.getId(), PromotionTypeEnum.SECKILL.name(), PromotionStatusEnum.START.name(), seckillVO.getStartTime(), seckillVO.getEndTime());
//更新延时任务
@ -323,11 +319,10 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
* 检查秒杀活动参数
*
* @param seckill 秒杀活动信息
* @param storeId 卖家编号
*/
private void checkSeckillParam(SeckillVO seckill, String storeId) {
private void checkSeckillParam(SeckillVO seckill) {
//同一时间段内相同的活动
QueryWrapper<Seckill> queryWrapper = PromotionTools.checkActiveTime(seckill.getStartTime(), seckill.getEndTime(), PromotionTypeEnum.SECKILL, storeId, seckill.getId());
QueryWrapper<Seckill> queryWrapper = PromotionTools.checkActiveTime(seckill.getStartTime(), seckill.getEndTime(), PromotionTypeEnum.SECKILL, null, seckill.getId());
int sameNum = this.count(queryWrapper);
//当前时间段是否存在同类活动
if (sameNum > 0) {

View File

@ -1,8 +1,6 @@
package cn.lili.controller.promotion;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.Seckill;
@ -44,9 +42,6 @@ public class SeckillManagerController {
@ApiOperation(value = "修改秒杀活动")
@PutMapping
public ResultMessage<Seckill> updateSeckill(SeckillVO seckillVO) {
AuthUser currentUser = UserContext.getCurrentUser();
seckillVO.setStoreId(currentUser.getId());
seckillVO.setStoreName(currentUser.getUsername());
seckillService.modifySeckill(seckillVO);
return ResultUtil.data(seckillVO);
}