123 lines
5.2 KiB
Java
123 lines
5.2 KiB
Java
package ssw.dacli.menu.builder;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 按钮菜单 builder (Button, type=0)
|
|
*
|
|
* <p>JNPF 平台没有独立 "Button" type, Button 概念 = 父菜单的子节点 (add/edit/delete 等按钮权限).
|
|
* 老 JNPF 用 type=0 表示按钮, 本 builder 沿用此惯例用于按钮级权限控制场景.
|
|
*
|
|
* <p>0 误差对齐 (JNPF Form.vue line 281-291 实测, v13-f2 Task 2.6 决策):
|
|
* <ul>
|
|
* <li><b>type</b> = 0 (int, 老 JNPF Button 概念, 盲点 JNPF-30)</li>
|
|
* <li><b>category</b> = "Web" (按钮是 Web 父菜单的子节点, 跟父菜单一致)</li>
|
|
* <li><b>parentId</b> 必填 != -1 (按钮必须挂到具体菜单下, 不能是顶级)</li>
|
|
* <li><b>linkTarget</b> = "_self" (按钮不跳转, 默认 _self)</li>
|
|
* <li><b>urlAddress</b> = null (按钮无页面, 不写字段)</li>
|
|
* <li><b>pageAddress</b> = null (按钮无页面, 不写字段)</li>
|
|
* <li><b>4 authorize 字段全 0</b> (Form.vue line 287-290: type=0 不在 [2,3,4,9,11] 列表 → 全 0)</li>
|
|
* <li><b>moduleId</b> = "" (按钮无关联表单, 跟 propertyJson.moduleId 同步, 盲点 JNPF-30)</li>
|
|
* <li><b>propertyJson 3 字段</b> {moduleId:"", iconBackgroundColor:"", isTree:0} (跟 Link 一致)</li>
|
|
* <li><b>icon</b> 用户指定 (默认 "") (按钮通常无图标)</li>
|
|
* <li><b>enabledMark</b> = 1, <b>noShow</b> = 0, <b>sortCode</b> = 0 (默认)</li>
|
|
* <li><b>systemId</b> 透传 (parent menu 在子应用下)</li>
|
|
* </ul>
|
|
*
|
|
* <p>enCode 命名约定: add / edit / delete / batch / import / export / print / download / upload 等动词.
|
|
*
|
|
* <p>与 WebMenuBuilder 区别:
|
|
* <ul>
|
|
* <li><b>Web(type=1/2/3/9)</b>: 有 urlAddress/pageAddress/moduleId, 4 authorize=1</li>
|
|
* <li><b>Button</b>: 无 urlAddress/pageAddress, 4 authorize=0, type=0</li>
|
|
* </ul>
|
|
*
|
|
* <p>与 LinkMenuBuilder 区别:
|
|
* <ul>
|
|
* <li><b>Link(type=7)</b>: 有 http(s):// urlAddress, linkTarget=_blank</li>
|
|
* <li><b>Button</b>: 无 urlAddress, linkTarget=_self, type=0</li>
|
|
* </ul>
|
|
*
|
|
* @author v13-f2 Agent-F2
|
|
*/
|
|
public class ButtonMenuBuilder implements MenuBuilder {
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
@Override
|
|
public String category() {
|
|
return "Button";
|
|
}
|
|
|
|
@Override
|
|
public String buildMenuEntity(MenuBuildContext ctx) {
|
|
try {
|
|
// 1. 校验 parentId 必填且 != -1 (按钮必须挂到具体菜单下)
|
|
if (ctx.parentId == null || "-1".equals(ctx.parentId)) {
|
|
throw new IllegalArgumentException(
|
|
"Button 菜单必须挂到具体菜单下, parentId 不能是 -1 或 null, 实际: " + ctx.parentId
|
|
);
|
|
}
|
|
|
|
// 2. type=0 (int, 盲点 JNPF-30)
|
|
int type = ctx.menuType != null ? Integer.parseInt(ctx.menuType) : 0;
|
|
if (type != 0) {
|
|
throw new IllegalArgumentException(
|
|
"Button 菜单 type 必须是 0, 实际: " + type
|
|
);
|
|
}
|
|
|
|
// 3. 构造 entity (LinkedHashMap 保 key 顺序)
|
|
Map<String, Object> entity = new LinkedHashMap<>();
|
|
entity.put("fullName", ctx.name);
|
|
entity.put("enCode", ctx.enCode);
|
|
entity.put("parentId", ctx.parentId);
|
|
entity.put("category", "Web");
|
|
entity.put("type", type); // int 0, 盲点 JNPF-30
|
|
entity.put("webType", ctx.webType == 0 ? 0 : ctx.webType); // 透传 (默认 0)
|
|
entity.put("icon", ctx.icon == null ? "" : ctx.icon);
|
|
entity.put("linkTarget", "_self");
|
|
// 按钮: 不带 urlAddress / pageAddress / moduleId (留空)
|
|
|
|
// 4 authorize 字段全 0 (Form.vue line 287-290: type=0 不在 [2,3,4,9,11] → 全 0)
|
|
entity.put("isButtonAuthorize", 0);
|
|
entity.put("isColumnAuthorize", 0);
|
|
entity.put("isDataAuthorize", 0);
|
|
entity.put("isFormAuthorize", 0);
|
|
|
|
// propertyJson: 3 字段 (跟 Link 一致)
|
|
Map<String, Object> pj = new LinkedHashMap<>();
|
|
pj.put("moduleId", "");
|
|
pj.put("iconBackgroundColor", "");
|
|
pj.put("isTree", 0);
|
|
entity.put("propertyJson", mapper.writeValueAsString(pj));
|
|
|
|
// moduleId 实体字段 = "" (与 propertyJson.moduleId 一致, 盲点 JNPF-30)
|
|
entity.put("moduleId", "");
|
|
|
|
// sortCode: extra 优先, 默认 0
|
|
Object sortCodeObj = ctx.extra != null ? ctx.extra.get("sortCode") : null;
|
|
entity.put("sortCode", sortCodeObj != null ? sortCodeObj : 0);
|
|
|
|
entity.put("enabledMark", 1);
|
|
entity.put("noShow", 0);
|
|
|
|
// systemId 透传
|
|
if (ctx.extra != null && ctx.extra.get("systemId") != null) {
|
|
entity.put("systemId", ctx.extra.get("systemId"));
|
|
}
|
|
|
|
if (ctx.description != null) entity.put("description", ctx.description);
|
|
|
|
return mapper.writeValueAsString(entity);
|
|
} catch (IllegalArgumentException e) {
|
|
throw e;
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("ButtonMenuBuilder failed: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
}
|