Merge remote-tracking branch 'origin/dev' into dev

dev
luotaiqian 2026-07-06 17:45:43 +08:00
commit 3b7303682f
12 changed files with 114 additions and 39 deletions

View File

@ -1,6 +1,7 @@
package org.qinan.safetyeval.adapter.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@ -28,6 +30,13 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
@Autowired
private AccountMapper accountMapper;
private final AntPathMatcher pathMatcher = new AntPathMatcher();
private final String[] anonymousUrl = {
"/**/account/syncUserToGBS/**",
"/**/org-info/save/**",
"/**/account/save/**"
};
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@ -36,6 +45,10 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
if (!(handler instanceof HandlerMethod)) {
return true;
}
log.info("url: {}", request.getRequestURI());
if (isWhiteUrl(request.getRequestURI())) {
return true;
}
AuthUserInfo currentUser = AuthUserContextAdapter.getCurrentUser();
if (currentUser == null || currentUser.getUserId() == null) {
throw new BizException(ErrorCode.GBS_USER_ERROR);
@ -63,5 +76,24 @@ public class GbsUserSyncInterceptor implements WebMvcConfigurer {
}
}).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;
}
}

View File

@ -3,7 +3,6 @@ package org.qinan.safetyeval.adapter.config;
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

View File

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

View File

@ -76,6 +76,7 @@ public class OrgInfoExecutor implements OrgInfoApi {
entity.setFilingRecordStatusCode(cmd.getFilingRecordStatusCode());
entity.setFilingRecordStatusName(cmd.getFilingRecordStatusName());
entity.setAttachmentUrls(cmd.getAttachmentUrls());
entity.setRegisterUserId(cmd.getRegisterUserId());
OrgInfoEntity result = orgInfoDomainService.add(entity);
return SingleResponse.success(toCO(result));

View File

@ -1,9 +1,10 @@
package org.qinan.safetyeval.client.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Data;
/**
*
@ -138,4 +139,8 @@ public class OrgInfoAddCmd {
@ApiModelProperty(value = "上传附件地址(多个逗号分隔)")
private String attachmentUrls;
@ApiModelProperty(value = "用户注册")
private Long registerUserId;
}

View File

@ -1,5 +1,6 @@
package org.qinan.safetyeval.domain.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@ -156,4 +157,7 @@ public class OrgInfoEntity {
/** 创建时间(开户时间) */
private LocalDateTime createTime;
@ApiModelProperty(value = "用户注册")
private Long registerUserId;
}

View File

@ -78,6 +78,7 @@ public enum ErrorCode {
// ---- 用户 ----
ACCOUNT_NOT_FOUND("04-01-001", "用户不存在"),
ACCOUNT_EXISTS("04-01-002", "账号已存在"),
PHONE_EXISTS("04-01-0023", "手机号已存在"),
// ---- 文件存储 ----
FILE_UPLOAD_FAILED("03-01-001", "文件上传失败"),

View File

@ -22,4 +22,6 @@ public interface AccountGateway {
void delete(Long id);
PageResult<AccountEntity> page(AccountQuery query);
AccountEntity foundByPhone(String phone);
}

View File

@ -24,7 +24,10 @@ public class AccountDomainService {
private AccountGateway accountGateway;
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);
}
@ -37,7 +40,7 @@ public class AccountDomainService {
if (existing == null) {
throw new BizException(ErrorCode.ACCOUNT_NOT_FOUND);
}
assertAccountUnique(entity.getAccount(), entity.getId());
assertAccountUnique(entity.getAccount(), entity.getId(), entity.getPhone());
return accountGateway.modify(entity);
}
@ -53,14 +56,21 @@ public class AccountDomainService {
return accountGateway.page(query);
}
private void assertAccountUnique(String account, Long excludeId) {
if (!StringUtils.hasText(account)) {
return;
private AccountEntity assertAccountUnique(String account, Long excludeId, String phone) {
if (!StringUtils.hasText(account) || !StringUtils.hasText(phone)) {
return null;
}
AccountEntity found = accountGateway.getByAccount(account);
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) {

View File

@ -94,6 +94,15 @@ public class AccountGatewayImpl implements AccountGateway {
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) {
AccountDO dataObject = new AccountDO();
dataObject.setUserName(entity.getUserName());

View File

@ -67,13 +67,22 @@ public class OrgInfoGatewayImpl implements OrgInfoGateway {
@Override
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);
if (dataObject.getState() == null) {
dataObject.setState(0);
}
InsertFieldDefaults.apply(dataObject);
dataObject.setCreateId(entity.getCreateId());
dataObject.setUpdateId(entity.getCreateId());
entity.setCreateId(entity.getRegisterUserId());
orgInfoMapper.insert(dataObject);
entity.setId(dataObject.getId());
return entity;
}

View File

@ -38,25 +38,27 @@ public final class InsertFieldDefaults {
setIfNull(dataObject, "updateTime", now);
// 用户上下文字段:从 AuthUserContextAdapter 获取
Long userId = AuthUserContextAdapter.getCurrentUserId();
String userName = AuthUserContextAdapter.getCurrentUserName();
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
// 机构信息id
Long orgInfoId = ThreadLocalUserInfoAdapter.get();
if (userId != null) {
Long userId = AuthUserContextAdapter.getCurrentUserId();
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, "updateId", userId);
}
if (userName != null) {
setIfNull(dataObject, "createName", userName);
setIfNull(dataObject, "updateName", userName);
}
if (tenantId != null) {
setIfNull(dataObject, "tenantId", tenantId);
}
if (orgInfoId != null) {
// 机构信息id
setIfNull(dataObject, "orgId", orgInfoId);
@ -134,20 +136,21 @@ public final class InsertFieldDefaults {
// 用户上下文字段:从 AuthUserContextAdapter 获取
Long userId = AuthUserContextAdapter.getCurrentUserId();
if (userId == null) {
userId = 0L;
}
String userName = AuthUserContextAdapter.getCurrentUserName();
if (userName == null) {
userName = "系统";
}
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
if (userId != null) {
if (tenantId == null) {
tenantId = 2069596397920849920L;
}
setIfNull(dataObject, "createId", userId);
setIfNull(dataObject, "updateId", userId);
}
if (userName != null) {
setIfNull(dataObject, "createName", userName);
setIfNull(dataObject, "updateName", userName);
}
if (tenantId != null) {
setIfNull(dataObject, "tenantId", tenantId);
}
}
}