diff --git a/scripts/extract-ocr-baseline.py b/scripts/extract-ocr-baseline.py new file mode 100644 index 0000000..e5c7b6c --- /dev/null +++ b/scripts/extract-ocr-baseline.py @@ -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}") diff --git a/scripts/extract-sign-baseline.py b/scripts/extract-sign-baseline.py new file mode 100644 index 0000000..64fbc8c --- /dev/null +++ b/scripts/extract-sign-baseline.py @@ -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}") diff --git a/scripts/extract-signature-baseline.py b/scripts/extract-signature-baseline.py new file mode 100644 index 0000000..617598a --- /dev/null +++ b/scripts/extract-signature-baseline.py @@ -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}") diff --git a/scripts/ocr-baseline-samples.jsonl b/scripts/ocr-baseline-samples.jsonl new file mode 100644 index 0000000..e69de29 diff --git a/scripts/sign-baseline-samples.jsonl b/scripts/sign-baseline-samples.jsonl new file mode 100644 index 0000000..e69de29 diff --git a/scripts/signature-baseline-samples.jsonl b/scripts/signature-baseline-samples.jsonl new file mode 100644 index 0000000..e69de29 diff --git a/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/OcrFieldBuilder.java b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/OcrFieldBuilder.java new file mode 100644 index 0000000..949f8e4 --- /dev/null +++ b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/OcrFieldBuilder.java @@ -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). + * + *
对应 JNPF 设计器 jnpfKey="textOcr" / tag="JnpfOcr" (OCR 文本/证照识别). + * baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 2157-2232, commonOcrItem). + * + *
输出结构 (~36 字段 = 15 顶层 + 21 __config__): + *
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 对应 JNPF 设计器 jnpfKey="sign" / tag="JnpfSign" (手写签名).
+ * baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 1532-1561).
+ *
+ * 输出结构 (~35 字段 = 16 顶层 + 19 __config__):
+ * 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 对应 JNPF 设计器 jnpfKey="signature" / tag="JnpfSignature" (电子签章).
+ * baseline 0 sample (P2 低频) - 字段对齐权威源: JNPF 前端 componentMap.ts (line 1502-1531).
+ *
+ * 输出结构 (~32 字段 = 14 顶层 + 18 __config__):
+ * 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 校验关键结构 (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 校验关键结构 (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);
+ }
+}
diff --git a/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/SignatureFieldBuilderTest.java b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/SignatureFieldBuilderTest.java
new file mode 100644
index 0000000..805be2f
--- /dev/null
+++ b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/SignatureFieldBuilderTest.java
@@ -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).
+ *
+ * 校验关键结构 (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);
+ }
+}
+ *
+ *
+ *
+ *
+ *
+ *