无关风月
2025-01-14 6ccd0f9e28c083e5f62d7d5074a85584a77af6bb
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/SeckillActivityInfoServiceImpl.java
@@ -14,6 +14,7 @@
import com.ruoyi.other.mapper.GoodsShopMapper;
import com.ruoyi.other.mapper.SeckillActivityInfoMapper;
import com.ruoyi.other.mapper.ShopMapper;
import com.ruoyi.other.service.GoodsEvaluateService;
import com.ruoyi.other.service.GoodsSeckillService;
import com.ruoyi.other.service.GoodsService;
import com.ruoyi.other.service.SeckillActivityInfoService;
@@ -57,6 +58,8 @@
    private GoodsService goodsService;
    @Resource
    private OrderClient orderClient;
    @Resource
    private GoodsEvaluateService goodsEvaluateService;
    @Override
    public List<SeckillActivityVO> listSeckillActivity(Goods goods) {
@@ -90,6 +93,16 @@
            AppUser appUser = appUserClient.getAppUserById(userid);
            vipId = appUser.getVipId();
        }
        SeckillActivityInfo activityInfo = this.getById(seckillActivityId);
        if(null == activityInfo || activityInfo.getDelFlag() == 1){
            throw new RuntimeException("活动不存在");
        }
        if(activityInfo.getIsShelves() == 0){
            throw new RuntimeException("活动已下架");
        }
        if(!activityInfo.getVipIds().contains(vipId.toString())){
            throw new RuntimeException("权限不足");
        }
        SeckillActivityDetailVO seckillActivityDetailVO = seckillActivityInfoMapper.selectDetail(seckillActivityId, vipId);
        Integer goodsId = seckillActivityDetailVO.getGoodsId();
@@ -106,25 +119,44 @@
            shops = shopMapper.selectList(new LambdaUpdateWrapper<Shop>().eq(Shop::getDelFlag, 0));
        }
        for (Shop shop : shops) {
            Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, shop.getLongitude() + "," + shop.getLatitude()).get("WGS84");
            shop.setDistance(wgs84);
        }
        shops.sort(new Comparator<Shop>() {
            @Override
            public int compare(Shop o1, Shop o2) {
                return o1.getDistance().compareTo(o2.getDistance());
        if(StringUtils.isNotEmpty(longitude) && StringUtils.isNotEmpty(latitude)){
            for (Shop shop : shops) {
                Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, shop.getLongitude() + "," + shop.getLatitude()).get("WGS84");
                shop.setDistance(wgs84);
            }
        });
            shops.sort(new Comparator<Shop>() {
                @Override
                public int compare(Shop o1, Shop o2) {
                    return o1.getDistance().compareTo(o2.getDistance());
                }
            });
        }
        seckillActivityDetailVO.setShopList(shops);
        Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 2).getData();
        seckillActivityDetailVO.setSaleNum(integer);
        GoodsEvaluate goodsEvaluate = goodsEvaluateService.lambdaQuery().eq(GoodsEvaluate::getGoodsId, goodsId).isNotNull(GoodsEvaluate::getComment).ne(GoodsEvaluate::getComment, "")
                .orderByDesc(GoodsEvaluate::getGrade).eq(GoodsEvaluate::getStatus, 2).eq(GoodsEvaluate::getDelFlag, 0).last(" limit 0, 1").one();
        if (null != goodsEvaluate) {
            AppUser appUserById = appUserClient.getAppUserById(goodsEvaluate.getAppUserId());
            if(null != appUserById){
                goodsEvaluate.setUserName(appUserById.getName());
                goodsEvaluate.setAvatar(appUserById.getAvatar());
                goodsEvaluate.setIdStr(String.valueOf(goodsEvaluate.getId()));
            }
        }
        seckillActivityDetailVO.setGoodsEvaluate(goodsEvaluate);
        return seckillActivityDetailVO;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveSeckillActivityInfo(SeckillActivityInfo seckillActivityInfo) {
        Integer goodId = seckillActivityInfo.getGoodId();
        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"));
        if(0 < count){
            throw new RuntimeException("该秒杀商品已在其他秒杀活动中存在");
        }
        this.baseMapper.insert(seckillActivityInfo);
        List<GoodsSeckill> goodsSeckills = seckillActivityInfo.getGoodsSeckills();
        for (GoodsSeckill goodsSeckill : goodsSeckills) {
@@ -138,6 +170,12 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateSeckillActivityInfo(SeckillActivityInfo seckillActivityInfo) {
        Integer goodId = seckillActivityInfo.getGoodId();
        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"));
        if(1 < count){
            throw new RuntimeException("该秒杀商品已在其他秒杀活动中存在");
        }
        this.baseMapper.updateById(seckillActivityInfo);
        goodsSeckillService.remove(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, seckillActivityInfo.getId()));
        List<GoodsSeckill> goodsSeckills = seckillActivityInfo.getGoodsSeckills();