Skip to content

Commit

Permalink
秒杀活动自动创建调整为7天
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed Aug 31, 2021
1 parent c12dd02 commit e9075a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void endFullDiscount(Query query) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
public interface SeckillService extends IService<Seckill> {

/**
* 预创建活动数量
*/
public static final Integer PRE_CREATION = 7;

/**
* 从mysql中根据条件获取秒杀活动分页列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
@Transactional(rollbackFor = Exception.class)
public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> implements SeckillService {

/**
* 预创建活动数量
*/
private final Integer preCreation = 30;

/**
* 延时任务
*/
Expand Down Expand Up @@ -143,7 +140,8 @@ public void init() {

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);
}
Expand All @@ -158,7 +156,7 @@ public boolean saveSeckill(Seckill seckill) {
seckillVO.setSeckillApplyStatus(SeckillApplyStatusEnum.NOT_APPLY.name());
seckillVO.setSeckillApplyList(null);
//检查秒杀活动参数
checkSeckillParam(seckillVO, seckill.getStoreId());
checkSeckillParam(seckillVO);
//保存到MYSQL中
boolean result = this.save(seckillVO);
//保存到MONGO中
Expand Down Expand Up @@ -189,13 +187,11 @@ public boolean modifySeckill(SeckillVO seckillVO) {
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());
//更新延时任务
Expand Down Expand Up @@ -323,11 +319,10 @@ private SeckillVO checkSeckillExist(String id) {
* 检查秒杀活动参数
*
* @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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,9 +42,6 @@ public void addSeckill() {
@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);
}
Expand Down

0 comments on commit e9075a9

Please sign in to comment.