|
@ -17,6 +17,8 @@ |
|
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
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.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
@ -31,6 +33,7 @@ import com.epmet.constant.UserMessageTypeConstant; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.AddReceiverGroupResultDTO; |
|
|
import com.epmet.dto.result.AddReceiverGroupResultDTO; |
|
|
|
|
|
import com.epmet.dto.result.ReceiverGroupCommonResultDTO; |
|
|
import com.epmet.dto.result.ReplyInfoResultDTO; |
|
|
import com.epmet.dto.result.ReplyInfoResultDTO; |
|
|
import com.epmet.dto.result.SendInfoResultDTO; |
|
|
import com.epmet.dto.result.SendInfoResultDTO; |
|
|
import com.epmet.entity.*; |
|
|
import com.epmet.entity.*; |
|
@ -44,9 +47,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
import java.util.*; |
|
|
import java.util.LinkedHashSet; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 消息主表 |
|
|
* 消息主表 |
|
@ -428,20 +430,100 @@ public class InfoServiceImpl extends BaseServiceImpl<InfoDao, InfoEntity> 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<InfoReceiverGroupEntity> 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<InfoGroupReceiversEntity> 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<InfoGroupReceiversEntity> query = new LambdaQueryWrapper(); |
|
|
|
|
|
query.eq(InfoGroupReceiversEntity::getInfoReceiverGroupId, receiverGroupId); |
|
|
|
|
|
infoGroupReceiversDao.delete(query); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional |
|
|
|
|
|
public void addInfoGroupMember(String receiverGroupId, String operatorId, Set<OrgCommonDTO> orgList, List<String> 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<String> 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<String> 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<String> 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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |