| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | import static org.apache.commons.lang3.StringUtils.isBlank; |
| | | import static org.apache.commons.lang3.StringUtils.isNotBlank; |
| | | |
| | |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.panzhihua.common.model.dtos.community.integral.admin.AddComActIntegralUserDTO; |
| | | import com.panzhihua.service_community.dao.*; |
| | | import com.panzhihua.service_community.entity.ComActActivityCode; |
| | | import com.panzhihua.service_community.model.dos.*; |
| | | import com.panzhihua.service_community.service.ComActActivityCodeService; |
| | | import com.panzhihua.service_community.service.ComActIntegralUserTradeService; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.constants.HttpStatus; |
| | | import com.panzhihua.common.model.dtos.community.bigscreen.work.ScreenActActivityListDTO; |
| | | import com.panzhihua.common.model.dtos.community.bigscreen.work.ScreenActActivityPeopleListDTO; |
| | | import com.panzhihua.common.model.dtos.community.integral.admin.AddComActIntegralUserDTO; |
| | | import com.panzhihua.common.model.vos.IndexDataVO; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | |
| | | import com.panzhihua.common.model.vos.community.ComActActPictureVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActRegistVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActivityStatisticsVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActivityTypeVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActivityVO; |
| | | import com.panzhihua.common.model.vos.community.CommunityActivitiesVO; |
| | | import com.panzhihua.common.model.vos.community.CommunityGovernanceTrendsVO; |
| | |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.WxUtil; |
| | | import com.panzhihua.common.utlis.WxXCXTempSend; |
| | | import com.panzhihua.service_community.dao.ComActActEvaluateDAO; |
| | | import com.panzhihua.service_community.dao.ComActActPictureDAO; |
| | | import com.panzhihua.service_community.dao.ComActActRegistDAO; |
| | | import com.panzhihua.service_community.dao.ComActActSignDAO; |
| | | import com.panzhihua.service_community.dao.ComActActivityCodeDao; |
| | | import com.panzhihua.service_community.dao.ComActActivityDAO; |
| | | import com.panzhihua.service_community.dao.ComBpActivityDAO; |
| | | import com.panzhihua.service_community.entity.ComActActivityCode; |
| | | import com.panzhihua.service_community.model.dos.ComActActEvaluateDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActPictureDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActRegistDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActSignDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActivityDO; |
| | | import com.panzhihua.service_community.service.ComActActivityCodeService; |
| | | import com.panzhihua.service_community.service.ComActActivityService; |
| | | import com.panzhihua.service_community.service.ComActIntegralUserTradeService; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | LambdaQueryWrapper<ComActActSignDO> actSignQuery = new LambdaQueryWrapper<>(); |
| | | actSignQuery.eq(ComActActSignDO::getActivityId, id); |
| | | actSignQuery.eq(ComActActSignDO::getUserId, userId); |
| | | actSignQuery.eq(ComActActSignDO::getStatus, 1); |
| | | ComActActSignDO comActActSignDO = comActActSignDAO.selectOne(actSignQuery); |
| | | if (!ObjectUtils.isEmpty(comActActSignDO)) { |
| | | comActActivityVO.setIsSign(1); |
| | |
| | | } |
| | | } |
| | | } |
| | | comActActivityVO.setCodeType(1); |
| | | return comActActivityVO; |
| | | } |
| | | |
| | |
| | | Long activityId = signactivityVO.getActivityId(); |
| | | Integer type = signactivityVO.getType(); |
| | | Long userId = signactivityVO.getUserId(); |
| | | Integer isVolunteer = signactivityVO.getIsVolunteer(); |
| | | Integer isVolunteer = 0; |
| | | // 查询社区活动 |
| | | ComActActivityDO actActivityDO = this.baseMapper.selectById(activityId); |
| | | if (isNull(actActivityDO)) { |
| | | return R.fail("活动不存在"); |
| | | } |
| | | int num = 0; |
| | | ComActActSignDO comActActSignDO = comActActSignDAO.selectOne(new QueryWrapper<ComActActSignDO>() |
| | | .lambda().eq(ComActActSignDO::getActivityId, activityId).eq(ComActActSignDO::getUserId, userId)); |
| | | if (1 == type) { |
| | | if (nonNull(comActActSignDO) && comActActSignDO.getStatus().equals(1)) { |
| | | return R.fail("已经报名过了,请勿重复提交"); |
| | | } |
| | | Integer volunteerMax = actActivityDO.getVolunteerMax(); |
| | | Integer residentMax = actActivityDO.getParticipantMax(); |
| | | R<LoginUserInfoVO> userInfoR = userService.getUserInfoByUserId(String.valueOf(userId)); |
| | | LoginUserInfoVO loginUserInfoVO = |
| | | JSONObject.parseObject(JSONObject.toJSONString(userInfoR.getData()), LoginUserInfoVO.class); |
| | | boolean userNotVolunteer = !(loginUserInfoVO.getIsVolunteer() == 1); |
| | | if (isVolunteer == 1 && userNotVolunteer) { |
| | | return R.fail("只有志愿者才能报名"); |
| | | // 查询当前活动下参与居民 |
| | | Integer residentCount = comActActSignDAO.selectCount(new QueryWrapper<ComActActSignDO>().lambda() |
| | | .eq(ComActActSignDO::getActivityId, activityId).eq(ComActActSignDO::getIsVolunteer, 0)); |
| | | if (volunteerMax != 0) { |
| | | //志愿者活动 |
| | | boolean userIsVolunteer = loginUserInfoVO.getIsVolunteer() == 1; |
| | | // 查询当前活动下参与志愿者 |
| | | Integer volunteerCount = comActActSignDAO.selectCount(new QueryWrapper<ComActActSignDO>().lambda() |
| | | .eq(ComActActSignDO::getActivityId, activityId).eq(ComActActSignDO::getIsVolunteer, 1)); |
| | | if (userIsVolunteer) { |
| | | //用户是志愿者以志愿者身份参加 |
| | | if (volunteerMax > volunteerCount || volunteerMax.equals(-1)) { |
| | | //以志愿者身份报名 |
| | | isVolunteer = 1; |
| | | } else if (nonNull(residentMax) && (residentMax > residentCount || residentMax.equals(-1))) { |
| | | //志愿者报名人数已满,再以居民身份报名参加 |
| | | isVolunteer = 0; |
| | | } else { |
| | | return R.fail("报名人数已满"); |
| | | } |
| | | |
| | | // 查询当前活动下参与志愿者/居民数量 |
| | | Integer count = comActActSignDAO.selectCount(new QueryWrapper<ComActActSignDO>().lambda() |
| | | .eq(ComActActSignDO::getActivityId, activityId).eq(ComActActSignDO::getIsVolunteer, isVolunteer)); |
| | | if (isVolunteer.equals(1) && actActivityDO.getVolunteerMax() <= count |
| | | && !actActivityDO.getVolunteerMax().equals(-1)) { |
| | | return R.fail("志愿者报名人数已满"); |
| | | } else { |
| | | //用户是普通居民已居民身份参加 |
| | | if (nonNull(residentMax) && (residentMax > residentCount || residentMax.equals(-1))) { |
| | | //以居民身份报名参加 |
| | | isVolunteer = 0; |
| | | } else if (volunteerMax > volunteerCount || volunteerMax.equals(-1)) { |
| | | return R.fail(HttpStatus.NOT_ACCEPTABLE, "您还不是志愿者哦~"); |
| | | } else { |
| | | return R.fail("报名人数已满"); |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | //普通居民活动 |
| | | //审查用户是否有该活动报名权限(是否活动指定参与人群) |
| | | String currentUserTags = loginUserInfoVO.getTags(); |
| | | String attendPeople = actActivityDO.getAattendPeople(); |
| | | if (isVolunteer.intValue() == 0 && isNotBlank(attendPeople)) { |
| | | if (isNotBlank(attendPeople)) { |
| | | if (isBlank(currentUserTags)) { |
| | | currentUserTags = "全部居民"; |
| | | } else { |
| | |
| | | return R.fail("您不是指定参与人群!"); |
| | | } |
| | | } |
| | | |
| | | if (isVolunteer.equals(0) && actActivityDO.getParticipantMax() <= count |
| | | && !actActivityDO.getParticipantMax().equals(-1)) { |
| | | return R.fail("居民报名人数已满"); |
| | | if (residentMax > residentCount || residentMax.equals(-1)) { |
| | | //用户参加居民活动 |
| | | isVolunteer = 0; |
| | | } else { |
| | | return R.fail("报名人数已满"); |
| | | } |
| | | |
| | | ComActActSignDO comActActSignDO = new ComActActSignDO(); |
| | | } |
| | | if (nonNull(comActActSignDO)) { |
| | | comActActSignDO.setStatus(1); |
| | | comActActSignDO.setCreateAt(new Date()); |
| | | comActActSignDO.setReason(null); |
| | | comActActSignDO.setIsVolunteer(isVolunteer); |
| | | num = comActActSignDAO.updateById(comActActSignDO); |
| | | } else { |
| | | comActActSignDO = new ComActActSignDO(); |
| | | comActActSignDO.setActivityId(activityId); |
| | | comActActSignDO.setUserId(userId); |
| | | comActActSignDO.setIsVolunteer(isVolunteer); |
| | | try { |
| | | num = comActActSignDAO.insert(comActActSignDO); |
| | | } catch (Exception e) { |
| | | if (e.getMessage().contains("unique_activity_id_user_id")) { |
| | | return R.fail("已经报名过了,请勿重复提交"); |
| | | } |
| | | log.error(e.getMessage()); |
| | | } |
| | | } else { |
| | | if (isNull(signactivityVO.getReason())) { |
| | | return R.fail("缺少取消原因"); |
| | | } |
| | | ComActActSignDO comActActSignDO = comActActSignDAO.selectOne(new QueryWrapper<ComActActSignDO>() |
| | | .lambda().eq(ComActActSignDO::getActivityId, activityId).eq(ComActActSignDO::getUserId, userId)); |
| | | if (isNull(comActActSignDO)) { |
| | | return R.fail("未报名"); |
| | | } |
| | |
| | | num = comActActSignDAO.updateById(comActActSignDO); |
| | | } |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | return R.ok(isVolunteer); |
| | | } |
| | | return R.fail(); |
| | | } |
| | |
| | | * |
| | | * @param userId |
| | | * 用户id |
| | | * @param status |
| | | * @return 活动列表 |
| | | */ |
| | | @Override |
| | | public R listActivity(Long userId) { |
| | | public R listActivity(Long userId, Integer status) { |
| | | List<ActivitySignVO> activitySignVOList = comActActSignDAO.selectList(userId); |
| | | if (ObjectUtils.isEmpty(activitySignVOList)) { |
| | | return R.fail(); |
| | |
| | | .collect(Collectors.toList()); |
| | | 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 (!comActActivityDOS.isEmpty()) { |
| | | comActActivityDOS.forEach(comActActivityDO -> { |
| | | ComActActivityVO comActActivityVO = new ComActActivityVO(); |
| | | BeanUtils.copyProperties(comActActivityDO, comActActivityVO); |
| | |
| | | } else { |
| | | comActActivityVO.setType(2); |
| | | } |
| | | Integer status = comActActivityVO.getStatus(); |
| | | if (status.intValue() == 3) { |
| | | Integer activityStatus = comActActivityVO.getStatus(); |
| | | if (activityStatus.intValue() == 3) { |
| | | comActActivityVO.setStatus(4); |
| | | } |
| | | Date createAt = null; |
| | | try { |
| | | createAt = DateUtils.parseDate(activitySignVO.getCreateAt()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | createAt = simpleDateFormat.parse(activitySignVO.getCreateAt()); |
| | | } catch (ParseException e) { |
| | | log.error("时间转换异常{【】}", e.getMessage()); |
| | | log.error("时间转换异常【{}】", e.getMessage()); |
| | | } |
| | | comActActivityVO.setSingDate(createAt); |
| | | comActActivityVO.setTimes(activitySignVO.getTimes()); |
| | | comActActivityVO.setAward(activitySignVO.getAward()); |
| | | comActActivityVOS.add(comActActivityVO); |
| | | }); |
| | | } |
| | | return R.ok(comActActivityVOS); |
| | | } |
| | | |
| | |
| | | .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId).eq(ComActActRegistDO::getCodeId,comActActRegistVO.getCodeId())); |
| | | int signAllCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId)); |
| | | if (signDayCount >= 0) { |
| | | if (signDayCount > 0) { |
| | | return R.fail("请扫描新的签到码"); |
| | | } |
| | | if(signAllCount>=comActActivityDO.getLimit()){ |
| | | int limit = comActActivityDO.getLimit().intValue(); |
| | | if(limit != -1 && signAllCount >= limit){ |
| | | return R.fail("签到次数上限"); |
| | | } |
| | | |
| | |
| | | comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO); |
| | | // ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | // opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | return R.ok(comActActivityDO.getRewardIntegral()); |
| | | } |
| | | return R.fail("网络错误,请重试"); |
| | | } |
| | | else { |
| | | ComPbActivityDO comPbActivityDO=comBpActivityDAO.selectById(activityId); |
| | | if (isNull(comPbActivityDO)) { |
| | | return R.fail("活动不存在!"); |
| | | } |
| | | // else { |
| | | // ComPbActivityDO comPbActivityDO=comBpActivityDAO.selectById(activityId); |
| | | // if (isNull(comPbActivityDO)) { |
| | | // return R.fail("活动不存在!"); |
| | | // } |
| | | // |
| | | // Date beginAt = comPbActivityDO.getActivityTimeBegin(); |
| | | // Date endAt = comPbActivityDO.getActivityTimeEnd(); |
| | | // Date nowDate = new Date(); |
| | | // if (nowDate.before(beginAt) || nowDate.after(endAt)) { |
| | | // return R.fail("不在活动时间范围内"); |
| | | // } |
| | | // |
| | | // int signDayCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | // .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId).eq(ComActActRegistDO::getCodeId,comActActRegistVO.getCodeId())); |
| | | // int signAllCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | // .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId)); |
| | | // if (signDayCount >= 0) { |
| | | // return R.fail("请扫描新的签到码"); |
| | | // } |
| | | // int limit = comPbActivityDO.getLimit().intValue(); |
| | | // if(limit != -1 && signAllCount >= limit){ |
| | | // return R.fail("签到次数上限"); |
| | | // } |
| | | // |
| | | // ComActActRegistDO comActActRegistDO = new ComActActRegistDO(); |
| | | // comActActRegistDO.setActivityId(activityId); |
| | | // comActActRegistDO.setType(2); |
| | | // comActActRegistDO.setUserId(userId); |
| | | // comActActRegistDO.setIsVolunteer(comActActRegistVO.getIsVolunteer()); |
| | | // comActActRegistDO.setCreateAt(nowDate); |
| | | // comActActRegistDO.setCodeId(comActActRegistVO.getCodeId()); |
| | | // comActActRegistDO.setAward(comPbActivityDO.getRewardIntegral()); |
| | | // 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(2); |
| | | // addComActIntegralUserDTO.setCommunityId(comPbActivityDO.getCommunityId()); |
| | | // addComActIntegralUserDTO.setServiceId(activityId); |
| | | // comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO); |
| | | //// ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | //// opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | // return R.ok(); |
| | | // } |
| | | // return R.fail("网络错误,请重试"); |
| | | // } |
| | | |
| | | Date beginAt = comPbActivityDO.getActivityTimeBegin(); |
| | | Date endAt = comPbActivityDO.getActivityTimeEnd(); |
| | | Date nowDate = new Date(); |
| | | if (nowDate.before(beginAt) || nowDate.after(endAt)) { |
| | | return R.fail("不在活动时间范围内"); |
| | | } |
| | | |
| | | int signDayCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId).eq(ComActActRegistDO::getCodeId,comActActRegistVO.getCodeId())); |
| | | int signAllCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId)); |
| | | if (signDayCount >= 0) { |
| | | return R.fail("请扫描新的签到码"); |
| | | } |
| | | if(signAllCount>=comPbActivityDO.getLimit()){ |
| | | return R.fail("签到次数上限"); |
| | | } |
| | | |
| | | ComActActRegistDO comActActRegistDO = new ComActActRegistDO(); |
| | | comActActRegistDO.setActivityId(activityId); |
| | | comActActRegistDO.setType(2); |
| | | comActActRegistDO.setUserId(userId); |
| | | comActActRegistDO.setIsVolunteer(comActActRegistVO.getIsVolunteer()); |
| | | comActActRegistDO.setCreateAt(nowDate); |
| | | comActActRegistDO.setCodeId(comActActRegistVO.getCodeId()); |
| | | comActActRegistDO.setAward(comPbActivityDO.getRewardIntegral()); |
| | | 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(2); |
| | | addComActIntegralUserDTO.setCommunityId(comPbActivityDO.getCommunityId()); |
| | | addComActIntegralUserDTO.setServiceId(activityId); |
| | | comActIntegralUserTradeService.addIntegralTradeAdmin(addComActIntegralUserDTO); |
| | | // ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | // opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |
| | | return R.fail("网络错误,请重试"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | public R listRegistRecord(Long id, Long userId) { |
| | | return R.ok(comActActRegistDAO.listRegistRecord(id, userId)); |
| | | } |
| | | |
| | | /** |
| | | * 获取活动类型(目前只有志愿者活动需要获取) |
| | | * @param communityId |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R listActivityType(Long communityId, Integer type) { |
| | | return R.ok(this.baseMapper.listActivityType(communityId, type)); |
| | | } |
| | | |
| | | /** |
| | | * 添加活动类型 |
| | | * @param comActActivityTypeVO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R addActivityType(ComActActivityTypeVO comActActivityTypeVO) { |
| | | try { |
| | | this.baseMapper.addActivityType(comActActivityTypeVO); |
| | | } catch (Exception e) { |
| | | log.error("添加活动类型错误【{}】", e.getMessage()); |
| | | return R.fail("活动类型已存在"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |