From 5c04b5dff52ae6de65d705c5e90fa8effdeb9b38 Mon Sep 17 00:00:00 2001
From: 张天森 <1292933220@qq.com>
Date: 星期四, 29 九月 2022 17:07:10 +0800
Subject: [PATCH] 三说会堂用户逻辑修改
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActEasyPhotoActivityServiceImpl.java | 208 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 195 insertions(+), 13 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..623fe85 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,19 +1,26 @@
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.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;
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
@@ -22,24 +29,199 @@
*/
@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)
- .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 随手拍活动列表
+ */
+ @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