feat:REQ-1419 增加用户注册IM接口
This commit is contained in:
parent
4141a1785f
commit
40fbda85a0
@ -1,10 +1,7 @@
|
||||
package cn.axzo.im.center.api.feign;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.im.center.api.vo.req.AccountQuery;
|
||||
import cn.axzo.im.center.api.vo.req.BatchAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.RobotAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.UserAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.*;
|
||||
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -45,6 +42,16 @@ public interface AccountApi {
|
||||
ApiResult<List<UserAccountResp>> queryRegisterAccountInfo(@RequestBody @Validated AccountQuery accountQuery);
|
||||
|
||||
|
||||
/**
|
||||
* 查询注册账户信息, 如果已注册就返回注册信息,
|
||||
* 如果未注册就进行IM注册,并返回IM账户
|
||||
* @param accountQuery 账户查询条件
|
||||
* @return 返回IM账户
|
||||
*/
|
||||
@PostMapping("api/im/account/register/if-absent")
|
||||
ApiResult<List<UserAccountResp>> registerAccountIfAbsent(@RequestBody @Validated AccountAbsentQuery accountQuery);
|
||||
|
||||
|
||||
/**
|
||||
* 机器人生成IM账户
|
||||
* 机器人通过PC端创建IM账户,不需要appType来区分
|
||||
@ -59,6 +66,7 @@ public interface AccountApi {
|
||||
/**
|
||||
* 批量生成普通用户IM账户
|
||||
* 只生成普通IM账户
|
||||
*
|
||||
* @param userAccountReq 生成云信账户参数
|
||||
* @return 返回云信IM账户
|
||||
*/
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.axzo.im.center.api.vo.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zuoqinbo
|
||||
* @version V1.0
|
||||
* @date 2023/10/9 16:01
|
||||
*/
|
||||
@Data
|
||||
public class AccountAbsentQuery {
|
||||
/**
|
||||
* 注册用户唯一标识,普通用户personId
|
||||
*/
|
||||
@NotNull(message = "注册用户personId不能为空")
|
||||
private String personId;
|
||||
|
||||
}
|
||||
@ -21,6 +21,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.basics</groupId>
|
||||
<artifactId>basics-profiles-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
||||
@ -2,10 +2,7 @@ package cn.axzo.im.controller;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.im.center.api.feign.AccountApi;
|
||||
import cn.axzo.im.center.api.vo.req.AccountQuery;
|
||||
import cn.axzo.im.center.api.vo.req.BatchAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.RobotAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.UserAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.*;
|
||||
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
|
||||
import cn.axzo.im.channel.netease.INotifyService;
|
||||
import cn.axzo.im.service.AccountService;
|
||||
@ -46,7 +43,11 @@ public class AccountController implements AccountApi {
|
||||
List<UserAccountResp> userAccountList = accountService.queryAccountInfo(accountQuery);
|
||||
return ApiResult.ok(userAccountList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<List<UserAccountResp>> registerAccountIfAbsent(AccountAbsentQuery accountQuery) {
|
||||
List<UserAccountResp> userAccountList = accountService.registerAccountIfAbsent(accountQuery);
|
||||
return ApiResult.ok(userAccountList);
|
||||
}
|
||||
@Override
|
||||
public ApiResult<UserAccountResp> generateRobotAccount(RobotAccountReq robotAccountReq) {
|
||||
UserAccountResp userAccountResp = accountService.generateRobotAccount(robotAccountReq, iNotifyService);
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package cn.axzo.im.job;
|
||||
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.azxo.framework.common.utils.LogUtil;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 定时同步新建用户IM账户
|
||||
* 1.捞取当前未注册IM账户的用户
|
||||
@ -23,6 +26,10 @@ public class SyncImAccountJobHandler extends BaseJobHandler {
|
||||
*/
|
||||
public static final String CTX_LOG_ID_MDC = "ctxLogId";
|
||||
|
||||
@Resource
|
||||
private UserProfileServiceApi userProfileServiceApi;
|
||||
|
||||
|
||||
@Override
|
||||
@XxlJob("syncImAccountJobHandler")
|
||||
public ReturnT<String> execute(String param) {
|
||||
|
||||
@ -15,6 +15,7 @@ import cn.axzo.im.channel.netease.dto.NimAccountInfo;
|
||||
import cn.axzo.im.center.common.enums.AccountTypeEnum;
|
||||
import cn.axzo.im.center.common.enums.AppTypeEnum;
|
||||
import cn.axzo.im.entity.RobotInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@ -49,9 +50,14 @@ public class AccountService {
|
||||
@Resource
|
||||
private RobotInfoService robotInfoService;
|
||||
|
||||
@Resource
|
||||
private INotifyService iNotifyService;
|
||||
|
||||
@Resource
|
||||
private RobotInfoDao robotInfoDao;
|
||||
|
||||
private static final String DEFAULT_NICK_NAME = "普通IM用户-";
|
||||
|
||||
/**
|
||||
* 创建IM账户
|
||||
*
|
||||
@ -168,13 +174,41 @@ public class AccountService {
|
||||
accountQuery.getAppType())
|
||||
.list();
|
||||
if (CollectionUtils.isNotEmpty(accountRegisterList)) {
|
||||
return accountRegisterList.stream().map(accountRegister -> {
|
||||
return UserAccountResp.builder()
|
||||
.userId(accountRegister.getAccountWrapper())
|
||||
.token(accountRegister.getToken())
|
||||
.imAccount(accountRegister.getImAccount()).build();
|
||||
}).collect(Collectors.toList());
|
||||
return accountRegisterList.stream().map(accountRegister -> UserAccountResp.builder()
|
||||
.userId(accountRegister.getAccountWrapper())
|
||||
.token(accountRegister.getToken())
|
||||
.imAccount(accountRegister.getImAccount()).build()).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户注册IM账户信息,如果没有则进行注册
|
||||
*
|
||||
* @param accountAbsentQuery 查询IM账户请求
|
||||
* @return IM注册信息
|
||||
*/
|
||||
public List<UserAccountResp> registerAccountIfAbsent(AccountAbsentQuery accountAbsentQuery) {
|
||||
List<UserAccountResp> userAccountAll = Lists.newArrayList();
|
||||
for (AppTypeEnum appTypeEnum : AppTypeEnum.values()) {
|
||||
if (appTypeEnum == AppTypeEnum.SYSTEM) {
|
||||
continue;
|
||||
}
|
||||
AccountQuery accountQuery = new AccountQuery();
|
||||
accountQuery.setAppType(appTypeEnum.getCode());
|
||||
accountQuery.setAccountId(accountAbsentQuery.getPersonId());
|
||||
List<UserAccountResp> userAccountRespList = queryAccountInfo(accountQuery);
|
||||
if (CollectionUtils.isNotEmpty(userAccountRespList)) {
|
||||
userAccountAll.addAll(userAccountRespList);
|
||||
} else {
|
||||
UserAccountReq userAccountReq = new UserAccountReq();
|
||||
userAccountReq.setAppType(appTypeEnum.getCode());
|
||||
userAccountReq.setUserId(accountAbsentQuery.getPersonId());
|
||||
userAccountReq.setNickName(DEFAULT_NICK_NAME);
|
||||
UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService);
|
||||
userAccountAll.add(accountResp);
|
||||
}
|
||||
}
|
||||
return userAccountAll;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class NotifyChannelServiceImpl implements INotifyService {
|
||||
|
||||
@Override
|
||||
public void notifyUserAccountChange(String accountId, String nickName) {
|
||||
log.info("普通用户信息发生变更,userId:{},正在通知到IM系统", accountId);
|
||||
log.info("普通用户信息发生变更,userId:{},正在通知并且更新到IM系统", accountId);
|
||||
HashMap<String, Object> userProfileMap = Maps.newHashMap();
|
||||
userProfileMap.put("accountType", AccountTypeEnum.USER.getCode());
|
||||
String extJson = JSONUtil.toJsonStr(userProfileMap);
|
||||
@ -74,7 +74,7 @@ public class NotifyChannelServiceImpl implements INotifyService {
|
||||
updateProfile.setAccid(accountId);
|
||||
updateProfile.setName(nickName);
|
||||
updateProfile.setExtJson(extJson);
|
||||
log.info("更新普通用户:{},网易云信账户信息", JSONUtil.toJsonStr(updateProfile));
|
||||
log.info("更新普通用户:{},到网易云信账户信息", JSONUtil.toJsonStr(updateProfile));
|
||||
channelProvider.updateAccountProfile(updateProfile);
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user