feat: 用户注册
parent
18194a382d
commit
dc13f2c48d
|
|
@ -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("/**");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -102,4 +102,10 @@ public class AccountController {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("用户同步gbs")
|
||||||
|
@PostMapping("/syncUserToGBS")
|
||||||
|
public SingleResponse<AccountCO> syncUserToGBS(@ApiParam("账号") @RequestParam String account) {
|
||||||
|
return accountApi.syncUserToGBS(account);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,7 @@ import com.zcloud.gbscommon.utils.MD5;
|
||||||
import com.zcloud.gbscommon.utils.Sm2Util;
|
import com.zcloud.gbscommon.utils.Sm2Util;
|
||||||
import org.qinan.safetyeval.client.api.AccountApi;
|
import org.qinan.safetyeval.client.api.AccountApi;
|
||||||
import org.qinan.safetyeval.client.co.AccountCO;
|
import org.qinan.safetyeval.client.co.AccountCO;
|
||||||
import org.qinan.safetyeval.client.dto.AccountAddCmd;
|
import org.qinan.safetyeval.client.dto.*;
|
||||||
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.domain.entity.AccountEntity;
|
import org.qinan.safetyeval.domain.entity.AccountEntity;
|
||||||
import org.qinan.safetyeval.domain.query.AccountQuery;
|
import org.qinan.safetyeval.domain.query.AccountQuery;
|
||||||
import org.qinan.safetyeval.domain.query.PageResult;
|
import org.qinan.safetyeval.domain.query.PageResult;
|
||||||
|
|
@ -51,15 +47,6 @@ public class AccountExecutor implements AccountApi {
|
||||||
entity.setProfileUrl(cmd.getProfileUrl());
|
entity.setProfileUrl(cmd.getProfileUrl());
|
||||||
entity.setType(cmd.getType());
|
entity.setType(cmd.getType());
|
||||||
AccountEntity result = accountDomainService.add(entity);
|
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));
|
return SingleResponse.success(toCO(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,6 +97,21 @@ public class AccountExecutor implements AccountApi {
|
||||||
pageResult.getTotal());
|
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) {
|
private AccountCO toCO(AccountEntity entity) {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,6 @@ public interface AccountApi {
|
||||||
SingleResponse<Void> delete(Long id);
|
SingleResponse<Void> delete(Long id);
|
||||||
|
|
||||||
PageResponse<AccountCO> page(AccountPageQuery query);
|
PageResponse<AccountCO> page(AccountPageQuery query);
|
||||||
|
|
||||||
|
SingleResponse<AccountCO> syncUserToGBS(String account);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,5 @@ public class AccountAddCmd {
|
||||||
private String profileUrl;
|
private String profileUrl;
|
||||||
|
|
||||||
@ApiModelProperty(value = "类型(1机构端2监管端)")
|
@ApiModelProperty(value = "类型(1机构端2监管端)")
|
||||||
private Integer type;
|
private Integer type = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,9 @@ public enum ErrorCode {
|
||||||
*/
|
*/
|
||||||
SMS_SOURCE_CODE_NOT_EXIST("04-01-001", "短信码不存在"),
|
SMS_SOURCE_CODE_NOT_EXIST("04-01-001", "短信码不存在"),
|
||||||
|
|
||||||
|
// gbs
|
||||||
|
GBS_USER_ERROR("04-01-001", "gbs用户未登录"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 未知错误
|
* 未知错误
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户领域服务
|
* 用户领域服务
|
||||||
|
|
@ -61,4 +62,12 @@ public class AccountDomainService {
|
||||||
throw new BizException(ErrorCode.ACCOUNT_EXISTS);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ public class AuthUserInfo {
|
||||||
String userName;
|
String userName;
|
||||||
Long tenantId;
|
Long tenantId;
|
||||||
Long orgId;
|
Long orgId;
|
||||||
|
String mobile;
|
||||||
|
String account;
|
||||||
|
|
||||||
public static AuthUserInfo from(SSOUser user) {
|
public static AuthUserInfo from(SSOUser user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|
@ -25,6 +27,8 @@ public class AuthUserInfo {
|
||||||
.userName(user.getName())
|
.userName(user.getName())
|
||||||
.tenantId(user.getTenantId())
|
.tenantId(user.getTenantId())
|
||||||
.orgId(user.getOrgId())
|
.orgId(user.getOrgId())
|
||||||
|
.mobile(user.getMobile())
|
||||||
|
.account(user.getAccount())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue