luodangjia
2025-01-17 d0b043b8fa5f19d1295cac50fece0c65fceb3920
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/SeckillActivityInfoServiceImpl.java
@@ -8,6 +8,7 @@
import com.ruoyi.common.core.utils.PageUtils;
import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.order.feignClient.OrderClient;
@@ -63,7 +64,7 @@
    private GoodsEvaluateService goodsEvaluateService;
    @Override
    public List<SeckillActivityVO> listSeckillActivity(Goods goods) {
    public TableDataInfo<SeckillActivityVO> listSeckillActivity(Goods goods) {
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        AppUser appUser = appUserClient.getAppUserById(loginUserApplet.getUserid());
        goods.setVipId(appUser.getVipId());
@@ -77,7 +78,7 @@
            LocalDateTime endTime = seckillActivityVO.getEndTime();
            if (endTime.isBefore(now)){
                seckillActivityVO.setStatus(3); //已结束
            }else if (startTime.isBefore(now)){
            }else if (startTime.isBefore(now) && endTime.isAfter(now)){
                seckillActivityVO.setStatus(2); // 已开始
            }else {
                seckillActivityVO.setStatus(1); // 未开始
@@ -99,12 +100,19 @@
        int endIndex = Math.min(startIndex + pageSize, sortedList.size());
        if (startIndex >= sortedList.size()) {
            return new ArrayList<>();
            return new TableDataInfo();
        }
        return sortedList.subList(startIndex, endIndex);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(sortedList.subList(startIndex, endIndex));
        tableDataInfo.setTotal(sortedList.size());
        tableDataInfo.setCode(200);
        return tableDataInfo;
    }
    private Comparator<SeckillActivityVO> getComparator(String orderByColumn, String isAsc) {
        if (StringUtils.isEmpty(orderByColumn)){
            return Comparator.comparing(SeckillActivityVO::getId);
        }
        Comparator<SeckillActivityVO> comparator;
        switch (orderByColumn) {
@@ -197,8 +205,10 @@
    @Transactional(rollbackFor = Exception.class)
    public void saveSeckillActivityInfo(SeckillActivityInfo seckillActivityInfo) {
        Integer goodId = seckillActivityInfo.getGoodId();
        LocalDateTime startTime = seckillActivityInfo.getStartTime();
        LocalDateTime endTime = seckillActivityInfo.getEndTime();
        long count = this.count(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, goodId).eq(SeckillActivityInfo::getDelFlag, 0)
                .eq(SeckillActivityInfo::getIsShelves, 1).last(" and now() between start_time and end_time"));
                .eq(SeckillActivityInfo::getIsShelves, 1).last(" and (" + startTime + " between start_time and end_time or " + endTime + " between start_time and end_time)"));
        if(0 < count){
            throw new RuntimeException("该秒杀商品已在其他秒杀活动中存在");
        }
@@ -216,8 +226,10 @@
    @Transactional(rollbackFor = Exception.class)
    public void updateSeckillActivityInfo(SeckillActivityInfo seckillActivityInfo) {
        Integer goodId = seckillActivityInfo.getGoodId();
        LocalDateTime startTime = seckillActivityInfo.getStartTime();
        LocalDateTime endTime = seckillActivityInfo.getEndTime();
        long count = this.count(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, goodId).eq(SeckillActivityInfo::getDelFlag, 0)
                .eq(SeckillActivityInfo::getIsShelves, 1).last(" and now() between start_time and end_time"));
                .eq(SeckillActivityInfo::getIsShelves, 1).last(" and (" + startTime + " between start_time and end_time or " + endTime + " between start_time and end_time)"));
        if(1 < count){
            throw new RuntimeException("该秒杀商品已在其他秒杀活动中存在");
        }