Browse Source
- 新增 OnlineFormOperationEnum 枚举类,定义在线表单操作按钮类型映射关系 - 修改 OpenApiConfigServiceImpl 实现类,使用 type 字段派生操作编码替代 code 字段 - 更新 OpenApiExecServiceImpl 实现类,通过操作编码匹配启用状态验证逻辑 - 实现按钮类型到操作编码的稳定转换,解决前端表单设计器按钮改名导致匹配失效问题 - 添加未知类型回退机制,避免设计器新增按钮类型后配置流程阻塞 - 优化参数模式推导逻辑,按操作编码判断保存类操作而非按钮中文名feature/2026-08/0812-ccc-dev
3 changed files with 205 additions and 8 deletions
@ -0,0 +1,183 @@
@@ -0,0 +1,183 @@
|
||||
package apelet.common.openapi.onlineFormOperationEnum; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 在线表单操作按钮类型枚举。 |
||||
* <p>widgetJson 的 {@code pc}/{@code mobile}.operationList 中,每个按钮靠整数属性 {@code type} 区分, |
||||
* 而同一层的 {@code code} 字段目前恒为 null —— 前端表单设计器不产出它,后端快捷表单生成路径 |
||||
* (OnlineQuickForm 的 widget 构造)也只写 {@code name} 与 {@code pluginList}。 |
||||
* 因此 OpenAPI 配置的可选操作必须由 {@code type} 派生出稳定、唯一的编码,作为 |
||||
* {@code xy_sys_open_api_config.operation_code} 使用。</p> |
||||
* <p>之所以不能按 {@code name} 派生:name 是设计者可改的中文标签且可能重复,而 type 恒定唯一。 |
||||
* 例如设计者把「保存」改叫「保存草稿」,按 name 就再也匹配不上了。</p> |
||||
* |
||||
* @author chenchuchuan |
||||
* @date 2026-10-09 |
||||
*/ |
||||
public enum OnlineFormOperationEnum { |
||||
|
||||
/** |
||||
* 新建。 |
||||
*/ |
||||
CREATE(0, "create", "新建"), |
||||
/** |
||||
* 编辑。 |
||||
*/ |
||||
EDIT(1, "edit", "编辑"), |
||||
/** |
||||
* 删除。 |
||||
*/ |
||||
DELETE(2, "delete", "删除"), |
||||
/** |
||||
* 导出。 |
||||
*/ |
||||
EXPORT(3, "export", "导出"), |
||||
/** |
||||
* 导入。 |
||||
*/ |
||||
IMPORT(4, "import", "导入"), |
||||
/** |
||||
* 批量删除。 |
||||
*/ |
||||
BATCH_DELETE(10, "batchDelete", "批量删除"), |
||||
/** |
||||
* 保存。 |
||||
*/ |
||||
SAVE(30, "save", "保存"), |
||||
/** |
||||
* 上移。 |
||||
*/ |
||||
MOVE_UP(53, "moveUp", "上移"), |
||||
/** |
||||
* 下移。 |
||||
*/ |
||||
MOVE_DOWN(54, "moveDown", "下移"), |
||||
/** |
||||
* 下推。 |
||||
*/ |
||||
PUSH_DOWN(650, "pushDown", "下推"), |
||||
/** |
||||
* 上查。 |
||||
*/ |
||||
QUERY_UP(651, "queryUp", "上查"), |
||||
/** |
||||
* 下查。 |
||||
*/ |
||||
QUERY_DOWN(652, "queryDown", "下查"), |
||||
/** |
||||
* 审核。 |
||||
*/ |
||||
AUDIT(654, "audit", "审核"), |
||||
/** |
||||
* 撤销。 |
||||
*/ |
||||
REVOKE(655, "revoke", "撤销"), |
||||
/** |
||||
* 反审核。 |
||||
*/ |
||||
UNAUDIT(656, "unaudit", "反审核"), |
||||
/** |
||||
* 查看。 |
||||
*/ |
||||
VIEW(701, "view", "查看"), |
||||
/** |
||||
* 流程图。 |
||||
*/ |
||||
DIAGRAM(702, "diagram", "流程图"), |
||||
/** |
||||
* 提交。 |
||||
*/ |
||||
SUBMIT(703, "submit", "提交"), |
||||
/** |
||||
* project 导入。 |
||||
*/ |
||||
PROJECT_IMPORT(710, "projectImport", "project导入"), |
||||
/** |
||||
* project 导出。 |
||||
*/ |
||||
PROJECT_EXPORT(720, "projectExport", "project导出"); |
||||
|
||||
/** |
||||
* 未知 type 的编码前缀,回退为 type_<n>,避免设计器新增按钮类型后配置流程再次阻塞。 |
||||
*/ |
||||
private static final String UNKNOWN_CODE_PREFIX = "type_"; |
||||
|
||||
private static final Map<Integer, OnlineFormOperationEnum> TYPE_MAP = new HashMap<>(32); |
||||
|
||||
static { |
||||
for (OnlineFormOperationEnum item : values()) { |
||||
TYPE_MAP.put(item.type, item); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 按钮类型(widgetJson.operationList[].type)。 |
||||
*/ |
||||
private final Integer type; |
||||
/** |
||||
* 操作编码,作为开放接口的 operation_code 与请求路径末段。 |
||||
*/ |
||||
private final String code; |
||||
/** |
||||
* 默认显示名。 |
||||
*/ |
||||
private final String name; |
||||
|
||||
OnlineFormOperationEnum(Integer type, String code, String name) { |
||||
this.type = type; |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Integer getType() { |
||||
return type; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
/** |
||||
* 按按钮类型取枚举,未覆盖的类型返回 null。 |
||||
* |
||||
* @param type 按钮类型。 |
||||
* @return 匹配的枚举项,无匹配返回 null。 |
||||
*/ |
||||
public static OnlineFormOperationEnum ofType(Integer type) { |
||||
return type == null ? null : TYPE_MAP.get(type); |
||||
} |
||||
|
||||
/** |
||||
* 按按钮类型派生操作编码。 |
||||
* |
||||
* @param type 按钮类型。 |
||||
* @return 操作编码;type 为空返回 null,未覆盖的类型回退为 type_<n>。 |
||||
*/ |
||||
public static String codeOfType(Integer type) { |
||||
if (type == null) { |
||||
return null; |
||||
} |
||||
OnlineFormOperationEnum item = TYPE_MAP.get(type); |
||||
return item != null ? item.code : (UNKNOWN_CODE_PREFIX + type); |
||||
} |
||||
|
||||
/** |
||||
* 判断操作编码是否为保存类操作(保存 / 提交)。 |
||||
* <p>OpenAPI 的 FIELD_DIRECT 参数模式(字段直传走 executePlugin)以此为界, |
||||
* 原先靠按钮中文名 equalsAny("保存", "提交") 判断,按钮改名即失效,故改为按编码判断。</p> |
||||
* |
||||
* @param code 操作编码。 |
||||
* @return 是保存类操作返回 true。 |
||||
*/ |
||||
public static boolean isSaveLike(String code) { |
||||
return StrUtil.isNotBlank(code) && (SAVE.code.equals(code) || SUBMIT.code.equals(code)); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue