From ce4a770744d7a0b4e4ea3b5101556b94e72bdf1c Mon Sep 17 00:00:00 2001
From: lidongdong <1459917685@qq.com>
Date: 星期二, 14 十一月 2023 17:49:20 +0800
Subject: [PATCH] 修改打卡

---
 springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComBpActivityServiceImpl.java |  501 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 440 insertions(+), 61 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComBpActivityServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComBpActivityServiceImpl.java
index f4e020f..185499d 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComBpActivityServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComBpActivityServiceImpl.java
@@ -1,28 +1,42 @@
 package com.panzhihua.service_dangjian.service.impl;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import org.apache.http.client.utils.DateUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.panzhihua.common.exceptions.PartyBuildingMemberException;
+import com.panzhihua.common.model.dtos.partybuilding.ActivitySignUpDTO;
+import com.panzhihua.common.model.dtos.partybuilding.ComPbActivityDTO;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
 import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.community.ComActActivityVO;
 import com.panzhihua.common.model.vos.partybuilding.PageActivityMembersVO;
 import com.panzhihua.common.model.vos.partybuilding.PartyBuildingActivityVO;
 import com.panzhihua.common.model.vos.partybuilding.PartyBuildingMemberVO;
+import com.panzhihua.common.utlis.SensitiveUtil;
 import com.panzhihua.service_dangjian.dao.ComBpActivityDAO;
 import com.panzhihua.service_dangjian.dao.ComPbActivityMemberDAO;
 import com.panzhihua.service_dangjian.dao.ComPbMemberDAO;
-import com.panzhihua.service_dangjian.model.dos.ComBpActivityDO;
+import com.panzhihua.service_dangjian.model.dos.ComPbActivityDO;
 import com.panzhihua.service_dangjian.model.dos.ComPbActivityMemberDO;
 import com.panzhihua.service_dangjian.model.dos.ComPbMemberDO;
 import com.panzhihua.service_dangjian.service.ComBpActivityService;
-import org.springframework.beans.BeanUtils;
-import org.springframework.stereotype.Service;
-import org.springframework.util.ObjectUtils;
 
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
+
+import static java.util.Objects.nonNull;
 
 /**
  * @program: springcloud_k8s_panzhihuazhihuishequ
@@ -30,6 +44,7 @@
  * @author: huang.hongfa weixin hhf9596 qq 959656820
  * @create: 2020-12-01 09:16
  **/
+@Slf4j
 @Service
 public class ComBpActivityServiceImpl implements ComBpActivityService {
     @Resource
@@ -39,22 +54,31 @@
     @Resource
     private ComPbMemberDAO comPbMemberDAO;
 
+    public static void main(String[] args) {
+        DateFormat formatTo = new SimpleDateFormat("M月d ahh:mm");
+        String format = formatTo.format(new Date());
+        System.out.println(format);
+    }
+
     /**
      * 查询某个党员加入的所有党员活动
      *
-     * @param partyBuildingActivityVO 查询参数
+     * @param partyBuildingActivityVO
+     *            查询参数
      * @return 活动集合
      */
     @Override
     public R listPartyMemberActivities(PartyBuildingActivityVO partyBuildingActivityVO) {
-        List<PartyBuildingActivityVO> partyBuildingActivityVOS = comBpActivityDAO.listPartyMemberActivities(partyBuildingActivityVO);
+        List<PartyBuildingActivityVO> partyBuildingActivityVOS =
+            comBpActivityDAO.listPartyMemberActivities(partyBuildingActivityVO);
         return R.ok(partyBuildingActivityVOS);
     }
 
     /**
      * 活动报名名单分页查询
      *
-     * @param pageActivityMembersVO 查询参数 手机号 名字
+     * @param pageActivityMembersVO
+     *            查询参数 手机号 名字
      * @return 分页数据
      */
     @Override
@@ -62,60 +86,131 @@
         Page page = new Page<>();
         Long pageNum = pageActivityMembersVO.getPageNum();
         Long pageSize = pageActivityMembersVO.getPageSize();
-        if (ObjectUtils.isEmpty(pageNum)) {
+        Long activityId = pageActivityMembersVO.getActivityId();
+        if (null == pageNum) {
             pageNum = 1l;
         }
-        if (ObjectUtils.isEmpty(pageSize)) {
+        if (null == pageSize) {
             pageSize = 10l;
         }
         page.setSize(pageSize);
         page.setCurrent(pageNum);
         IPage<PageActivityMembersVO> iPage = comPbActivityMemberDAO.pageActivityMembers(page, pageActivityMembersVO);
-        return R.ok(iPage);
+        iPage.getRecords().forEach(record -> {
+            record.setPhone(SensitiveUtil.desensitizedPhoneNumber(record.getPhone()));
+        });
+        Map<String, Object> map = new HashMap<>(3);
+        ComPbActivityDO comPbActivityDO = comBpActivityDAO.selectById(activityId);
+        map.put("page", iPage);
+        map.put("name", comPbActivityDO.getName());
+        map.put("createAt", DateUtils.formatDate(comPbActivityDO.getCreateAt(), "yyyy-MM-dd HH:mm:ss"));
+        return R.ok(map);
     }
 
     /**
      * 党员活动详情
      *
-     * @param id 活动id
+     * @param id
+     *            活动id
      * @return 活动详情内容
      */
     @Override
-    public R activityinfo(Long id) {
-        ComBpActivityDO comBpActivityDO = comBpActivityDAO.selectById(id);
-        if (ObjectUtils.isEmpty(comBpActivityDO)) {
-            return R.fail();
+    public R activityinfo(Long id, Long userId) {
+        ComPbActivityDO comPbActivityDO = comBpActivityDAO.selectById(id);
+        if (ObjectUtils.isEmpty(comPbActivityDO)) {
+            return R.fail("活动不存在");
         }
-        PartyBuildingActivityVO partyBuildingActivityVO=new PartyBuildingActivityVO();
-        BeanUtils.copyProperties(comBpActivityDO,partyBuildingActivityVO);
-        List<ComPbActivityMemberDO> comPbActivityMemberDOS = comPbActivityMemberDAO.selectList(new QueryWrapper<ComPbActivityMemberDO>().lambda().eq(ComPbActivityMemberDO::getActivityId, id));
+        LoginUserInfoVO loginUserInfoVO = comBpActivityDAO.selectUserInfoByUserId(comPbActivityDO.getCreateBy());
+        Integer type = loginUserInfoVO.getType();
+        int isPerson = 0;
+        if (type.intValue() == 1) {
+            isPerson = 1;
+        }
+        PartyBuildingActivityVO partyBuildingActivityVO = new PartyBuildingActivityVO();
+        BeanUtils.copyProperties(comPbActivityDO, partyBuildingActivityVO);
+
+        List<PartyBuildingMemberVO> partyBuildingMemberVOS = new ArrayList<>();
+        List<ComPbActivityMemberDO> comPbActivityMemberDOS =
+            comPbActivityMemberDAO.selectList(new QueryWrapper<ComPbActivityMemberDO>().lambda()
+                .eq(ComPbActivityMemberDO::getActivityId, id).orderByDesc(ComPbActivityMemberDO::getCreateAt));
         if (!ObjectUtils.isEmpty(comPbActivityMemberDOS)) {
-            List<Long> collect = comPbActivityMemberDOS.stream().map(ComPbActivityMemberDO::getMemberId).collect(Collectors.toList());
-            List<ComPbMemberDO> comPbMemberDOS = comPbMemberDAO.selectList(new QueryWrapper<ComPbMemberDO>().lambda().in(ComPbMemberDO::getId, collect));
-            List<PartyBuildingMemberVO> partyBuildingMemberVOS=new ArrayList<>();
-            comPbMemberDOS.forEach(comPbMemberDO -> {
-                PartyBuildingMemberVO partyBuildingMemberVO=new PartyBuildingMemberVO();
-                BeanUtils.copyProperties(comPbMemberDO,partyBuildingMemberVO);
+            int size = comPbActivityMemberDOS.size();
+            if (size >= 6) {
+                comPbActivityMemberDOS = comPbActivityMemberDOS.subList(0, 6);
+            }
+            comPbActivityMemberDOS.forEach(member -> {
+                PartyBuildingMemberVO partyBuildingMemberVO = new PartyBuildingMemberVO();
+                BeanUtils.copyProperties(member, partyBuildingMemberVO);
+                partyBuildingMemberVO.setCreateAt(member.getCreateAt());
                 partyBuildingMemberVOS.add(partyBuildingMemberVO);
             });
-            partyBuildingActivityVO.setPartyBuildingMemberVOS(partyBuildingMemberVOS);
+            partyBuildingActivityVO.setParticipationActualNum(comPbActivityMemberDOS.size());
+        } else {
+            partyBuildingActivityVO.setParticipationActualNum(0);
         }
+        // List<ComPbActivityMemberDO> comPbActivityMemberDOS = comPbActivityMemberDAO.selectList(new
+        // QueryWrapper<ComPbActivityMemberDO>().lambda().eq(ComPbActivityMemberDO::getActivityId,
+        // id).orderByDesc(ComPbActivityMemberDO::getCreateAt));
+        /* List<PartyBuildingMemberVO> partyBuildingMemberVOS = new ArrayList<>();
+        if (!ObjectUtils.isEmpty(comPbActivityMemberDOS)) {
+            List<Long> collect = comPbActivityMemberDOS.stream().map(ComPbActivityMemberDO::getMemberId).collect(Collectors.toList());
+            int size = collect.size();
+            if (size>=6) {
+                collect=collect.subList(0,6);
+            }
+            List<ComPbMemberDO> comPbMemberDOS = comPbMemberDAO.selectList(new QueryWrapper<ComPbMemberDO>().lambda().in(ComPbMemberDO::getId, collect));
+            comPbMemberDOS.forEach(comPbMemberDO -> {
+                PartyBuildingMemberVO partyBuildingMemberVO = new PartyBuildingMemberVO();
+                BeanUtils.copyProperties(comPbMemberDO, partyBuildingMemberVO);
+                partyBuildingMemberVOS.add(partyBuildingMemberVO);
+            });
+            partyBuildingActivityVO.setParticipationActualNum(size);
+        } else {
+            partyBuildingActivityVO.setParticipationActualNum(0);
+        }*/
+        ComPbActivityMemberDO comPbActivityMemberDO = comPbActivityMemberDAO.selectByUserIdActivityId(id, userId);
+        if (ObjectUtils.isEmpty(comPbActivityMemberDO)) {
+            partyBuildingActivityVO.setIsSign(0);
+        } else {
+            partyBuildingActivityVO.setIsSign(1);
+        }
+        partyBuildingActivityVO.setPartyBuildingMemberVOS(partyBuildingMemberVOS);
+        partyBuildingActivityVO.setIsPerson(isPerson);
+        partyBuildingActivityVO.setCreateByName(loginUserInfoVO.getName());
+
+        // 查询社区名称
+        if (partyBuildingActivityVO.getCommunityId() != null) {
+            partyBuildingActivityVO.setCommunityName(
+                comBpActivityDAO.selectCommunityNameByCommunityId(partyBuildingActivityVO.getCommunityId()));
+        }
+
+        partyBuildingActivityVO.setCodeType(2);
         return R.ok(partyBuildingActivityVO);
     }
 
     /**
      * 新增党员活动
      *
-     * @param partyBuildingActivityVO 参数
+     * @param partyBuildingActivityVO
+     *            参数
      * @return 新增结果
      */
     @Override
     public R addactivity(PartyBuildingActivityVO partyBuildingActivityVO) {
-        ComBpActivityDO comBpActivityDO=new ComBpActivityDO();
-        BeanUtils.copyProperties(partyBuildingActivityVO,comBpActivityDO);
-        comBpActivityDO.setCreateAt(new Date());
-        int insert = comBpActivityDAO.insert(comBpActivityDO);
-        if (insert>0) {
+        ComPbActivityDO comPbActivityDO = new ComPbActivityDO();
+        BeanUtils.copyProperties(partyBuildingActivityVO, comPbActivityDO);
+        Date now = new Date();
+        comPbActivityDO.setEnrollTimeBegin(now);
+        comPbActivityDO.setCreateAt(now);
+
+        Integer status = partyBuildingActivityVO.getStatus();
+        if (status != null && status.intValue() == 2) {// 点击'保存并发布' 按钮
+            // 默认设置为“进行中”
+            comPbActivityDO.setStatus(4);
+        }
+
+        int insert = comBpActivityDAO.insert(comPbActivityDO);
+        if (insert > 0) {
             return R.ok();
         }
         return R.fail();
@@ -124,15 +219,16 @@
     /**
      * 编辑党员活动
      *
-     * @param partyBuildingActivityVO 编辑内容
+     * @param partyBuildingActivityVO
+     *            编辑内容
      * @return 编辑结果
      */
     @Override
     public R updateActivity(PartyBuildingActivityVO partyBuildingActivityVO) {
-        ComBpActivityDO comBpActivityDO=new ComBpActivityDO();
-        BeanUtils.copyProperties(partyBuildingActivityVO,comBpActivityDO);
-        int update = comBpActivityDAO.updateById(comBpActivityDO);
-        if (update>0) {
+        ComPbActivityDO comPbActivityDO = new ComPbActivityDO();
+        BeanUtils.copyProperties(partyBuildingActivityVO, comPbActivityDO);
+        int update = comBpActivityDAO.updateById(comPbActivityDO);
+        if (update > 0) {
             return R.ok();
         }
         return R.fail();
@@ -141,17 +237,18 @@
     /**
      * 发布党员活动
      *
-     * @param id 主键id
+     * @param id
+     *            主键id
      * @return 发布结果
      */
     @Override
     public R releaseActivity(Long id) {
-        ComBpActivityDO comBpActivityDO=new ComBpActivityDO();
-        comBpActivityDO.setId(id);
-        comBpActivityDO.setStatus(2);
-        comBpActivityDO.setReleaseTime(new Date());
-        int update = comBpActivityDAO.updateById(comBpActivityDO);
-        if (update>0) {
+        ComPbActivityDO comPbActivityDO = new ComPbActivityDO();
+        comPbActivityDO.setId(id);
+        comPbActivityDO.setStatus(2);
+        comPbActivityDO.setReleaseTime(new Date());
+        int update = comBpActivityDAO.updateById(comPbActivityDO);
+        if (update > 0) {
             return R.ok();
         }
         return R.fail();
@@ -160,13 +257,14 @@
     /**
      * 删除党员活动
      *
-     * @param id 主键id
+     * @param id
+     *            主键id
      * @return 删除结果
      */
     @Override
     public R deleteActivity(Long id) {
         int delete = comBpActivityDAO.deleteById(id);
-        if (delete>0) {
+        if (delete > 0) {
             return R.ok();
         }
         return R.fail();
@@ -175,7 +273,8 @@
     /**
      * 分页查询党员活动
      *
-     * @param partyBuildingActivityVO 查询条件
+     * @param partyBuildingActivityVO
+     *            查询条件
      * @return 查询结果
      */
     @Override
@@ -183,36 +282,316 @@
         Page page = new Page<>();
         Long pageNum = partyBuildingActivityVO.getPageNum();
         Long pageSize = partyBuildingActivityVO.getPageSize();
-        if (ObjectUtils.isEmpty(pageNum)) {
+        if (null == pageNum) {
             pageNum = 1l;
         }
-        if (ObjectUtils.isEmpty(pageSize)) {
+        if (null == pageSize) {
             pageSize = 10l;
         }
         page.setSize(pageSize);
         page.setCurrent(pageNum);
-        IPage<PageActivityMembersVO> iPage = comBpActivityDAO.pageActivity(page, partyBuildingActivityVO);
+        IPage<PartyBuildingActivityVO> iPage = comBpActivityDAO.pageActivity(page, partyBuildingActivityVO);
+        List<PartyBuildingActivityVO> records = iPage.getRecords();
+        if (!ObjectUtils.isEmpty(records)) {
+            DateFormat formatTo = new SimpleDateFormat("M月d ahh:mm");
+            records.forEach(partyBuildingActivityVO1 -> {
+                Date activityTimeBegin = partyBuildingActivityVO1.getActivityTimeBegin();
+                Integer status = partyBuildingActivityVO1.getStatus();
+                String createByName = partyBuildingActivityVO1.getCreateByName();
+                if (!ObjectUtils.isEmpty(activityTimeBegin)) {
+                    partyBuildingActivityVO1.setActivityTimeBeginFormat(formatTo.format(activityTimeBegin));
+                }
+                if (status.intValue() == 3) {
+                    partyBuildingActivityVO1.setStatus(4);
+                }
+                if (!ObjectUtils.isEmpty(createByName) && createByName.equals("管理员")) {
+                    partyBuildingActivityVO1.setIsPerson(0);
+                } else {
+                    partyBuildingActivityVO1.setIsPerson(1);
+                }
+            });
+        }
         return R.ok(iPage);
     }
 
     /**
      * 取消活动
      *
-     * @param partyBuildingActivityVO 取消原因
+     * @param partyBuildingActivityVO
+     *            取消原因
      * @return 操作结果
      */
     @Override
     public R cancelActivity(PartyBuildingActivityVO partyBuildingActivityVO) {
-        ComBpActivityDO comBpActivityDO=new ComBpActivityDO();
-        comBpActivityDO.setId(partyBuildingActivityVO.getId());
-        comBpActivityDO.setCancelReason(partyBuildingActivityVO.getCancelReason());
-        comBpActivityDO.setCreateBy(partyBuildingActivityVO.getCreateBy());
-        int update = comBpActivityDAO.updateById(comBpActivityDO);
-        if (update>0) {
+        ComPbActivityDO comPbActivityDO = new ComPbActivityDO();
+        comPbActivityDO.setId(partyBuildingActivityVO.getId());
+        comPbActivityDO.setCancelReason(partyBuildingActivityVO.getCancelReason());
+        comPbActivityDO.setStatus(6);
+        int update = comBpActivityDAO.updateById(comPbActivityDO);
+        if (update > 0) {
             return R.ok();
         }
         return R.fail();
     }
 
+    /**
+     * 用户的所有党建活动
+     *
+     * @param userId
+     *            用户id
+     * @param communityId
+     *            社区id
+     * @param status
+     * @return 党建活动列表
+     */
+    @Override
+    public R listActivity(Long userId, Long communityId, Integer status) {
+        List<ComActActivityVO> comActActivityVOS = new ArrayList<>();
+        /*Long memberId=comPbActivityMemberDAO.selectMemberIdByUserId(userId,communityId);
+        if (ObjectUtils.isEmpty(memberId)) {
+            return R.fail();
+        }*/
+        List<ComPbActivityMemberDO> comPbActivityMemberDOS = comPbActivityMemberDAO.selectList(
+            new QueryWrapper<ComPbActivityMemberDO>().lambda().eq(ComPbActivityMemberDO::getUserId, userId));
+        if (ObjectUtils.isEmpty(comPbActivityMemberDOS)) {
+            return R.fail();
+        }
+        List<Long> collect = comPbActivityMemberDOS.stream()
+            .map(comPbActivityMemberDO -> comPbActivityMemberDO.getActivityId()).collect(Collectors.toList());
+        List<ComPbActivityDO> comPbActivityDOS = comBpActivityDAO.selectBatchIds(collect);
+        if (nonNull(status)) {
+            comPbActivityDOS = comPbActivityDOS.stream()
+                    .filter(activityDO -> activityDO.getStatus().equals(status)).collect(Collectors.toList());
+        }
+        if (!comPbActivityDOS.isEmpty()) {
+            comPbActivityDOS.forEach(comPbActivityDO -> {
+                ComActActivityVO comActActivityVO = new ComActActivityVO();
+                Long createBy = comPbActivityDO.getCreateBy();
+                LoginUserInfoVO loginUserInfoVO = comPbActivityMemberDAO.selectUserInfo(createBy);
+                Integer type = loginUserInfoVO.getType();
+                if (type == 1) {
+                    comActActivityVO.setIsPerson(1);
+                } else {
+                    comActActivityVO.setIsPerson(0);
+                }
+                Integer activityStatus = comPbActivityDO.getStatus();
+                if (activityStatus.intValue() == 3) {
+                    activityStatus = 4;
+                }
+                comActActivityVO.setType(3);
+                comActActivityVO.setId(comPbActivityDO.getId());
+                comActActivityVO.setStatus(activityStatus);
+                comActActivityVO.setActivityName(comPbActivityDO.getName());
+                comActActivityVO.setCover(comPbActivityDO.getCover());
+                comActActivityVO.setBeginAt(comPbActivityDO.getActivityTimeBegin());
+                comActActivityVO.setSingDate(comPbActivityMemberDOS.stream()
+                        .filter(comPbActivityMemberDO -> comPbActivityMemberDO.getActivityId().equals(comActActivityVO.getId()))
+                        .collect(Collectors.toList()).get(0).getCreateAt());
+                comActActivityVOS.add(comActActivityVO);
+            });
+        }
+        return R.ok(comActActivityVOS);
+    }
+
+    /**
+     * 党员活动人员参入列表
+     *
+     * @param id
+     *            活动id
+     * @return 党员集合
+     */
+    @Override
+    public R listPartyBuildingMember(Long id) {
+        List<PartyBuildingMemberVO> partyBuildingMemberVOS = new ArrayList<>();
+        List<ComPbActivityMemberDO> comPbActivityMemberDOS =
+            comPbActivityMemberDAO.selectList(new QueryWrapper<ComPbActivityMemberDO>().lambda()
+                .eq(ComPbActivityMemberDO::getActivityId, id).orderByDesc(ComPbActivityMemberDO::getCreateAt));
+        if (!ObjectUtils.isEmpty(comPbActivityMemberDOS)) {
+            comPbActivityMemberDOS.forEach(member -> {
+                PartyBuildingMemberVO partyBuildingMemberVO = new PartyBuildingMemberVO();
+                BeanUtils.copyProperties(member, partyBuildingMemberVO);
+                partyBuildingMemberVO.setCreateAt(member.getCreateAt());
+                partyBuildingMemberVOS.add(partyBuildingMemberVO);
+            });
+        }
+        /*if (!ObjectUtils.isEmpty(comPbActivityMemberDOS)) {
+            List<Long> collect = comPbActivityMemberDOS.stream().map(ComPbActivityMemberDO::getMemberId).collect(Collectors.toList());
+            List<ComPbMemberDO> comPbMemberDOS = comPbMemberDAO.selectList(new QueryWrapper<ComPbMemberDO>().lambda().in(ComPbMemberDO::getId, collect));
+            comPbMemberDOS.forEach(comPbMemberDO -> {
+                PartyBuildingMemberVO partyBuildingMemberVO = new PartyBuildingMemberVO();
+                BeanUtils.copyProperties(comPbMemberDO, partyBuildingMemberVO);
+                ComPbActivityMemberDO comPbActivityMemberDO1 = comPbActivityMemberDOS.stream().filter(comPbActivityMemberDO -> comPbActivityMemberDO.getMemberId().equals(comPbMemberDO.getId())).collect(Collectors.toList()).get(0);
+                partyBuildingMemberVO.setCreateAt(comPbActivityMemberDO1.getCreateAt());
+                partyBuildingMemberVOS.add(partyBuildingMemberVO);
+            });
+        }*/
+        return R.ok(partyBuildingMemberVOS);
+    }
+
+    /**
+     * 报名、取消报名党员活动
+     *
+     * @param activitySignUpDTO
+     *            操作参数
+     * @return 操作结果
+     */
+    @Override
+    public R putActivitySignUp(ActivitySignUpDTO activitySignUpDTO) {
+        Long id = activitySignUpDTO.getId();
+        Long userId = activitySignUpDTO.getUserId();
+        ComPbActivityDO comPbActivityDO = comBpActivityDAO.selectById(id);
+        if (ObjectUtils.isEmpty(comPbActivityDO)) {
+            return R.fail("活动不存在");
+        }
+        ComPbMemberDO comPbMemberDO = comPbMemberDAO.selectByUserId(userId);
+        if (ObjectUtils.isEmpty(comPbMemberDO)) {
+            return R.fail("您不是党员");
+        }
+        Integer type = activitySignUpDTO.getType();
+        ComPbActivityMemberDO comPbActivityMemberDO =
+            comPbActivityMemberDAO.selectOne(new QueryWrapper<ComPbActivityMemberDO>().lambda()
+                .eq(ComPbActivityMemberDO::getMemberId, comPbMemberDO.getId())
+                .eq(ComPbActivityMemberDO::getActivityId, id));
+        boolean empty = ObjectUtils.isEmpty(comPbActivityMemberDO);
+        int mum = 0;
+        if (type.intValue() == 1) {
+            if (empty) {
+                ComPbActivityMemberDO comPbActivityMemberDO1 = new ComPbActivityMemberDO();
+                comPbActivityMemberDO1.setActivityId(id);
+                comPbActivityMemberDO1.setMemberId(comPbMemberDO.getId());
+                comPbActivityMemberDO1.setUserId(userId);
+                // 添加参加活动的党员快照信息,防止党员信息删除后无法显示
+                comPbActivityMemberDO1.setName(comPbMemberDO.getName());
+                comPbActivityMemberDO1.setPhotoPath(comPbMemberDO.getPhotoPath());
+                comPbActivityMemberDO1.setCreateAt(new Date());
+                mum = comPbActivityMemberDAO.insert(comPbActivityMemberDO1);
+            } else {
+                return R.ok(null, "已经加入了");
+            }
+        } else {
+            if (empty) {
+                return R.ok(null, "已经取消");
+            } else {
+                Long createBy = comPbActivityDO.getCreateBy();
+                if (createBy.equals(userId)) {
+                    return R.fail("发起者不能取消报名");
+                }
+                mum = comPbActivityMemberDAO.deleteById(comPbActivityMemberDO.getId());
+            }
+        }
+        if (mum > 0) {
+            return R.ok();
+        }
+        return R.fail();
+    }
+
+    /**
+     * 获取党建活动所有参入人员的id集合
+     *
+     * @param id
+     *            党建活动id
+     * @return 人员id集合
+     */
+    @Override
+    public R selectAllPartyBuildingActivityMembers(Long id) {
+        List<Long> longs = comPbActivityMemberDAO.selectAllPartyBuildingActivityMembers(id);
+        return R.ok(longs);
+    }
+
+    /**
+     * 定时任务取消党建活动
+     *
+     * @return 取消党建活动数量
+     */
+    @Override
+    public R timedTaskPartyBuildingActivity() {
+        List<Long> ids = comBpActivityDAO.selectTimedTaskPartyBuildingActivity();
+        List<PartyBuildingActivityVO> partyBuildingActivityVOS = new ArrayList<>();
+        if (!ObjectUtils.isEmpty(ids)) {
+            List<ComPbActivityDO> comPbActivityDOS = comBpActivityDAO.selectBatchIds(ids);
+            comPbActivityDOS.forEach(comPbActivityDO -> {
+                PartyBuildingActivityVO partyBuildingActivityVO = new PartyBuildingActivityVO();
+                BeanUtils.copyProperties(comPbActivityDO, partyBuildingActivityVO);
+                List<Long> userIdS =
+                    comBpActivityDAO.selectTimedTaskPartyBuildingActivityUserids(comPbActivityDO.getId());
+                partyBuildingActivityVO.setUserIds(userIdS);
+                partyBuildingActivityVOS.add(partyBuildingActivityVO);
+            });
+            int i = comBpActivityDAO.updateBatchIds(ids);
+            log.info("定时任务取消党建活动数量【{}】", i);
+        }
+        return R.ok(partyBuildingActivityVOS);
+    }
+
+    /**
+     * 定时任务刷新党建活动的各个状态 除取消外
+     *
+     * @return 修改结果
+     */
+    @Override
+    public R timedTaskPartyBuildingActivityAll() {
+        // 修改发布状态为未开始
+        int num = comBpActivityDAO.updateStatusToNotBegin();
+        log.info("定时任务修改党建活动--修改发布状态为未开始数量【{}】", num);
+        // 修改报名状态为报名中
+        int num1 = comBpActivityDAO.updateStatusToSign();
+        log.info("定时任务修改党建活动--修改报名状态为报名中始数量【{}】", num1);
+        // 查询已结束的活动id,便于计算用户积分
+        List<Long> pbActivityEndIds = comBpActivityDAO.getTaskPbActivityEndIds();
+        // 修改进行状态为进行中 或者已结束
+        int num2 = comBpActivityDAO.updateStatusToActiveOrEnd();
+        log.info("定时任务修改党建活动--修改进行状态为进行中 或者已结束数量【{}】", num2);
+        return R.ok(pbActivityEndIds);
+    }
+
+    /**
+     * 创建党员活动 小程序创建党员活动
+     *
+     * @param comPbActivityDTO
+     *            创建内容
+     * @return 创建结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R addActivityApplets(ComPbActivityDTO comPbActivityDTO) {
+        ComPbActivityDO comPbActivityDO = new ComPbActivityDO();
+        Long createBy = comPbActivityDTO.getCreateBy();
+        BeanUtils.copyProperties(comPbActivityDTO, comPbActivityDO);
+        int insert = comBpActivityDAO.insert(comPbActivityDO);
+        if (insert > 0) {
+            ComPbActivityDO comPbActivityDO1 = comBpActivityDAO.selectOne(new QueryWrapper<ComPbActivityDO>().lambda()
+                .eq(ComPbActivityDO::getName, comPbActivityDTO.getName())
+                .eq(ComPbActivityDO::getCover, comPbActivityDTO.getCover()).last(" order by create_at desc limit 1 "));
+            Long comPbActivityDO1Id = comPbActivityDO1.getId();
+            ComPbMemberDO comPbMemberDO = comPbMemberDAO.selectByUserId(createBy);
+            if (ObjectUtils.isEmpty(comPbMemberDO)) {
+                log.error("【{}】不是党员", createBy);
+                throw new PartyBuildingMemberException("用户不是党员");
+            }
+            Long comPbMemberDOId = comPbMemberDO.getId();
+            ComPbActivityMemberDO comPbActivityMemberDO = new ComPbActivityMemberDO();
+            comPbActivityMemberDO.setMemberId(comPbMemberDOId);
+            comPbActivityMemberDO.setActivityId(comPbActivityDO1Id);
+            comPbActivityMemberDO.setCreateAt(new Date());
+            comPbActivityMemberDO.setUserId(comPbActivityDTO.getCreateBy());
+            comPbActivityMemberDO.setName(comPbMemberDO.getName());
+            comPbActivityMemberDO.setPhotoPath(comPbMemberDO.getPhotoPath());
+            comPbActivityMemberDAO.insert(comPbActivityMemberDO);
+            return R.ok();
+        }
+        return R.fail();
+    }
+
+    /**
+     * 根据党员活动id查询活动下报名人员
+     *
+     * @param activityId
+     *            党员活动id
+     * @return 活动下报名人员
+     */
+    @Override
+    public R getTaskPbActivityPeopleList(Long activityId) {
+        return R.ok(this.comBpActivityDAO.getTaskPbActivityPeopleList(activityId));
+    }
 
 }

--
Gitblit v1.7.1