feat(converter): 机制①定制视图 delta 注入 + filterscript 级联过滤
机制①(engineclass Java delta 移植):老系统「定制视图」=数据驱动 XML 由
默认模板引擎渲染,但配 engineclass 的视图有 Java 子类在默认引擎之上加/改
按钮。转换器已复刻默认页但抓不到 Java delta——新增 EngineclassDelta 注册表
(engineclass FQN → 工具栏按钮 builder),convertGraded 增 engineclass 入参,
默认页转好后追加注入(默认页不变,仅 append);BatchConvertCli 透传
view_template.engineclass。
本轮注册 4 个 framework 定制视图:
- UserManageView:设置主岗位 + 查看用户菜单
- SystemLogMainView:按类型删除 + 全部删除
- SysUserLoginHistoryMainView:按查询条件删除记录
- SysUserLoginInfoMainView:查看登录记录(下钻登录历史)
配套后端:
- LogController(/api/admin/log/delete-all|delete-by-type|delete-by-logintime)
接 SystemLogManager;deleteByType 用 LogType 枚举白名单防注入。
- MenuController 新增 /api/admin/user/{userId}/menu(查看指定用户可见菜单树,
移植 UserRoleView,与 /api/admin/menu 共用 menuTreeFor 构建逻辑)。
filterscript 级联(P1):view_page 字段 filterscript 的「按其它字段值过滤本
字段」语义无法统一脚本引擎,故按性能优先做模式匹配——动态/常量等值绑定追加
到 select source(&COL=${TRIG}),含 SQL/服务调用/控制流/WhereClause 的复杂
脚本整条跳过(不误改);动态触发设 initFetchOn,添加态不发空参全量请求。
测试全绿(platform-converter + platform-metadata 共 490,0 失败 0 错误)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.log.service.SystemLogManager;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
/**
|
||||
* 系统日志删除端点(移植 engineclass {@code SystemLogMainView} 的删除按钮 delta)。
|
||||
*
|
||||
* <p>老系统 {@code SystemLogMainView.bindingDataView} 在默认日志列表页之上加两个按钮:
|
||||
* <ul>
|
||||
* <li>「通过类型删除」:弹窗选 {@code SystemLogManager.LogType}(Errors/Info/Debug/Warnings)→
|
||||
* {@code systemLogManager.deleteByType(value)};</li>
|
||||
* <li>「全部删除」:{@code systemLogManager.deleteAll()}。</li>
|
||||
* </ul>
|
||||
* 转换器机制① {@code EngineclassDelta} 注入对应工具栏按钮,按钮 ajax 调本端点。
|
||||
*
|
||||
* <p>{@code systemLogManager} 是 platform-legacy-core 的真实现 bean({@code @Service("systemLogManager")},
|
||||
* 与老引擎方法签名一致),构造器注入。鉴权沿用 SecurityFilterChain(JWT),与 {@link MenuController} 同惯例。
|
||||
*
|
||||
* <p>返回 amis 动作契约 {@code {status:0,msg:""}}(status=0 成功,amis 据此 toast + crud 自动重载)。
|
||||
*/
|
||||
@Tag(name = "系统日志删除", description = "移植 SystemLogMainView 删除 delta(全部删除 / 按类型删除)")
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/log")
|
||||
public class LogController {
|
||||
|
||||
private final SystemLogManager systemLogManager;
|
||||
|
||||
public LogController(SystemLogManager systemLogManager) {
|
||||
this.systemLogManager = systemLogManager;
|
||||
}
|
||||
|
||||
/** 全部删除系统日志(移植 SystemLogMainView.deleteAll)。 */
|
||||
@Operation(summary = "删除全部系统日志")
|
||||
@PostMapping("/delete-all")
|
||||
public Map<String, Object> deleteAll() {
|
||||
systemLogManager.deleteAll();
|
||||
return ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按日志类型删除(移植 SystemLogMainView.deleteByType)。
|
||||
* {@code type} 取 {@code SystemLogManager.LogType} 的 value(Errors/Info/Debug/Warnings);
|
||||
* 兼容查询参或 JSON body(amis ajax 默认 JSON body {@code {type:...}})。空类型 → 不删除(防误清全部)。
|
||||
*/
|
||||
@Operation(summary = "按类型删除系统日志")
|
||||
@PostMapping("/delete-by-type")
|
||||
public Map<String, Object> deleteByType(@RequestParam(required = false) String type,
|
||||
@RequestBody(required = false) Map<String, Object> body) {
|
||||
String t = (type != null && !type.isBlank())
|
||||
? type
|
||||
: (body != null && body.get("type") != null ? String.valueOf(body.get("type")) : null);
|
||||
if (t == null || t.isBlank()) {
|
||||
// 空类型不下推删除(避免退化成删全部);返回成功但无操作
|
||||
return ok();
|
||||
}
|
||||
// 安全白名单:仅允许 LogType 枚举值(Errors/Info/Debug/Warnings)。底层实现是字符串拼接
|
||||
// (DELETE FROM SYS_LOG WHERE TYPE='<t>'),不白名单则已认证用户可经 type 注入 → 此处用枚举闸住。
|
||||
if (SystemLogManager.LogType.getType(t.trim()) == null) {
|
||||
return ok(); // 非 LogType 枚举值 → 拒绝(不删除)
|
||||
}
|
||||
systemLogManager.deleteByType(t.trim());
|
||||
return ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按登录历史查询条件删除(移植 SysUserLoginHistoryMainView.deleteRecord → systemLogManager
|
||||
* .deleteByLoginTime(userIds, loginTimes))。读 amis crud filter 的 {@code USERID}(多选 picker,
|
||||
* 逗号串 _id)+ {@code LOGINTIME}(datetime-range,amis 默认 valueFormat=X 秒,值 "起,止")。
|
||||
*
|
||||
* <p>底层 impl:{@code DELETE FROM SYS_USERLOGIN_HISTORY WHERE 1=1 [AND USERID IN(...)]
|
||||
* [AND LOGINTIME >= / <= millis]}。<b>无任何条件 → 删除全部</b>(与老引擎一致;前端按钮带二次确认)。
|
||||
* USERID 经 {@code StringUtil.TO_STRING} 引号转义进 IN(杜绝注入),LOGINTIME 取毫秒数值。
|
||||
*/
|
||||
@Operation(summary = "按查询条件删除登录历史")
|
||||
@PostMapping("/delete-by-logintime")
|
||||
public Map<String, Object> deleteByLoginTime(@RequestBody(required = false) Map<String, Object> body) {
|
||||
List<String> userIds = body == null ? new ArrayList<>() : parseIds(body.get("USERID"));
|
||||
DateTime[] times = body == null ? null : parseRange(body.get("LOGINTIME"));
|
||||
systemLogManager.deleteByLoginTime(userIds.isEmpty() ? null : userIds, times);
|
||||
return ok();
|
||||
}
|
||||
|
||||
/** 解析 USERID:逗号串 / 数组 → List<String>(trim + 去空)。 */
|
||||
private static List<String> parseIds(Object v) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
if (v == null) {
|
||||
return ids;
|
||||
}
|
||||
if (v instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o != null && !String.valueOf(o).isBlank()) {
|
||||
ids.add(String.valueOf(o).trim());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String p : String.valueOf(v).split(",")) {
|
||||
if (!p.isBlank()) {
|
||||
ids.add(p.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** 解析 datetime-range:字符串 "起,止" / 数组 → {@code DateTime[2]}(秒/毫秒自适应)。全空 → null(不加时间条件)。 */
|
||||
private static DateTime[] parseRange(Object v) {
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
String s = String.valueOf(v).trim();
|
||||
if (s.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String[] parts = s.split(",");
|
||||
DateTime start = parts.length > 0 ? toDateTime(parts[0]) : null;
|
||||
DateTime end = parts.length > 1 ? toDateTime(parts[1]) : null;
|
||||
if (start == null && end == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime[]{start, end};
|
||||
}
|
||||
|
||||
/** 数值时间戳 → DateTime:<1e11 视为秒(×1000),否则毫秒;非数值兜底按 ISO 解析;失败 null。 */
|
||||
private static DateTime toDateTime(String x) {
|
||||
if (x == null) {
|
||||
return null;
|
||||
}
|
||||
x = x.trim();
|
||||
if (x.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
long n = Long.parseLong(x);
|
||||
if (n < 100_000_000_000L) { // 10 位秒 < 1e11 < 13 位毫秒 → 秒转毫秒
|
||||
n *= 1000L;
|
||||
}
|
||||
return new DateTime(n);
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
return new DateTime(x); // ISO 日期字符串兜底
|
||||
} catch (RuntimeException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> ok() {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("status", 0);
|
||||
m.put("msg", "");
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
@@ -62,6 +63,28 @@ public class MenuController {
|
||||
return emptyRoots();
|
||||
}
|
||||
|
||||
return menuTreeFor(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 「查看用户菜单」(移植 UserManageView.buildUserRoleBtn / UserRoleView):返回**指定用户**可见的菜单树,
|
||||
* 裁剪依据 view_sys_usermenuid(userid=该用户),与 {@link #menu()} 同一棵树构建逻辑(仅用户来源不同)。
|
||||
*
|
||||
* @param userId 目标用户 SYS_USER_ID(用户管理列表选中行主键)
|
||||
* @return {@code { roots: [...] }};空/无菜单返回空 roots
|
||||
*/
|
||||
@Operation(summary = "指定用户可见菜单树(查看用户菜单)",
|
||||
description = "裁剪依据:view_sys_usermenuid(userid=指定用户);移植自老 UserRoleView")
|
||||
@GetMapping("/api/admin/user/{userId}/menu")
|
||||
public Map<String, Object> userMenu(@PathVariable String userId) {
|
||||
if (userId == null || userId.isBlank()) {
|
||||
return emptyRoots();
|
||||
}
|
||||
return menuTreeFor(userId.trim());
|
||||
}
|
||||
|
||||
/** 按给定 userId 构建按权限裁剪的菜单树({@link #menu()} 与 {@link #userMenu} 共用)。 */
|
||||
private Map<String, Object> menuTreeFor(String userId) {
|
||||
// 2. 查询 root 列表(全量 isactive=1,按 seq 排序)
|
||||
List<Map<String, Object>> roots = jdbcTemplate.query(
|
||||
"SELECT trim(sys_menu_root_id) AS id, trim(name) AS name, seq"
|
||||
@@ -97,10 +120,10 @@ public class MenuController {
|
||||
return m;
|
||||
});
|
||||
|
||||
// 4. 计算当前用户可见叶子菜单 id 集合
|
||||
// 4. 计算该用户可见叶子菜单 id 集合
|
||||
// 超管(ADMIN):bypass 裁剪,可见集 = 全部 isactive 叶子菜单(与老框架
|
||||
// ViewMenuServiceImpl 一致——admin 不 JOIN view_sys_usermenuid,见全部菜单)。
|
||||
// 普通用户:按 view_sys_usermenuid(userid=当前用户) 裁剪。
|
||||
// 普通用户:按 view_sys_usermenuid(userid=该用户) 裁剪。
|
||||
Set<String> visibleMenuIds;
|
||||
if (isAdmin(userId)) {
|
||||
visibleMenuIds = MenuService.allLeafMenuIds(menus);
|
||||
|
||||
Reference in New Issue
Block a user