|  |  |  | 
|---|
|  |  |  | package com.panzhihua.service_community.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.panzhihua.service_community.dao.ComActEasyPhotoActivityMapper; | 
|---|
|  |  |  | import com.panzhihua.service_community.model.dos.ComActEasyPhotoActivityDO; | 
|---|
|  |  |  | import com.panzhihua.service_community.service.ComActEasyPhotoActivityService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @auther lyq | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class ComActEasyPhotoActivityServiceImpl extends ServiceImpl<ComActEasyPhotoActivityMapper, ComActEasyPhotoActivityDO> implements ComActEasyPhotoActivityService { | 
|---|
|  |  |  | public class ComActEasyPhotoActivityServiceImpl extends | 
|---|
|  |  |  | ServiceImpl<ComActEasyPhotoActivityMapper, ComActEasyPhotoActivityDO> implements ComActEasyPhotoActivityService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询随手拍是否有活动 | 
|---|
|  |  |  | * @return  活动详情 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return 活动详情 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R getEasyPhotoActivity(Long communityId){ | 
|---|
|  |  |  | public R getEasyPhotoActivity(Long communityId) { | 
|---|
|  |  |  | ComActEasyPhotoActivityVO photoActivityVO = new ComActEasyPhotoActivityVO(); | 
|---|
|  |  |  | Date nowDate = DateUtils.getCurrentDate(DateUtils.ymdhms_format); | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> photoActivityDOS = this.baseMapper.selectList( | 
|---|
|  |  |  | new QueryWrapper<ComActEasyPhotoActivityDO>().lambda().eq(ComActEasyPhotoActivityDO::getCommunityId,communityId) | 
|---|
|  |  |  | .eq(ComActEasyPhotoActivityDO::getStatus,ComActEasyPhotoActivityDO.status.jxz) | 
|---|
|  |  |  | .le(ComActEasyPhotoActivityDO::getActivityStartAt,nowDate).ge(ComActEasyPhotoActivityDO::getActivityEndAt,nowDate)); | 
|---|
|  |  |  | if(!photoActivityDOS.isEmpty()){ | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> photoActivityDOS = | 
|---|
|  |  |  | this.baseMapper.selectList(new QueryWrapper<ComActEasyPhotoActivityDO>().lambda() | 
|---|
|  |  |  | .eq(ComActEasyPhotoActivityDO::getCommunityId, communityId) | 
|---|
|  |  |  | .eq(ComActEasyPhotoActivityDO::getStatus, ComActEasyPhotoActivityDO.status.jxz) | 
|---|
|  |  |  | .le(ComActEasyPhotoActivityDO::getActivityStartAt, nowDate) | 
|---|
|  |  |  | .ge(ComActEasyPhotoActivityDO::getActivityEndAt, nowDate)); | 
|---|
|  |  |  | if (!photoActivityDOS.isEmpty()) { | 
|---|
|  |  |  | ComActEasyPhotoActivityDO photoActivityDO = photoActivityDOS.get(0); | 
|---|
|  |  |  | BeanUtils.copyProperties(photoActivityDO,photoActivityVO); | 
|---|
|  |  |  | BeanUtils.copyProperties(photoActivityDO, photoActivityVO); | 
|---|
|  |  |  | return R.ok(photoActivityVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 社区后台-分页查询随手拍活动列表 | 
|---|
|  |  |  | * @param pageEasyPhotoActivityDTO  请求参数 | 
|---|
|  |  |  | * @return  随手拍活动列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param pageEasyPhotoActivityDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 随手拍活动列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R pageActivity(PageEasyPhotoActivityDTO pageEasyPhotoActivityDTO){ | 
|---|
|  |  |  | return R.ok(this.baseMapper.pageActivity(new Page(pageEasyPhotoActivityDTO.getPageNum(),pageEasyPhotoActivityDTO.getPageSize()),pageEasyPhotoActivityDTO)); | 
|---|
|  |  |  | public R pageActivity(PageEasyPhotoActivityDTO pageEasyPhotoActivityDTO) { | 
|---|
|  |  |  | return R.ok(this.baseMapper.pageActivity( | 
|---|
|  |  |  | new Page(pageEasyPhotoActivityDTO.getPageNum(), pageEasyPhotoActivityDTO.getPageSize()), | 
|---|
|  |  |  | pageEasyPhotoActivityDTO)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 社区后台-添加随手拍活动 | 
|---|
|  |  |  | * @param addEasyPhotoActivityDTO   请求参数 | 
|---|
|  |  |  | * @return  添加结果 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param addEasyPhotoActivityDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 添加结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R addActivity(AddEasyPhotoActivityDTO addEasyPhotoActivityDTO){ | 
|---|
|  |  |  | public R addActivity(AddEasyPhotoActivityDTO addEasyPhotoActivityDTO) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断当前活动时间是否与其他时间有冲突 | 
|---|
|  |  |  | Integer count = this.baseMapper.getEasyPhotoActivityTimeConflict(addEasyPhotoActivityDTO.getActivityStartAt(),addEasyPhotoActivityDTO.getActivityEndAt(),null); | 
|---|
|  |  |  | if(count > 0){ | 
|---|
|  |  |  | // 判断当前活动时间是否与其他时间有冲突 | 
|---|
|  |  |  | Integer count = this.baseMapper.getEasyPhotoActivityTimeConflict(addEasyPhotoActivityDTO.getActivityStartAt(), | 
|---|
|  |  |  | addEasyPhotoActivityDTO.getActivityEndAt(), null, addEasyPhotoActivityDTO.getCommunityId()); | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | return R.fail("在此期间已有活动,请勿重复添加"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date nowDate = new Date(); | 
|---|
|  |  |  | ComActEasyPhotoActivityDO photoActivityDO = new ComActEasyPhotoActivityDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(addEasyPhotoActivityDTO,photoActivityDO); | 
|---|
|  |  |  | photoActivityDO.setActivityStartAt(DateUtils.stringToDate(addEasyPhotoActivityDTO.getActivityStartAt(),DateUtils.ymdhm_format)); | 
|---|
|  |  |  | photoActivityDO.setActivityEndAt(DateUtils.stringToDate(addEasyPhotoActivityDTO.getActivityEndAt(),DateUtils.ymdhm_format)); | 
|---|
|  |  |  | BeanUtils.copyProperties(addEasyPhotoActivityDTO, photoActivityDO); | 
|---|
|  |  |  | photoActivityDO.setActivityStartAt( | 
|---|
|  |  |  | DateUtils.stringToDate(addEasyPhotoActivityDTO.getActivityStartAt(), DateUtils.ymdhm_format)); | 
|---|
|  |  |  | photoActivityDO.setActivityEndAt( | 
|---|
|  |  |  | DateUtils.stringToDate(addEasyPhotoActivityDTO.getActivityEndAt(), DateUtils.ymdhm_format)); | 
|---|
|  |  |  | photoActivityDO.setCreateAt(new Date()); | 
|---|
|  |  |  | photoActivityDO.setReleaseAt(new Date()); | 
|---|
|  |  |  | if(new Date().getTime() > photoActivityDO.getActivityStartAt().getTime()){ | 
|---|
|  |  |  | photoActivityDO.setStatus(2); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | photoActivityDO.setStatus(1); | 
|---|
|  |  |  | if (photoActivityDO.getActivityEndAt().getTime() <= nowDate.getTime()) { | 
|---|
|  |  |  | return R.fail("活动结束时间不可小于当前时间"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (nowDate.getTime() >= photoActivityDO.getActivityStartAt().getTime()) { | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.jxz); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.dks); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | photoActivityDO.setCount(0); | 
|---|
|  |  |  | if(this.baseMapper.insert(photoActivityDO) > 0){ | 
|---|
|  |  |  | if (this.baseMapper.insert(photoActivityDO) > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail("添加失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 社区后台-编辑随手拍活动 | 
|---|
|  |  |  | * @param editEasyPhotoActivityDTO  请求参数 | 
|---|
|  |  |  | * @return  编辑结果 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param editEasyPhotoActivityDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 编辑结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R editActivity(EditEasyPhotoActivityDTO editEasyPhotoActivityDTO){ | 
|---|
|  |  |  | public R editActivity(EditEasyPhotoActivityDTO editEasyPhotoActivityDTO) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ComActEasyPhotoActivityDO photoActivityDO = this.baseMapper.selectById(editEasyPhotoActivityDTO.getId()); | 
|---|
|  |  |  | if(photoActivityDO == null){ | 
|---|
|  |  |  | if (photoActivityDO == null) { | 
|---|
|  |  |  | return R.fail("未查询到活动记录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer count = this.baseMapper.getEasyPhotoActivityTimeConflict(editEasyPhotoActivityDTO.getActivityStartAt(),editEasyPhotoActivityDTO.getActivityEndAt(),editEasyPhotoActivityDTO.getId()); | 
|---|
|  |  |  | if(count > 0){ | 
|---|
|  |  |  | Integer count = this.baseMapper.getEasyPhotoActivityTimeConflict(editEasyPhotoActivityDTO.getActivityStartAt(), | 
|---|
|  |  |  | editEasyPhotoActivityDTO.getActivityEndAt(), editEasyPhotoActivityDTO.getId(), | 
|---|
|  |  |  | photoActivityDO.getCommunityId()); | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | return R.fail("在此期间已有活动,请勿重复添加"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BeanUtils.copyProperties(editEasyPhotoActivityDTO,photoActivityDO); | 
|---|
|  |  |  | photoActivityDO.setActivityStartAt(DateUtils.stringToDate(editEasyPhotoActivityDTO.getActivityStartAt(),DateUtils.ymdhms_format)); | 
|---|
|  |  |  | photoActivityDO.setActivityEndAt(DateUtils.stringToDate(editEasyPhotoActivityDTO.getActivityEndAt(),DateUtils.ymdhms_format)); | 
|---|
|  |  |  | if(this.baseMapper.updateById(photoActivityDO) > 0){ | 
|---|
|  |  |  | BeanUtils.copyProperties(editEasyPhotoActivityDTO, photoActivityDO); | 
|---|
|  |  |  | photoActivityDO.setActivityStartAt( | 
|---|
|  |  |  | DateUtils.stringToDate(editEasyPhotoActivityDTO.getActivityStartAt(), DateUtils.ymdhm_format)); | 
|---|
|  |  |  | photoActivityDO.setActivityEndAt( | 
|---|
|  |  |  | DateUtils.stringToDate(editEasyPhotoActivityDTO.getActivityEndAt(), DateUtils.ymdhm_format)); | 
|---|
|  |  |  | if (new Date().getTime() > photoActivityDO.getActivityStartAt().getTime()) { | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.jxz); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.dks); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (new Date().getTime() > photoActivityDO.getActivityEndAt().getTime()) { | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.yjs); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.baseMapper.updateById(photoActivityDO) > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail("编辑失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 社区后台-取消随手拍活动 | 
|---|
|  |  |  | * @param id    随手拍活动id | 
|---|
|  |  |  | * @return  取消结果 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | *            随手拍活动id | 
|---|
|  |  |  | * @return 取消结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R cancelActivity(Long id){ | 
|---|
|  |  |  | public R cancelActivity(Long id) { | 
|---|
|  |  |  | ComActEasyPhotoActivityDO photoActivityDO = this.baseMapper.selectById(id); | 
|---|
|  |  |  | if(photoActivityDO == null){ | 
|---|
|  |  |  | if (photoActivityDO == null) { | 
|---|
|  |  |  | return R.fail("未查询到活动记录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.yqx); | 
|---|
|  |  |  | if(this.baseMapper.updateById(photoActivityDO) > 0){ | 
|---|
|  |  |  | if (this.baseMapper.updateById(photoActivityDO) > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail("取消失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分页查询随手拍活动下居民参与记录 | 
|---|
|  |  |  | * @param activityUserDTO  请求参数 | 
|---|
|  |  |  | * @return  居民参与记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param activityUserDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 居民参与记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R pageActivityUser(PageEasyPhotoActivityUserDTO activityUserDTO){ | 
|---|
|  |  |  | return R.ok(this.baseMapper.pageActivityUser(new Page(activityUserDTO.getPageNum(),activityUserDTO.getPageSize()),activityUserDTO)); | 
|---|
|  |  |  | public R pageActivityUser(PageEasyPhotoActivityUserDTO activityUserDTO) { | 
|---|
|  |  |  | return R.ok(this.baseMapper | 
|---|
|  |  |  | .pageActivityUser(new Page(activityUserDTO.getPageNum(), activityUserDTO.getPageSize()), activityUserDTO)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 随手拍活动定时任务 | 
|---|
|  |  |  | * @return  执行结果 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return 执行结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R timeTaskEasyPhotoActivity(){ | 
|---|
|  |  |  | //定时任务扫描未开始活动,如果开始时间大于当前时间则更新活动状态 | 
|---|
|  |  |  | public R timeTaskEasyPhotoActivity() { | 
|---|
|  |  |  | // 定时任务扫描未开始活动,如果开始时间大于当前时间则更新活动状态 | 
|---|
|  |  |  | log.info("定时任务检测未开始的随手拍活动,判断是否开始"); | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> photoActivityDOS = this.baseMapper.selectList(new QueryWrapper<ComActEasyPhotoActivityDO>() | 
|---|
|  |  |  | .lambda().eq(ComActEasyPhotoActivityDO::getStatus,ComActEasyPhotoActivityDO.status.dks)); | 
|---|
|  |  |  | if(!photoActivityDOS.isEmpty()){ | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> photoActivityDOS = | 
|---|
|  |  |  | this.baseMapper.selectList(new QueryWrapper<ComActEasyPhotoActivityDO>().lambda() | 
|---|
|  |  |  | .eq(ComActEasyPhotoActivityDO::getStatus, ComActEasyPhotoActivityDO.status.dks)); | 
|---|
|  |  |  | if (!photoActivityDOS.isEmpty()) { | 
|---|
|  |  |  | Date nowDate = new Date(); | 
|---|
|  |  |  | photoActivityDOS.forEach(photoActivity -> { | 
|---|
|  |  |  | if(photoActivity.getActivityStartAt().getTime() <= nowDate.getTime()){ | 
|---|
|  |  |  | if (photoActivity.getActivityStartAt().getTime() <= nowDate.getTime()) { | 
|---|
|  |  |  | photoActivity.setStatus(ComActEasyPhotoActivityDO.status.jxz); | 
|---|
|  |  |  | this.baseMapper.updateById(photoActivity); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //定时任务扫描已开始活动,如果结束时间大于当前时间则更新活动状态 | 
|---|
|  |  |  | // 定时任务扫描已开始活动,如果结束时间大于当前时间则更新活动状态 | 
|---|
|  |  |  | log.info("定时任务检测已开始的随手拍活动,判断活动是否已结束"); | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> oldPhotoActivityDOS = this.baseMapper.selectList(new QueryWrapper<ComActEasyPhotoActivityDO>() | 
|---|
|  |  |  | .lambda().eq(ComActEasyPhotoActivityDO::getStatus,ComActEasyPhotoActivityDO.status.jxz)); | 
|---|
|  |  |  | if(!oldPhotoActivityDOS.isEmpty()){ | 
|---|
|  |  |  | List<ComActEasyPhotoActivityDO> oldPhotoActivityDOS = | 
|---|
|  |  |  | this.baseMapper.selectList(new QueryWrapper<ComActEasyPhotoActivityDO>().lambda() | 
|---|
|  |  |  | .eq(ComActEasyPhotoActivityDO::getStatus, ComActEasyPhotoActivityDO.status.jxz)); | 
|---|
|  |  |  | if (!oldPhotoActivityDOS.isEmpty()) { | 
|---|
|  |  |  | Date nowDate = new Date(); | 
|---|
|  |  |  | oldPhotoActivityDOS.forEach(photoActivity -> { | 
|---|
|  |  |  | if(photoActivity.getActivityEndAt().getTime() <= nowDate.getTime()){ | 
|---|
|  |  |  | if (photoActivity.getActivityEndAt().getTime() <= nowDate.getTime()) { | 
|---|
|  |  |  | photoActivity.setStatus(ComActEasyPhotoActivityDO.status.yjs); | 
|---|
|  |  |  | this.baseMapper.updateById(photoActivity); | 
|---|
|  |  |  | } | 
|---|