feat: 注册用户
parent
c31b0707e2
commit
d3471e5618
|
|
@ -1,6 +1,7 @@
|
||||||
package org.qinan.safetyeval.adapter.config;
|
package org.qinan.safetyeval.adapter.config;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.qinan.safetyeval.domain.exception.BizException;
|
import org.qinan.safetyeval.domain.exception.BizException;
|
||||||
import org.qinan.safetyeval.domain.exception.ErrorCode;
|
import org.qinan.safetyeval.domain.exception.ErrorCode;
|
||||||
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||||
|
|
@ -10,6 +11,7 @@ import org.qinan.safetyeval.infrastructure.mapper.AccountMapper;
|
||||||
import org.qinan.safetyeval.infrastructure.support.InsertFieldDefaults;
|
import org.qinan.safetyeval.infrastructure.support.InsertFieldDefaults;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.util.AntPathMatcher;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
|
@ -28,6 +30,13 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
|
||||||
@Autowired
|
@Autowired
|
||||||
private AccountMapper accountMapper;
|
private AccountMapper accountMapper;
|
||||||
|
|
||||||
|
private final AntPathMatcher pathMatcher = new AntPathMatcher();
|
||||||
|
|
||||||
|
private final String[] anonymousUrl = {
|
||||||
|
"/**/account/syncUserToGBS/**",
|
||||||
|
"/**/org-info/save/**",
|
||||||
|
"/**/account/save/**"
|
||||||
|
};
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new HandlerInterceptor() {
|
registry.addInterceptor(new HandlerInterceptor() {
|
||||||
|
|
@ -36,6 +45,10 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
log.info("url: {}", request.getRequestURI());
|
||||||
|
if (isWhiteUrl(request.getRequestURI())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
AuthUserInfo currentUser = AuthUserContextAdapter.getCurrentUser();
|
AuthUserInfo currentUser = AuthUserContextAdapter.getCurrentUser();
|
||||||
if (currentUser == null || currentUser.getUserId() == null) {
|
if (currentUser == null || currentUser.getUserId() == null) {
|
||||||
throw new BizException(ErrorCode.GBS_USER_ERROR);
|
throw new BizException(ErrorCode.GBS_USER_ERROR);
|
||||||
|
|
@ -63,5 +76,24 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
|
||||||
|
|
||||||
}
|
}
|
||||||
}).addPathPatterns("/**").order(2);
|
}).addPathPatterns("/**").order(2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 放行白名单
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isWhiteUrl(String url) {
|
||||||
|
if (StringUtils.isBlank(url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String s : anonymousUrl) {
|
||||||
|
if (pathMatcher.match(s, url)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package org.qinan.safetyeval.adapter.config;
|
||||||
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
|
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class AccountController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("用户同步gbs")
|
@ApiOperation("用户同步gbs")
|
||||||
@PostMapping("/syncUserToGBS")
|
@GetMapping("/syncUserToGBS")
|
||||||
public SingleResponse<AccountCO> syncUserToGBS(@ApiParam("账号") @RequestParam String account) {
|
public SingleResponse<AccountCO> syncUserToGBS(@ApiParam("账号") @RequestParam String account) {
|
||||||
return accountApi.syncUserToGBS(account);
|
return accountApi.syncUserToGBS(account);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ public class OrgInfoExecutor implements OrgInfoApi {
|
||||||
entity.setFilingRecordStatusCode(cmd.getFilingRecordStatusCode());
|
entity.setFilingRecordStatusCode(cmd.getFilingRecordStatusCode());
|
||||||
entity.setFilingRecordStatusName(cmd.getFilingRecordStatusName());
|
entity.setFilingRecordStatusName(cmd.getFilingRecordStatusName());
|
||||||
entity.setAttachmentUrls(cmd.getAttachmentUrls());
|
entity.setAttachmentUrls(cmd.getAttachmentUrls());
|
||||||
|
entity.setRegisterUserId(cmd.getRegisterUserId());
|
||||||
|
|
||||||
OrgInfoEntity result = orgInfoDomainService.add(entity);
|
OrgInfoEntity result = orgInfoDomainService.add(entity);
|
||||||
return SingleResponse.success(toCO(result));
|
return SingleResponse.success(toCO(result));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package org.qinan.safetyeval.client.dto;
|
package org.qinan.safetyeval.client.dto;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机构信息新增命令
|
* 机构信息新增命令
|
||||||
|
|
@ -138,4 +139,8 @@ public class OrgInfoAddCmd {
|
||||||
|
|
||||||
@ApiModelProperty(value = "上传附件地址(多个逗号分隔)")
|
@ApiModelProperty(value = "上传附件地址(多个逗号分隔)")
|
||||||
private String attachmentUrls;
|
private String attachmentUrls;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户注册")
|
||||||
|
private Long registerUserId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.qinan.safetyeval.domain.entity;
|
package org.qinan.safetyeval.domain.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -156,4 +157,7 @@ public class OrgInfoEntity {
|
||||||
|
|
||||||
/** 创建时间(开户时间) */
|
/** 创建时间(开户时间) */
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户注册")
|
||||||
|
private Long registerUserId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ public enum ErrorCode {
|
||||||
// ---- 用户 ----
|
// ---- 用户 ----
|
||||||
ACCOUNT_NOT_FOUND("04-01-001", "用户不存在"),
|
ACCOUNT_NOT_FOUND("04-01-001", "用户不存在"),
|
||||||
ACCOUNT_EXISTS("04-01-002", "账号已存在"),
|
ACCOUNT_EXISTS("04-01-002", "账号已存在"),
|
||||||
|
PHONE_EXISTS("04-01-0023", "手机号已存在"),
|
||||||
|
|
||||||
// ---- 文件存储 ----
|
// ---- 文件存储 ----
|
||||||
FILE_UPLOAD_FAILED("03-01-001", "文件上传失败"),
|
FILE_UPLOAD_FAILED("03-01-001", "文件上传失败"),
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,6 @@ public interface AccountGateway {
|
||||||
void delete(Long id);
|
void delete(Long id);
|
||||||
|
|
||||||
PageResult<AccountEntity> page(AccountQuery query);
|
PageResult<AccountEntity> page(AccountQuery query);
|
||||||
|
|
||||||
|
AccountEntity foundByPhone(String phone);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,10 @@ public class AccountDomainService {
|
||||||
private AccountGateway accountGateway;
|
private AccountGateway accountGateway;
|
||||||
|
|
||||||
public AccountEntity add(AccountEntity entity) {
|
public AccountEntity add(AccountEntity entity) {
|
||||||
assertAccountUnique(entity.getAccount(), null);
|
AccountEntity account = assertAccountUnique(entity.getAccount(), null, entity.getPhone());
|
||||||
|
if (account != null) {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
return accountGateway.save(entity);
|
return accountGateway.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +40,7 @@ public class AccountDomainService {
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
throw new BizException(ErrorCode.ACCOUNT_NOT_FOUND);
|
throw new BizException(ErrorCode.ACCOUNT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
assertAccountUnique(entity.getAccount(), entity.getId());
|
assertAccountUnique(entity.getAccount(), entity.getId(), entity.getPhone());
|
||||||
return accountGateway.modify(entity);
|
return accountGateway.modify(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,14 +56,21 @@ public class AccountDomainService {
|
||||||
return accountGateway.page(query);
|
return accountGateway.page(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertAccountUnique(String account, Long excludeId) {
|
private AccountEntity assertAccountUnique(String account, Long excludeId, String phone) {
|
||||||
if (!StringUtils.hasText(account)) {
|
if (!StringUtils.hasText(account) || !StringUtils.hasText(phone)) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
AccountEntity found = accountGateway.getByAccount(account);
|
AccountEntity found = accountGateway.getByAccount(account);
|
||||||
if (found != null && (excludeId == null || !excludeId.equals(found.getId()))) {
|
if (found != null && (excludeId == null || !excludeId.equals(found.getId()))) {
|
||||||
throw new BizException(ErrorCode.ACCOUNT_EXISTS);
|
// throw new BizException(ErrorCode.ACCOUNT_EXISTS);
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
AccountEntity foundByPhone = accountGateway.foundByPhone(phone);
|
||||||
|
if (foundByPhone != null && !excludeId.equals(foundByPhone.getId())) {
|
||||||
|
// throw new BizException(ErrorCode.PHONE_EXISTS, foundByPhone.getAccount());
|
||||||
|
return foundByPhone;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountEntity syncUserToGBS(String account) {
|
public AccountEntity syncUserToGBS(String account) {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,15 @@ public class AccountGatewayImpl implements AccountGateway {
|
||||||
return PageResult.of(entities, result.getTotal(), result.getCurrent(), result.getSize());
|
return PageResult.of(entities, result.getTotal(), result.getCurrent(), result.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountEntity foundByPhone(String phone) {
|
||||||
|
LambdaQueryWrapper<AccountDO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(AccountDO::getPhone, phone);
|
||||||
|
wrapper.eq(AccountDO::getDeleteEnum, "false");
|
||||||
|
AccountDO dataObject = accountMapper.selectOne(wrapper);
|
||||||
|
return toEntity(dataObject);
|
||||||
|
}
|
||||||
|
|
||||||
private AccountDO toDO(AccountEntity entity) {
|
private AccountDO toDO(AccountEntity entity) {
|
||||||
AccountDO dataObject = new AccountDO();
|
AccountDO dataObject = new AccountDO();
|
||||||
dataObject.setUserName(entity.getUserName());
|
dataObject.setUserName(entity.getUserName());
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,22 @@ public class OrgInfoGatewayImpl implements OrgInfoGateway {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrgInfoEntity save(OrgInfoEntity entity) {
|
public OrgInfoEntity save(OrgInfoEntity entity) {
|
||||||
|
if (entity.getRegisterUserId() != null) {
|
||||||
|
List<OrgInfoDO> orgInfoDOS = orgInfoMapper.selectList(new LambdaQueryWrapper<OrgInfoDO>()
|
||||||
|
.eq(OrgInfoDO::getCreateId, entity.getRegisterUserId()).last("limit 1"));
|
||||||
|
if (!CollectionUtils.isEmpty(orgInfoDOS)) {
|
||||||
|
return toEntity(orgInfoDOS.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
OrgInfoDO dataObject = toDO(entity);
|
OrgInfoDO dataObject = toDO(entity);
|
||||||
if (dataObject.getState() == null) {
|
if (dataObject.getState() == null) {
|
||||||
dataObject.setState(0);
|
dataObject.setState(0);
|
||||||
}
|
}
|
||||||
InsertFieldDefaults.apply(dataObject);
|
InsertFieldDefaults.apply(dataObject);
|
||||||
|
dataObject.setCreateId(entity.getCreateId());
|
||||||
|
dataObject.setUpdateId(entity.getCreateId());
|
||||||
|
entity.setCreateId(entity.getRegisterUserId());
|
||||||
orgInfoMapper.insert(dataObject);
|
orgInfoMapper.insert(dataObject);
|
||||||
entity.setId(dataObject.getId());
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,25 +38,27 @@ public final class InsertFieldDefaults {
|
||||||
setIfNull(dataObject, "updateTime", now);
|
setIfNull(dataObject, "updateTime", now);
|
||||||
|
|
||||||
// 用户上下文字段:从 AuthUserContextAdapter 获取
|
// 用户上下文字段:从 AuthUserContextAdapter 获取
|
||||||
Long userId = AuthUserContextAdapter.getCurrentUserId();
|
|
||||||
String userName = AuthUserContextAdapter.getCurrentUserName();
|
|
||||||
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
|
||||||
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
||||||
// 机构信息id
|
// 机构信息id
|
||||||
Long orgInfoId = ThreadLocalUserInfoAdapter.get();
|
Long orgInfoId = ThreadLocalUserInfoAdapter.get();
|
||||||
|
|
||||||
|
Long userId = AuthUserContextAdapter.getCurrentUserId();
|
||||||
if (userId != null) {
|
if (userId == null) {
|
||||||
|
userId = 0L;
|
||||||
|
}
|
||||||
|
String userName = AuthUserContextAdapter.getCurrentUserName();
|
||||||
|
if (userName == null) {
|
||||||
|
userName = "系统";
|
||||||
|
}
|
||||||
|
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
||||||
|
if (tenantId == null) {
|
||||||
|
tenantId = 2069596397920849920L;
|
||||||
|
}
|
||||||
setIfNull(dataObject, "createId", userId);
|
setIfNull(dataObject, "createId", userId);
|
||||||
setIfNull(dataObject, "updateId", userId);
|
setIfNull(dataObject, "updateId", userId);
|
||||||
}
|
|
||||||
if (userName != null) {
|
|
||||||
setIfNull(dataObject, "createName", userName);
|
setIfNull(dataObject, "createName", userName);
|
||||||
setIfNull(dataObject, "updateName", userName);
|
setIfNull(dataObject, "updateName", userName);
|
||||||
}
|
|
||||||
if (tenantId != null) {
|
|
||||||
setIfNull(dataObject, "tenantId", tenantId);
|
setIfNull(dataObject, "tenantId", tenantId);
|
||||||
}
|
|
||||||
if (orgInfoId != null) {
|
if (orgInfoId != null) {
|
||||||
// 机构信息id
|
// 机构信息id
|
||||||
setIfNull(dataObject, "orgId", orgInfoId);
|
setIfNull(dataObject, "orgId", orgInfoId);
|
||||||
|
|
@ -134,20 +136,21 @@ public final class InsertFieldDefaults {
|
||||||
|
|
||||||
// 用户上下文字段:从 AuthUserContextAdapter 获取
|
// 用户上下文字段:从 AuthUserContextAdapter 获取
|
||||||
Long userId = AuthUserContextAdapter.getCurrentUserId();
|
Long userId = AuthUserContextAdapter.getCurrentUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
userId = 0L;
|
||||||
|
}
|
||||||
String userName = AuthUserContextAdapter.getCurrentUserName();
|
String userName = AuthUserContextAdapter.getCurrentUserName();
|
||||||
|
if (userName == null) {
|
||||||
|
userName = "系统";
|
||||||
|
}
|
||||||
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
||||||
|
if (tenantId == null) {
|
||||||
|
tenantId = 2069596397920849920L;
|
||||||
if (userId != null) {
|
}
|
||||||
setIfNull(dataObject, "createId", userId);
|
setIfNull(dataObject, "createId", userId);
|
||||||
setIfNull(dataObject, "updateId", userId);
|
setIfNull(dataObject, "updateId", userId);
|
||||||
}
|
|
||||||
if (userName != null) {
|
|
||||||
setIfNull(dataObject, "createName", userName);
|
setIfNull(dataObject, "createName", userName);
|
||||||
setIfNull(dataObject, "updateName", userName);
|
setIfNull(dataObject, "updateName", userName);
|
||||||
}
|
|
||||||
if (tenantId != null) {
|
|
||||||
setIfNull(dataObject, "tenantId", tenantId);
|
setIfNull(dataObject, "tenantId", tenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue