| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActActEvaluateVO; |
| | | 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.ComActActEvaluateService; |
| | |
| | | private ComActActivityDAO comActActivityDAO; |
| | | @Resource |
| | | private ComActActSignDAO comActActSignDAO; |
| | | @Resource |
| | | private ComActActRegistDAO comActActRegistDAO; |
| | | /** |
| | | * 社区活动评价 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public R activityEvaluate(ComActActEvaluateVO comActActEvaluateVO) { |
| | | Long activityId = comActActEvaluateVO.getActivityId(); |
| | | Long userId = comActActEvaluateVO.getUserId(); |
| | | if (isNull(activityId)) { |
| | | return R.fail("参数有误"); |
| | | } |
| | | ComActActivityDO comActActivityDO = comActActivityDAO.selectById(activityId); |
| | | if (isNull(comActActivityDO)) { |
| | | return R.fail("活动不存在"); |
| | | } |
| | | Date beginAt = comActActivityDO.getBeginAt(); |
| | | Date nowDate = new Date(); |
| | | Integer isQrCode = comActActivityDO.getIsQrCode(); |
| | | if (nonNull(isQrCode) && isQrCode.equals(1)) { |
| | | //需要签到类型 |
| | | int registCount = comActActRegistDAO.selectCount(new QueryWrapper<ComActActRegistDO>() |
| | | .lambda().eq(ComActActRegistDO::getUserId, userId).eq(ComActActRegistDO::getActivityId, activityId)); |
| | | if (registCount <= 0) { |
| | | //未签到,不能评价 |
| | | return R.fail("未签到,不能评价"); |
| | | } |
| | | } else { |
| | | if (nowDate.before(beginAt)) { |
| | | return R.fail("活动还未开始,暂不支持评价"); |
| | | } |
| | | } |
| | | ComActActEvaluateDO currentUserEvaluateForThisActivity = this.baseMapper.selectOne(new QueryWrapper<ComActActEvaluateDO>() |
| | | .lambda().eq(ComActActEvaluateDO::getActivityId, activityId).eq(ComActActEvaluateDO::getUserId, userId)); |
| | | if (Objects.nonNull(currentUserEvaluateForThisActivity)) { |
| | | return R.fail("该用户已评论过了,请勿重复评论"); |
| | | } |
| | | ComActActEvaluateDO comActActEvaluateDO = new ComActActEvaluateDO(); |
| | | BeanUtils.copyProperties(comActActEvaluateVO, comActActEvaluateDO); |
| | | int result = this.baseMapper.insert(comActActEvaluateDO); |
| | | if (result < 0) { |
| | | return R.fail(); |
| | | return R.fail("评论失败,请重试"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | List<ComActActivityDO> comActActivityDOS = comActActivityDAO.selectList(new QueryWrapper<ComActActivityDO>().lambda() |
| | | .eq(ComActActivityDO::getStatus, 5) |
| | | .eq(ComActActivityDO::getIsDefaultPraise, 0) |
| | | .le(ComActActivityDO::getEndAt, DateUtils.addDays(new Date(), 7))); |
| | | .le(ComActActivityDO::getEndAt, DateUtils.addDays(new Date(), -7))); |
| | | //获取报名记录 |
| | | if (!ObjectUtils.isEmpty(comActActivityDOS)) { |
| | | List<Long> activityIds = comActActivityDOS.stream().map(ComActActivityDO::getId).collect(Collectors.toList()); |
| | |
| | | comActActEvaluateDO.setUserId(comActActSignDO.getUserId()); |
| | | comActActEvaluateDO.setCreateAt(new Date()); |
| | | comActActEvaluateDO.setStarLevel(5); |
| | | comActActEvaluateDO.setEvaluateContent("系统默认好评!"); |
| | | return comActActEvaluateDO; |
| | | }).collect(Collectors.toList()); |
| | | boolean result = this.saveBatch(comActActEvaluateDOList); |