feat: 用户注册

dev
zhanglei 2026-07-06 10:43:17 +08:00
parent 18194a382d
commit dc13f2c48d
8 changed files with 106 additions and 15 deletions

View File

@ -0,0 +1,65 @@
package org.qinan.safetyeval.adapter.config;
import lombok.extern.slf4j.Slf4j;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserInfo;
import org.qinan.safetyeval.infrastructure.dataobject.AccountDO;
import org.qinan.safetyeval.infrastructure.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* MyMetaObjectHandler org_id / tenant_id
*/
@Configuration
@Slf4j
public class GbsUserSyncConfig implements WebMvcConfigurer {
@Autowired
private AccountMapper accountMapper;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (!(handler instanceof HandlerMethod)) {
return true;
}
AuthUserInfo currentUser = AuthUserContextAdapter.getCurrentUser();
if (currentUser == null) {
throw new BizException(ErrorCode.GBS_USER_ERROR);
}
AccountDO accountDO = accountMapper.selectById(currentUser.getUserId());
if (accountDO == null) {
// 用户没有gbs信息,自动填充一条数据类型默认监管端
AccountDO accountSave = new AccountDO();
accountSave.setId(currentUser.getUserId());
accountSave.setUserName(currentUser.getUserName());
accountSave.setAccount(currentUser.getAccount());
accountSave.setPhone(currentUser.getMobile());
accountSave.setTenantId(currentUser.getTenantId());
accountSave.setType(2);
accountMapper.insert(accountSave);
log.info("用户{}同步gbs信息成功", currentUser.getUserName());
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception exception) {
}
}).addPathPatterns("/**");
}
}

View File

@ -102,4 +102,10 @@ public class AccountController {
return result;
}
@ApiOperation("用户同步gbs")
@PostMapping("/syncUserToGBS")
public SingleResponse<AccountCO> syncUserToGBS(@ApiParam("账号") @RequestParam String account) {
return accountApi.syncUserToGBS(account);
}
}

View File

@ -5,11 +5,7 @@ import com.zcloud.gbscommon.utils.MD5;
import com.zcloud.gbscommon.utils.Sm2Util;
import org.qinan.safetyeval.client.api.AccountApi;
import org.qinan.safetyeval.client.co.AccountCO;
import org.qinan.safetyeval.client.dto.AccountAddCmd;
import org.qinan.safetyeval.client.dto.AccountModifyCmd;
import org.qinan.safetyeval.client.dto.AccountPageQuery;
import org.qinan.safetyeval.client.dto.PageResponse;
import org.qinan.safetyeval.client.dto.SingleResponse;
import org.qinan.safetyeval.client.dto.*;
import org.qinan.safetyeval.domain.entity.AccountEntity;
import org.qinan.safetyeval.domain.query.AccountQuery;
import org.qinan.safetyeval.domain.query.PageResult;
@ -51,15 +47,6 @@ public class AccountExecutor implements AccountApi {
entity.setProfileUrl(cmd.getProfileUrl());
entity.setType(cmd.getType());
AccountEntity result = accountDomainService.add(entity);
// 同步gbs用户
UserAddCmd userAddCmd = new UserAddCmd();
userAddCmd.setId(result.getId());
userAddCmd.setAccount(result.getAccount());
userAddCmd.setTenantId(result.getTenantId());
userAddCmd.setName(result.getUserName());
String encrypt = Sm2Util.encryptHex(MD5.md5(defPassword), publicKey);
userAddCmd.setPassword(encrypt);
gbsUserFacadeClient.add(userAddCmd);
return SingleResponse.success(toCO(result));
}
@ -110,6 +97,21 @@ public class AccountExecutor implements AccountApi {
pageResult.getTotal());
}
@Override
public SingleResponse<AccountCO> syncUserToGBS(String account) {
AccountEntity result = accountDomainService.syncUserToGBS(account);
// 同步gbs用户
UserAddCmd userAddCmd = new UserAddCmd();
userAddCmd.setId(result.getId());
userAddCmd.setAccount(result.getAccount());
userAddCmd.setTenantId(result.getTenantId());
userAddCmd.setName(result.getUserName());
String encrypt = Sm2Util.encryptHex(MD5.md5(defPassword), publicKey);
userAddCmd.setPassword(encrypt);
gbsUserFacadeClient.add(userAddCmd);
return SingleResponse.success(toCO(result));
}
private AccountCO toCO(AccountEntity entity) {
if (entity == null) {
return null;

View File

@ -23,4 +23,6 @@ public interface AccountApi {
SingleResponse<Void> delete(Long id);
PageResponse<AccountCO> page(AccountPageQuery query);
SingleResponse<AccountCO> syncUserToGBS(String account);
}

View File

@ -27,5 +27,5 @@ public class AccountAddCmd {
private String profileUrl;
@ApiModelProperty(value = "类型(1机构端2监管端)")
private Integer type;
private Integer type = 1;
}

View File

@ -95,6 +95,9 @@ public enum ErrorCode {
*/
SMS_SOURCE_CODE_NOT_EXIST("04-01-001", "短信码不存在"),
// gbs
GBS_USER_ERROR("04-01-001", "gbs用户未登录"),
/**
*
*/

View File

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Objects;
/**
*
@ -61,4 +62,12 @@ public class AccountDomainService {
throw new BizException(ErrorCode.ACCOUNT_EXISTS);
}
}
public AccountEntity syncUserToGBS(String account) {
AccountEntity found = accountGateway.getByAccount(account);
if (Objects.isNull(found)) {
throw new BizException(ErrorCode.ACCOUNT_NOT_FOUND);
}
return found;
}
}

View File

@ -15,6 +15,8 @@ public class AuthUserInfo {
String userName;
Long tenantId;
Long orgId;
String mobile;
String account;
public static AuthUserInfo from(SSOUser user) {
if (user == null) {
@ -25,6 +27,8 @@ public class AuthUserInfo {
.userName(user.getName())
.tenantId(user.getTenantId())
.orgId(user.getOrgId())
.mobile(user.getMobile())
.account(user.getAccount())
.build();
}
}