From f8e2210f248a008108b30b889378b56adc8a9c23 Mon Sep 17 00:00:00 2001 From: wxz Date: Mon, 13 Sep 2021 14:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=201.=E3=80=90?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E3=80=91=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BB=84=E6=88=90=E5=91=98=202.=E3=80=90=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E3=80=91=E7=A7=BB=E9=99=A4=E7=BB=84=E6=88=90?= =?UTF-8?q?=E5=91=98=203.=E3=80=90=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E6=94=B9=E7=BB=84=E4=BF=A1=E6=81=AF=204.?= =?UTF-8?q?=E3=80=90=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E3=80=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/exception/EpmetErrorCode.java | 2 + .../dto/form/ReceiverGroupCommonFormDTO.java | 43 ++++++++ .../result/ReceiverGroupCommonResultDTO.java | 16 +++ .../com/epmet/controller/InfoController.java | 79 +++++++++++++- .../java/com/epmet/service/InfoService.java | 53 ++++++++++ .../epmet/service/impl/InfoServiceImpl.java | 100 ++++++++++++++++-- .../src/main/resources/logback-spring.xml | 2 +- 7 files changed, 284 insertions(+), 11 deletions(-) create mode 100644 epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/ReceiverGroupCommonFormDTO.java create mode 100644 epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/result/ReceiverGroupCommonResultDTO.java diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index aa74cd8e2a..865c9eddc4 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -108,6 +108,8 @@ public enum EpmetErrorCode { PLEASE_CHOOSE_MEMBER(8611,"请选择成员"), INFO_GROUP_NAME_EXISTS(8612,"名称已存在"), INFO_REPLY_CONTENT_LENGTH_LIMIT(8613,"回复内容最多输入500字"), + INFO_GROUP_NOT_EXISTS(8614,"群不存在"), + INFO_GROUP_OPE_PERMISSION_REQUIRED(8615,"无权操作"), // 爱心互助 居民端 NOT_IN_THE_SIGN_IN_RANGE(8510, "您还未进入指定的签到范围~"), diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/ReceiverGroupCommonFormDTO.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/ReceiverGroupCommonFormDTO.java new file mode 100644 index 0000000000..afcf24e16e --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/ReceiverGroupCommonFormDTO.java @@ -0,0 +1,43 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import java.util.List; +import java.util.Set; + +/** + * @Description 通用的ReceiverGroup 入参dto + * @author wxz + * @date 2021.09.11 22:03:02 +*/ +@Data +public class ReceiverGroupCommonFormDTO { + + public interface UpdateGroup {} + public interface RemoveMember {} + public interface AddMember {} + public interface DeleteGroup {} + + /** 群id */ + @NotBlank(message = "群ID不能为空", groups = { UpdateGroup.class, AddMember.class, RemoveMember.class, DeleteGroup.class }) + private String receiverGroupId; + + /** 群名字 */ + @NotBlank(message = "群名字不能为空", groups = { UpdateGroup.class }) + private String name; + + /** 成员id */ + @NotBlank(message = "组成员ID不能为空", groups = { RemoveMember.class }) + private String staffId; + + /** 成员ID列表 */ + private List staffIdList; + + /** + * 按架构选择的,组织或者网格或者部门的集合 + */ + private Set orgList; + +} diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/result/ReceiverGroupCommonResultDTO.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/result/ReceiverGroupCommonResultDTO.java new file mode 100644 index 0000000000..5d072c938d --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/result/ReceiverGroupCommonResultDTO.java @@ -0,0 +1,16 @@ +package com.epmet.dto.result; + +import lombok.Data; + +/** + * @Description 群通用Result dto + * @author wxz + * @date 2021.09.11 22:08:36 +*/ +@Data +public class ReceiverGroupCommonResultDTO { + + private String receiverGroupId; + private String name; + +} diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/InfoController.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/InfoController.java index 25b0414b59..81bd630e91 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/InfoController.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/InfoController.java @@ -33,6 +33,10 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.NotBlank; +import java.util.List; +import java.util.Set; + /** * 消息主表 @@ -139,10 +143,83 @@ public class InfoController { return new Result().ok(infoService.addReceiverGroup(formDTO)); } + /** + * @description 【发送消息】更新群信息 + * + * @param form + * @param tokenDto + * @return + * @author wxz + * @date 2021.09.11 22:05:08 + */ + @PostMapping("/receivergroup/update") + public Result updateInfoReceiverGroup(@RequestBody ReceiverGroupCommonFormDTO form, @LoginUser TokenDto tokenDto) { + ValidatorUtils.validateEntity(form, ReceiverGroupCommonFormDTO.UpdateGroup.class); + String userId = tokenDto.getUserId(); + String receiverGroupId = form.getReceiverGroupId(); + String name = form.getName(); + + infoService.updateReceiverGroup(userId, receiverGroupId, name); + return new Result(); + } + /** + * @description 【发送消息】移除群成员 + * + * @param form + * @param tokenDto + * @return + * @author wxz + * @date 2021.09.11 22:26:44 + */ + @PostMapping("/receivergroup/member/remove") + public Result removeInfoGroupMember(@RequestBody ReceiverGroupCommonFormDTO form, @LoginUser TokenDto tokenDto) { + ValidatorUtils.validateEntity(form, ReceiverGroupCommonFormDTO.RemoveMember.class); + String userId = tokenDto.getUserId(); + String receiverGroupId = form.getReceiverGroupId(); + String staffId = form.getStaffId(); + infoService.removeGroupMember(receiverGroupId, staffId, userId); + return new Result(); + } + /** + * @description 【发送消息】添加新成员 + * + * @param form + * @param tokenDto + * @return + * @author wxz + * @date 2021.09.13 13:54:02 + */ + @PostMapping("/receivergroup/member/add") + public Result addInfoGroupMember(@RequestBody ReceiverGroupCommonFormDTO form, @LoginUser TokenDto tokenDto) { + ValidatorUtils.validateEntity(form, ReceiverGroupCommonFormDTO.AddMember.class); + String userId = tokenDto.getUserId(); + String receiverGroupId = form.getReceiverGroupId(); + Set orgList = form.getOrgList(); + List staffIdList = form.getStaffIdList(); + + infoService.addInfoGroupMember(receiverGroupId, userId, orgList, staffIdList); + return new Result(); + } - + /** + * @description 【发送消息】删除群组 + * + * @param form + * @param tokenDto + * @return + * @author wxz + * @date 2021.09.11 22:35:21 + */ + @PostMapping("/receivergroup/remove") + public Result deleteInfoGroup(@RequestBody ReceiverGroupCommonFormDTO form, @LoginUser TokenDto tokenDto) { + ValidatorUtils.validateEntity(form, ReceiverGroupCommonFormDTO.DeleteGroup.class); + String operatorId = tokenDto.getUserId(); + String receiverGroupId = form.getReceiverGroupId(); + infoService.deleteInfoGroup(receiverGroupId, operatorId); + return new Result(); + } diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/InfoService.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/InfoService.java index 601cbb4ab0..277bb43a64 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/InfoService.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/InfoService.java @@ -20,10 +20,14 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.dto.form.*; import com.epmet.dto.result.AddReceiverGroupResultDTO; +import com.epmet.dto.result.ReceiverGroupCommonResultDTO; import com.epmet.dto.result.ReplyInfoResultDTO; import com.epmet.dto.result.SendInfoResultDTO; import com.epmet.entity.InfoEntity; +import java.util.List; +import java.util.Set; + /** * 消息主表 * @@ -81,4 +85,53 @@ public interface InfoService extends BaseService { * @date 2021/8/20 9:58 上午 */ AddReceiverGroupResultDTO addReceiverGroup(AddReceiverGroupFormDTO formDTO); + + /** + * @description 更新群信息 + * + * @param operatorId + * @param receiverGroupId + * @param name + * @return + * @author wxz + * @date 2021.09.11 22:07:25 + */ + void updateReceiverGroup(String operatorId, String receiverGroupId, String name); + + /** + * @description 移除群成员 + * + * @param receiverGroupId + * + * @param staffId + * @param operatorId + * @return + * @author wxz + * @date 2021.09.11 22:27:16 + */ + void removeGroupMember(String receiverGroupId, String staffId, String operatorId); + + /** + * @description 删除群 + * + * @param receiverGroupId + * @param operatorId + * @return + * @author wxz + * @date 2021.09.11 22:36:27 + */ + void deleteInfoGroup(String receiverGroupId, String operatorId); + + /** + * @description 【发送消息】添加新成员 + * + * @param receiverGroupId + * @param operatorId + * @param orgList + * @param staffIdList + * @return + * @author wxz + * @date 2021.09.13 13:54:45 + */ + void addInfoGroupMember(String receiverGroupId, String operatorId, Set orgList, List staffIdList); } \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/InfoServiceImpl.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/InfoServiceImpl.java index 292cf37b2d..1b15da4495 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/InfoServiceImpl.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/InfoServiceImpl.java @@ -17,6 +17,8 @@ package com.epmet.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.NumConstant; @@ -31,6 +33,7 @@ import com.epmet.constant.UserMessageTypeConstant; import com.epmet.dao.*; import com.epmet.dto.form.*; import com.epmet.dto.result.AddReceiverGroupResultDTO; +import com.epmet.dto.result.ReceiverGroupCommonResultDTO; import com.epmet.dto.result.ReplyInfoResultDTO; import com.epmet.dto.result.SendInfoResultDTO; import com.epmet.entity.*; @@ -44,9 +47,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; /** * 消息主表 @@ -428,20 +430,100 @@ public class InfoServiceImpl extends BaseServiceImpl implem } + @Override + public void updateReceiverGroup(String operatorId, String receiverGroupId, String name) { + InfoReceiverGroupEntity groupEntity = baseValidate(receiverGroupId, operatorId); + // 检查重名 + if (infoReceiverGroupDao.selectCountName(name.trim(),groupEntity.getCustomerId(),operatorId) > 1) { + throw new RenException(EpmetErrorCode.INFO_GROUP_NAME_EXISTS.getCode(), EpmetErrorCode.INFO_GROUP_NAME_EXISTS.getMsg()); + } + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(InfoReceiverGroupEntity::getId, receiverGroupId); + updateWrapper.set(InfoReceiverGroupEntity::getName, name); + infoReceiverGroupDao.update(null, updateWrapper); + } + @Override + public void removeGroupMember(String receiverGroupId, String staffId, String operatorId) { + baseValidate(receiverGroupId, operatorId); + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(InfoGroupReceiversEntity::getStaffId, staffId); + query.eq(InfoGroupReceiversEntity::getInfoReceiverGroupId, receiverGroupId); + infoGroupReceiversDao.delete(query); + } + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteInfoGroup(String receiverGroupId, String operatorId) { + baseValidate(receiverGroupId, operatorId); + // 1.先删除群 + infoReceiverGroupDao.deleteById(receiverGroupId); + // 2.再删除成员 + LambdaQueryWrapper query = new LambdaQueryWrapper(); + query.eq(InfoGroupReceiversEntity::getInfoReceiverGroupId, receiverGroupId); + infoGroupReceiversDao.delete(query); + } + @Override + @Transactional + public void addInfoGroupMember(String receiverGroupId, String operatorId, Set orgList, List staffIdList) { + InfoReceiverGroupEntity groupInfo = baseValidate(receiverGroupId, operatorId); + // 1、人员列表和组织列表不能同时为空 + if (CollectionUtils.isEmpty(staffIdList) && CollectionUtils.isEmpty(orgList)) { + throw new RenException(EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getCode(), EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getMsg()); + } + // 2、如果没有单选人,选择的组织内也没有人,那么给出提示 + Set orgStaffIds = queryOrgStaffIds(groupInfo.getCustomerId(), orgList); + if (CollectionUtils.isEmpty(staffIdList) && CollectionUtils.isEmpty(orgStaffIds)) { + throw new RenException(EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getCode(), EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getMsg()); + } + // 3、用户合并,去重,如果当前用户也在所选成员中,去掉当前用户,不给自己发消息 + Set members = new LinkedHashSet<>(CollectionUtils.size(staffIdList) + orgStaffIds.size()); + members.addAll(staffIdList); + members.addAll(orgStaffIds); + if (CollectionUtils.isNotEmpty(members) && members.contains(operatorId)) { + members.remove(operatorId); + } + if (CollectionUtils.isEmpty(members)) { + throw new RenException(EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getCode(), EpmetErrorCode.PLEASE_CHOOSE_MEMBER.getMsg()); + } + // 4、现有成员去重 + Set existingStaffIds = infoGroupReceiversDao.selectStaffIds(new HashSet<>(Arrays.asList(receiverGroupId))); + members = members.stream().filter(mId -> !existingStaffIds.contains(mId)).collect(Collectors.toSet()); + // 5、插入新成员 + members.forEach(memStaffId->{ + InfoGroupReceiversEntity memberEntity=new InfoGroupReceiversEntity(); + memberEntity.setCustomerId(groupInfo.getCustomerId()); + memberEntity.setInfoReceiverGroupId(receiverGroupId); + memberEntity.setStaffId(memStaffId); + infoGroupReceiversDao.insert(memberEntity); + }); + } - - - - - - + /** + * @description 基础检查,并且返回组信息 + * + * @param receiverGroupId + * @param operatorId + * @return + * @author wxz + * @date 2021.09.13 13:48:26 + */ + private InfoReceiverGroupEntity baseValidate(String receiverGroupId, String operatorId) { + InfoReceiverGroupEntity groupEntity = infoReceiverGroupDao.selectById(receiverGroupId); + if (groupEntity == null) { + throw new RenException(EpmetErrorCode.INFO_GROUP_NOT_EXISTS.getCode(), "群不存在"); + } + if (!groupEntity.getCreateStaffId().equals(operatorId)) { + // 不是拥有者 ,不允许删除 + throw new RenException(EpmetErrorCode.INFO_GROUP_OPE_PERMISSION_REQUIRED.getCode(), "只有群所有者可以进行此操作"); + } + return groupEntity; + } } \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/resources/logback-spring.xml b/epmet-module/epmet-message/epmet-message-server/src/main/resources/logback-spring.xml index ee1f62a8ef..00797f713e 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/resources/logback-spring.xml +++ b/epmet-module/epmet-message/epmet-message-server/src/main/resources/logback-spring.xml @@ -139,7 +139,7 @@ - +