puhanshu
2021-12-21 89044714eef77f834078e878533e93060a0c5e17
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActActivityServiceImpl.java
@@ -115,6 +115,9 @@
     */
    @Override
    public R addActivity(ComActActivityVO comActActivityVO) {
        if (comActActivityVO.getHaveIntegralReward().intValue() == 2) {
            comActActivityVO.setRewardWay(null);
        }
        ComActActivityDO comActActivityDO = new ComActActivityDO();
        BeanUtils.copyProperties(comActActivityVO, comActActivityDO);
        Integer status = comActActivityVO.getStatus();
@@ -200,11 +203,15 @@
                }
            }
        }
        if (comActActivityVO.getHaveIntegralReward().intValue() == 2) {
            comActActivityVO.setRewardWay(null);
        }
        BeanUtils.copyProperties(comActActivityVO, comActActivityDO);
        // 结束时间大于当前时间则设置为“进行中”
        Date now = new Date();
        if (comActActivityVO.getSignUpEnd() != null && now.getTime() < comActActivityVO.getSignUpEnd().getTime()) {
        if (comActActivityVO.getSignUpEnd() != null && now.getTime() < comActActivityVO.getSignUpEnd().getTime()
        && now.getTime() > comActActivityVO.getSignUpBegin().getTime()) {
            comActActivityDO.setStatus(3);
        }
        boolean b = this.updateById(comActActivityDO);
@@ -278,8 +285,7 @@
     */
    @Override
    public R cancelActivity(ComActActivityVO comActActivityVO) {
        ComActActivityDO comActActivityDO = new ComActActivityDO();
        comActActivityDO.setId(comActActivityVO.getId());
        ComActActivityDO comActActivityDO = comActActivityDAO.selectById(comActActivityVO.getId());
        comActActivityDO.setStatus(comActActivityVO.getStatus());
        comActActivityDO.setCancelReason(comActActivityVO.getCancelReason());
        int update = comActActivityDAO.updateById(comActActivityDO);
@@ -544,6 +550,10 @@
                num = comActActSignDAO.insert(comActActSignDO);
            }
        } else {
            Integer canCancel = actActivityDO.getCanCancel();
            if (nonNull(canCancel) && canCancel.equals(2)) {
                return R.fail("该活动暂不支持取消");
            }
            if (isNull(signactivityVO.getReason())) {
                return R.fail("缺少取消原因");
            }
@@ -553,6 +563,15 @@
            comActActSignDO.setStatus(0);
            comActActSignDO.setReason(signactivityVO.getReason());
            num = comActActSignDAO.updateById(comActActSignDO);
            if (num > 0) {
                AddComActIntegralUserDTO addComActIntegralUserDTO = new AddComActIntegralUserDTO();
                addComActIntegralUserDTO.setUserId(userId);
                addComActIntegralUserDTO.setIntegralType(9);
                addComActIntegralUserDTO.setActivityType(1);
                addComActIntegralUserDTO.setCommunityId(actActivityDO.getCommunityId());
                addComActIntegralUserDTO.setServiceId(activityId);
                comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO);
            }
        }
        if (num > 0) {
            return R.ok(isVolunteer);
@@ -579,8 +598,13 @@
        List<ComActActivityDO> comActActivityDOS = comActActivityDAO.selectBatchIds(longs);
        List<ComActActivityVO> comActActivityVOS = new ArrayList<>();
        if (nonNull(status)) {
            comActActivityDOS = comActActivityDOS.stream()
                    .filter(activityDO -> activityDO.getStatus().equals(status)).collect(Collectors.toList());
            if(status.equals(4)){
                comActActivityDOS = comActActivityDOS.stream()
                        .filter(activityDO -> activityDO.getStatus().equals(3)||activityDO.getStatus().equals(4)).collect(Collectors.toList());
            }else{
                comActActivityDOS = comActActivityDOS.stream()
                        .filter(activityDO -> activityDO.getStatus().equals(status)).collect(Collectors.toList());
            }
        }
        if (!comActActivityDOS.isEmpty()) {
            comActActivityDOS.forEach(comActActivityDO -> {
@@ -609,7 +633,8 @@
                }
                comActActivityVO.setSingDate(createAt);
                comActActivityVO.setTimes(activitySignVO.getTimes());
                comActActivityVO.setAward(activitySignVO.getAward());
                Integer totalAward = comActActRegistDAO.selectTotalAwardWithRegist(activitySignVO.getActivityId(), userId);
                comActActivityVO.setAward(totalAward);
                comActActivityVOS.add(comActActivityVO);
            });
        }
@@ -884,9 +909,13 @@
            if (signDayCount > 0) {
                return R.fail("请扫描新的签到码");
            }
            int limit = comActActivityDO.getLimit().intValue();
            if(limit != -1 && signAllCount >= limit){
                return R.fail("签到次数上限");
            Integer haveIntegralReward = comActActivityDO.getHaveIntegralReward();
            boolean isHave = nonNull(haveIntegralReward) && haveIntegralReward.equals(1);
            if (isHave) {
                int limit = comActActivityDO.getLimit().intValue();
                if(limit != -1 && signAllCount >= limit){
                    return R.fail("签到次数上限");
                }
            }
//        String activitySignInKey = String.join(DELIMITER, ACTIVITY_SIGN_IN, userId.toString(), activityId.toString());
@@ -900,21 +929,23 @@
            comActActRegistDO.setIsVolunteer(comActActRegistVO.getIsVolunteer());
            comActActRegistDO.setCreateAt(nowDate);
            comActActRegistDO.setCodeId(comActActRegistVO.getCodeId());
            comActActRegistDO.setAward(comActActivityDO.getRewardIntegral());
            comActActRegistDO.setAward(isHave ? comActActivityDO.getRewardIntegral() : 0);
            comActActRegistDO.setPosition(comActActRegistVO.getPosition());
            comActActRegistDO.setTimes(signAllCount+1);
            int result = comActActRegistDAO.insert(comActActRegistDO);
            if (result > 0) {
                AddComActIntegralUserDTO addComActIntegralUserDTO=new AddComActIntegralUserDTO();
                addComActIntegralUserDTO.setUserId(userId);
                addComActIntegralUserDTO.setIntegralType(8);
                addComActIntegralUserDTO.setActivityType(1);
                addComActIntegralUserDTO.setCommunityId(comActActivityDO.getCommunityId());
                addComActIntegralUserDTO.setServiceId(activityId);
                comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO);
//            ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
//            opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS);
                return R.ok(comActActivityDO.getRewardIntegral());
                if (isHave) {
                    AddComActIntegralUserDTO addComActIntegralUserDTO=new AddComActIntegralUserDTO();
                    addComActIntegralUserDTO.setUserId(userId);
                    addComActIntegralUserDTO.setIntegralType(8);
                    addComActIntegralUserDTO.setActivityType(1);
                    addComActIntegralUserDTO.setCommunityId(comActActivityDO.getCommunityId());
                    addComActIntegralUserDTO.setServiceId(activityId);
                    comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO);
                    return R.ok(comActActivityDO.getRewardIntegral());
                } else {
                    return R.ok();
                }
            }
            return R.fail("网络错误,请重试");
        }