From ba9b14de42b6034071342177c1ce761c9ca35de5 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Thu, 6 May 2021 13:17:29 +0800 Subject: [PATCH] exit group --- .../group/controller/ExitGroupController.java | 16 +++ .../group/service/ExitGroupService.java | 7 ++ .../service/impl/ExitGroupServiceImpl.java | 100 +++++++++++++++++- .../member/entity/ExitGroupRecordEntity.java | 2 +- 4 files changed, 120 insertions(+), 5 deletions(-) diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java index a987253c0d..ca8e7013fd 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java @@ -7,6 +7,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.modules.group.service.ExitGroupService; import com.epmet.resi.group.dto.group.form.ExitGroupFormDTO; +import com.epmet.resi.group.dto.group.form.MemExitGroupFormDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -45,4 +46,19 @@ public class ExitGroupController { return new Result(); } + /** + * @return com.epmet.commons.tools.utils.Result + * @param tokenDto + * @param formDTO + * @author yinzuomei + * @description 组员自主退群 + * @Date 2021/4/30 15:09 + **/ + @PostMapping("memexitgroup") + public Result memExitGroup(@LoginUser TokenDto tokenDto, @RequestBody MemExitGroupFormDTO formDTO){ + formDTO.setUserId(tokenDto.getUserId()); + formDTO.setCustomerId(tokenDto.getCustomerId()); + exitGroupService.memExitGroup(formDTO); + return new Result(); + } } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ExitGroupService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ExitGroupService.java index af8b7f30c7..4182194bcc 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ExitGroupService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ExitGroupService.java @@ -1,6 +1,7 @@ package com.epmet.modules.group.service; import com.epmet.resi.group.dto.group.form.ExitGroupFormDTO; +import com.epmet.resi.group.dto.group.form.MemExitGroupFormDTO; /** * @author sun @@ -15,4 +16,10 @@ public interface ExitGroupService { */ void removeMember(ExitGroupFormDTO formDTO); + /** + * 组员退出小组 + * + * @param formDTO + */ + void memExitGroup(MemExitGroupFormDTO formDTO); } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java index 0f627b2a11..7e3b2a7533 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java @@ -1,9 +1,6 @@ package com.epmet.modules.group.service.impl; -import com.epmet.commons.tools.constant.AppClientConstant; -import com.epmet.commons.tools.constant.Constant; -import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; -import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.*; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.UserRoleFormDTO; @@ -23,13 +20,18 @@ import com.epmet.modules.member.dao.ExitGroupRecordDao; import com.epmet.modules.member.dao.GroupMemeberOperationDao; import com.epmet.modules.member.dao.ResiGroupMemberDao; import com.epmet.modules.member.entity.ExitGroupRecordEntity; +import com.epmet.modules.member.service.GroupMemeberOperationService; +import com.epmet.modules.member.service.ResiGroupMemberService; import com.epmet.modules.topic.dao.ResiTopicCommentDao; import com.epmet.modules.topic.dao.ResiTopicDao; import com.epmet.modules.topic.entity.ResiTopicOperationEntity; import com.epmet.modules.topic.service.ResiTopicOperationService; +import com.epmet.modules.utils.ModuleConstant; import com.epmet.resi.group.constant.TopicConstant; import com.epmet.resi.group.dto.group.form.ExitGroupFormDTO; +import com.epmet.resi.group.dto.group.form.MemExitGroupFormDTO; import com.epmet.resi.group.dto.member.GroupMemeberOperationDTO; +import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -37,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -72,6 +75,10 @@ public class ExitGroupServiceImpl implements ExitGroupService { private ResiGroupDao resiGroupDao; @Autowired private GroupMessageDao groupMessageDao; + @Autowired + private ResiGroupMemberService resiGroupMemberService; + @Autowired + private GroupMemeberOperationService groupMemeberOperationService; /** * @param formDTO @@ -205,4 +212,89 @@ public class ExitGroupServiceImpl implements ExitGroupService { } + /** + * 组员退出小组 + * + * @param formDTO + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void memExitGroup(MemExitGroupFormDTO formDTO) { + //1、当前组员是否还在群里? + ResiGroupMemberDTO resiGroupMemberDTO=resiGroupMemberDao.selectGroupMemberInfo(formDTO.getGroupId(),formDTO.getUserId()); + if(null == resiGroupMemberDTO){ + throw new RenException("已退出当前小组,请勿重复操作"); + } + //2、组长不允许退群,提示:请先转移组长身份后再退组 + if(ModuleConstant.GROUP_LEADER.equals(resiGroupMemberDTO.getGroupLeaderFlag())){ + //改成错误码 + throw new RenException("请先转移组长身份后再退组"); + } + //3.修改组成员出入群记录表数据状态、删除组成员关系表数据、新增退群记录表数据 + //3.1.修改组成员出入群记录表数据状态 group_memeber_operation + // TODO ??? + GroupMemeberOperationDTO lastRec=groupMemeberOperationService.selectLatestRecord(formDTO.getGroupId(),formDTO.getUserId()); + GroupMemeberOperationDTO operationDTO = new GroupMemeberOperationDTO(); + operationDTO.setCustomerId(formDTO.getCustomerId()); + operationDTO.setCustomerUserId(formDTO.getUserId()); + operationDTO.setGroupId(formDTO.getGroupId()); + operationDTO.setOperateUserId(formDTO.getUserId()); + operationDTO.setOperateStatus("exit"); + operationDTO.setEnterGroupType(null != lastRec ? lastRec.getEnterGroupType() : StrConstant.EPMETY_STR); + groupMemeberOperationService.save(operationDTO); + + //3.2.删除组成员关系表数据并修改状态 resi_group_member + resiGroupMemberDTO.setStatus("exit"); + resiGroupMemberDTO.setUpdatedBy(formDTO.getUserId()); + resiGroupMemberDTO.setDelFlag(NumConstant.ONE_STR); + resiGroupMemberDTO.setUpdatedTime(new Date()); + resiGroupMemberService.update(resiGroupMemberDTO); + + //3.3.新增退群记录表数据 exit_group_record + ExitGroupRecordEntity entity = new ExitGroupRecordEntity(); + entity.setCustomerId(formDTO.getCustomerId()); + entity.setGroupId(formDTO.getGroupId()); + entity.setMemberUserId(formDTO.getUserId()); + //默认不 屏蔽他的话题及评论 + entity.setShieldFlag(Constant.NO); + //0:组长移除; 1:自主退群 + entity.setLeaveType(NumConstant.ONE_STR); + exitGroupRecordDao.insert(entity); + + //4.群组统计表修改数据 + //4.1.获取被删人员当前网格居民端角色信息 + ResiGroupEntity groupEntity = resiGroupDao.selectById(formDTO.getGroupId()); + UserRoleFormDTO dto = new UserRoleFormDTO(); + dto.setApp(AppClientConstant.APP_RESI); + dto.setUserId(formDTO.getUserId()); + dto.setCustomerId(formDTO.getCustomerId()); + dto.setGridId(groupEntity.getGridId()); + Result> resultUser = epmetUserOpenFeignClient.getUserRoleInfo(dto); + if (!resultUser.success()) { + throw new RenException(resultUser.getInternalMsg()); + } + List roleList = resultUser.getData(); + //4.2.群组统计表数据修改,缓存数据修改 + ResiGroupStatisticalEntity statisticalEntity = resiGroupStatisticalDao.selectByResiGroupId(formDTO.getGroupId()); + if (null == statisticalEntity) { + throw new RenException("未查询到群组统计数据,删除失败"); + } + statisticalEntity.setTotalMembers(statisticalEntity.getTotalMembers() - 1); + statisticalEntity.setTotalNormalMemebers(statisticalEntity.getTotalNormalMemebers() - 1); + roleList.forEach(r -> { + if (EpmetRoleKeyConstant.PARTYMEMBER.equals(r.getRoleKey())) {//党员总数减一 + statisticalEntity.setTotalPartyMembers(statisticalEntity.getTotalPartyMembers() - 1); + } + if (EpmetRoleKeyConstant.WARMHEARTED.equals(r.getRoleKey())) {//热心居民总数减一 + statisticalEntity.setTotalEarnestMemebers(statisticalEntity.getTotalEarnestMemebers() - 1); + } + }); + resiGroupStatisticalDao.updateById(statisticalEntity); + + resiGroupRedis.delGroup(formDTO.getGroupId()); + + resiGroupRedis.get(formDTO.getGroupId()); + } + + } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ExitGroupRecordEntity.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ExitGroupRecordEntity.java index 2af81275a9..916d030ff8 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ExitGroupRecordEntity.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ExitGroupRecordEntity.java @@ -56,7 +56,7 @@ public class ExitGroupRecordEntity extends BaseEpmetEntity { private String shieldFlag; /** - * 0:组长移除; + * 0:组长移除; 1:自主退群 */ private String leaveType;