jiangqs
2023-08-05 7c9dda6138ceea88a312583a3fcc9b2bb356fbc4
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/activity/ActivityServiceImpl.java
@@ -29,6 +29,7 @@
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 org.redisson.api.RLock;
@@ -81,8 +82,12 @@
    @Resource
    private RedisService redisService;
    @Autowired
    private RedissonClient redissonClient;
    @Resource
    private RemoteFileService remoteFileService;
    /**
     * @param mgtActivityEditDto
@@ -122,6 +127,12 @@
            activityTotal.setRefundTotal(0);
            activityTotal.setOrderMoneyTotal(BigDecimal.ZERO);
            activityTotalService.save(activityTotal);
            CodeGetDto codeGetDto = new CodeGetDto();
            String url = "https://wxapp.hhhrt.cn/mini/activity?activityId="+activityId;
            codeGetDto.setUrl(url);
            codeGetDto.setFileName("activity-"+activityId);
            String codeUrl = remoteFileService.getAppOrderTotal(codeGetDto).getData();
            activity.setActivityCode(codeUrl);
        }
        // 获取活动开始时间和结束时间
        Date activityStartTime = mgtActivityEditDto.getActivityStartTime();
@@ -179,8 +190,8 @@
        if(checkTime.compareTo(activityStartTime)>0){
            String activityId = activity.getActivityId();
            long currentTimeMillis = System.currentTimeMillis();
            long startTimeDifference = currentTimeMillis - activityStartTime.getTime();
            long endTimeDifference = currentTimeMillis - activityEndTime.getTime();
            long startTimeDifference = activityStartTime.getTime() - currentTimeMillis;
            long endTimeDifference = activityEndTime.getTime() - currentTimeMillis;
            // 查询延时任务
            DelayTask startDelayTask = remoteConfigService.getDelayTask(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId).getData();
            // 如果延时任务为空,创建延时任务控制活动定时开始和结束
@@ -192,9 +203,21 @@
                startDelayTask.setEndTime(activityStartTime);
                startDelayTask.setRedisKey(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId);
                remoteConfigService.addDelayTask(startDelayTask);
            }else{
                if(startDelayTask.getEndTime().compareTo(activityStartTime)!=0){
                    remoteConfigService.deleteDelayTask(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId);
                    redisService.deleteObject(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId);
                    redisService.setCacheObject(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId, activityStartTime, startTimeDifference, TimeUnit.MILLISECONDS);
                    startDelayTask = new DelayTask();
                    startDelayTask.setDelFlag(0);
                    startDelayTask.setCreateTime(new Date());
                    startDelayTask.setEndTime(activityStartTime);
                    startDelayTask.setRedisKey(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId);
                    remoteConfigService.addDelayTask(startDelayTask);
                }
            }
            // 查询延时任务
            DelayTask endDelayTask = remoteConfigService.getDelayTask(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId).getData();
            DelayTask endDelayTask = remoteConfigService.getDelayTask(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId).getData();
            // 如果延时任务为空,创建延时任务控制活动定时开始和结束
            if (endDelayTask == null) {
                redisService.setCacheObject(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId, activityEndTime, endTimeDifference, TimeUnit.MILLISECONDS);
@@ -204,6 +227,18 @@
                endDelayTask.setEndTime(activityEndTime);
                endDelayTask.setRedisKey(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId);
                remoteConfigService.addDelayTask(endDelayTask);
            }else{
                if(endDelayTask.getEndTime().compareTo(activityEndTime)!=0){
                    remoteConfigService.deleteDelayTask(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId);
                    redisService.deleteObject(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId);
                    redisService.setCacheObject(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId, activityEndTime, startTimeDifference, TimeUnit.MILLISECONDS);
                    endDelayTask = new DelayTask();
                    endDelayTask.setDelFlag(0);
                    endDelayTask.setCreateTime(new Date());
                    endDelayTask.setEndTime(activityStartTime);
                    endDelayTask.setRedisKey(DelayTaskEnum.ACTIVITY_END_TASK.getCode() + "-" + activityId);
                    remoteConfigService.addDelayTask(endDelayTask);
                }
            }
        }
    }
@@ -384,6 +419,7 @@
        String goodsId = activityGoodsGetDto.getGoodsId();
        Activity activity = this.getById(activityId);
        ActivityGoods activityGoods = activityGoodsService.getByGoodsId(activityId,goodsId);
        activityGoodsGetVo.setActivityName(activity.getActivityName());
        activityGoodsGetVo.setActivityPrice(activityGoods.getActivityPrice());
        activityGoodsGetVo.setActivitySubscription(activityGoods.getActivitySubscription());
        activityGoodsGetVo.setActivityStatus(activity.getActivityStatus());
@@ -427,8 +463,8 @@
                Date activityStartTime = activity.getActivityStartTime();
                Date activityEndTime = activity.getActivityEndTime();
                long currentTimeMillis = System.currentTimeMillis();
                long startTimeDifference = currentTimeMillis - activityStartTime.getTime();
                long endTimeDifference = currentTimeMillis - activityEndTime.getTime();
                long startTimeDifference = activityStartTime.getTime() - currentTimeMillis;
                long endTimeDifference = activityEndTime.getTime() - currentTimeMillis;
                // 查询延时任务
                DelayTask startDelayTask = remoteConfigService.getDelayTask(DelayTaskEnum.ACTIVITY_START_TASK.getCode() + "-" + activityId).getData();
                // 如果延时任务为空,创建延时任务控制活动定时开始和结束
@@ -466,6 +502,7 @@
     */
    @Override
    public void startActivity(String activityId){
        log.debug(activityId+"活动开始");
        Activity activity = this.getById(activityId);
        if(activity!=null&&activity.getActivityStatus()==0){
            activity.setActivityStatus(1);
@@ -571,4 +608,11 @@
    public List<MgtActivityListVo> listStaffActivity(StaffActivityListDto staffActivityListDto){
        return activityMapper.listStaffActivity(staffActivityListDto);
    }
    private void createActivityCode(String activityId){
    }
}