优化:缓存查询与智能分析页面,修复组织下钻和草稿保留

This commit is contained in:
2026-10-23 16:06:59 +08:00
parent 6394e057bf
commit f14400bd60
9 changed files with 261 additions and 50 deletions
@@ -0,0 +1,42 @@
package cn.yunsheng.quality.common;
import cn.yunsheng.quality.governance.GovernanceAccessService;
import cn.yunsheng.quality.identity.AppUserPrincipal;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/** 只校验缓存依赖,不读取业务事实表,也不向前端返回权限策略正文。 */
@RestController
public class WorkspaceStateController {
private final JdbcTemplate jdbc;
private final GovernanceAccessService access;
public WorkspaceStateController(JdbcTemplate jdbc, GovernanceAccessService access) {
this.jdbc = jdbc; this.access = access;
}
@GetMapping("/api/workspace/state")
public Map<String, String> state(@AuthenticationPrincipal AppUserPrincipal actor) {
access.requireUserActivePolicy(actor);
var policy = jdbc.queryForList("SELECT detail_allowed,evidence_allowed,original_download_allowed,CAST(allowed_fields AS CHAR) AS allowed_fields,valid_until,inherit_department_children,row_version FROM user_access_policy WHERE user_id=?", actor.getId().toString());
String auth = digest(List.of(actor.getId(), actor.getRoleCodes().stream().sorted().toList(),
actor.getDepartments().stream().sorted().toList(), actor.getGroups().stream().sorted().toList(), policy));
String data = digest(List.of(
jdbc.queryForList("SELECT * FROM current_release ORDER BY dataset_id"),
jdbc.queryForList("SELECT * FROM platform_metadata ORDER BY metadata_key"),
jdbc.queryForList("SELECT id,row_version FROM target_version WHERE status='ACTIVE' ORDER BY id"),
jdbc.queryForList("SELECT * FROM query_filter_field ORDER BY field_key"),
jdbc.queryForList("SELECT id,row_version FROM service_identity ORDER BY id"),
jdbc.queryForList("SELECT * FROM service_binding ORDER BY service_type")));
return Map.of("authRevision", auth, "dataRevision", data);
}
private static String digest(Object value) {
try { return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(value.toString().getBytes(StandardCharsets.UTF_8))); }
catch (java.security.NoSuchAlgorithmException exception) { throw new IllegalStateException(exception); }
}
}