| | |
| | | package com.ruoyi.goods.service.impl.activity; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | |
| | | import com.ruoyi.system.api.domain.dto.*; |
| | | import com.ruoyi.system.api.domain.poji.activity.ActivityGoods; |
| | | import com.ruoyi.system.api.domain.poji.config.DelayTask; |
| | | import com.ruoyi.system.api.domain.poji.goods.Goods; |
| | | import com.ruoyi.system.api.domain.vo.ActivityGoodsGetVo; |
| | | import com.ruoyi.system.api.domain.vo.MgtSimpleMemberVo; |
| | | import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo; |
| | | import com.ruoyi.system.api.domain.vo.MgtUserIdByKeywordVo; |
| | | import com.ruoyi.system.api.service.RemoteConfigService; |
| | | import com.ruoyi.system.api.service.RemoteFileService; |
| | | import com.ruoyi.system.api.service.RemoteMemberService; |
| | | import com.ruoyi.system.api.service.RemoteShopService; |
| | | import com.ruoyi.system.api.service.*; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private RemoteOrderService remoteOrderService; |
| | | |
| | | @Resource |
| | | private RemoteGoodsService remoteGoodsService; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | |
| | | if (StringUtils.isNotBlank(mgtActivityEditDto.getActivityId())) { |
| | | // 获取活动信息 |
| | | activity = this.getById(mgtActivityEditDto.getActivityId()); |
| | | // 如果活动状态不为0,则表示活动正在进行中,不能修改 |
| | | if (activity.getActivityStatus() != 0) { |
| | | throw new ServiceException(AppErrorConstant.ACTIVITY_ING_EDIT); |
| | | if(activity.getDelFlag() == 1){ |
| | | throw new ServiceException(AppErrorConstant.ACTIVITY_DEL); |
| | | } |
| | | // 删除活动商品信息 |
| | | activityGoodsService.deleteByActivityId(activity.getActivityId()); |
| | | if(activity.getActivityStatus() == 2){ |
| | | throw new ServiceException(AppErrorConstant.ACTIVITY_END); |
| | | } |
| | | //校验可以修改的项 |
| | | if(activity.getActivityStatus() == 1){ |
| | | /** |
| | | * 1、活动时间:已经开始活动开始时间不可修改,结束时间不能小于当前时间 |
| | | * 2、是否限购 |
| | | * - 不限购:无法修改。 |
| | | * - 限购:只能增加 |
| | | * 3、适用地区 |
| | | * - 全部地区:无法修改。 |
| | | * - 指定地区:只能新增 |
| | | * 4、适用店铺 |
| | | * - 全部店铺:无法修改 |
| | | * - 指定店铺:只能新增 |
| | | * 5、秒杀库存:只能增加 |
| | | * 6、活动名称、宣传海报、是否推荐、活动简介:可直接修改 |
| | | * 7、秒杀价和定金不能修改 |
| | | */ |
| | | if(activity.getActivityStartTime().getTime() != mgtActivityEditDto.getActivityStartTime().getTime()){ |
| | | throw new ServiceException("活动开始后无法修改开始时间"); |
| | | } |
| | | if(System.currentTimeMillis() >= mgtActivityEditDto.getActivityEndTime().getTime()){ |
| | | throw new ServiceException("活动结束时间必须大于当前时间"); |
| | | } |
| | | if(activity.getPurchaseLimitationFlag() == 0 && activity.getPurchaseLimitationFlag().compareTo(mgtActivityEditDto.getPurchaseLimitationFlag()) != 0){ |
| | | throw new ServiceException("不能修改限购配置"); |
| | | } |
| | | if(activity.getPurchaseLimitationFlag() == 1 && mgtActivityEditDto.getLimitNumber().compareTo(activity.getLimitNumber()) < 0){ |
| | | throw new ServiceException("限购数量不能小于原始数量"); |
| | | } |
| | | if(activity.getAreaFlag() == 1 && activity.getAreaFlag().compareTo(mgtActivityEditDto.getAreaFlag()) != 0){ |
| | | throw new ServiceException("不能修改适用地区配置"); |
| | | } |
| | | if(activity.getAreaFlag() == 2){ |
| | | List<String> list = Arrays.asList(activity.getDesignatedArea().split(",")); |
| | | List<String> list1 = Arrays.asList(mgtActivityEditDto.getDesignatedArea().split(",")); |
| | | for (String s : list) { |
| | | if(!list1.contains(s)){ |
| | | throw new ServiceException("适用地区只能增加"); |
| | | } |
| | | } |
| | | } |
| | | if(activity.getShopFlag() == 1 && activity.getShopFlag().compareTo(mgtActivityEditDto.getShopFlag()) != 0){ |
| | | throw new ServiceException("不能修改适用店铺配置"); |
| | | } |
| | | if(activity.getShopFlag() == 2){ |
| | | List<String> list = Arrays.asList(activity.getApplicableShop().split(",")); |
| | | List<String> list1 = Arrays.asList(mgtActivityEditDto.getApplicableShop().split(",")); |
| | | for (String s : list) { |
| | | if(!list1.contains(s)){ |
| | | throw new ServiceException("适用店铺只能增加"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<MgtActivityGoodsEditDto> mgtActivityGoodsEditDtoList = mgtActivityEditDto.getMgtActivityGoodsEditDtoList(); |
| | | List<String> collect = mgtActivityGoodsEditDtoList.stream().map(MgtActivityGoodsEditDto::getGoodsId).collect(Collectors.toList()); |
| | | List<ActivityGoods> list = activityGoodsService.list(new QueryWrapper<ActivityGoods>() |
| | | .eq("del_flag", 0) |
| | | .eq("activity_id", activity.getActivityId()) |
| | | ); |
| | | for (ActivityGoods activityGoods : list) { |
| | | String goodsId = activityGoods.getGoodsId(); |
| | | BigDecimal activitySubscription1 = activityGoods.getActivitySubscription(); |
| | | BigDecimal activityPrice1 = activityGoods.getActivityPrice(); |
| | | Integer activityNumber1 = activityGoods.getActivityNumber(); |
| | | if(!collect.contains(goodsId)){ |
| | | throw new ServiceException("只能新增商品数据"); |
| | | } |
| | | for (MgtActivityGoodsEditDto mgtActivityGoodsEditDto : mgtActivityGoodsEditDtoList) { |
| | | String goodsId1 = mgtActivityGoodsEditDto.getGoodsId(); |
| | | BigDecimal activityPrice = mgtActivityGoodsEditDto.getActivityPrice(); |
| | | BigDecimal activitySubscription = mgtActivityGoodsEditDto.getActivitySubscription(); |
| | | Integer activityNumber = mgtActivityGoodsEditDto.getActivityNumber(); |
| | | if(goodsId.equals(goodsId1) && activitySubscription1.compareTo(activitySubscription) != 0){ |
| | | throw new ServiceException("不能修改定金"); |
| | | } |
| | | if(goodsId.equals(goodsId1) && activityPrice1.compareTo(activityPrice) != 0){ |
| | | throw new ServiceException("不能修改秒杀价"); |
| | | } |
| | | if(goodsId.equals(goodsId1) && activityNumber1.compareTo(activityNumber) > 0){ |
| | | throw new ServiceException("只能增加商品库存"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 如果活动ID为空,则表示新增活动信息 |
| | | activity = new Activity(); |
| | |
| | | codeGetDto.setFileName("activity-"+activityId); |
| | | String codeUrl = remoteFileService.getAppOrderTotal(codeGetDto).getData(); |
| | | activity.setActivityCode(codeUrl); |
| | | activity.setActivityStatus(0); |
| | | } |
| | | // 获取活动开始时间和结束时间 |
| | | Date activityStartTime = mgtActivityEditDto.getActivityStartTime(); |
| | |
| | | activity.setApplicableShop(result); |
| | | } |
| | | } |
| | | activity.setActivityStatus(0); |
| | | this.saveOrUpdate(activity); |
| | | // 获取活动商品信息 |
| | | List<MgtActivityGoodsEditDto> mgtActivityGoodsEditDtoList = mgtActivityEditDto.getMgtActivityGoodsEditDtoList(); |
| | |
| | | if (!mgtActivityGoodsEditDtoList.isEmpty()) { |
| | | List<ActivityGoods> activityGoodsList = mgtActivityGoodsEditDtoList.stream().map( |
| | | dto -> { |
| | | ActivityGoods activityGoods = new ActivityGoods(); |
| | | activityGoods.setDelFlag(0); |
| | | activityGoods.setGoodsId(dto.getGoodsId()); |
| | | activityGoods.setActivityId(activity.getActivityId()); |
| | | activityGoods.setActivityPrice(dto.getActivityPrice()); |
| | | activityGoods.setActivitySubscription(dto.getActivitySubscription()); |
| | | activityGoods.setActivityNumber(dto.getActivityNumber()); |
| | | activityGoods.setActivityStock(dto.getActivityNumber()); |
| | | activityGoods.setSalesNumber(0); |
| | | activityGoods.setActivityDeadline(activity.getActivityEndTime()); |
| | | activityGoods.setSellOutFlag(0); |
| | | activityGoods.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag()); |
| | | activityGoods.setLimitNumber(activity.getLimitNumber()); |
| | | ActivityGoods activityGoods = activityGoodsService.getOne(new LambdaQueryWrapper<ActivityGoods>() |
| | | .eq(ActivityGoods::getActivityId, activity.getActivityId()) |
| | | .eq(ActivityGoods::getGoodsId, dto.getGoodsId()) |
| | | .eq(ActivityGoods::getDelFlag, 0) |
| | | ); |
| | | if(null != activityGoods){ |
| | | activityGoods.setActivityId(activity.getActivityId()); |
| | | activityGoods.setActivityPrice(dto.getActivityPrice()); |
| | | activityGoods.setActivitySubscription(dto.getActivitySubscription()); |
| | | activityGoods.setActivityNumber(dto.getActivityNumber()); |
| | | activityGoods.setActivityStock(dto.getActivityNumber()); |
| | | activityGoods.setActivityDeadline(activity.getActivityEndTime()); |
| | | activityGoods.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag()); |
| | | activityGoods.setLimitNumber(activity.getLimitNumber()); |
| | | }else{ |
| | | activityGoods = new ActivityGoods(); |
| | | activityGoods.setDelFlag(0); |
| | | activityGoods.setGoodsId(dto.getGoodsId()); |
| | | activityGoods.setActivityId(activity.getActivityId()); |
| | | activityGoods.setActivityPrice(dto.getActivityPrice()); |
| | | activityGoods.setActivitySubscription(dto.getActivitySubscription()); |
| | | activityGoods.setActivityNumber(dto.getActivityNumber()); |
| | | activityGoods.setActivityStock(dto.getActivityNumber()); |
| | | activityGoods.setSalesNumber(0); |
| | | activityGoods.setActivityDeadline(activity.getActivityEndTime()); |
| | | activityGoods.setSellOutFlag(0); |
| | | activityGoods.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag()); |
| | | activityGoods.setLimitNumber(activity.getLimitNumber()); |
| | | } |
| | | return activityGoods; |
| | | } |
| | | ).collect(Collectors.toList()); |
| | | if (!activityGoodsList.isEmpty()) { |
| | | activityGoodsService.saveBatch(activityGoodsList); |
| | | activityGoodsService.saveOrUpdateBatch(activityGoodsList); |
| | | } |
| | | } |
| | | //如果活动在1小时内生成自动开始任务的延时任务 |
| | |
| | | String activityId = activity.getActivityId(); |
| | | long currentTimeMillis = System.currentTimeMillis(); |
| | | long startTimeDifference = activityStartTime.getTime() - currentTimeMillis; |
| | | startTimeDifference = startTimeDifference < 0 ? 3L : startTimeDifference; |
| | | long endTimeDifference = activityEndTime.getTime() - currentTimeMillis; |
| | | //判断任务是否已经开始,已经开始则3秒后立即开始 |
| | | if(nowTime.compareTo(activityStartTime) > 0){ |