Search in sources :

Example 1 with SeckillSetting

use of cn.lili.modules.system.entity.dto.SeckillSetting in project lilishop by lilishop.

the class SeckillServiceImpl method init.

@Override
@Transactional(rollbackFor = Exception.class)
public void init() {
    // 清除演示数据
    List<Seckill> seckillList = this.list();
    for (Seckill seckill : seckillList) {
        seckill.setStartTime(null);
        seckill.setEndTime(null);
        this.updateEsGoodsIndex(seckill);
    }
    this.remove(new QueryWrapper<>());
    Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
    SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
    for (int i = 1; i <= PRE_CREATION; i++) {
        Seckill seckill = new Seckill(i, seckillSetting.getHours(), seckillSetting.getSeckillRule());
        this.savePromotions(seckill);
    }
}
Also used : SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Setting(cn.lili.modules.system.entity.dos.Setting) SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Gson(com.google.gson.Gson) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SeckillSetting

use of cn.lili.modules.system.entity.dto.SeckillSetting in project lilishop by lilishop.

the class PromotionEverydayExecute method addSeckill.

/**
 * 添加秒杀活动
 * 从系统设置中获取秒杀活动的配置
 * 添加明天后的秒杀活动
 */
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());
        LambdaQueryWrapper<Seckill> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Seckill::getStartTime, seckill.getStartTime());
        // 如果已经存在促销,则不再次保存
        if (seckillService.list(lambdaQueryWrapper).isEmpty()) {
            boolean result = seckillService.savePromotions(seckill);
            log.info("生成秒杀活动参数:{},结果:{}", seckill, result);
        }
    }
}
Also used : SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Setting(cn.lili.modules.system.entity.dos.Setting) SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Gson(com.google.gson.Gson) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with SeckillSetting

use of cn.lili.modules.system.entity.dto.SeckillSetting in project lilishop by lilishop.

the class SeckillTest method add.

@Test
void add() {
    Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
    System.out.println(setting);
    SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
    System.out.println(seckillSetting);
    boolean result = true;
    for (int i = 1; i <= SeckillService.PRE_CREATION; i++) {
        Seckill seckill = new Seckill(i, seckillSetting.getHours(), seckillSetting.getSeckillRule());
        seckillService.savePromotions(seckill);
    }
    Assertions.assertTrue(result);
}
Also used : SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Setting(cn.lili.modules.system.entity.dos.Setting) SeckillSetting(cn.lili.modules.system.entity.dto.SeckillSetting) Gson(com.google.gson.Gson) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Seckill (cn.lili.modules.promotion.entity.dos.Seckill)3 Setting (cn.lili.modules.system.entity.dos.Setting)3 SeckillSetting (cn.lili.modules.system.entity.dto.SeckillSetting)3 Gson (com.google.gson.Gson)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1