| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static org.apache.commons.lang3.StringUtils.isBlank; |
| | | import static org.apache.commons.lang3.StringUtils.isNotBlank; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.panzhihua.common.model.vos.community.*; |
| | | import com.panzhihua.common.model.vos.screen.ComActPopulationCultureVO; |
| | | import com.panzhihua.service_community.dao.*; |
| | | import com.panzhihua.service_community.model.dos.ComActActEvaluateDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActPictureDO; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | |
| | | 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.ActivitySignVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActEvaluateVO; |
| | | 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.ComActActivityVO; |
| | | import com.panzhihua.common.model.vos.community.CommunityActivitiesVO; |
| | | import com.panzhihua.common.model.vos.community.CommunityGovernanceTrendsVO; |
| | | import com.panzhihua.common.model.vos.community.SignactivityVO; |
| | | import com.panzhihua.common.model.vos.community.screen.work.ActActivityListVO; |
| | | 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.ComActActivityDAO; |
| | | 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; |
| | |
| | | if (status.intValue() == 2) {// 点击‘保存并发布’ 按钮 |
| | | // 报名结束时间大于当前时间则设置为“进行中” |
| | | if (comActActivityVO.getSignUpEnd() != null && now.getTime() < comActActivityVO.getSignUpEnd().getTime()) { |
| | | comActActivityDO.setStatus(4); |
| | | comActActivityDO.setStatus(3); |
| | | } |
| | | } |
| | | |
| | |
| | | comActActPictureDO.setActivityId(activityId); |
| | | comActActPictureDO.setUserId(comActActivityVO.getUserId()); |
| | | comActActPictureDO.setUploadPicture(comActActivityVO.getCover()); |
| | | comActActPictureDO.setSysFlag(0); |
| | | comActActPictureDAO.insert(comActActPictureDO); |
| | | return R.ok(activityId); |
| | | } |
| | |
| | | // 结束时间大于当前时间则设置为“进行中” |
| | | Date now = new Date(); |
| | | if (comActActivityVO.getSignUpEnd() != null && now.getTime() < comActActivityVO.getSignUpEnd().getTime()) { |
| | | comActActivityDO.setStatus(4); |
| | | comActActivityDO.setStatus(3); |
| | | } |
| | | boolean b = this.updateById(comActActivityDO); |
| | | if (b) { |
| | |
| | | page.setSize(pageSize); |
| | | page.setCurrent(pageNum); |
| | | IPage<ComActActivityVO> iPage = comActActivityDAO.pageActivity(page, comActActivityVO); |
| | | List<ComActActivityVO> records = iPage.getRecords(); |
| | | if (!ObjectUtils.isEmpty(records)) { |
| | | records.forEach(comActActivityVO1 -> { |
| | | Integer status = comActActivityVO1.getStatus(); |
| | | if (status.intValue() == 3) { |
| | | comActActivityVO1.setStatus(4); |
| | | } |
| | | }); |
| | | } |
| | | // List<ComActActivityVO> records = iPage.getRecords(); |
| | | // if (!ObjectUtils.isEmpty(records)) { |
| | | // records.forEach(comActActivityVO1 -> { |
| | | // Integer status = comActActivityVO1.getStatus(); |
| | | // if (status.intValue() == 3) { |
| | | // comActActivityVO1.setStatus(4); |
| | | // } |
| | | // }); |
| | | // } |
| | | return R.ok(iPage); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public R releaseActivity(ComActActivityVO comActActivityVO) { |
| | | ComActActivityDO comActActivityDO = new ComActActivityDO(); |
| | | comActActivityDO.setId(comActActivityVO.getId()); |
| | | ComActActivityDO comActActivityDO = comActActivityDAO.selectById(comActActivityVO.getId()); |
| | | comActActivityDO.setPublishAt(comActActivityVO.getPublishAt()); |
| | | comActActivityDO.setStatus(comActActivityVO.getStatus()); |
| | | comActActivityDO.setStatus(3); |
| | | if (comActActivityVO.getPublishAt().after(comActActivityDO.getSignUpEnd())) { |
| | | comActActivityVO.setStatus(4); |
| | | } |
| | | int update = comActActivityDAO.updateById(comActActivityDO); |
| | | if (update > 0) { |
| | | return R.ok(); |
| | |
| | | return R.ok(comActActPictureVOS); |
| | | } |
| | | |
| | | @Override |
| | | public R getSysPictureList(Integer type) { |
| | | List<ComActActPictureVO> comActActPictureVOS = new ArrayList<>(); |
| | | List<ComActActPictureDO> comActActPictureDOS = comActActPictureDAO.selectList(new QueryWrapper<ComActActPictureDO>().lambda(). |
| | | eq(ComActActPictureDO::getSysFlag, 1).eq(ComActActPictureDO :: getType, type)); |
| | | if (comActActPictureDOS != null && comActActPictureDOS.size() != 0) { |
| | | comActActPictureDOS.forEach(comActActPictureDO -> { |
| | | ComActActPictureVO comActActPictureVO = new ComActActPictureVO(); |
| | | BeanUtils.copyProperties(comActActPictureDO, comActActPictureVO); |
| | | comActActPictureVOS.add(comActActPictureVO); |
| | | }); |
| | | } |
| | | return R.ok(comActActPictureVOS); |
| | | } |
| | | |
| | | /** |
| | | * 分页展示我的所有活动 时间倒序排列 |
| | | * |
| | |
| | | Integer type = signactivityVO.getType(); |
| | | Long userId = signactivityVO.getUserId(); |
| | | Integer isVolunteer = signactivityVO.getIsVolunteer(); |
| | | |
| | | // 查询社区活动 |
| | | ComActActivityDO actActivityDO = this.baseMapper.selectById(activityId); |
| | | if (isNull(actActivityDO)) { |
| | | return R.fail("活动不存在"); |
| | | } |
| | | int num = 0; |
| | | if (1 == type) { |
| | | R<LoginUserInfoVO> userInfoR = userService.getUserInfoByUserId(String.valueOf(userId)); |
| | |
| | | return R.fail("只有志愿者才能报名"); |
| | | } |
| | | |
| | | // 查询社区活动 |
| | | ComActActivityDO actActivityDO = this.baseMapper.selectById(activityId); |
| | | if (actActivityDO != null) { |
| | | // 查询当前活动下参与志愿者/居民数量 |
| | | 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("志愿者报名人数已满"); |
| | | } |
| | | // 查询当前活动下参与志愿者/居民数量 |
| | | 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("志愿者报名人数已满"); |
| | | } |
| | | |
| | | if (isVolunteer.equals(0) && actActivityDO.getParticipantMax() <= count |
| | | && !actActivityDO.getParticipantMax().equals(-1)) { |
| | | return R.fail("居民报名人数已满"); |
| | | //审查用户是否有该活动报名权限(是否活动指定参与人群) |
| | | String currentUserTags = loginUserInfoVO.getTags(); |
| | | String attendPeople = actActivityDO.getAattendPeople(); |
| | | if (isVolunteer.intValue() == 0 && isNotBlank(attendPeople)) { |
| | | if (isBlank(currentUserTags)) { |
| | | return R.fail("您不是指定参与人群!"); |
| | | } |
| | | List<String> currentUserTagList = Arrays.asList(currentUserTags.split(",")); |
| | | boolean checkResult = currentUserTagList.stream().anyMatch(currentUserTag -> attendPeople.contains(currentUserTag)); |
| | | if (!checkResult) { |
| | | return R.fail("您不是指定参与人群!"); |
| | | } |
| | | } |
| | | |
| | | if (isVolunteer.equals(0) && actActivityDO.getParticipantMax() <= count |
| | | && !actActivityDO.getParticipantMax().equals(-1)) { |
| | | return R.fail("居民报名人数已满"); |
| | | } |
| | | |
| | | ComActActSignDO comActActSignDO = new ComActActSignDO(); |
| | |
| | | */ |
| | | @Override |
| | | public R timedTaskActActivity() { |
| | | List<Long> longs = comActActivityDAO.selectTimedTaskActActivity(); |
| | | if (ObjectUtils.isEmpty(longs)) { |
| | | return R.fail("没有需要取消的社区活动"); |
| | | } |
| | | List<ComActActivityDO> comActActivityDOS = comActActivityDAO.selectBatchIds(longs); |
| | | List<ComActActivityVO> comActActivityVOS = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(comActActivityDOS)) { |
| | | comActActivityDOS.forEach(comActActivityDO -> { |
| | | ComActActivityVO comActActivityVO = new ComActActivityVO(); |
| | | BeanUtils.copyProperties(comActActivityDO, comActActivityVO); |
| | | List<ComActActSignDO> comActActSignDOS = comActActSignDAO.selectList(new QueryWrapper<ComActActSignDO>() |
| | | .lambda().eq(ComActActSignDO::getActivityId, comActActivityDO.getId())); |
| | | if (!ObjectUtils.isEmpty(comActActSignDOS)) { |
| | | List<ActivitySignVO> activitySignVOList = new ArrayList<>(); |
| | | comActActSignDOS.forEach(comActActSignDO -> { |
| | | ActivitySignVO activitySignVO = new ActivitySignVO(); |
| | | BeanUtils.copyProperties(comActActSignDO, activitySignVO); |
| | | activitySignVOList.add(activitySignVO); |
| | | comActActivityVO.setActivitySignVOList(activitySignVOList); |
| | | }); |
| | | } |
| | | comActActivityVOS.add(comActActivityVO); |
| | | }); |
| | | int num = comActActivityDAO.updateIdBatch(longs); |
| | | log.info("定时任务--一共取消社区活动数量【{}】", num); |
| | | } |
| | | return R.ok(comActActivityVOS); |
| | | // List<Long> longs = comActActivityDAO.selectTimedTaskActActivity(); |
| | | // if (ObjectUtils.isEmpty(longs)) { |
| | | // return R.fail("没有需要取消的社区活动"); |
| | | // } |
| | | // List<ComActActivityDO> comActActivityDOS = comActActivityDAO.selectBatchIds(longs); |
| | | // List<ComActActivityVO> comActActivityVOS = new ArrayList<>(); |
| | | // if (!ObjectUtils.isEmpty(comActActivityDOS)) { |
| | | // comActActivityDOS.forEach(comActActivityDO -> { |
| | | // ComActActivityVO comActActivityVO = new ComActActivityVO(); |
| | | // BeanUtils.copyProperties(comActActivityDO, comActActivityVO); |
| | | // List<ComActActSignDO> comActActSignDOS = comActActSignDAO.selectList(new QueryWrapper<ComActActSignDO>() |
| | | // .lambda().eq(ComActActSignDO::getActivityId, comActActivityDO.getId())); |
| | | // if (!ObjectUtils.isEmpty(comActActSignDOS)) { |
| | | // List<ActivitySignVO> activitySignVOList = new ArrayList<>(); |
| | | // comActActSignDOS.forEach(comActActSignDO -> { |
| | | // ActivitySignVO activitySignVO = new ActivitySignVO(); |
| | | // BeanUtils.copyProperties(comActActSignDO, activitySignVO); |
| | | // activitySignVOList.add(activitySignVO); |
| | | // comActActivityVO.setActivitySignVOList(activitySignVOList); |
| | | // }); |
| | | // } |
| | | // comActActivityVOS.add(comActActivityVO); |
| | | // }); |
| | | // int num = comActActivityDAO.updateIdBatch(longs); |
| | | // log.info("定时任务--一共取消社区活动数量【{}】", num); |
| | | // } |
| | | // return R.ok(comActActivityVOS); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | int num = comActActivityDAO.updateStatusToNotBegin(); |
| | | log.info("定时任务--修改社区活动发布状态活动数量【{}】", num); |
| | | // 修改报名状态 变为报名中 |
| | | int num1 = comActActivityDAO.updateStatusToBeginSign(); |
| | | log.info("定时任务--修改社区活动报名状态活动数量【{}】", num1); |
| | | // int num1 = comActActivityDAO.updateStatusToBeginSign(); |
| | | // log.info("定时任务--修改社区活动报名状态活动数量【{}】", num1); |
| | | int num3 = comActActivityDAO.updateStatusToBeginAfterSingEnd(); |
| | | log.info("定时任务--报名结束修改社区活动进行状态活动数量【{}】", num3); |
| | | // 查询已经结束的活动,需要计算积分 |
| | | List<Long> activityEndIds = comActActivityDAO.getActivityEndIds(); |
| | | // 修改进行状态 变为进行中或者已结束 |
| | | int num2 = comActActivityDAO.updateStatusToBeginActiveOrEnd(); |
| | | log.info("定时任务--修改社区活动进行状态活动数量【{}】", num2); |
| | | int num3 = comActActivityDAO.updateStatusToBeginAfterSingEnd(); |
| | | log.info("定时任务--报名结束修改社区活动进行状态活动数量【{}】", num3); |
| | | return R.ok(activityEndIds); |
| | | } |
| | | |
| | |
| | | iPage.getRecords().forEach(vo ->{ |
| | | List<ComActActEvaluateDO> comActActEvaluateDOList = comActActEvaluateDAO |
| | | .selectList(new QueryWrapper<ComActActEvaluateDO>().lambda().eq(ComActActEvaluateDO::getActivityId, vo.getId())); |
| | | if (comActActEvaluateDOList != null && comActActEvaluateDOList.size() != 0) { |
| | | if (comActActEvaluateDOList != null && comActActEvaluateDOList.size() > 0) { |
| | | BigDecimal starNum = BigDecimal.ZERO; |
| | | //总星级 |
| | | int starNum = comActActEvaluateDOList.stream().mapToInt(ComActActEvaluateDO::getStarLevel).sum(); |
| | | //评分星级=总星级/总评价人数 |
| | | vo.setEvaluateLevel(Double.valueOf(starNum/comActActEvaluateDOList.size())); |
| | | for (ComActActEvaluateDO evaluateDO:comActActEvaluateDOList) { |
| | | starNum = starNum.add(BigDecimal.valueOf(evaluateDO.getStarLevel()==null?0:evaluateDO.getStarLevel())); |
| | | } |
| | | //评分星级(如果无评分默认5分)=总星级/总评价人数 |
| | | if(starNum.compareTo(BigDecimal.ZERO) == 0){ |
| | | vo.setEvaluateLevel(BigDecimal.valueOf(5)); |
| | | }else{ |
| | | vo.setEvaluateLevel(starNum.divide(BigDecimal.valueOf(comActActEvaluateDOList.size()),2, RoundingMode.HALF_UP)); |
| | | } |
| | | }else{ |
| | | vo.setEvaluateLevel(BigDecimal.valueOf(5)); |
| | | } |
| | | }); |
| | | return R.ok(iPage); |
| | |
| | | public R activitySignIn(ComActActRegistVO comActActRegistVO) { |
| | | Long activityId = comActActRegistVO.getActivityId(); |
| | | Long userId = comActActRegistVO.getUserId(); |
| | | String activitySignInKey = String.join(DELIMITER, ACTIVITY_SIGN_IN, userId.toString(), activityId.toString()); |
| | | if (stringRedisTemplate.hasKey(activitySignInKey)) { |
| | | return R.fail("你已签到,如要再次签到请三十分钟后尝试!"); |
| | | if (isNull(activityId)) { |
| | | return R.fail("签到所属活动id不能为空!"); |
| | | } |
| | | ComActActivityDO comActActivityDO = comActActivityDAO.selectById(activityId); |
| | | if (isNull(comActActivityDO)) { |
| | | return R.fail("活动不存在!"); |
| | | } |
| | | |
| | | Date beginAt = comActActivityDO.getBeginAt(); |
| | | Date endAt = comActActivityDO.getEndAt(); |
| | | Date nowDate = new Date(); |
| | | if (nowDate.before(beginAt) || nowDate.after(endAt)) { |
| | | return R.fail("不在活动时间范围内"); |
| | | } |
| | | |
| | | int signCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getActivityId, activityId).eq(ComActActRegistDO::getUserId, userId)); |
| | | |
| | | if (signCount > 0) { |
| | | return R.fail("请勿重复签到"); |
| | | } |
| | | |
| | | // String activitySignInKey = String.join(DELIMITER, ACTIVITY_SIGN_IN, userId.toString(), activityId.toString()); |
| | | // if (stringRedisTemplate.hasKey(activitySignInKey)) { |
| | | // return R.fail("你已签到,如要再次签到请三十分钟后尝试!"); |
| | | // } |
| | | ComActActRegistDO comActActRegistDO = new ComActActRegistDO(); |
| | | comActActRegistDO.setActivityId(activityId); |
| | | comActActRegistDO.setUserId(userId); |
| | | comActActRegistDO.setIsVolunteer(comActActRegistVO.getIsVolunteer()); |
| | | comActActRegistDO.setCreateAt(new Date()); |
| | | comActActRegistDO.setCreateAt(nowDate); |
| | | int result = comActActRegistDAO.insert(comActActRegistDO); |
| | | if (result > 0) { |
| | | ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | // ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | // opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |
| | | return R.ok(); |
| | | return R.fail("网络错误,请重试"); |
| | | } |
| | | |
| | | /** |