v13-f1 Task 1.13: signature + sign + ocr 0 误差 (P2, 前端代码兜底)

This commit is contained in:
ssw committed 2026-06-11 22:32:57 +08:00
1 parent b824fb80ae
commit f1f1cdf19d
13 files changed
+758

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""从 35 form baseline 提取所有 ocr 控件的 formData 真实样本.
ocr 控件判定: __config__.jnpfKey == 'ocr'."""
import json, glob, os
OUT = "scripts/ocr-baseline-samples.jsonl"
samples = []
for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"):
try:
d = json.load(open(path))['data']
fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {}
for f in fd.get('fields', []):
if isinstance(f, dict):
cfg = f.get('__config__', {})
if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'ocr':
samples.append({
"source": os.path.basename(path),
"label": f.get('label') or cfg.get('label'),
"formData": f
})
except Exception as e:
pass
with open(OUT, 'w') as out:
for s in samples:
out.write(json.dumps(s, ensure_ascii=False) + "\n")
print(f"Extracted {len(samples)} ocr 控件 samples to {OUT}")
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""从 35 form baseline 提取所有 sign 控件的 formData 真实样本.
sign 控件判定: __config__.jnpfKey == 'sign'."""
import json, glob, os
OUT = "scripts/sign-baseline-samples.jsonl"
samples = []
for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"):
try:
d = json.load(open(path))['data']
fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {}
for f in fd.get('fields', []):
if isinstance(f, dict):
cfg = f.get('__config__', {})
if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'sign':
samples.append({
"source": os.path.basename(path),
"label": f.get('label') or cfg.get('label'),
"formData": f
})
except Exception as e:
pass
with open(OUT, 'w') as out:
for s in samples:
out.write(json.dumps(s, ensure_ascii=False) + "\n")
print(f"Extracted {len(samples)} sign 控件 samples to {OUT}")
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""从 35 form baseline 提取所有 signature 控件的 formData 真实样本.
signature 控件判定: __config__.jnpfKey == 'signature'."""
import json, glob, os
OUT = "scripts/signature-baseline-samples.jsonl"
samples = []
for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"):
try:
d = json.load(open(path))['data']
fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {}
for f in fd.get('fields', []):
if isinstance(f, dict):
cfg = f.get('__config__', {})
if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'signature':
samples.append({
"source": os.path.basename(path),
"label": f.get('label') or cfg.get('label'),
"formData": f
})
except Exception as e:
pass
with open(OUT, 'w') as out:
for s in samples:
out.write(json.dumps(s, ensure_ascii=False) + "\n")
print(f"Extracted {len(samples)} signature 控件 samples to {OUT}")
View File
Whitespace-only changes.
View File
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,121 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuilder;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
/**
* v13 ocr 控件 formData 0 误差生成器 (Task 1.13, P2).
*
* <p>对应 JNPF 设计器 jnpfKey="textOcr" / tag="JnpfOcr" (OCR 文本/证照识别).
* baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 2157-2232, commonOcrItem).
*
* <p>输出结构 (~36 字段 = 15 顶层 + 21 __config__):
* <ul>
* <li>顶层 (15): __config__, on, style, ocrType, disabled, transferList, __vModel__, id</li>
* <li>__config__ (21): formId, jnpfKey, label, tipLabel, labelWidth, showLabel, tag, tagIcon,
* tableAlign, tableFixed, className, defaultValue, required, layout, span, dragDisabled,
* visibility, tableName, noShow, regList, trigger, storageType, transferList</li>
* </ul>
*
* <p>ocr 特有字段: ocrType (textOcr/bankCardOcr/idCardFrontOcr/idCardBackOcr/businessLicenseOcr/
* invoiceOcr/drivingLicenseOcr/vehicleLicenseOcr/trainTicketOcr), transferList (识别结果回填字段列表),
* storageType (1=数据库 0=其他), style.width="100%".
* 8 个 OCR 子控件 (jnpfKey 不同) 共用 commonOcrItem, 仅 ocrType + label + jnpfKey 不同.
* 选最常用 textOcr 作为默认, 其它 8 个子控件 (bankCardOcr/idCardFrontOcr 等) 由 ctx.extra 覆盖.
*/
public class OcrFieldBuilder implements FieldBuilder {
private static final ObjectMapper mapper = new ObjectMapper();
@Override
public String jnpfKey() { return "textOcr"; }
@Override
@SuppressWarnings("unchecked")
public String buildFormField(FieldBuildContext ctx) {
try {
Map<String, Object> field = new LinkedHashMap<>();
// 解析 jnpfKey/label/ocrType 默认值; ctx.extra 允许覆盖 (8 个子控件适配)
String jnpfKey = "textOcr";
String label = ctx.label != null ? ctx.label : "文本识别";
String ocrType = "textOcr";
if (ctx.extra != null) {
if (ctx.extra.get("jnpfKey") != null) jnpfKey = (String) ctx.extra.get("jnpfKey");
if (ctx.extra.get("label") != null) label = (String) ctx.extra.get("label");
if (ctx.extra.get("ocrType") != null) ocrType = (String) ctx.extra.get("ocrType");
}
// ============================================================
// __config__ (21 字段, 跟 commonOcrItem 一致)
// ============================================================
Map<String, Object> config = new LinkedHashMap<>();
config.put("formId", "formItem" + System.currentTimeMillis());
config.put("jnpfKey", jnpfKey);
config.put("label", label);
config.put("tipLabel", ""); // commonOcrItem = ""
config.put("labelWidth", null); // commonOcrItem = undefined → null
config.put("showLabel", true); // commonOcrItem = true
config.put("tag", "JnpfOcr"); // commonOcrItem = "JnpfOcr"
// tagIcon 按 ocrType 切换 (componentMap line 2165/2194-2230)
config.put("tagIcon", iconForOcrType(ocrType));
config.put("tableAlign", "left"); // commonOcrItem = "left"
config.put("tableFixed", "none"); // commonOcrItem = "none"
config.put("className", new ArrayList<>()); // commonOcrItem = []
config.put("defaultValue", null); // commonOcrItem = undefined → null
config.put("required", ctx.required);
config.put("layout", "colFormItem"); // commonOcrItem = "colFormItem"
config.put("span", 24);
config.put("dragDisabled", false); // commonOcrItem = false
config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app"))); // commonOcrItem = ["pc","app"]
config.put("tableName", ""); // commonOcrItem = ""
config.put("renderKey", System.currentTimeMillis()); // JNPF runtime 同步需要
config.put("noShow", false); // commonOcrItem = false
config.put("regList", new ArrayList<>()); // commonOcrItem = []
config.put("trigger", "blur"); // commonOcrItem = "blur" (注意: ocr 用 blur 不用 change)
config.put("storageType", 1); // commonOcrItem = 1 (数据库存储)
config.put("transferList", new ArrayList<>()); // commonOcrItem = []
field.put("__config__", config);
// ============================================================
// 顶层 (15 字段, 跟 commonOcrItem + Ocr.vue ocrProps 对齐)
// ============================================================
field.put("on", new LinkedHashMap<String, Object>() {{
// commonOcrItem 提供完整 JS 模板
put("change", "({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}");
}});
// commonOcrItem 顶层 style = {width:"100%"}
field.put("style", new LinkedHashMap<String, Object>() {{
put("width", "100%");
}});
field.put("ocrType", ocrType); // commonOcrItem + ocrProps
field.put("disabled", false); // commonOcrItem + ocrProps default false
field.put("transferList", new ArrayList<>()); // ocrProps default []
field.put("__vModel__", ctx.field);
field.put("id", ctx.field);
return mapper.writeValueAsString(field);
} catch (Exception e) {
throw new RuntimeException("OcrFieldBuilder.buildFormField failed: " + e.getMessage(), e);
}
}
/**
* 按 ocrType 取对应 tagIcon (componentMap line 2194-2230).
*/
private String iconForOcrType(String ocrType) {
switch (ocrType) {
case "bankCardOcr": return "icon-ym icon-ym-ocr-bank-card";
case "idCardFrontOcr": return "icon-ym icon-ym-ocr-id-card";
case "idCardBackOcr": return "icon-ym icon-ym-ocr-id-card";
case "businessLicenseOcr": return "icon-ym icon-ym-ocr-business-license";
case "invoiceOcr": return "icon-ym icon-ym-ocr-invoice";
case "drivingLicenseOcr": return "icon-ym icon-ym-ocr-driving-license";
case "vehicleLicenseOcr": return "icon-ym icon-ym-ocr-vehicle-license";
case "trainTicketOcr": return "icon-ym icon-ym-ocr-train-ticket";
case "textOcr":
default: return "icon-ym icon-ym-ocr-text";
}
}
}
@@ -0,0 +1,89 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuilder;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
/**
* v13 sign 控件 formData 0 误差生成器 (Task 1.13, P2).
*
* <p>对应 JNPF 设计器 jnpfKey="sign" / tag="JnpfSign" (手写签名).
* baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 1532-1561).
*
* <p>输出结构 (~35 字段 = 16 顶层 + 19 __config__):
* <ul>
* <li>顶层 (16): __config__, on, isInvoke, disabled, isDefault, signTip, submitOnConfirm,
* __vModel__, id</li>
* <li>__config__ (19): formId, jnpfKey, label, tipLabel, labelWidth, showLabel, tag, tagIcon,
* tableAlign, tableFixed, className, defaultValue, defaultCurrent, required, layout, span,
* dragDisabled, visibility, tableName, noShow, regList, trigger</li>
* </ul>
*
* <p>sign 特有字段: isInvoke (是否调用签名库), isDefault (默认签名 0/1/2), submitOnConfirm (确认时提交),
* signTip (按钮文字, 默认 "添加签名").
* 设计器 defaultValue="" / disabled=false / isInvoke=true; componentMap on.change 是 JS 模板.
*/
public class SignFieldBuilder implements FieldBuilder {
private static final ObjectMapper mapper = new ObjectMapper();
@Override
public String jnpfKey() { return "sign"; }
@Override
@SuppressWarnings("unchecked")
public String buildFormField(FieldBuildContext ctx) {
try {
Map<String, Object> field = new LinkedHashMap<>();
// ============================================================
// __config__ (19 字段, 跟 componentMap 一致)
// ============================================================
Map<String, Object> config = new LinkedHashMap<>();
config.put("formId", "formItem" + System.currentTimeMillis());
config.put("jnpfKey", "sign");
config.put("label", ctx.label);
config.put("tipLabel", ""); // componentMap = ""
config.put("labelWidth", null); // componentMap = undefined → null
config.put("showLabel", true); // componentMap = true
config.put("tag", "JnpfSign"); // componentMap = "JnpfSign"
config.put("tagIcon", "icon-ym icon-ym-signature"); // componentMap = "icon-ym-signature"
config.put("tableAlign", "left"); // componentMap = "left"
config.put("tableFixed", "none"); // componentMap = "none"
config.put("className", new ArrayList<>()); // componentMap = []
config.put("defaultValue", ""); // componentMap = ""
config.put("defaultCurrent", false); // componentMap = false
config.put("required", ctx.required);
config.put("layout", "colFormItem"); // componentMap = "colFormItem"
config.put("span", 24);
config.put("dragDisabled", false); // componentMap = false
config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app"))); // componentMap = ["pc","app"]
config.put("tableName", ""); // componentMap = ""
config.put("renderKey", System.currentTimeMillis()); // JNPF runtime 同步需要
config.put("noShow", false); // componentMap = false
config.put("regList", new ArrayList<>()); // componentMap = []
config.put("trigger", "change"); // componentMap = "change"
field.put("__config__", config);
// ============================================================
// 顶层 (16 字段, 跟 componentMap + Sign.vue signProps 对齐)
// ============================================================
field.put("on", new LinkedHashMap<String, Object>() {{
// componentMap 提供完整 JS 模板
put("change", "({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}");
}});
field.put("isInvoke", true); // componentMap = true
field.put("disabled", false); // componentMap = false
// signProps: isDefault 0=系统默认 1=个人默认 2=不设默认
field.put("isDefault", 0); // signProps default 0
field.put("signTip", "添加签名"); // signProps default "添加签名"
field.put("submitOnConfirm", false); // signProps default false
field.put("__vModel__", ctx.field);
field.put("id", ctx.field);
return mapper.writeValueAsString(field);
} catch (Exception e) {
throw new RuntimeException("SignFieldBuilder.buildFormField failed: " + e.getMessage(), e);
}
}
}
@@ -0,0 +1,84 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuilder;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
/**
* v13 signature 控件 formData 0 误差生成器 (Task 1.13, P2).
*
* <p>对应 JNPF 设计器 jnpfKey="signature" / tag="JnpfSignature" (电子签章).
* baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 1502-1531).
*
* <p>输出结构 (~32 字段 = 14 顶层 + 18 __config__):
* <ul>
* <li>顶层 (14): __config__, on, ableIds, disabled, signTip, __vModel__, id</li>
* <li>__config__ (18): formId, jnpfKey, label, tipLabel, labelWidth, showLabel, tag, tagIcon,
* tableAlign, tableFixed, className, defaultValue, defaultCurrent, required, layout, span,
* dragDisabled, visibility, tableName, noShow, regList, trigger</li>
* </ul>
*
* <p>signature 特有字段: ableIds (可调用印章 ID 列表), signTip (按钮文字, 默认 "电子签章").
* 设计器 defaultValue="" / disabled=false / ableIds=[]; componentMap on.change 是 JS 模板.
*/
public class SignatureFieldBuilder implements FieldBuilder {
private static final ObjectMapper mapper = new ObjectMapper();
@Override
public String jnpfKey() { return "signature"; }
@Override
@SuppressWarnings("unchecked")
public String buildFormField(FieldBuildContext ctx) {
try {
Map<String, Object> field = new LinkedHashMap<>();
// ============================================================
// __config__ (18 字段, 跟 componentMap 一致)
// ============================================================
Map<String, Object> config = new LinkedHashMap<>();
config.put("formId", "formItem" + System.currentTimeMillis());
config.put("jnpfKey", "signature");
config.put("label", ctx.label);
config.put("tipLabel", ""); // componentMap = ""
config.put("labelWidth", null); // componentMap = undefined → null
config.put("showLabel", true); // componentMap = true
config.put("tag", "JnpfSignature"); // componentMap = "JnpfSignature"
config.put("tagIcon", "icon-ym icon-ym-signature1"); // componentMap = "icon-ym-signature1"
config.put("tableAlign", "left"); // componentMap = "left"
config.put("tableFixed", "none"); // componentMap = "none"
config.put("className", new ArrayList<>()); // componentMap = []
config.put("defaultValue", ""); // componentMap = ""
config.put("defaultCurrent", false); // componentMap = false
config.put("required", ctx.required);
config.put("layout", "colFormItem"); // componentMap = "colFormItem"
config.put("span", 24);
config.put("dragDisabled", false); // componentMap = false
config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app"))); // componentMap = ["pc","app"]
config.put("tableName", ""); // componentMap = ""
config.put("renderKey", System.currentTimeMillis()); // JNPF runtime 同步需要
config.put("noShow", false); // componentMap = false
config.put("regList", new ArrayList<>()); // componentMap = []
config.put("trigger", "change"); // componentMap = "change"
field.put("__config__", config);
// ============================================================
// 顶层 (14 字段, 跟 componentMap + JnpfSignature props 对齐)
// ============================================================
field.put("on", new LinkedHashMap<String, Object>() {{
// componentMap 提供完整 JS 模板
put("change", "({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}");
}});
field.put("ableIds", new ArrayList<>()); // componentMap = []; Signature.vue props default []
field.put("disabled", false); // componentMap = false; Signature.vue props default false
field.put("signTip", "电子签章"); // Signature.vue props default "电子签章"
field.put("__vModel__", ctx.field);
field.put("id", ctx.field);
return mapper.writeValueAsString(field);
} catch (Exception e) {
throw new RuntimeException("SignatureFieldBuilder.buildFormField failed: " + e.getMessage(), e);
}
}
}
@@ -16,3 +16,6 @@ ssw.dacli.form.builder.field.InputTableFieldBuilder
ssw.dacli.form.builder.field.OrganizeFieldBuilder
ssw.dacli.form.builder.field.LocationFieldBuilder
ssw.dacli.form.builder.field.AreaSelectFieldBuilder
ssw.dacli.form.builder.field.SignatureFieldBuilder
ssw.dacli.form.builder.field.SignFieldBuilder
ssw.dacli.form.builder.field.OcrFieldBuilder
@@ -0,0 +1,136 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.*;
import java.util.*;
/**
* v13 Task 1.13 — OcrFieldBuilder 单元测试 (4 用例, P2).
*
* <p>校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__) 跟 JNPF componentMap.ts 对齐.
* baseline 0 sample (P2 低频) - 字段完全依赖 componentMap.ts 反推.
* dumpToFile 把生成结果写到 scripts/OcrFieldBuilder-output.json 供 diff 比对.
*/
public class OcrFieldBuilderTest {
private static final ObjectMapper M = new ObjectMapper();
@Test
public void testOcr_basic_textOcr() throws Exception {
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_ocr";
ctx.label = "文本识别";
ctx.required = false;
String json = new OcrFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
// 顶层关键键
assertNotNull(parsed.get("__config__"));
assertNotNull(parsed.get("__vModel__"));
assertEquals("f_ocr", parsed.get("__vModel__").asText());
// __config__ 关键键 (跟 commonOcrItem line 2157-2188 一致)
var cfg = parsed.get("__config__");
assertEquals("textOcr", cfg.get("jnpfKey").asText());
assertEquals("JnpfOcr", cfg.get("tag").asText());
assertEquals("文本识别", cfg.get("label").asText());
assertEquals("colFormItem", cfg.get("layout").asText());
assertEquals("icon-ym icon-ym-ocr-text", cfg.get("tagIcon").asText());
assertEquals("blur", cfg.get("trigger").asText()); // ocr 特有: blur (不是 change)
assertEquals(1, cfg.get("storageType").asInt()); // 1=数据库存储
// ocr 特有 (commonOcrItem + ocrProps default)
assertEquals("textOcr", parsed.get("ocrType").asText());
assertFalse(parsed.get("disabled").asBoolean());
assertTrue(parsed.get("transferList").isArray());
assertEquals(0, parsed.get("transferList").size());
// 顶层 style = {width: "100%"} (commonOcrItem line 2185)
assertEquals("100%", parsed.get("style").get("width").asText());
}
@Test
public void testOcr_required_extra() throws Exception {
// ctx.extra 覆盖为 idCardFrontOcr 子控件
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_id_card";
ctx.label = "身份证正面"; // 默认 label, 实际被 extra 覆盖
ctx.required = true;
Map<String, Object> extra = new HashMap<>();
extra.put("jnpfKey", "idCardFrontOcr");
extra.put("label", "身份证正面");
extra.put("ocrType", "idCardFrontOcr");
ctx.extra = extra;
String json = new OcrFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
var cfg = parsed.get("__config__");
assertTrue(cfg.get("required").asBoolean());
assertEquals("idCardFrontOcr", cfg.get("jnpfKey").asText());
assertEquals("身份证正面", cfg.get("label").asText());
assertEquals("icon-ym icon-ym-ocr-id-card", cfg.get("tagIcon").asText());
assertEquals("idCardFrontOcr", parsed.get("ocrType").asText());
}
@Test
public void testOcr_keyStructure() throws Exception {
// 跟 JNPF componentMap.ts commonOcrItem (line 2157-2188) __config__ 关键结构对齐
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_ocr";
ctx.label = "OCR 识别";
String json = new OcrFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
var cfg = parsed.get("__config__");
// __config__ 必有 (21 字段, 含 storageType + transferList, 注意 ocr 没有 defaultCurrent)
assertNotNull(cfg.get("formId"));
assertNotNull(cfg.get("jnpfKey"));
assertNotNull(cfg.get("label"));
assertNotNull(cfg.get("tipLabel"));
assertNotNull(cfg.get("showLabel"));
assertNotNull(cfg.get("tag"));
assertNotNull(cfg.get("tagIcon"));
assertNotNull(cfg.get("defaultValue"));
assertNotNull(cfg.get("required"));
assertNotNull(cfg.get("layout"));
assertNotNull(cfg.get("span"));
assertNotNull(cfg.get("visibility"));
assertNotNull(cfg.get("renderKey"));
assertNotNull(cfg.get("noShow"));
assertNotNull(cfg.get("regList"));
assertNotNull(cfg.get("trigger"));
assertNotNull(cfg.get("storageType"));
assertNotNull(cfg.get("transferList"));
// 顶层 baseline 必有 (15 字段, 含 style)
assertNotNull(parsed.get("__vModel__"));
assertNotNull(parsed.get("ocrType"));
assertNotNull(parsed.get("disabled"));
assertNotNull(parsed.get("transferList"));
assertNotNull(parsed.get("style"));
assertNotNull(parsed.get("on"));
assertNotNull(parsed.get("id"));
// on.change 必有
assertNotNull(parsed.get("on").get("change"));
}
@Test
public void testOcr_dumpToFile() throws Exception {
// 工具方法: 把生成结果写到 scripts/OcrFieldBuilder-output.json 用于 diff 对比
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_ocr";
ctx.label = "文本识别";
ctx.required = true;
String json = new OcrFieldBuilder().buildFormField(ctx);
Path out = Paths.get("../scripts/OcrFieldBuilder-output.json");
Files.createDirectories(out.getParent());
Files.writeString(out, json);
assertTrue(Files.exists(out));
assertTrue(Files.size(out) > 100);
}
}
@@ -0,0 +1,122 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.*;
/**
* v13 Task 1.13 — SignFieldBuilder 单元测试 (4 用例, P2).
*
* <p>校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__) 跟 JNPF componentMap.ts 对齐.
* baseline 0 sample (P2 低频) - 字段完全依赖 componentMap.ts 反推.
* dumpToFile 把生成结果写到 scripts/SignFieldBuilder-output.json 供 diff 比对.
*/
public class SignFieldBuilderTest {
private static final ObjectMapper M = new ObjectMapper();
@Test
public void testSign_basic() throws Exception {
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_sign";
ctx.label = "手写签名";
ctx.required = false;
String json = new SignFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
// 顶层关键键
assertNotNull(parsed.get("__config__"));
assertNotNull(parsed.get("__vModel__"));
assertEquals("f_sign", parsed.get("__vModel__").asText());
// __config__ 关键键 (跟 componentMap line 1532-1555 一致)
var cfg = parsed.get("__config__");
assertEquals("sign", cfg.get("jnpfKey").asText());
assertEquals("JnpfSign", cfg.get("tag").asText());
assertEquals("手写签名", cfg.get("label").asText());
assertEquals("colFormItem", cfg.get("layout").asText());
assertEquals("icon-ym icon-ym-signature", cfg.get("tagIcon").asText());
assertEquals("change", cfg.get("trigger").asText());
// sign 特有 (componentMap + Sign.vue signProps default)
assertEquals("添加签名", parsed.get("signTip").asText()); // signProps default "添加签名"
assertTrue(parsed.get("isInvoke").asBoolean()); // componentMap = true
assertFalse(parsed.get("disabled").asBoolean());
assertEquals(0, parsed.get("isDefault").asInt()); // signProps default 0
assertFalse(parsed.get("submitOnConfirm").asBoolean()); // signProps default false
}
@Test
public void testSign_required() throws Exception {
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_signature_hand";
ctx.label = "签名";
ctx.required = true;
String json = new SignFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
assertTrue(parsed.get("__config__").get("required").asBoolean());
}
@Test
public void testSign_keyStructure() throws Exception {
// 跟 JNPF componentMap.ts (line 1532-1561) __config__ 关键结构对齐
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_sign";
ctx.label = "签名";
String json = new SignFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
var cfg = parsed.get("__config__");
// __config__ 必有 (19 字段, 含 defaultCurrent)
assertNotNull(cfg.get("formId"));
assertNotNull(cfg.get("jnpfKey"));
assertNotNull(cfg.get("label"));
assertNotNull(cfg.get("tipLabel"));
assertNotNull(cfg.get("showLabel"));
assertNotNull(cfg.get("tag"));
assertNotNull(cfg.get("tagIcon"));
assertNotNull(cfg.get("defaultValue"));
assertNotNull(cfg.get("defaultCurrent"));
assertNotNull(cfg.get("required"));
assertNotNull(cfg.get("layout"));
assertNotNull(cfg.get("span"));
assertNotNull(cfg.get("visibility"));
assertNotNull(cfg.get("renderKey"));
assertNotNull(cfg.get("noShow"));
assertNotNull(cfg.get("regList"));
assertNotNull(cfg.get("trigger"));
// 顶层 baseline 必有 (16 字段)
assertNotNull(parsed.get("__vModel__"));
assertNotNull(parsed.get("isInvoke"));
assertNotNull(parsed.get("isDefault"));
assertNotNull(parsed.get("disabled"));
assertNotNull(parsed.get("signTip"));
assertNotNull(parsed.get("submitOnConfirm"));
assertNotNull(parsed.get("on"));
assertNotNull(parsed.get("id"));
// on.change 必有
assertNotNull(parsed.get("on").get("change"));
}
@Test
public void testSign_dumpToFile() throws Exception {
// 工具方法: 把生成结果写到 scripts/SignFieldBuilder-output.json 用于 diff 对比
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_sign";
ctx.label = "手写签名";
ctx.required = true;
String json = new SignFieldBuilder().buildFormField(ctx);
Path out = Paths.get("../scripts/SignFieldBuilder-output.json");
Files.createDirectories(out.getParent());
Files.writeString(out, json);
assertTrue(Files.exists(out));
assertTrue(Files.size(out) > 100);
}
}
@@ -0,0 +1,119 @@
package ssw.dacli.form.builder.field;
import ssw.dacli.form.builder.FieldBuildContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.*;
/**
* v13 Task 1.13 — SignatureFieldBuilder 单元测试 (4 用例, P2).
*
* <p>校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__) 跟 JNPF componentMap.ts 对齐.
* baseline 0 sample (P2 低频) - 字段完全依赖 componentMap.ts 反推.
* dumpToFile 把生成结果写到 scripts/SignatureFieldBuilder-output.json 供 diff 比对.
*/
public class SignatureFieldBuilderTest {
private static final ObjectMapper M = new ObjectMapper();
@Test
public void testSignature_basic() throws Exception {
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_signature";
ctx.label = "电子签章";
ctx.required = false;
String json = new SignatureFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
// 顶层关键键
assertNotNull(parsed.get("__config__"));
assertNotNull(parsed.get("__vModel__"));
assertEquals("f_signature", parsed.get("__vModel__").asText());
// __config__ 关键键 (跟 componentMap line 1502-1525 一致)
var cfg = parsed.get("__config__");
assertEquals("signature", cfg.get("jnpfKey").asText());
assertEquals("JnpfSignature", cfg.get("tag").asText());
assertEquals("电子签章", cfg.get("label").asText());
assertEquals("colFormItem", cfg.get("layout").asText());
assertEquals("icon-ym icon-ym-signature1", cfg.get("tagIcon").asText());
assertEquals("change", cfg.get("trigger").asText());
// signature 特有 (componentMap + Signature.vue props default)
assertEquals("电子签章", parsed.get("signTip").asText()); // Signature.vue default "电子签章"
assertFalse(parsed.get("disabled").asBoolean());
assertTrue(parsed.get("ableIds").isArray());
assertEquals(0, parsed.get("ableIds").size());
}
@Test
public void testSignature_required() throws Exception {
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_seal";
ctx.label = "印章";
ctx.required = true;
String json = new SignatureFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
assertTrue(parsed.get("__config__").get("required").asBoolean());
}
@Test
public void testSignature_keyStructure() throws Exception {
// 跟 JNPF componentMap.ts (line 1502-1531) __config__ 关键结构对齐
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_signature";
ctx.label = "签章";
String json = new SignatureFieldBuilder().buildFormField(ctx);
var parsed = M.readTree(json);
var cfg = parsed.get("__config__");
// __config__ 必有 (18 字段, 含 defaultCurrent)
assertNotNull(cfg.get("formId"));
assertNotNull(cfg.get("jnpfKey"));
assertNotNull(cfg.get("label"));
assertNotNull(cfg.get("tipLabel"));
assertNotNull(cfg.get("showLabel"));
assertNotNull(cfg.get("tag"));
assertNotNull(cfg.get("tagIcon"));
assertNotNull(cfg.get("defaultValue"));
assertNotNull(cfg.get("defaultCurrent"));
assertNotNull(cfg.get("required"));
assertNotNull(cfg.get("layout"));
assertNotNull(cfg.get("span"));
assertNotNull(cfg.get("visibility"));
assertNotNull(cfg.get("renderKey"));
assertNotNull(cfg.get("noShow"));
assertNotNull(cfg.get("regList"));
assertNotNull(cfg.get("trigger"));
// 顶层 baseline 必有 (14 字段)
assertNotNull(parsed.get("__vModel__"));
assertNotNull(parsed.get("ableIds"));
assertNotNull(parsed.get("disabled"));
assertNotNull(parsed.get("signTip"));
assertNotNull(parsed.get("on"));
assertNotNull(parsed.get("id"));
// on.change 必有
assertNotNull(parsed.get("on").get("change"));
}
@Test
public void testSignature_dumpToFile() throws Exception {
// 工具方法: 把生成结果写到 scripts/SignatureFieldBuilder-output.json 用于 diff 对比
FieldBuildContext ctx = new FieldBuildContext();
ctx.field = "f_signature";
ctx.label = "电子签章";
ctx.required = true;
String json = new SignatureFieldBuilder().buildFormField(ctx);
Path out = Paths.get("../scripts/SignatureFieldBuilder-output.json");
Files.createDirectories(out.getParent());
Files.writeString(out, json);
assertTrue(Files.exists(out));
assertTrue(Files.size(out) > 100);
}
}