From 2e64c232ab6b51b2cecf1ee96e1e9b709234f326 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期六, 21 八月 2021 16:35:14 +0800
Subject: [PATCH] 随手拍改版接口开发

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 insertions(+), 0 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java
index 0755115..df1c936 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java
@@ -1,7 +1,12 @@
 package com.panzhihua.service_community.service.impl;
 
 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.common.model.dtos.community.easyPhoto.AddEasyPhotoActivityDTO;
+import com.panzhihua.common.model.dtos.community.easyPhoto.EditEasyPhotoActivityDTO;
+import com.panzhihua.common.model.dtos.community.easyPhoto.PageEasyPhotoActivityDTO;
+import com.panzhihua.common.model.dtos.community.easyPhoto.PageEasyPhotoActivityUserDTO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.ComActEasyPhotoActivityVO;
 import com.panzhihua.common.utlis.DateUtils;
@@ -34,6 +39,7 @@
         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()){
             ComActEasyPhotoActivityDO photoActivityDO = photoActivityDOS.get(0);
@@ -42,4 +48,151 @@
         }
         return R.ok();
     }
+
+    /**
+     * 社区后台-分页查询随手拍活动列表
+     * @param pageEasyPhotoActivityDTO  请求参数
+     * @return  随手拍活动列表
+     */
+    @Override
+    public R pageActivity(PageEasyPhotoActivityDTO pageEasyPhotoActivityDTO){
+        return R.ok(this.baseMapper.pageActivity(new Page(pageEasyPhotoActivityDTO.getPageNum(),pageEasyPhotoActivityDTO.getPageSize()),pageEasyPhotoActivityDTO));
+    }
+
+    /**
+     * 社区后台-添加随手拍活动
+     * @param addEasyPhotoActivityDTO   请求参数
+     * @return  添加结果
+     */
+    @Override
+    public R addActivity(AddEasyPhotoActivityDTO addEasyPhotoActivityDTO){
+
+        //判断当前活动时间是否与其他时间有冲突
+        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));
+        photoActivityDO.setCreateAt(new Date());
+        photoActivityDO.setReleaseAt(new Date());
+        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){
+            return R.ok();
+        }
+        return R.fail("添加失败");
+    }
+
+    /**
+     * 社区后台-编辑随手拍活动
+     * @param editEasyPhotoActivityDTO  请求参数
+     * @return  编辑结果
+     */
+    @Override
+    public R editActivity(EditEasyPhotoActivityDTO editEasyPhotoActivityDTO){
+
+        ComActEasyPhotoActivityDO photoActivityDO = this.baseMapper.selectById(editEasyPhotoActivityDTO.getId());
+        if(photoActivityDO == null){
+            return R.fail("未查询到活动记录");
+        }
+
+        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.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  取消结果
+     */
+    @Override
+    public R cancelActivity(Long id){
+        ComActEasyPhotoActivityDO photoActivityDO = this.baseMapper.selectById(id);
+        if(photoActivityDO == null){
+            return R.fail("未查询到活动记录");
+        }
+        photoActivityDO.setStatus(ComActEasyPhotoActivityDO.status.yqx);
+        if(this.baseMapper.updateById(photoActivityDO) > 0){
+            return R.ok();
+        }
+        return R.fail("取消失败");
+    }
+
+    /**
+     * 分页查询随手拍活动下居民参与记录
+     * @param activityUserDTO  请求参数
+     * @return  居民参与记录
+     */
+    @Override
+    public R pageActivityUser(PageEasyPhotoActivityUserDTO activityUserDTO){
+        return R.ok(this.baseMapper.pageActivityUser(new Page(activityUserDTO.getPageNum(),activityUserDTO.getPageSize()),activityUserDTO));
+    }
+
+    /**
+     * 随手拍活动定时任务
+     * @return  执行结果
+     */
+    @Override
+    public R timeTaskEasyPhotoActivity(){
+        //定时任务扫描未开始活动,如果开始时间大于当前时间则更新活动状态
+        log.info("定时任务检测未开始的随手拍活动,判断是否开始");
+        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()){
+                    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()){
+            Date nowDate = new Date();
+            oldPhotoActivityDOS.forEach(photoActivity -> {
+                if(photoActivity.getActivityEndAt().getTime() <= nowDate.getTime()){
+                    photoActivity.setStatus(ComActEasyPhotoActivityDO.status.yjs);
+                    this.baseMapper.updateById(photoActivity);
+                }
+            });
+        }
+        return R.ok();
+    }
 }

--
Gitblit v1.7.1