From a26741ca117d2e2360487ceb3307e76e0d045169 Mon Sep 17 00:00:00 2001 From: liujiang <569804566@qq.com> Date: Sun, 9 Nov 2025 14:41:10 +0800 Subject: [PATCH] =?UTF-8?q?master=EF=BC=9A=E6=A1=A3=E5=8F=A3=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E6=8E=A8=E5=B9=BF=EF=BC=8C=E7=BB=99=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9EstoreBuyLimit=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=A1=A3=E5=8F=A3=E8=B4=AD=E4=B9=B0=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/advertRound/AdRoundTypeRoundResVO.java | 2 + .../advertRound/AdRoundTypeRoundResDTO.java | 2 + .../ruoyi/xkt/mapper/AdvertRoundMapper.java | 12 ---- .../service/impl/AdvertRoundServiceImpl.java | 69 ++++++++++--------- .../resources/mapper/AdvertRoundMapper.xml | 21 ------ 5 files changed, 42 insertions(+), 64 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/advertRound/AdRoundTypeRoundResVO.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/advertRound/AdRoundTypeRoundResVO.java index 30f70e1ac..bc920b8c3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/advertRound/AdRoundTypeRoundResVO.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/advertRound/AdRoundTypeRoundResVO.java @@ -21,6 +21,8 @@ public class AdRoundTypeRoundResVO { private Long advertId; @ApiModelProperty(value = "广告轮次ID") private Integer roundId; + @ApiModelProperty(value = "每个档口可以购买当前广告位数量限制") + private Integer storeBuyLimit; @ApiModelProperty(value = "是否可购买 true:可购买 false:不可购买") private Boolean canPurchased; @ApiModelProperty(value = "展示类型") diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/advertRound/AdRoundTypeRoundResDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/advertRound/AdRoundTypeRoundResDTO.java index 7ee56dbc9..dae0264f0 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/advertRound/AdRoundTypeRoundResDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/advertRound/AdRoundTypeRoundResDTO.java @@ -23,6 +23,8 @@ public class AdRoundTypeRoundResDTO { private Long advertId; @ApiModelProperty(value = "广告轮次ID") private Integer roundId; + @ApiModelProperty(value = "每个档口可以购买当前广告位数量限制") + private Integer storeBuyLimit; @ApiModelProperty(value = "是否可购买") private Boolean canPurchased; @ApiModelProperty(value = "展示类型") diff --git a/xkt/src/main/java/com/ruoyi/xkt/mapper/AdvertRoundMapper.java b/xkt/src/main/java/com/ruoyi/xkt/mapper/AdvertRoundMapper.java index 095afbd5f..005764ebb 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/mapper/AdvertRoundMapper.java +++ b/xkt/src/main/java/com/ruoyi/xkt/mapper/AdvertRoundMapper.java @@ -20,18 +20,6 @@ import java.util.List; */ public interface AdvertRoundMapper extends BaseMapper { - /** - * 判断当前档口是否超买广告位 - * - * @param advertId 推广位ID - * @param roundId 播放轮次ID - * @param storeId 档口ID - * @param launchStatusList 播放的轮次状态 - * @return true 已超 false 未超 - */ - boolean isStallOverBuy(@Param("advertId") Long advertId, @Param("roundId") Long roundId, @Param("storeId") Long storeId, - @Param("launchStatusList") List launchStatusList); - /** * 获取档口已订购的推广列表 * diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java index cd440c13e..9276d5565 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java @@ -232,13 +232,15 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { // 如果有当前当前档口购买的推广轮次,则取该条记录,因为setCanPurchased会用到。反之则取第一个 AdvertRound advertRound = currentRoundList.stream().filter(x -> Objects.equals(x.getStoreId(), storeId)) .findFirst().orElse(currentRoundList.get(0)); + // 获取档口能够购买的推广数量 + Advert advert = redisCache.getCacheObject(CacheConstants.ADVERT_KEY + advertRound.getAdvertId()); Integer durationDay = calculateDurationDay(advertRound.getStartTime(), advertRound.getEndTime(), Boolean.TRUE); AdRoundTypeRoundResDTO typeRoundResDTO = new AdRoundTypeRoundResDTO().setAdvertId(advertRound.getAdvertId()).setRoundId(advertRound.getRoundId()) .setSymbol(advertRound.getSymbol()).setLaunchStatus(advertRound.getLaunchStatus()).setStartTime(advertRound.getStartTime()) .setEndTime(advertRound.getEndTime()).setStartWeekDay(getDayOfWeek(advertRound.getStartTime())).setDurationDay(durationDay) // 设置是否可以购买当前推广位 .setCanPurchased(this.setRoundCanPurchased(advertRound, storeId, currentRoundList)) - .setEndWeekDay(getDayOfWeek(advertRound.getEndTime())) + .setEndWeekDay(getDayOfWeek(advertRound.getEndTime())).setStoreBuyLimit(ObjectUtils.isEmpty(advert) ? 1 : advert.getStoreBuyLimit()) .setShowType(advertRound.getShowType()).setPosition(advertRound.getPosition()) .setUploadDeadline(redisCache.getCacheObject(ADVERT_UPLOAD_FILTER_TIME_KEY + advertRound.getSymbol())); // 如果是播放轮,则播放开始时间展示为当天,因为有可能是播放的中间某一天 @@ -528,42 +530,16 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { @Override @Transactional public Integer create(AdRoundStoreCreateDTO createDTO) { - // 判断截止时间是否超时,并且只会处理马上播放的这一轮。比如 5.1-5.3,当前为4.30,处理这一轮;当前为5.2,处理这一轮;当前为5.3(最后一天),处理下一轮。 - if (DateUtils.getTime().compareTo(this.getDeadline(createDTO.getSymbol())) > 0) { - throw new ServiceException("竞价失败,已过系统截止时间!", HttpStatus.ERROR); - } Store store = redisCache.getCacheObject(CacheConstants.STORE_KEY + createDTO.getStoreId()); if (ObjectUtils.isEmpty(store)) { - throw new ServiceException("档口不存在!", HttpStatus.ERROR); - } - // 如果是位置枚举的推广位,则需要传position - if (Objects.equals(createDTO.getShowType(), AdShowType.POSITION_ENUM.getValue()) && StringUtils.isEmpty(createDTO.getPosition())) { - throw new ServiceException("当前推广类型position:必传!", HttpStatus.ERROR); - } - // 如果是时间范围的推广位,则不需要传position - if (Objects.equals(createDTO.getShowType(), AdShowType.TIME_RANGE.getValue()) && StringUtils.isNotBlank(createDTO.getPosition())) { - throw new ServiceException("当前推广类型position:不传!", HttpStatus.ERROR); - } - // 用户是否为档口管理者或子账户 - if (!SecurityUtils.isAdmin() && !SecurityUtils.isStoreManagerOrSub(createDTO.getStoreId())) { - throw new ServiceException("当前用户非档口管理者或子账号,无权限操作!", HttpStatus.ERROR); - } - //校验推广支付方式是否存在 - AdPayWay.of(createDTO.getPayWay()); - // 校验使用余额情况下,密码是否正确 - if (Objects.equals(createDTO.getPayWay(), AdPayWay.BALANCE.getValue()) - && !assetService.checkTransactionPassword(createDTO.getStoreId(), createDTO.getTransactionPassword())) { - throw new ServiceException("支付密码错误!请重新输入", HttpStatus.ERROR); + store = Optional.ofNullable(this.storeMapper.selectById(createDTO.getStoreId())).orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR)); + redisCache.setCacheObject(CacheConstants.STORE_KEY + createDTO.getStoreId(), store); } + // 购买推广前置校验 + this.advertPreBuyCheck(createDTO); // 当前营销推广位的锁 Object lockObj = Optional.ofNullable(advertLockMap.get(createDTO.getSymbol())).orElseThrow(() -> new ServiceException("symbol不存在!", HttpStatus.ERROR)); synchronized (lockObj) { - // 判断当前推广位的这一轮每个档口可以买几个,不可超买 - boolean isOverBuy = this.advertRoundMapper.isStallOverBuy(createDTO.getAdvertId(), createDTO.getRoundId(), createDTO.getStoreId(), - Arrays.asList(AdLaunchStatus.LAUNCHING.getValue(), AdLaunchStatus.UN_LAUNCH.getValue())); - if (isOverBuy) { - throw new ServiceException("已购买过该推广位,不可超买哦!", HttpStatus.ERROR); - } LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(AdvertRound::getAdvertId, createDTO.getAdvertId()).eq(AdvertRound::getRoundId, createDTO.getRoundId()) .in(AdvertRound::getLaunchStatus, LAUNCHING_STATUS_LIST).in(AdvertRound::getBiddingStatus, BIDDING_STATUS_LIST) @@ -1147,4 +1123,35 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { return canPurchased; } + /** + * 购买推广前置校验 + * @param createDTO 购买入参 + */ + private void advertPreBuyCheck(AdRoundStoreCreateDTO createDTO) { + // 判断截止时间是否超时,并且只会处理马上播放的这一轮。比如 5.1-5.3,当前为4.30,处理这一轮;当前为5.2,处理这一轮;当前为5.3(最后一天),处理下一轮。 + if (DateUtils.getTime().compareTo(this.getDeadline(createDTO.getSymbol())) > 0) { + throw new ServiceException("竞价失败,已过系统截止时间!", HttpStatus.ERROR); + } + // 如果是位置枚举的推广位,则需要传position + if (Objects.equals(createDTO.getShowType(), AdShowType.POSITION_ENUM.getValue()) && StringUtils.isEmpty(createDTO.getPosition())) { + throw new ServiceException("当前推广类型position:必传!", HttpStatus.ERROR); + } + // 如果是时间范围的推广位,则不需要传position + if (Objects.equals(createDTO.getShowType(), AdShowType.TIME_RANGE.getValue()) && StringUtils.isNotBlank(createDTO.getPosition())) { + throw new ServiceException("当前推广类型position:不传!", HttpStatus.ERROR); + } + // 用户是否为档口管理者或子账户 + if (!SecurityUtils.isAdmin() && !SecurityUtils.isStoreManagerOrSub(createDTO.getStoreId())) { + throw new ServiceException("当前用户非档口管理者或子账号,无权限操作!", HttpStatus.ERROR); + } + //校验推广支付方式是否存在 + AdPayWay.of(createDTO.getPayWay()); + // 校验使用余额情况下,密码是否正确 + if (Objects.equals(createDTO.getPayWay(), AdPayWay.BALANCE.getValue()) + && !assetService.checkTransactionPassword(createDTO.getStoreId(), createDTO.getTransactionPassword())) { + throw new ServiceException("支付密码错误!请重新输入", HttpStatus.ERROR); + } + } + + } diff --git a/xkt/src/main/resources/mapper/AdvertRoundMapper.xml b/xkt/src/main/resources/mapper/AdvertRoundMapper.xml index 32af32971..dd4793640 100644 --- a/xkt/src/main/resources/mapper/AdvertRoundMapper.xml +++ b/xkt/src/main/resources/mapper/AdvertRoundMapper.xml @@ -4,27 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - -