| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | 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.*; |
| | | 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.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.ComActActRegistDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActSignDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActivityDO; |
| | | import com.panzhihua.service_community.service.ComActActivityService; |
| | |
| | | @Service |
| | | public class ComActActivityServiceImpl extends ServiceImpl<ComActActivityDAO, ComActActivityDO> |
| | | implements ComActActivityService { |
| | | private static final String DELIMITER = ":"; |
| | | private static final String ACTIVITY_SIGN_IN = "ACTIVITY:SIGN:IN"; |
| | | @Resource |
| | | private ComActActivityDAO comActActivityDAO; |
| | | @Resource |
| | | private ComActActSignDAO comActActSignDAO; |
| | | @Resource |
| | | private UserService userService; |
| | | @Resource |
| | | private ComActActEvaluateDAO comActActEvaluateDAO; |
| | | @Resource |
| | | private ComActActRegistDAO comActActRegistDAO; |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | @Resource |
| | | private ComActActPictureDAO comActActPictureDAO; |
| | | |
| | | /** |
| | | * 新增社区活动 |
| | |
| | | .eq(ComActActivityDO::getActivityName, comActActivityDO.getActivityName()) |
| | | .orderByDesc(ComActActivityDO::getCreateAt).last(" limit 1 ")); |
| | | Long activityId = one.getId(); |
| | | |
| | | //保存上传照片 |
| | | ComActActPictureDO comActActPictureDO = new ComActActPictureDO(); |
| | | comActActPictureDO.setActivityId(activityId); |
| | | comActActPictureDO.setUserId(comActActivityVO.getUserId()); |
| | | comActActPictureDO.setUploadPicture(comActActivityVO.getCover()); |
| | | comActActPictureDAO.insert(comActActPictureDO); |
| | | return R.ok(activityId); |
| | | } |
| | | |
| | |
| | | public R listActivitySigns(ActivitySignVO activitySignVO) { |
| | | List<ActivitySignVO> activitySignVOS = comActActSignDAO.listActivitySigns(activitySignVO); |
| | | return R.ok(activitySignVOS); |
| | | } |
| | | |
| | | @Override |
| | | public R getSignLists(ActivitySignVO activitySignVO) { |
| | | return R.ok(comActActSignDAO.getSignLists(activitySignVO)); |
| | | } |
| | | |
| | | @Override |
| | | public R pageActivityEvaluates(ComActActEvaluateVO comActActEvaluateVO) { |
| | | IPage<ComActActEvaluateVO> comActActEvaluateVOIPage = comActActEvaluateDAO |
| | | .pageActivityEvaluates(new Page(comActActEvaluateVO.getPageNum(), comActActEvaluateVO.getPageSize()), comActActEvaluateVO); |
| | | return R.ok(comActActEvaluateVOIPage); |
| | | } |
| | | |
| | | @Override |
| | | public R getEvaluateLists(ComActActEvaluateVO comActActEvaluateVO) { |
| | | return R.ok(comActActEvaluateDAO.getEvaluateLists(comActActEvaluateVO)); |
| | | } |
| | | |
| | | @Override |
| | | public R pageActivityRegists(ComActActRegistVO comActActRegistVO) { |
| | | IPage<ComActActRegistVO> comActActRegistVOIPage = comActActRegistDAO.pageActivityRegists(new Page(comActActRegistVO.getPageNum(), comActActRegistVO.getPageSize()), comActActRegistVO); |
| | | return R.ok(comActActRegistVOIPage); |
| | | } |
| | | |
| | | @Override |
| | | public R getRegistLists(ComActActRegistVO comActActRegistVO) { |
| | | return R.ok(comActActRegistDAO.getRegistLists(comActActRegistVO)); |
| | | } |
| | | |
| | | @Override |
| | | public R getNoRegistLists(ComActActRegistVO comActActRegistVO) { |
| | | return R.ok(comActActRegistDAO.getNoRegistLists(comActActRegistVO)); |
| | | } |
| | | |
| | | @Override |
| | | public R activityStatistics(Long activityId) { |
| | | ComActActivityStatisticsVO comActActivityStatisticsVO = comActActivityDAO.activityStatistics(activityId); |
| | | if (comActActivityStatisticsVO != null) { |
| | | if (comActActivityStatisticsVO.getSignTotal().equals(0)){ |
| | | comActActivityStatisticsVO.setSignTotalStr("不限"); |
| | | comActActivityStatisticsVO.setNoSignTotalStr(""); |
| | | comActActivityStatisticsVO.setSignPersent(""); |
| | | }else { |
| | | comActActivityStatisticsVO.setSignTotalStr(String.valueOf(comActActivityStatisticsVO.getSignTotal())); |
| | | comActActivityStatisticsVO.setNoSignTotalStr(String.valueOf(Integer.valueOf(comActActivityStatisticsVO.getSignTotalStr()) - comActActivityStatisticsVO.getReallySignTotal())); |
| | | comActActivityStatisticsVO.setSignPersent(getPersent(comActActivityStatisticsVO.getReallySignTotal(),comActActivityStatisticsVO.getSignTotal())); |
| | | } |
| | | comActActivityStatisticsVO.setRegistPersent(getPersent(comActActivityStatisticsVO.getReallyRegistTotal(),comActActivityStatisticsVO.getRegistTotal())); |
| | | comActActivityStatisticsVO.setEvaluatePersent(getPersent(comActActivityStatisticsVO.getReallyEvaluateTotal(),comActActivityStatisticsVO.getEvaluateTotal())); |
| | | } |
| | | return R.ok(comActActivityStatisticsVO); |
| | | } |
| | | |
| | | @Override |
| | | public R getPictureList(Long userId) { |
| | | List<ComActActPictureVO> comActActPictureVOS = new ArrayList<>(); |
| | | List<ComActActPictureDO> comActActPictureDOS = comActActPictureDAO.selectList(new QueryWrapper<ComActActPictureDO>().lambda(). |
| | | eq(ComActActPictureDO::getUserId, userId)); |
| | | if (comActActPictureDOS != null && comActActPictureDOS.size() != 0) { |
| | | comActActPictureDOS.forEach(comActActPictureDO -> { |
| | | ComActActPictureVO comActActPictureVO = new ComActActPictureVO(); |
| | | BeanUtils.copyProperties(comActActPictureDO, comActActPictureVO); |
| | | comActActPictureVOS.add(comActActPictureVO); |
| | | }); |
| | | } |
| | | return R.ok(comActActPictureVOS); |
| | | } |
| | | |
| | | /** |
| | |
| | | page.setSize(pageSize); |
| | | page.setCurrent(pageNum); |
| | | IPage<ComActActivityVO> iPage = comActActivityDAO.pageActivityCommunityBack(page, comActActivityVO); |
| | | iPage.getRecords().forEach(vo ->{ |
| | | List<ComActActEvaluateDO> comActActEvaluateDOList = comActActEvaluateDAO |
| | | .selectList(new QueryWrapper<ComActActEvaluateDO>().lambda().eq(ComActActEvaluateDO::getActivityId, vo.getId())); |
| | | if (comActActEvaluateDOList != null && comActActEvaluateDOList.size() != 0) { |
| | | //总星级 |
| | | int starNum = comActActEvaluateDOList.stream().mapToInt(ComActActEvaluateDO::getStarLevel).sum(); |
| | | //评分星级=总星级/总评价人数 |
| | | vo.setEvaluateLevel(Double.valueOf(starNum/comActActEvaluateDOList.size())); |
| | | } |
| | | }); |
| | | return R.ok(iPage); |
| | | } |
| | | |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private String getPersent(int x, int y){ |
| | | if (y == 0) { |
| | | return ""; |
| | | } |
| | | if (x == 0) { |
| | | return "0.00%"; |
| | | } |
| | | double d1 = x * 1.0; |
| | | double d2 = y * 1.0; |
| | | DecimalFormat decimalFormat = new DecimalFormat("##.00%"); |
| | | return decimalFormat.format(d1 / d2); |
| | | } |
| | | |
| | | /** |
| | | * 用户签到 |
| | | * |
| | | * @param comActActRegistVO 签到参数 |
| | | * @return 签到结果 |
| | | */ |
| | | @Override |
| | | 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("你已签到,如要再次签到请三十分钟后尝试!"); |
| | | } |
| | | ComActActRegistDO comActActRegistDO = new ComActActRegistDO(); |
| | | comActActRegistDO.setActivityId(activityId); |
| | | comActActRegistDO.setUserId(userId); |
| | | comActActRegistDO.setIsVolunteer(comActActRegistVO.getIsVolunteer()); |
| | | comActActRegistDO.setCreateAt(new Date()); |
| | | int result = comActActRegistDAO.insert(comActActRegistDO); |
| | | if (result > 0) { |
| | | ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue(); |
| | | opsForValue.set(activitySignInKey, "", 1800L, TimeUnit.SECONDS); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | *用户签到记录列表 |
| | | * |
| | | * @param userId 用id |
| | | * @return 用户签到列表 |
| | | */ |
| | | @Override |
| | | public R listSignInActivity(Long userId) { |
| | | List<ComActActRegistDO> comActActRegistDOS = comActActRegistDAO.selectList(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getUserId, userId)); |
| | | ArrayList<ComActActRegistVO> comActActRegistVOS = new ArrayList<>(); |
| | | comActActRegistDOS.forEach(comActActRegistDO -> { |
| | | ComActActRegistVO comActActRegistVO = new ComActActRegistVO(); |
| | | BeanUtils.copyProperties(comActActRegistDO, comActActRegistVO); |
| | | comActActRegistVOS.add(comActActRegistVO); |
| | | }); |
| | | return R.ok(comActActRegistVOS); |
| | | } |
| | | } |