|
|
@ -17,29 +17,64 @@ |
|
|
|
|
|
|
|
package com.epmet.modules.member.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; |
|
|
|
import com.epmet.commons.tools.constant.MqConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.MqBaseMsgDTO; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg; |
|
|
|
import com.epmet.commons.tools.enums.EventEnum; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.SendMqMsgUtils; |
|
|
|
import com.epmet.dto.IssueShareLinkRecordDTO; |
|
|
|
import com.epmet.dto.IssueShareLinkVisitRecordDTO; |
|
|
|
import com.epmet.dto.form.GetRoleKeyListFormDTO; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.GovIssueOpenFeignClient; |
|
|
|
import com.epmet.modules.group.dao.ResiGroupDao; |
|
|
|
import com.epmet.modules.group.entity.ResiGroupEntity; |
|
|
|
import com.epmet.modules.group.redis.ResiGroupRedis; |
|
|
|
import com.epmet.modules.group.service.ResiGroupService; |
|
|
|
import com.epmet.modules.member.dao.GroupMemeberOperationDao; |
|
|
|
import com.epmet.modules.member.dao.ResiGroupMemberDao; |
|
|
|
import com.epmet.modules.member.entity.GroupMemeberOperationEntity; |
|
|
|
import com.epmet.modules.member.entity.ResiGroupMemberEntity; |
|
|
|
import com.epmet.modules.member.redis.GroupMemeberOperationRedis; |
|
|
|
import com.epmet.modules.member.service.GroupMemeberOperationService; |
|
|
|
import com.epmet.modules.member.service.ResiGroupMemberService; |
|
|
|
import com.epmet.modules.topic.dao.ResiTopicDao; |
|
|
|
import com.epmet.modules.topic.dao.TopicShareLinkRecordDao; |
|
|
|
import com.epmet.modules.topic.dao.TopicShareLinkVisitRecordDao; |
|
|
|
import com.epmet.modules.topic.entity.TopicShareLinkRecordEntity; |
|
|
|
import com.epmet.modules.topic.entity.TopicShareLinkVisitRecordEntity; |
|
|
|
import com.epmet.modules.utils.ModuleConstant; |
|
|
|
import com.epmet.resi.group.constant.GroupStateConstant; |
|
|
|
import com.epmet.resi.group.constant.LeaderFlagConstant; |
|
|
|
import com.epmet.resi.group.constant.MemberStateConstant; |
|
|
|
import com.epmet.resi.group.dto.UserRoleDTO; |
|
|
|
import com.epmet.resi.group.dto.group.ResiGroupDTO; |
|
|
|
import com.epmet.resi.group.dto.group.ResiGroupInfoRedisDTO; |
|
|
|
import com.epmet.resi.group.dto.member.GroupMemeberOperationDTO; |
|
|
|
import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; |
|
|
|
import com.epmet.resi.group.dto.member.form.JoinGroupByShareLinkFormDTO; |
|
|
|
import com.epmet.resi.group.dto.member.form.RemoveMemberFormDTO; |
|
|
|
import com.epmet.resi.group.dto.member.result.JoinGroupApplyRealTimeResultDTO; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 组成员出入群记录表 |
|
|
@ -48,10 +83,31 @@ import java.util.Map; |
|
|
|
* @since v1.0.0 2020-03-29 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class GroupMemeberOperationServiceImpl extends BaseServiceImpl<GroupMemeberOperationDao, GroupMemeberOperationEntity> implements GroupMemeberOperationService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GroupMemeberOperationRedis groupMemeberOperationRedis; |
|
|
|
@Autowired |
|
|
|
private ResiGroupMemberDao resiGroupMemberDao; |
|
|
|
@Autowired |
|
|
|
private TopicShareLinkRecordDao topicShareLinkRecordDao; |
|
|
|
@Autowired |
|
|
|
private GovIssueOpenFeignClient issueOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private ResiTopicDao topicDao; |
|
|
|
@Autowired |
|
|
|
private GroupMemeberOperationDao operationDao; |
|
|
|
@Autowired |
|
|
|
private ResiGroupService groupService; |
|
|
|
@Autowired |
|
|
|
private ResiGroupMemberService memberService; |
|
|
|
@Autowired |
|
|
|
private ResiGroupRedis groupRedis; |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient userClient; |
|
|
|
@Autowired |
|
|
|
private TopicShareLinkVisitRecordDao topicShareLinkVisitRecordDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<GroupMemeberOperationDTO> page(Map<String, Object> params) { |
|
|
@ -143,4 +199,190 @@ public class GroupMemeberOperationServiceImpl extends BaseServiceImpl<GroupMemeb |
|
|
|
this.save(groupMemeberOperation); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 通过话题/议题分享链接申请入组 |
|
|
|
* @param param |
|
|
|
* @return com.epmet.resi.group.dto.member.result.JoinGroupApplyRealTimeResultDTO |
|
|
|
* @author wangc |
|
|
|
* @date 2020.12.22 10:36 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JoinGroupApplyRealTimeResultDTO applyEnterByLink(JoinGroupByShareLinkFormDTO param) { |
|
|
|
JoinGroupApplyRealTimeResultDTO result = new JoinGroupApplyRealTimeResultDTO(); |
|
|
|
Date current = new Date(); |
|
|
|
//根据链接查询群Id
|
|
|
|
String groupId = null; |
|
|
|
String inviter = null; |
|
|
|
if(StringUtils.equals("topic",param.getShareLinkType())){ |
|
|
|
TopicShareLinkRecordEntity topicShareLink = topicShareLinkRecordDao.selectById(param.getShareLinkId()); |
|
|
|
if(null == topicShareLink){ |
|
|
|
throw new RenException("没有找到分享链接"); |
|
|
|
} |
|
|
|
groupId = topicShareLink.getGroupId(); |
|
|
|
inviter = topicShareLink.getShareUserId(); |
|
|
|
}else { |
|
|
|
Result<IssueShareLinkRecordDTO> response = issueOpenFeignClient.shareLinkInfo(param.getShareLinkId()); |
|
|
|
if(response.success() && null != response.getData()){ |
|
|
|
groupId = topicDao.selectGroupIdByIssueId(response.getData().getIssueId()); |
|
|
|
inviter = response.getData().getShareUserId(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(StringUtils.isBlank(groupId)){ |
|
|
|
throw new RenException("没有找到议题分享链接对应的组Id"); |
|
|
|
} |
|
|
|
//查询是否在群内
|
|
|
|
ResiGroupMemberDTO groupMember = resiGroupMemberDao.selectGroupMemberInfo(groupId, param.getUserId()); |
|
|
|
if (null != groupMember && !MemberStateConstant.REMOVED.equals(groupMember.getStatus())) { |
|
|
|
log.info("已经在群内,直接返回成功,但是不发送积分事件"); |
|
|
|
result.setStatus("entered"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
//先判断用户是否有在审核的入组申请,有的话直接给提示
|
|
|
|
GroupMemeberOperationDTO groupMemeberOperationDTO = operationDao.selectLatestRecord(groupId, param.getUserId()); |
|
|
|
if (null != groupMemeberOperationDTO && MemberStateConstant.UNDER_AUDITTING.equals(groupMemeberOperationDTO.getOperateStatus())) { |
|
|
|
log.info("已存在待审核入组申请,不能重复审核"); |
|
|
|
result.setStatus("auditing"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
ResiGroupDTO resiGroupDTO = groupService.get(groupId); |
|
|
|
if(null == resiGroupDTO){ |
|
|
|
log.error("没有找到对应的组,组Id:{}",groupId); |
|
|
|
throw new RenException("没有找到对应的组"); |
|
|
|
} |
|
|
|
GetRoleKeyListFormDTO roleParam = new GetRoleKeyListFormDTO(); |
|
|
|
roleParam.setFromApp("resi"); |
|
|
|
roleParam.setUserId(param.getUserId()); |
|
|
|
roleParam.setGridId(resiGroupDTO.getGridId()); |
|
|
|
Result<List<String>> userRoleResponse = userClient.getUserRoleKeyList(roleParam); |
|
|
|
if(!userRoleResponse.success() || CollectionUtils.isEmpty(userRoleResponse.getData())){ |
|
|
|
throw new RenException("未找到当前用户的有效身份信息"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//进组是否需要审核的逻辑
|
|
|
|
GroupMemeberOperationDTO groupMemeberOperation = new GroupMemeberOperationDTO(); |
|
|
|
groupMemeberOperation.setGroupId(groupId); |
|
|
|
groupMemeberOperation.setCustomerUserId(param.getUserId()); |
|
|
|
groupMemeberOperation.setEnterGroupType(StringUtils.equals("topic",param.getShareLinkType()) ? ModuleConstant.ENTER_GROUP_TYPE_TOPIC_LINK : ModuleConstant.ENTER_GROUP_TYPE_ISSUE_LINK); |
|
|
|
groupMemeberOperation.setGroupInvitationId(param.getShareLinkId()); |
|
|
|
groupMemeberOperation.setOperateUserId(param.getUserId()); |
|
|
|
groupMemeberOperation.setOperateDes(StringUtils.equals("topic",param.getShareLinkType()) ? "通过话题分享链接申请入组" : "通过议题分享链接申请入组"); |
|
|
|
|
|
|
|
//入组审核开关是开启状态则需要组长审核
|
|
|
|
if (StringUtils.equals(GroupStateConstant.AUDIT_SWITCH_OPEN , resiGroupDTO.getAuditSwitch())) { |
|
|
|
groupMemeberOperation.setOperateStatus(MemberStateConstant.UNDER_AUDITTING); |
|
|
|
save(groupMemeberOperation); |
|
|
|
//给组长推送站内信
|
|
|
|
//memberService.sendMessageToGroupLeader(resiGroupDTO, param.getUserId());
|
|
|
|
result.setStatus("auditing"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
UserRoleDTO userRoleDTO = getUserRoleDTO(userRoleResponse.getData()); |
|
|
|
//新增一条邀请入群、直接审核通过的入群记录
|
|
|
|
groupMemeberOperation.setOperateStatus(MemberStateConstant.APPROVED); |
|
|
|
groupMemeberOperation.setOperateDes("通过分享链接入组,入组审核开关关闭,直接入组"); |
|
|
|
save(groupMemeberOperation); |
|
|
|
result.setStatus("entered"); |
|
|
|
//发送积分事件
|
|
|
|
boolean isNew = false; |
|
|
|
|
|
|
|
if(StringUtils.equals("topic",param.getShareLinkType())){ |
|
|
|
TopicShareLinkVisitRecordEntity record = topicShareLinkVisitRecordDao.selectRecordByLinkIdAndInvitee(param.getShareLinkId(), param.getUserId()); |
|
|
|
if(null == record){ |
|
|
|
log.error("【%s】该用户入组方式为话题分享链接入组,但未查询到链接访问记录,链接Id【%s】",param.getUserId(),param.getShareLinkId()); |
|
|
|
throw new RenException("未找到链接访问记录"); |
|
|
|
} |
|
|
|
if(NumConstant.ZERO == record.getIsInviteRegister()) isNew = true; |
|
|
|
}else{ |
|
|
|
Result<IssueShareLinkVisitRecordDTO> visitRecordResult = issueOpenFeignClient.visitRecord(param.getShareLinkId(), param.getUserId()); |
|
|
|
if(!visitRecordResult.success() || null == visitRecordResult.getData()){ |
|
|
|
log.error("【%s】该用户入组方式为议题分享链接入组,但未查询到链接访问记录,链接Id【%s】",param.getUserId(),param.getShareLinkId()); |
|
|
|
throw new RenException("未找到链接访问记录"); |
|
|
|
} |
|
|
|
if(!visitRecordResult.getData().getIfJoinGroup()){ |
|
|
|
log.error("【%s】该用户入组方式为议题分享链接入组,但并不是通过该链接发起的入群申请,链接Id【%s】",param.getUserId(),param.getShareLinkId()); |
|
|
|
throw new RenException("用户并非通过当前链接申请入组"); |
|
|
|
} |
|
|
|
if(NumConstant.ZERO == visitRecordResult.getData().getIsInviteRegister()) isNew = true; |
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(inviter)){ |
|
|
|
//mq的事件类型
|
|
|
|
MqBaseMsgDTO mqBaseMsgDTO = new MqBaseMsgDTO(); |
|
|
|
//事件code
|
|
|
|
mqBaseMsgDTO.setEventTag(isNew ? EventEnum.INVITE_NEW_RESIDENT_INTO_GROUP.getEventTag() : EventEnum.INVITE_RESIDENT_INTO_GROUP.getEventTag()); |
|
|
|
List<BasePointEventMsg> pointEventMsgList = new ArrayList<>(); |
|
|
|
BasePointEventMsg pointEventMsg = new BasePointEventMsg(); |
|
|
|
pointEventMsg.setCustomerId(resiGroupDTO.getCustomerId()); |
|
|
|
pointEventMsg.setUserId(inviter); |
|
|
|
pointEventMsg.setActionFlag(MqConstant.PLUS); |
|
|
|
pointEventMsg.setIsCommon(false); |
|
|
|
pointEventMsg.setTargetDate(current); |
|
|
|
pointEventMsgList.add(pointEventMsg); |
|
|
|
|
|
|
|
mqBaseMsgDTO.setMsg(JSON.toJSONString(pointEventMsgList)); |
|
|
|
Result sendResult = SendMqMsgUtils.sendMsg(mqBaseMsgDTO); |
|
|
|
if(!sendResult.success()){ |
|
|
|
log.error((isNew ? "拉新用户入组事件发送失败" : "邀请已注册用户入组事件发送失败").concat(",参数:%s"),JSON.toJSONString(param)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//直接加入群成员关系表
|
|
|
|
//如果是之前被移除的,则修改resi_group_member记录
|
|
|
|
ResiGroupMemberDTO resiGroupMemberDTO = new ResiGroupMemberDTO(); |
|
|
|
ResiGroupMemberDTO resiGroupMember = resiGroupMemberDao.selectGroupMemberInfo(groupId, param.getUserId()); |
|
|
|
if (null != resiGroupMember) { |
|
|
|
resiGroupMemberDTO.setId(resiGroupMember.getId()); |
|
|
|
} |
|
|
|
resiGroupMemberDTO.setCustomerUserId(groupMemeberOperation.getCustomerUserId()); |
|
|
|
resiGroupMemberDTO.setResiGroupId(groupMemeberOperation.getGroupId()); |
|
|
|
resiGroupMemberDTO.setGroupLeaderFlag(LeaderFlagConstant.GROUP_MEMBER); |
|
|
|
resiGroupMemberDTO.setEnterGroupType(groupMemeberOperation.getEnterGroupType()); |
|
|
|
resiGroupMemberDTO.setStatus(MemberStateConstant.APPROVED); |
|
|
|
resiGroupMemberDTO.setCreatedBy(groupMemeberOperation.getCustomerUserId()); |
|
|
|
memberService.saveOrUpdate(resiGroupMemberDTO); |
|
|
|
//修改群统计值
|
|
|
|
resiGroupMemberDao.updateResiGroupStatistical(groupMemeberOperation.getGroupId(), userRoleDTO); |
|
|
|
ResiGroupInfoRedisDTO groupCache = |
|
|
|
groupRedis.get(groupId); |
|
|
|
if(null != groupCache && null != groupCache.getGroupStatisticalInfo()){ |
|
|
|
groupCache.getGroupStatisticalInfo().setTotalMembers( |
|
|
|
null == groupCache.getGroupStatisticalInfo().getTotalMembers() ? NumConstant.TWO : groupCache.getGroupStatisticalInfo().getTotalMembers() +NumConstant.ONE |
|
|
|
); |
|
|
|
if(StringUtils.equals(userRoleDTO.getPartymemberFlag(),NumConstant.ONE_STR)) groupCache.getGroupStatisticalInfo().setTotalPartyMembers( |
|
|
|
null == groupCache.getGroupStatisticalInfo().getTotalPartyMembers() ? NumConstant.ONE : groupCache.getGroupStatisticalInfo().getTotalPartyMembers()+NumConstant.ONE |
|
|
|
); |
|
|
|
if(StringUtils.equals(userRoleDTO.getRegisteredResiFlag(),NumConstant.ONE_STR)) groupCache.getGroupStatisticalInfo().setTotalNormalMembers( |
|
|
|
null == groupCache.getGroupStatisticalInfo().getTotalNormalMembers() ? NumConstant.TWO : groupCache.getGroupStatisticalInfo().getTotalNormalMembers()+NumConstant.ONE |
|
|
|
); |
|
|
|
if(StringUtils.equals(userRoleDTO.getWarmHeartedFlag(),NumConstant.ONE_STR)) groupCache.getGroupStatisticalInfo().setTotalEarnestMembers( |
|
|
|
null == groupCache.getGroupStatisticalInfo().getTotalEarnestMembers() ? NumConstant.ONE : groupCache.getGroupStatisticalInfo().getTotalEarnestMembers()+NumConstant.ONE |
|
|
|
); |
|
|
|
groupRedis.set(groupCache); |
|
|
|
} |
|
|
|
//发送消息
|
|
|
|
//this.sendMessageToLeader(formDTO, resiGroupDTO,groupInvitationDTO);
|
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private UserRoleDTO getUserRoleDTO(List<String> userRoleList) { |
|
|
|
UserRoleDTO userRoleDTO=new UserRoleDTO(); |
|
|
|
for (String roleKey : userRoleList) { |
|
|
|
if (EpmetRoleKeyConstant.PARTYMEMBER.equals(roleKey)) { |
|
|
|
userRoleDTO.setPartymemberFlag(NumConstant.ONE_STR); |
|
|
|
} |
|
|
|
if (EpmetRoleKeyConstant.WARMHEARTED.equals(roleKey)) { |
|
|
|
userRoleDTO.setWarmHeartedFlag(NumConstant.ONE_STR); |
|
|
|
} |
|
|
|
if (EpmetRoleKeyConstant.REGISTERED_RESI.equals(roleKey)) { |
|
|
|
userRoleDTO.setRegisteredResiFlag(NumConstant.ONE_STR); |
|
|
|
} |
|
|
|
} |
|
|
|
return userRoleDTO; |
|
|
|
} |
|
|
|
} |
|
|
|