dev-tmp1^2
luotaiqian 2026-08-28 18:04:15 +08:00
parent 8e19dc4581
commit 4bc477aba1
2 changed files with 26 additions and 2 deletions

View File

@ -80,7 +80,7 @@ public class InstitutionDashboardExecutor implements InstitutionDashboardApi {
@Override
public SingleResponse<InstitutionDashboardProjectNodeStatsCO> projectNodeStats() {
Long orgId = ThreadLocalUserInfoAdapter.getOrgId() ;
Long orgId = institutionOrgSupport.resolveCurrentOrgIdByUserId();
if (orgId == null) {
return SingleResponse.success(new InstitutionDashboardProjectNodeStatsCO());
}

View File

@ -1,6 +1,9 @@
package org.qinan.safetyeval.infrastructure.support;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.springframework.stereotype.Component;
@ -32,6 +35,9 @@ public class UserOrgIdResolver {
@Resource
private OrgPersonnelMapper orgPersonnelMapper;
@Resource
private OrgInfoMapper orgInfoMapper;
private final Map<Long, CacheEntry> cache = new ConcurrentHashMap<>();
/**
@ -72,7 +78,25 @@ public class UserOrgIdResolver {
private Long queryOrgIdByUserId(Long userId) {
OrgPersonnelDO personnel = orgPersonnelMapper.selectById(userId);
return personnel == null ? null : personnel.getOrgId();
if (personnel != null) {
return personnel.getOrgId();
}
// 兜底用户可能是机构注册人org_info.create_id = userId取其创建的机构
return queryOrgIdByCreator(userId);
}
/**
* id orgId
*
* @param userId idorg_info.create_id
* @return orgId null
*/
private Long queryOrgIdByCreator(Long userId) {
OrgInfoDO orgInfo = orgInfoMapper.selectOne(new LambdaQueryWrapper<OrgInfoDO>()
.select(OrgInfoDO::getId)
.eq(OrgInfoDO::getCreateId, userId)
.last("limit 1"));
return orgInfo == null ? null : orgInfo.getId();
}
private static class CacheEntry {