fix(ssw): FormRepairController ClassCastException + collectDiCategories BS-新47 + FormRepairServiceImpl Java 8 compat
This commit is contained in:
1 parent
9e66931b57
commit
e3440e037b
2 files changed
+59
-32
No files matched your search
+31
-29
@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ssw.common.service.FormRepairService;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -28,55 +29,56 @@ public class FormRepairServiceImpl implements FormRepairService {
|
||||
|
||||
// label 关键词 → jnpfKey 映射 (按顺序, 第一个命中胜出)
|
||||
// 镜像 web jnpf 控件类型全集 (jnpf-form-design/src/components/Generator/index.ts)
|
||||
// 注: Java 8 没有 Map.entry(), 用 AbstractMap.SimpleEntry 替代 (Java 9+ 才有的 Map.entry)
|
||||
private static final List<Map.Entry<Pattern, String>> LABEL_TO_JNPFKEY = new ArrayList<Map.Entry<Pattern, String>>() {{
|
||||
// 数值类
|
||||
add(Map.entry(Pattern.compile("数量|数目|个数"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("价格|金额|费用|总价|单价|工资|薪资|收入|支出"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("里程|油耗|耗油|公里"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("系数|比例|比率|百分比|百分点"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("年龄|岁数"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("分数|得分|成绩|积分"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("时长|耗时|秒数|毫秒|分钟|小时"), "inputNumber"));
|
||||
add(Map.entry(Pattern.compile("^num|count|num_|number$"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("数量|数目|个数"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("价格|金额|费用|总价|单价|工资|薪资|收入|支出"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("里程|油耗|耗油|公里"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("系数|比例|比率|百分比|百分点"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("年龄|岁数"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("分数|得分|成绩|积分"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("时长|耗时|秒数|毫秒|分钟|小时"), "inputNumber"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("^num|count|num_|number$"), "inputNumber"));
|
||||
|
||||
// 部门/组织类
|
||||
add(Map.entry(Pattern.compile("部门|组织|机构|单位|公司"), "depSelect"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("部门|组织|机构|单位|公司"), "depSelect"));
|
||||
|
||||
// 人员/用户类
|
||||
add(Map.entry(Pattern.compile("人员|用户|员工|申请人|审批人|负责人|操作人"), "userSelect"));
|
||||
add(Map.entry(Pattern.compile("姓名$|name$"), "userSelect"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("人员|用户|员工|申请人|审批人|负责人|操作人"), "userSelect"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("姓名$|name$"), "userSelect"));
|
||||
|
||||
// 日期/时间类
|
||||
add(Map.entry(Pattern.compile("日期|日$"), "datePicker"));
|
||||
add(Map.entry(Pattern.compile("时间|时刻"), "timePicker"));
|
||||
add(Map.entry(Pattern.compile("年$|月$|日$"), "datePicker"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("日期|日$"), "datePicker"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("时间|时刻"), "timePicker"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("年$|月$|日$"), "datePicker"));
|
||||
|
||||
// 联系类
|
||||
add(Map.entry(Pattern.compile("邮箱|email|邮件|mail"), "input"));
|
||||
add(Map.entry(Pattern.compile("手机|电话|phone|mobile|tel"), "input"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("邮箱|email|邮件|mail"), "input"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("手机|电话|phone|mobile|tel"), "input"));
|
||||
|
||||
// 开关/多选
|
||||
add(Map.entry(Pattern.compile("是否|开关|启用|禁用"), "switch"));
|
||||
add(Map.entry(Pattern.compile("多选|爱好|兴趣"), "checkbox"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("是否|开关|启用|禁用"), "switch"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("多选|爱好|兴趣"), "checkbox"));
|
||||
|
||||
// 文本长内容
|
||||
add(Map.entry(Pattern.compile("备注|说明|描述|详细|remark|desc|description"), "textarea"));
|
||||
add(Map.entry(Pattern.compile("内容|text|正文"), "textarea"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("备注|说明|描述|详细|remark|desc|description"), "textarea"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("内容|text|正文"), "textarea"));
|
||||
|
||||
// 选择类 (select 需字典, 这里仅标记, 字典由 form create --tables 或 NCPF AI 配)
|
||||
add(Map.entry(Pattern.compile("状态|state|status"), "select"));
|
||||
add(Map.entry(Pattern.compile("类型|分类|种类|类别"), "select"));
|
||||
add(Map.entry(Pattern.compile("性别"), "select"));
|
||||
add(Map.entry(Pattern.compile("等级|级别|优先级"), "select"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("状态|state|status"), "select"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("类型|分类|种类|类别"), "select"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("性别"), "select"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("等级|级别|优先级"), "select"));
|
||||
|
||||
// 上传/编辑器
|
||||
add(Map.entry(Pattern.compile("图片|照片|头像|封面"), "uploadImg"));
|
||||
add(Map.entry(Pattern.compile("附件|文件"), "uploadFile"));
|
||||
add(Map.entry(Pattern.compile("富文本|编辑器"), "editor"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("图片|照片|头像|封面"), "uploadImg"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("附件|文件"), "uploadFile"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("富文本|编辑器"), "editor"));
|
||||
|
||||
// 评分/颜色
|
||||
add(Map.entry(Pattern.compile("评分|星级|rate"), "rate"));
|
||||
add(Map.entry(Pattern.compile("颜色|color"), "colorPicker"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("评分|星级|rate"), "rate"));
|
||||
add(new AbstractMap.SimpleEntry<>(Pattern.compile("颜色|color"), "colorPicker"));
|
||||
}};
|
||||
|
||||
@Override
|
||||
|
||||
+28
-3
@@ -44,9 +44,24 @@ public class SswFormRepairController {
|
||||
@Operation(summary = "表单字段修复 (BS-新45)",
|
||||
description = "dacli form create --ai 后调用, 修复 type_drift (label→jnpfKey) + column_drift (F_ 前缀还原)")
|
||||
public ActionResult<Map<String, Object>> repairFields(@RequestBody Map<String, Object> body) {
|
||||
String formDataJson = (String) body.get("formData");
|
||||
String baselineLabelsJson = (String) body.get("baselineLabels");
|
||||
String baselineColumnListJson = (String) body.get("baselineColumnList");
|
||||
// 兼容 formData 为 String 或 Map (FastJSON 反序列化时可能为 Map)
|
||||
Object formDataRaw = body.get("formData");
|
||||
String formDataJson;
|
||||
if (formDataRaw instanceof String) {
|
||||
formDataJson = (String) formDataRaw;
|
||||
} else if (formDataRaw != null) {
|
||||
// 是 Map/List — 序列化回 JSON 字符串
|
||||
formDataJson = com.alibaba.fastjson.JSON.toJSONString(formDataRaw);
|
||||
} else {
|
||||
formDataJson = null;
|
||||
}
|
||||
// baselineLabels: 可能是 JSON 字符串 或 List<String>
|
||||
Object blRaw = body.get("baselineLabels");
|
||||
String baselineLabelsJson = normalizeJsonField(blRaw);
|
||||
// baselineColumnList: 可能是 JSON 字符串 或 List
|
||||
Object bcRaw = body.get("baselineColumnList");
|
||||
String baselineColumnListJson = normalizeJsonField(bcRaw);
|
||||
|
||||
if (formDataJson == null || formDataJson.isEmpty()) {
|
||||
return ActionResult.fail("formData 必填");
|
||||
}
|
||||
@@ -62,4 +77,14 @@ public class SswFormRepairController {
|
||||
return ActionResult.fail("表单修复异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把任意类型的 JSON 字段规整成 JSON 字符串.
|
||||
* 输入: String (原样), List/Map (serialize), null (null)
|
||||
*/
|
||||
private String normalizeJsonField(Object raw) {
|
||||
if (raw == null) return null;
|
||||
if (raw instanceof String) return (String) raw;
|
||||
return com.alibaba.fastjson.JSON.toJSONString(raw);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user