| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.service_community.dao.ComActActEvaluateDAO; |
| | | import com.panzhihua.service_community.model.dos.ComActActEvaluateDO; |
| | | import com.panzhihua.service_community.service.ComActActEvaluateService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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.ComActActSignDAO; |
| | | import com.panzhihua.service_community.dao.ComActActivityDAO; |
| | | import com.panzhihua.service_community.model.dos.ComActActEvaluateDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActSignDO; |
| | | import com.panzhihua.service_community.model.dos.ComActActivityDO; |
| | | import com.panzhihua.service_community.service.ComActActEvaluateService; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * title: ComActActEvaluateServiceImpl 社区》活动》活动评价表服务实现类 |
| | | * projectName 成都呐喊信息技术有限公司-智慧社区项目 |
| | |
| | | @Service |
| | | public class ComActActEvaluateServiceImpl extends ServiceImpl<ComActActEvaluateDAO, ComActActEvaluateDO> implements ComActActEvaluateService { |
| | | |
| | | @Resource |
| | | private ComActActivityDAO comActActivityDAO; |
| | | @Resource |
| | | private ComActActSignDAO comActActSignDAO; |
| | | /** |
| | | * 社区活动评价 |
| | | * |
| | | * @param comActActEvaluateVO 社区评价VO |
| | | * @return 评价结果 |
| | | */ |
| | | @Override |
| | | public R activityEvaluate(ComActActEvaluateVO comActActEvaluateVO) { |
| | | ComActActEvaluateDO comActActEvaluateDO = new ComActActEvaluateDO(); |
| | | BeanUtils.copyProperties(comActActEvaluateVO, comActActEvaluateDO); |
| | | int result = this.baseMapper.insert(comActActEvaluateDO); |
| | | if (result < 0) { |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 定时任务针对活动结束后7天还未评价的用户默认好评 |
| | | */ |
| | | @Override |
| | | public R timedTaskActivityDefaultPraise() { |
| | | //获取还未默认好评的活动 |
| | | 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))); |
| | | //获取报名记录 |
| | | if (!ObjectUtils.isEmpty(comActActivityDOS)) { |
| | | List<Long> activityIds = comActActivityDOS.stream().map(ComActActivityDO::getId).collect(Collectors.toList()); |
| | | List<ComActActSignDO> comActActSignDOS = comActActSignDAO.selectNeedEvaluateSignRecords(activityIds); |
| | | //批量插入好评 |
| | | if (!ObjectUtils.isEmpty(comActActSignDOS)) { |
| | | List<ComActActEvaluateDO> comActActEvaluateDOList = comActActSignDOS.stream().map(comActActSignDO -> { |
| | | ComActActEvaluateDO comActActEvaluateDO = new ComActActEvaluateDO(); |
| | | comActActEvaluateDO.setActivityId(comActActSignDO.getActivityId()); |
| | | comActActEvaluateDO.setIsVolunteer(comActActSignDO.getIsVolunteer()); |
| | | comActActEvaluateDO.setUserId(comActActSignDO.getUserId()); |
| | | comActActEvaluateDO.setCreateAt(new Date()); |
| | | comActActEvaluateDO.setStarLevel(5); |
| | | return comActActEvaluateDO; |
| | | }).collect(Collectors.toList()); |
| | | boolean result = this.saveBatch(comActActEvaluateDOList); |
| | | if (!result) { |
| | | return R.fail("批量插入评价失败"); |
| | | } |
| | | ComActActivityDO comActActivityDO = new ComActActivityDO(); |
| | | comActActivityDO.setIsDefaultPraise(1); |
| | | int updateResult = comActActivityDAO.update(comActActivityDO, new UpdateWrapper<ComActActivityDO>() |
| | | .lambda().in(ComActActivityDO::getId, activityIds)); |
| | | if (updateResult < 0) { |
| | | return R.fail("修改是否已默认评价状态失败"); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 用户评价列表 |
| | | * |
| | | * @param userId 用户id |
| | | * @return 当前用户对所有活动的评价列表 |
| | | */ |
| | | @Override |
| | | public R listEvaluate(Long userId) { |
| | | List<ComActActEvaluateDO> comActActEvaluateDOList = this.baseMapper.selectList(new QueryWrapper<ComActActEvaluateDO>() |
| | | .lambda().eq(ComActActEvaluateDO::getUserId, userId)); |
| | | ArrayList<ComActActEvaluateVO> comActActEvaluateVOS = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(comActActEvaluateDOList)) { |
| | | comActActEvaluateDOList.forEach(comActActEvaluateDO -> { |
| | | ComActActEvaluateVO comActActEvaluateVO = new ComActActEvaluateVO(); |
| | | BeanUtils.copyProperties(comActActEvaluateDO, comActActEvaluateVO); |
| | | comActActEvaluateVOS.add(comActActEvaluateVO); |
| | | }); |
| | | } |
| | | return R.ok(comActActEvaluateVOS); |
| | | } |
| | | } |