feat:REQ-1419 代码逻辑优化

This commit is contained in:
zuoqinbo 2023-10-26 10:24:20 +08:00
parent 5bc71a2786
commit 50c59e7cde
5 changed files with 36 additions and 34 deletions

View File

@ -26,7 +26,7 @@ public class AccountQuery {
/**
* 注册用户ID唯一
* 普通用户userId机器人robotId
* 普通用户personId机器人robotId
*/
@NotNull(message = "注册ID不能为空")
private String accountId;

View File

@ -1,7 +1,7 @@
package cn.axzo.im.channel.netease;
/**
* im-center
* 通知服务
*
* @author zuoqinbo
* @version V1.0
@ -12,15 +12,16 @@ public interface INotifyService {
/**
* 机器人信息变更通知到IM用户系统
*
* @param robotPrimaryId
* @param robotId 机器人ID
*/
void notifyAccountChange(Long robotPrimaryId);
void notifyRobotAccountChange(String robotId);
/**
* 普通用户信息变更通知到IM用户系统
*
* @param userId
* @param nickName
* @param imAccountId 用户IM账户accid
* @param nickName 用户IM账户昵称
* @param icon 用户IM账户头像
*/
void notifyUserAccountChange(String userId, String nickName);
void notifyUserAccountChange(String imAccountId, String nickName, String icon);
}

View File

@ -4,6 +4,7 @@ import cn.axzo.basics.common.BeanMapper;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.im.center.api.vo.req.*;
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
import cn.axzo.im.center.common.enums.RobotStatusEnum;
import cn.axzo.im.channel.IMChannelProvider;
import cn.axzo.im.channel.netease.INotifyService;
import cn.axzo.im.dao.repository.AccountRegisterDao;
@ -71,12 +72,12 @@ public class AccountService {
throw new ServiceException("当前appType,服务器不支持该类型!!");
}
String userIdWrapper = userAccountReq.getUserId() + "_" + appTypeEnum.getCode();
//后续AppKey可能会更换普通用户通过userIdappTypeappKey维度来保证唯一性
//后续AppKey可能会更换普通用户通过userIdappTypeappKey维度来保证数据库唯一性
UserAccountResp userAccountResp = createAccountRegister(userAccountReq.getUserId(), userIdWrapper, appType,
AccountTypeEnum.USER.getCode(), userAccountReq.getHeadImageUrl(), userAccountReq.getNickName());
if (iNotifyService != null) {
iNotifyService.notifyUserAccountChange(userAccountReq.getUserId(), userAccountReq.getNickName());
if (iNotifyService != null && userAccountResp != null) {
iNotifyService.notifyUserAccountChange(userAccountResp.getImAccount(), userAccountReq.getNickName(), null);
}
return userAccountResp;
}
@ -89,16 +90,15 @@ public class AccountService {
RobotInfo robotInfo = robotInfoDao.lambdaQuery().eq(RobotInfo::getIsDelete, 0)
.eq(RobotInfo::getRobotId, robotId).one();
if (robotInfo == null) {
throw new ServiceException("该机器人robotId:{}还未创建信息!");
throw new ServiceException("该机器人robotId:{} 还未创建信息!");
}
UserAccountResp userAccountResp = createAccountRegister(robotId, robotId, AppTypeEnum.SYSTEM.getCode(),
AccountTypeEnum.ROBOT.getCode(), robotAccountReq.getHeadImageUrl(), robotAccountReq.getNickName());
//生成后更新机器人信息表
robotInfoService.updateRobotStatus(robotId, userAccountResp.getImAccount());
//生成后更新机器人状态和IM账户
robotInfoService.updateRobotStatus(robotId, userAccountResp.getImAccount(), RobotStatusEnum.UN_ENABLE);
if (iNotifyService != null) {
iNotifyService.notifyAccountChange(robotInfo.getId());
iNotifyService.notifyUserAccountChange(userAccountResp.getImAccount(), robotInfo.getNickName(), null);
}
return userAccountResp;
}
@ -181,7 +181,7 @@ public class AccountService {
.appType(accountRegister.getAppType())
.imAccount(accountRegister.getImAccount()).build()).collect(Collectors.toList());
}
return null;
return Lists.newArrayList();
}
/**

View File

@ -1,7 +1,6 @@
package cn.axzo.im.service;
import cn.axzo.im.center.api.vo.resp.RobotInfoResp;
import cn.axzo.im.center.api.vo.resp.RobotMsgTemplateResp;
import cn.axzo.im.center.api.vo.resp.RobotTagResp;
import cn.axzo.im.center.common.enums.AccountTypeEnum;
import cn.axzo.im.channel.IMChannelProvider;
@ -35,9 +34,9 @@ public class NotifyChannelServiceImpl implements INotifyService {
private RobotInfoService robotInfoService;
@Override
public void notifyAccountChange(Long robotPrimaryId) {
public void notifyRobotAccountChange(String robotId) {
RegisterUpdateRequest updateProfile = new RegisterUpdateRequest();
RobotInfoResp robotInfoResp = robotInfoService.findRobotInfoById(robotPrimaryId);
RobotInfoResp robotInfoResp = robotInfoService.queryRobotInfo(robotId);
if (robotInfoResp == null) {
return;
}
@ -65,16 +64,16 @@ public class NotifyChannelServiceImpl implements INotifyService {
@Override
public void notifyUserAccountChange(String accountId, String nickName) {
log.info("普通用户信息发生变更,userId:{}正在通知并且更新到IM系统", accountId);
public void notifyUserAccountChange(String imAccountId, String nickName,String iconUrl) {
HashMap<String, Object> userProfileMap = Maps.newHashMap();
userProfileMap.put("accountType", AccountTypeEnum.USER.getCode());
String extJson = JSONUtil.toJsonStr(userProfileMap);
RegisterUpdateRequest updateProfile = new RegisterUpdateRequest();
updateProfile.setAccid(accountId);
updateProfile.setAccid(imAccountId);
updateProfile.setName(nickName);
updateProfile.setIcon(iconUrl);
updateProfile.setExtJson(extJson);
log.info("更新普通用户:{},到网易云信账户信息", JSONUtil.toJsonStr(updateProfile));
log.info("更新普通用户信息到网易云信账户:{},", JSONUtil.toJsonStr(updateProfile));
channelProvider.updateAccountProfile(updateProfile);
}

View File

@ -28,7 +28,6 @@ import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@ -81,22 +80,23 @@ public class RobotInfoService {
verifyRobotName(updateRobotInfoReq.getNickName(), robotId);
verifyRobotStatus(updateRobotInfoReq.getStatus(), robotId);
robotInfoOld.setUpdateAt(new Date());
if(CollectionUtils.isNotEmpty(updateRobotInfoReq.getTagNameList())){
if (CollectionUtils.isNotEmpty(updateRobotInfoReq.getTagNameList())) {
robotInfoOld.setTagNameList(updateRobotInfoReq.getTagNameList());
}
if(StringUtils.isNotEmpty(updateRobotInfoReq.getNickName())){
if (StringUtils.isNotEmpty(updateRobotInfoReq.getNickName())) {
robotInfoOld.setNickName(updateRobotInfoReq.getNickName());
}
if(StringUtils.isNotEmpty(updateRobotInfoReq.getHeadImageUrl())){
if (StringUtils.isNotEmpty(updateRobotInfoReq.getHeadImageUrl())) {
robotInfoOld.setHeadImageUrl(updateRobotInfoReq.getHeadImageUrl());
}
if(StringUtils.isNotEmpty(updateRobotInfoReq.getStatus())){
if (StringUtils.isNotEmpty(updateRobotInfoReq.getStatus())) {
robotInfoOld.setStatus(updateRobotInfoReq.getStatus());
}
RobotInfo robotInfoNew = robotInfoDao.saveOrUpdateRobotInfo(robotInfoOld);
if (iNotifyService != null) {
iNotifyService.notifyAccountChange(robotInfoNew.getId());
if (iNotifyService != null && robotInfoNew !=null) {
iNotifyService.notifyRobotAccountChange(robotInfoNew.getRobotId());
}
assert robotInfoNew != null;
return findRobotInfoById(robotInfoNew.getId());
}
@ -161,7 +161,7 @@ public class RobotInfoService {
RobotInfo robotInfo = robotInfoDao.lambdaQuery().eq(RobotInfo::getIsDelete, 0)
.eq(RobotInfo::getId, robotInfoResp.getId()).one();
if (robotInfo == null) {
return ;
return;
}
List<Long> tagIdList = robotInfo.getTagNameList();
List<RobotTag> robotTags = robotTagDao.queryRobotTagValidList(tagIdList);
@ -204,14 +204,16 @@ public class RobotInfoService {
}).collect(Collectors.toList());
}
public void updateRobotStatus(String robotId, String imAccount) {
public void updateRobotStatus(String robotId, String imAccount, RobotStatusEnum robotStatusEnum) {
RobotInfo robotInfo = robotInfoDao.lambdaQuery().eq(RobotInfo::getIsDelete, 0)
.eq(RobotInfo::getRobotId, robotId).one();
if (robotInfo == null) {
throw new ServiceException("该机器人robotId:{}还未创建信息!");
throw new ServiceException("该机器人robotId:{} 还未创建信息!");
}
robotInfo.setImAccount(imAccount);
robotInfo.setStatus(RobotStatusEnum.UN_ENABLE.getCode());
if (robotStatusEnum != null) {
robotInfo.setStatus(robotStatusEnum.getCode());
}
robotInfoDao.saveOrUpdateRobotInfo(robotInfo);
}
}