Merge remote-tracking branch 'origin/dev' into dev
commit
63389a7d42
|
|
@ -1,9 +1,9 @@
|
|||
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;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
|
@ -15,20 +15,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* 本地联调:为免鉴权的企业信息接口注入默认用户上下文,供 MyMetaObjectHandler 填充 org_id / tenant_id。
|
||||
*/
|
||||
@Configuration
|
||||
@Profile("local")
|
||||
public class LocalDevUserContextConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-id:1}")
|
||||
private Long systemUserId;
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-name:local-dev}")
|
||||
private String systemUserName;
|
||||
|
||||
@Value("${safety-eval.public-api.tenant-id:1001}")
|
||||
private Long tenantId;
|
||||
|
||||
@Value("${safety-eval.public-api.org-id:1}")
|
||||
private Long orgId;
|
||||
|
||||
private static final String[] LOCAL_DEV_PATHS = {
|
||||
"/org-info/**",
|
||||
|
|
@ -47,7 +35,10 @@ public class LocalDevUserContextConfig implements WebMvcConfigurer {
|
|||
registry.addInterceptor(new HandlerInterceptor() {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
ThreadLocalUserInfoAdapter.set(systemUserId, systemUserName, tenantId, orgId);
|
||||
String orgInfoId = request.getHeader("orgInfoId");
|
||||
if (StringUtils.hasText(orgInfoId)) {
|
||||
ThreadLocalUserInfoAdapter.set(Long.valueOf(orgInfoId));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -56,6 +47,6 @@ public class LocalDevUserContextConfig implements WebMvcConfigurer {
|
|||
Object handler, Exception exception) {
|
||||
ThreadLocalUserInfoAdapter.clear();
|
||||
}
|
||||
}).addPathPatterns(LOCAL_DEV_PATHS);
|
||||
}).addPathPatterns(LOCAL_DEV_PATHS).excludePathPatterns("/**/getInfo/**");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
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.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;
|
||||
|
||||
@Configuration
|
||||
public class PublicApiConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-id:0}")
|
||||
private Long systemUserId;
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-name:system}")
|
||||
private String systemUserName;
|
||||
|
||||
@Value("${safety-eval.public-api.tenant-id:0}")
|
||||
private Long tenantId;
|
||||
|
||||
@Value("${safety-eval.public-api.org-id:0}")
|
||||
private Long orgId;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new HandlerInterceptor() {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
ThreadLocalUserInfoAdapter.set(systemUserId, systemUserName, tenantId, orgId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception exception) {
|
||||
ThreadLocalUserInfoAdapter.clear();
|
||||
}
|
||||
}).addPathPatterns("/public/org-personnel/**");
|
||||
}
|
||||
}
|
||||
|
|
@ -33,12 +33,18 @@ public class OrgInfoController {
|
|||
return orgInfoApi.add(cmd);
|
||||
}
|
||||
|
||||
@ApiOperation("查询机构信息详情")
|
||||
@ApiOperation("根据查询机构信息详情")
|
||||
@GetMapping("/get")
|
||||
public SingleResponse<OrgInfoCO> get(@RequestParam Long id) {
|
||||
return orgInfoApi.get(id);
|
||||
}
|
||||
|
||||
@ApiOperation("查询机构信息详情(内部查询)")
|
||||
@GetMapping("/getInfo")
|
||||
public SingleResponse<OrgInfoCO> getInfo() {
|
||||
return orgInfoApi.getInfo();
|
||||
}
|
||||
|
||||
@ApiOperation("修改机构信息")
|
||||
@PostMapping("/modify")
|
||||
public SingleResponse<OrgInfoCO> modify(@Validated @RequestBody OrgInfoModifyCmd cmd) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class OrgDepartmentExecutor implements OrgDepartmentApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setParentId(query.getParentId());
|
||||
domainQuery.setDeptName(query.getDeptName());
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class OrgEquipmentExecutor implements OrgEquipmentApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setDeviceName(query.getDeviceName());
|
||||
domainQuery.setInstrumentType(query.getInstrumentType());
|
||||
domainQuery.setDeviceType(query.getDeviceType());
|
||||
|
|
|
|||
|
|
@ -142,6 +142,12 @@ public class OrgInfoExecutor implements OrgInfoApi {
|
|||
pageResult.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse<OrgInfoCO> getInfo() {
|
||||
OrgInfoEntity entity = orgInfoDomainService.getInfo();
|
||||
return SingleResponse.success(toCO(entity));
|
||||
}
|
||||
|
||||
private OrgInfoCO toCO(OrgInfoEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class OrgPersonnelCertExecutor implements OrgPersonnelCertApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setPersonnelId(query.getPersonnelId());
|
||||
domainQuery.setCertName(query.getCertName());
|
||||
domainQuery.setCertTypeCode(query.getCertTypeCode());
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class OrgPersonnelChangeExecutor implements OrgPersonnelChangeApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setPersonnelId(query.getPersonnelId());
|
||||
domainQuery.setChangeItem(query.getChangeItem());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package org.qinan.safetyeval.app.executor;
|
||||
|
||||
import com.jjb.saas.system.client.user.facade.UserFacade;
|
||||
import com.jjb.saas.system.client.user.request.FacadeUserAddCmd;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.qinan.safetyeval.app.support.OrgPersonnelChangeRecorder;
|
||||
import org.qinan.safetyeval.app.support.OrgPersonnelViewEnricher;
|
||||
import org.qinan.safetyeval.client.api.OrgPersonnelApi;
|
||||
|
|
@ -43,12 +46,16 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
|
|||
@Autowired(required = false)
|
||||
private OrgResignApplyGateway orgResignApplyGateway;
|
||||
|
||||
// @DubboReference
|
||||
// private UserFacade userFacade;
|
||||
|
||||
@Override
|
||||
public SingleResponse<OrgPersonnelCO> add(OrgPersonnelAddCmd cmd) {
|
||||
OrgPersonnelEntity entity = toEntity(cmd);
|
||||
OrgPersonnelEntity result = orgPersonnelDomainService.add(entity);
|
||||
OrgPersonnelCO co = toCO(result);
|
||||
enrich(co);
|
||||
// 同步用户信息GBS
|
||||
return SingleResponse.success(co);
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +102,7 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setDeptId(query.getDeptId());
|
||||
domainQuery.setPostId(query.getPostId());
|
||||
domainQuery.setUserName(query.getUserName());
|
||||
|
|
@ -103,7 +110,7 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
|
|||
domainQuery.setEmploymentStatusCode(query.getEmploymentStatusCode());
|
||||
if (query.getResignAuditStatus() != null && orgResignApplyGateway != null) {
|
||||
domainQuery.setPersonnelIds(orgResignApplyGateway.listPersonnelIdsByAuditStatus(
|
||||
query.getResignAuditStatus(), AuthUserContextAdapter.getCurrentOrgId()));
|
||||
query.getResignAuditStatus(), query.getOrgId()));
|
||||
}
|
||||
|
||||
PageResult<OrgPersonnelEntity> pageResult = orgPersonnelDomainService.page(domainQuery);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class OrgPositionExecutor implements OrgPositionApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setDeptId(query.getDeptId());
|
||||
domainQuery.setPositionName(query.getPositionName());
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class OrgQualificationExecutor implements OrgQualificationApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setCertName(query.getCertName());
|
||||
domainQuery.setCertNo(query.getCertNo());
|
||||
domainQuery.setEnableFlag(query.getEnableFlag());
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class OrgResignApplyExecutor implements OrgResignApplyApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setPersonnelId(query.getPersonnelId());
|
||||
domainQuery.setAuditStatusCode(query.getAuditStatusCode());
|
||||
domainQuery.setApplicantName(query.getApplicantName());
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public class QualFilingChangeExecutor implements QualFilingChangeApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setOriginFilingId(query.getOriginFilingId());
|
||||
domainQuery.setFilingNo(query.getFilingNo());
|
||||
domainQuery.setFilingStatusCode(query.getFilingStatusCode());
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class QualFilingExecutor implements QualFilingApi {
|
|||
domainQuery.setPageNum(query.getCurrent());
|
||||
domainQuery.setPageSize(query.getSize());
|
||||
domainQuery.setTenantId(AuthUserContextAdapter.getCurrentTenantId());
|
||||
domainQuery.setOrgId(AuthUserContextAdapter.getCurrentOrgId());
|
||||
domainQuery.setOrgId(query.getOrgId());
|
||||
domainQuery.setFilingNo(query.getFilingNo());
|
||||
domainQuery.setFilingUnitName(query.getFilingUnitName());
|
||||
domainQuery.setFilingStatusCode(query.getFilingStatusCode());
|
||||
|
|
|
|||
|
|
@ -23,4 +23,6 @@ public interface OrgInfoApi {
|
|||
SingleResponse<Void> delete(Long id);
|
||||
|
||||
PageResponse<OrgInfoCO> page(OrgInfoPageQuery query);
|
||||
|
||||
SingleResponse<OrgInfoCO> getInfo();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,7 @@ public interface OrgInfoGateway {
|
|||
void delete(Long id);
|
||||
|
||||
PageResult<OrgInfoEntity> page(OrgInfoQuery query);
|
||||
|
||||
OrgInfoEntity getInfo();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,8 @@ public class OrgInfoDomainService {
|
|||
public PageResult<OrgInfoEntity> page(OrgInfoQuery query) {
|
||||
return orgInfoGateway.page(query);
|
||||
}
|
||||
|
||||
public OrgInfoEntity getInfo() {
|
||||
return orgInfoGateway.getInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package org.qinan.safetyeval.infrastructure.adapter;
|
||||
|
||||
import org.qinan.safetyeval.domain.adapter.UserInfoAdapter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 基于 ThreadLocal 的用户信息适配器默认实现
|
||||
|
|
@ -12,41 +10,18 @@ import org.springframework.stereotype.Component;
|
|||
*
|
||||
* @author safety-eval
|
||||
*/
|
||||
@Component
|
||||
public class ThreadLocalUserInfoAdapter implements UserInfoAdapter {
|
||||
public class ThreadLocalUserInfoAdapter {
|
||||
|
||||
private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>();
|
||||
private static final ThreadLocal<String> USER_NAME = new ThreadLocal<>();
|
||||
private static final ThreadLocal<Long> TENANT_ID = new ThreadLocal<>();
|
||||
private static final ThreadLocal<Long> ORG_ID = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public Long getCurrentUserId() {
|
||||
return USER_ID.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentUserName() {
|
||||
return USER_NAME.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCurrentTenantId() {
|
||||
return TENANT_ID.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCurrentOrgId() {
|
||||
public static Long get() {
|
||||
return ORG_ID.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前线程的用户上下文信息
|
||||
*/
|
||||
public static void set(Long userId, String userName, Long tenantId, Long orgId) {
|
||||
USER_ID.set(userId);
|
||||
USER_NAME.set(userName);
|
||||
TENANT_ID.set(tenantId);
|
||||
public static void set(Long orgId) {
|
||||
ORG_ID.set(orgId);
|
||||
}
|
||||
|
||||
|
|
@ -54,9 +29,6 @@ public class ThreadLocalUserInfoAdapter implements UserInfoAdapter {
|
|||
* 清除当前线程的用户上下文信息,避免内存泄漏
|
||||
*/
|
||||
public static void clear() {
|
||||
USER_ID.remove();
|
||||
USER_NAME.remove();
|
||||
TENANT_ID.remove();
|
||||
ORG_ID.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,17 @@ import org.qinan.safetyeval.domain.query.OrgInfoQuery;
|
|||
import org.qinan.safetyeval.domain.query.PageResult;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||
import org.qinan.safetyeval.infrastructure.dataobject.OrgInfoDO;
|
||||
import org.qinan.safetyeval.infrastructure.dataobject.OrgPersonnelDO;
|
||||
import org.qinan.safetyeval.infrastructure.mapper.OrgInfoMapper;
|
||||
import org.qinan.safetyeval.infrastructure.mapper.OrgPersonnelMapper;
|
||||
import org.qinan.safetyeval.infrastructure.support.InsertFieldDefaults;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +32,8 @@ public class OrgInfoGatewayImpl implements OrgInfoGateway {
|
|||
|
||||
@Resource
|
||||
private OrgInfoMapper orgInfoMapper;
|
||||
@Resource
|
||||
private OrgPersonnelMapper orgPersonnelMapper;
|
||||
|
||||
@Override
|
||||
public OrgInfoEntity save(OrgInfoEntity entity) {
|
||||
|
|
@ -93,6 +99,24 @@ public class OrgInfoGatewayImpl implements OrgInfoGateway {
|
|||
return PageResult.of(entities, result.getTotal(), result.getCurrent(), result.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrgInfoEntity getInfo() {
|
||||
// 查询人员有无机构信息
|
||||
Long currentUserId = AuthUserContextAdapter.getCurrentUserId();
|
||||
OrgPersonnelDO orgPersonnelDO = orgPersonnelMapper.selectById(currentUserId);
|
||||
LambdaQueryWrapper<OrgInfoDO> lqw = new LambdaQueryWrapper<OrgInfoDO>()
|
||||
.eq(OrgInfoDO::getCreateId, currentUserId);
|
||||
if (orgPersonnelDO != null && orgPersonnelDO.getOrgId() != null) {
|
||||
lqw.or().eq(OrgInfoDO::getId, orgPersonnelDO.getOrgId());
|
||||
}
|
||||
lqw.last("limit 1").orderByDesc(OrgInfoDO::getId);
|
||||
List<OrgInfoDO> dataObject = orgInfoMapper.selectList(lqw);
|
||||
if (dataObject.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return toEntity(dataObject.get(0));
|
||||
}
|
||||
|
||||
private OrgInfoDO toDO(OrgInfoEntity entity) {
|
||||
OrgInfoDO dataObject = new OrgInfoDO();
|
||||
dataObject.setUnitName(entity.getUnitName());
|
||||
|
|
|
|||
|
|
@ -1,152 +1,152 @@
|
|||
package org.qinan.safetyeval.infrastructure.handler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.qinan.safetyeval.domain.adapter.UserInfoAdapter;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* MyBatis Plus 自动填充处理器
|
||||
* <p>
|
||||
* 在 insert 和 update 操作时自动填充 GBS 标准字段,
|
||||
* 优先通过 AuthUserContextAdapter 获取 SSO 真实登录用户信息,
|
||||
* 其次通过 UserInfoAdapter(ThreadLocal 方式)获取,最后回退到配置默认值。
|
||||
* 使用 strictFill 策略:仅当字段值为 null 时才填充。
|
||||
* </p>
|
||||
*
|
||||
* @author safety-eval
|
||||
*/
|
||||
@Component
|
||||
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
/** 系统环境标识 */
|
||||
private static final String DEFAULT_ENV = "prod";
|
||||
|
||||
@Resource
|
||||
private UserInfoAdapter userInfoAdapter;
|
||||
|
||||
/** 无登录上下文时的回退值(local 联调配置 org-id=1;生产默认 0 不生效) */
|
||||
@Value("${safety-eval.public-api.org-id:0}")
|
||||
private Long fallbackOrgId;
|
||||
|
||||
@Value("${safety-eval.public-api.tenant-id:0}")
|
||||
private Long fallbackTenantId;
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-id:0}")
|
||||
private Long fallbackUserId;
|
||||
|
||||
@Value("${safety-eval.public-api.system-user-name:system}")
|
||||
private String fallbackUserName;
|
||||
|
||||
/**
|
||||
* 解析用户ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
*/
|
||||
private Long resolveUserId() {
|
||||
Long userId = AuthUserContextAdapter.getCurrentUserId();
|
||||
if (userId != null) {
|
||||
return userId;
|
||||
}
|
||||
userId = userInfoAdapter.getCurrentUserId();
|
||||
if (userId == null && fallbackUserId != null && fallbackUserId > 0) {
|
||||
userId = fallbackUserId;
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析用户名:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
*/
|
||||
private String resolveUserName() {
|
||||
String userName = AuthUserContextAdapter.getCurrentUserName();
|
||||
if (userName != null) {
|
||||
return userName;
|
||||
}
|
||||
userName = userInfoAdapter.getCurrentUserName();
|
||||
if (userName == null && fallbackUserName != null) {
|
||||
userName = fallbackUserName;
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析租户ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
*/
|
||||
private Long resolveTenantId() {
|
||||
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
||||
if (tenantId != null) {
|
||||
return tenantId;
|
||||
}
|
||||
tenantId = userInfoAdapter.getCurrentTenantId();
|
||||
if (tenantId == null && fallbackTenantId != null && fallbackTenantId > 0) {
|
||||
tenantId = fallbackTenantId;
|
||||
}
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析机构ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
*/
|
||||
private Long resolveOrgId() {
|
||||
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
||||
if (orgId != null) {
|
||||
return orgId;
|
||||
}
|
||||
orgId = userInfoAdapter.getCurrentOrgId();
|
||||
if (orgId == null && fallbackOrgId != null && fallbackOrgId > 0) {
|
||||
orgId = fallbackOrgId;
|
||||
}
|
||||
return orgId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Long userId = resolveUserId();
|
||||
String userName = resolveUserName();
|
||||
Long tenantId = resolveTenantId();
|
||||
Long orgId = resolveOrgId();
|
||||
|
||||
// 严格填充:仅当字段值为 null 时填充,优先级最低
|
||||
this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, now);
|
||||
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, now);
|
||||
this.strictInsertFill(metaObject, "deleteEnum", String.class, "false");
|
||||
this.strictInsertFill(metaObject, "env", String.class, DEFAULT_ENV);
|
||||
this.strictInsertFill(metaObject, "version", Integer.class, 0);
|
||||
|
||||
// 用户相关字段:仅当解析值不为 null 时才填充
|
||||
if (userId != null) {
|
||||
this.strictInsertFill(metaObject, "createId", Long.class, userId);
|
||||
this.strictInsertFill(metaObject, "updateId", Long.class, userId);
|
||||
}
|
||||
if (userName != null) {
|
||||
this.strictInsertFill(metaObject, "createName", String.class, userName);
|
||||
this.strictInsertFill(metaObject, "updateName", String.class, userName);
|
||||
}
|
||||
if (tenantId != null) {
|
||||
this.strictInsertFill(metaObject, "tenantId", Long.class, tenantId);
|
||||
}
|
||||
if (orgId != null) {
|
||||
this.strictInsertFill(metaObject, "orgId", Long.class, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Long userId = resolveUserId();
|
||||
String userName = resolveUserName();
|
||||
|
||||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, now);
|
||||
if (userId != null) {
|
||||
this.strictUpdateFill(metaObject, "updateId", Long.class, userId);
|
||||
}
|
||||
if (userName != null) {
|
||||
this.strictUpdateFill(metaObject, "updateName", String.class, userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
//package org.qinan.safetyeval.infrastructure.handler;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
//import org.apache.ibatis.reflection.MetaObject;
|
||||
//import org.qinan.safetyeval.domain.adapter.UserInfoAdapter;
|
||||
//import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.time.LocalDateTime;
|
||||
//
|
||||
///**
|
||||
// * MyBatis Plus 自动填充处理器
|
||||
// * <p>
|
||||
// * 在 insert 和 update 操作时自动填充 GBS 标准字段,
|
||||
// * 优先通过 AuthUserContextAdapter 获取 SSO 真实登录用户信息,
|
||||
// * 其次通过 UserInfoAdapter(ThreadLocal 方式)获取,最后回退到配置默认值。
|
||||
// * 使用 strictFill 策略:仅当字段值为 null 时才填充。
|
||||
// * </p>
|
||||
// *
|
||||
// * @author safety-eval
|
||||
// */
|
||||
//@Component
|
||||
//public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
//
|
||||
// /** 系统环境标识 */
|
||||
// private static final String DEFAULT_ENV = "prod";
|
||||
//
|
||||
// @Resource
|
||||
// private UserInfoAdapter userInfoAdapter;
|
||||
//
|
||||
// /** 无登录上下文时的回退值(local 联调配置 org-id=1;生产默认 0 不生效) */
|
||||
// @Value("${safety-eval.public-api.org-id:0}")
|
||||
// private Long fallbackOrgId;
|
||||
//
|
||||
// @Value("${safety-eval.public-api.tenant-id:0}")
|
||||
// private Long fallbackTenantId;
|
||||
//
|
||||
// @Value("${safety-eval.public-api.system-user-id:0}")
|
||||
// private Long fallbackUserId;
|
||||
//
|
||||
// @Value("${safety-eval.public-api.system-user-name:system}")
|
||||
// private String fallbackUserName;
|
||||
//
|
||||
// /**
|
||||
// * 解析用户ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
// */
|
||||
// private Long resolveUserId() {
|
||||
// Long userId = AuthUserContextAdapter.getCurrentUserId();
|
||||
// if (userId != null) {
|
||||
// return userId;
|
||||
// }
|
||||
// userId = userInfoAdapter.getCurrentUserId();
|
||||
// if (userId == null && fallbackUserId != null && fallbackUserId > 0) {
|
||||
// userId = fallbackUserId;
|
||||
// }
|
||||
// return userId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解析用户名:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
// */
|
||||
// private String resolveUserName() {
|
||||
// String userName = AuthUserContextAdapter.getCurrentUserName();
|
||||
// if (userName != null) {
|
||||
// return userName;
|
||||
// }
|
||||
// userName = userInfoAdapter.getCurrentUserName();
|
||||
// if (userName == null && fallbackUserName != null) {
|
||||
// userName = fallbackUserName;
|
||||
// }
|
||||
// return userName;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解析租户ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
// */
|
||||
// private Long resolveTenantId() {
|
||||
// Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
||||
// if (tenantId != null) {
|
||||
// return tenantId;
|
||||
// }
|
||||
// tenantId = userInfoAdapter.getCurrentTenantId();
|
||||
// if (tenantId == null && fallbackTenantId != null && fallbackTenantId > 0) {
|
||||
// tenantId = fallbackTenantId;
|
||||
// }
|
||||
// return tenantId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解析机构ID:优先 AuthUserContextAdapter(SSO) → UserInfoAdapter(ThreadLocal) → 配置回退
|
||||
// */
|
||||
// private Long resolveOrgId() {
|
||||
// Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
||||
// if (orgId != null) {
|
||||
// return orgId;
|
||||
// }
|
||||
// orgId = userInfoAdapter.getCurrentOrgId();
|
||||
// if (orgId == null && fallbackOrgId != null && fallbackOrgId > 0) {
|
||||
// orgId = fallbackOrgId;
|
||||
// }
|
||||
// return orgId;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void insertFill(MetaObject metaObject) {
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// Long userId = resolveUserId();
|
||||
// String userName = resolveUserName();
|
||||
// Long tenantId = resolveTenantId();
|
||||
// Long orgId = resolveOrgId();
|
||||
//
|
||||
// // 严格填充:仅当字段值为 null 时填充,优先级最低
|
||||
// this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, now);
|
||||
// this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, now);
|
||||
// this.strictInsertFill(metaObject, "deleteEnum", String.class, "false");
|
||||
// this.strictInsertFill(metaObject, "env", String.class, DEFAULT_ENV);
|
||||
// this.strictInsertFill(metaObject, "version", Integer.class, 0);
|
||||
//
|
||||
// // 用户相关字段:仅当解析值不为 null 时才填充
|
||||
// if (userId != null) {
|
||||
// this.strictInsertFill(metaObject, "createId", Long.class, userId);
|
||||
// this.strictInsertFill(metaObject, "updateId", Long.class, userId);
|
||||
// }
|
||||
// if (userName != null) {
|
||||
// this.strictInsertFill(metaObject, "createName", String.class, userName);
|
||||
// this.strictInsertFill(metaObject, "updateName", String.class, userName);
|
||||
// }
|
||||
// if (tenantId != null) {
|
||||
// this.strictInsertFill(metaObject, "tenantId", Long.class, tenantId);
|
||||
// }
|
||||
// if (orgId != null) {
|
||||
// this.strictInsertFill(metaObject, "orgId", Long.class, orgId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void updateFill(MetaObject metaObject) {
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// Long userId = resolveUserId();
|
||||
// String userName = resolveUserName();
|
||||
//
|
||||
// this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, now);
|
||||
// if (userId != null) {
|
||||
// this.strictUpdateFill(metaObject, "updateId", Long.class, userId);
|
||||
// }
|
||||
// if (userName != null) {
|
||||
// this.strictUpdateFill(metaObject, "updateName", String.class, userName);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.qinan.safetyeval.infrastructure.support;
|
||||
|
||||
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -41,6 +42,9 @@ public final class InsertFieldDefaults {
|
|||
String userName = AuthUserContextAdapter.getCurrentUserName();
|
||||
Long tenantId = AuthUserContextAdapter.getCurrentTenantId();
|
||||
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
||||
// 机构信息id
|
||||
Long orgInfoId = ThreadLocalUserInfoAdapter.get();
|
||||
|
||||
|
||||
if (userId != null) {
|
||||
setIfNull(dataObject, "createId", userId);
|
||||
|
|
@ -54,7 +58,8 @@ public final class InsertFieldDefaults {
|
|||
setIfNull(dataObject, "tenantId", tenantId);
|
||||
}
|
||||
if (orgId != null) {
|
||||
setIfNull(dataObject, "orgId", orgId);
|
||||
// 机构信息id
|
||||
setIfNull(dataObject, "orgId", orgInfoId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package org.qinan.safetyeval.infrastructure.support;
|
||||
|
||||
import org.qinan.safetyeval.domain.adapter.UserInfoAdapter;
|
||||
import org.qinan.safetyeval.domain.exception.BizException;
|
||||
import org.qinan.safetyeval.domain.exception.ErrorCode;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
|
@ -13,30 +16,14 @@ import javax.annotation.Resource;
|
|||
@Component
|
||||
public class OrgContextResolver {
|
||||
|
||||
@Resource
|
||||
private UserInfoAdapter userInfoAdapter;
|
||||
|
||||
@Value("${safety-eval.public-api.org-id:0}")
|
||||
private Long fallbackOrgId;
|
||||
|
||||
public Long resolveOrgId(Long entityOrgId) {
|
||||
if (entityOrgId != null) {
|
||||
return entityOrgId;
|
||||
}
|
||||
// 优先 SSO 真实登录用户的 orgId
|
||||
Long orgId = AuthUserContextAdapter.getCurrentOrgId();
|
||||
if (orgId != null) {
|
||||
Long orgId = ThreadLocalUserInfoAdapter.get();
|
||||
if (orgId == null) {
|
||||
throw new BizException(ErrorCode.ORG_INFO_NOT_FOUND);
|
||||
}
|
||||
return orgId;
|
||||
}
|
||||
// 其次 ThreadLocal 方式
|
||||
orgId = userInfoAdapter.getCurrentOrgId();
|
||||
if (orgId != null) {
|
||||
return orgId;
|
||||
}
|
||||
// 最后配置回退
|
||||
if (fallbackOrgId != null && fallbackOrgId > 0) {
|
||||
return fallbackOrgId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package org.qinan.safetyeval.start.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 雪花 ID 超出 JS Number 安全整数范围,序列化为字符串避免前端精度丢失。
|
||||
*/
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer longToStringCustomizer() {
|
||||
return builder -> {
|
||||
builder.serializerByType(Long.class, ToStringSerializer.instance);
|
||||
builder.serializerByType(Long.TYPE, ToStringSerializer.instance);
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue