feat:REQ-1419 代码优化

This commit is contained in:
zuoqinbo 2023-10-23 10:21:50 +08:00
parent 884c296284
commit 4141a1785f
9 changed files with 63 additions and 54 deletions

View File

@ -6,22 +6,29 @@ import lombok.Getter;
/**
* IM账户类型
*
* @version V1.0
* @author zuoqinbo
* @version V1.0
* @date 2023/10/9 16:01
*/
@Getter
public enum AccountTypeEnum {
/**
* 机器人
*/
ROBOT("robot", "机器人"),
/**
* 普通用户
*/
USER("user", "普通用户");
private String code;
private final String code;
private String message;
private final String message;
AccountTypeEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@ -30,29 +30,15 @@ public enum AppTypeEnum {
SYSTEM("system", "服务器");
private String code;
private final String code;
private String message;
private final String message;
AppTypeEnum(String code, String message) {
this.code = code;
this.message = message;
}
public static AppTypeEnum isValidAppType(List<AppTypeEnum> appTypeList) {
if (appTypeList == null) {
return null;
}
AppTypeEnum[] appTypeEnums = AppTypeEnum.values();
for (AppTypeEnum appTypeEnum : appTypeEnums) {
if (appTypeEnum.getCode().equals("appType.toLowerCase()")) {
return appTypeEnum;
}
}
return null;
}
public static AppTypeEnum isValidAppType(String appType) {
if (StringUtils.isBlank(appType)) {
return null;

View File

@ -13,15 +13,23 @@ import lombok.Getter;
@Getter
public enum RobotMsgTemplateStatusEnum {
/**
* 已上架
*/
ENABLED(1, "已上架"),
/**
* 已停用
*/
DISABLED(0, "已停用");
private int code;
private final int code;
private String message;
private final String message;
RobotMsgTemplateStatusEnum(int code, String message) {
this.code = code;
this.message = message;
}
}

View File

@ -14,17 +14,30 @@ import org.apache.commons.lang3.StringUtils;
@Getter
public enum RobotStatusEnum {
/**
* 待生成IM账号
*/
CREATING("creating", "待生成IM账号"),
/**
* 待启用
*/
UN_ENABLE("un_enable", "待启用"),
/**
* 运行中
*/
ENABLED("enabled", "运行中"),
/**
* 已停用
*/
DISABLED("disabled", "已停用");
private String code;
private final String code;
private String message;
private final String message;
RobotStatusEnum(String code, String message) {
this.code = code;
this.message = message;
}

View File

@ -14,15 +14,23 @@ import org.apache.commons.lang3.StringUtils;
@Getter
public enum RobotTagStatusEnum {
/**
* 启用状态
*/
ENABLED(1, "已上架"),
/**
* 停用状态
*/
DISABLED(0, "已停用");
private int code;
private final int code;
private String message;
private final String message;
RobotTagStatusEnum(int code, String message) {
this.code = code;
this.message = message;
}
}

View File

@ -81,10 +81,13 @@ public class NimChannelService implements IMChannelProvider {
String result = response.body();
if (response.getStatus() == SUCCESS_CODE) {
RegisterResponse registerResponse = JSONUtil.toBean(result, RegisterResponse.class);
if (registerResponse == null) {
return RegisterResponse.builder().desc("请求网易云信Server异常[" + result + "],请联系管理员!").build();
}
if (registerResponse.getCode() != SUCCESS_CODE) {
log.warn("im-center请求网易云信Server:{},返回异常:{}", NIM_ACCOUNT_CREATE_URL, result);
if (StringUtils.isNotBlank(registerResponse.getDesc()) &&
registerResponse.getDesc().equals(NIM_ACCOUNT_ALREADY_REGISTER)) {
registerResponse.getDesc().contains(NIM_ACCOUNT_ALREADY_REGISTER)) {
HashMap<String, Object> queryParamMap = Maps.newHashMap();
JSONArray jsonArray = new JSONArray();
jsonArray.add(register.getAccid());

View File

@ -28,26 +28,13 @@ public enum NimMsgTypeEnum {
notify("notify", "通知消息");
private String code;
private final String code;
private String message;
private final String message;
NimMsgTypeEnum(String code, String message) {
this.code = code;
}
public static NimMsgTypeEnum isValidAppType(String appType) {
if (StringUtils.isBlank(appType)) {
return null;
}
NimMsgTypeEnum[] appTypeEnums = NimMsgTypeEnum.values();
for (NimMsgTypeEnum appTypeEnum : appTypeEnums) {
if (appTypeEnum.getCode().equals(appType.toLowerCase())) {
return appTypeEnum;
}
}
return null;
this.message = message;
}
}

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
/**
* 定时同步新建用户IM账户
* 1.捞取当前未注册IM账户的用户
* 2.创建IM账户
* 2.创建IM账户,多个App类型终端都创建
* 3.更新IM账户到用户系统
* @author zuoqinbo
* @see SyncImAccountJobHandler
@ -25,7 +25,7 @@ public class SyncImAccountJobHandler extends BaseJobHandler {
@Override
@XxlJob("syncImAccountJobHandler")
public ReturnT<String> execute(String param) throws Exception {
public ReturnT<String> execute(String param) {
return jobLoggerTemplate.execute(CTX_LOG_ID_MDC, () -> {
log.info("SyncImAccountJobHandler.execute task Start ......");
try {

View File

@ -55,7 +55,7 @@ public class AccountService {
/**
* 创建IM账户
*
* @param userAccountReq
* @param userAccountReq 创建IM账户请求参数
*/
@Transactional(rollbackFor = Exception.class)
public UserAccountResp generateAccount(@Valid UserAccountReq userAccountReq, INotifyService iNotifyService) {
@ -123,20 +123,19 @@ public class AccountService {
accountRegisterDao.saveOrUpdate(accountRegister);
} else {
//2.1注册出现异常
UserAccountResp userAccountResp = UserAccountResp.builder()
assert accountResp != null;
return UserAccountResp.builder()
.desc(accountResp.getDesc())
.build();
return userAccountResp;
}
return accountResp;
}
//1.1 如果已经创建直接返回
UserAccountResp userAccountResp = UserAccountResp.builder()
return UserAccountResp.builder()
.imAccount(accountRegister.getImAccount())
.userId(userIdWrapper)
.token(accountRegister.getToken())
.build();
return userAccountResp;
}
@ -169,14 +168,12 @@ public class AccountService {
accountQuery.getAppType())
.list();
if (CollectionUtils.isNotEmpty(accountRegisterList)) {
List<UserAccountResp> accountRespList = accountRegisterList.stream().map(accountRegister -> {
UserAccountResp userAccountResp = UserAccountResp.builder()
return accountRegisterList.stream().map(accountRegister -> {
return UserAccountResp.builder()
.userId(accountRegister.getAccountWrapper())
.token(accountRegister.getToken())
.imAccount(accountRegister.getImAccount()).build();
return userAccountResp;
}).collect(Collectors.toList());
return accountRespList;
}
return null;
}