From b096e0a10dad146788c0352ae3bd66d2e4bd67d7 Mon Sep 17 00:00:00 2001 From: ssw Date: Fri, 3 Jul 2026 13:41:56 +0800 Subject: [PATCH] auto(11bf28807ce8): session end @ 2026-07-03T13:41:56 (+3f) --- .../ssw/common/service/AIRepairService.java | 14 +++++++++ .../service/impl/AIRepairServiceImpl.java | 25 +++++++++++++++- .../controller/SswAIRepairController.java | 30 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/AIRepairService.java b/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/AIRepairService.java index 7bc07b7..e69b1fd 100644 --- a/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/AIRepairService.java +++ b/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/AIRepairService.java @@ -63,4 +63,18 @@ public interface AIRepairService { * @return VisualAiModel 兼容结构: {enCode, fullName, aiModelList} */ Map inferFields(String tableName, String fieldDesc); + + /** + * v0.15+ (2026-07-03): 推理表单业务分类 (dacli form --ai / --table 通用) + * + * 根据应用名+表单名, 从可选分类列表中选最合适的. + * 不需要 LLM — 简单的 JSON 解析+匹配, 纯规则即可 (AI 过度). + * 但未来 AI 能区分更 subtle 的分类 (e.g. "采购审批" → 项目管理 vs 费用相关). + * + * @param formName 表单中文名 (如 "用户管理") + * @param appCode 应用编码 (如 "testspace") + * @param categories 可选分类列表 JSON 字符串 (如 '[{"id":"x","fullName":"车辆管理"},...]') + * @return {id, fullName} 最佳分类 (LLM 返回) + */ + Map inferCategory(String formName, String appCode, String categories); } \ No newline at end of file diff --git a/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/impl/AIRepairServiceImpl.java b/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/impl/AIRepairServiceImpl.java index bfa1a8d..f8b2978 100644 --- a/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/impl/AIRepairServiceImpl.java +++ b/ssw-common/ssw-common-biz/src/main/java/ssw/common/service/impl/AIRepairServiceImpl.java @@ -444,4 +444,27 @@ public class AIRepairServiceImpl implements AIRepairService { "- 跳过: signature/editor/uploadImg/uploadFile (只适合表单, 不适合列表展示)\n" + "- 跳过: switch/checkbox (列表搜索不合适)\n" + "\n" + - "请只返回 JSON, 不要 markdown 包裹.";} + "请只返回 JSON, 不要 markdown 包裹."; + + @Override + public Map inferCategory(String formName, String appCode, String categories) { + log.info("[AIRepair-inferCategory] form={}, app={}", formName, appCode); + String userPrompt = String.format("表单" + formName + "(应用:" + appCode + "), 可选分类: " + categories); + String raw = llmClient.chat("", userPrompt); + if (raw == null || raw.isEmpty()) { + log.warn("[AIRepair-inferCategory] LLM 返回空"); + return new HashMap<>(); + } + try { + Map result = JSON.parseObject(raw.trim(), + new TypeReference>() {}); + if (result != null && result.containsKey("fullName")) { + log.info("[AIRepair-inferCategory] AI 选择: {}", result.get("fullName")); + return result; + } + } catch (Exception e) { + log.warn("[AIRepair-inferCategory] JSON 解析失败: {}", e.getMessage()); + } + return new HashMap<>(); + } +} diff --git a/ssw-common/ssw-common-controller/src/main/java/ssw/common/controller/SswAIRepairController.java b/ssw-common/ssw-common-controller/src/main/java/ssw/common/controller/SswAIRepairController.java index 4b8bbea..bf0850e 100644 --- a/ssw-common/ssw-common-controller/src/main/java/ssw/common/controller/SswAIRepairController.java +++ b/ssw-common/ssw-common-controller/src/main/java/ssw/common/controller/SswAIRepairController.java @@ -118,4 +118,34 @@ public class SswAIRepairController { return ActionResult.fail("字段推理异常: " + e.getMessage()); } } + + /** + * v0.15+ (2026-07-03): 业务分类推理 (dacli form --ai / --table 通用) + * + * 根据表单名+应用名, 从可选分类列表中选择最合适的业务分类. + * + * 请求: {formName: "用户管理", appCode: "testspace", categories: "[{\"id\":\"x\",\"fullName\":\"车辆管理\"},...]"} + * 响应: {id: "xxx", fullName: "车辆管理"} + */ + @PostMapping("/infer-category") + @Operation(summary = "业务分类推理", description = "根据表单+应用名从可选分类中选最合适的") + public ActionResult> inferCategory(@RequestBody Map body) { + String formName = (String) body.get("formName"); + String appCode = (String) body.get("appCode"); + String categories = (String) body.get("categories"); + if (formName == null || categories == null) { + return ActionResult.fail("formName 和 categories 必填"); + } + try { + Map result = aiRepairService.inferCategory( + formName, appCode != null ? appCode : "", categories); + if (result.isEmpty() || !result.containsKey("fullName")) { + return ActionResult.fail("分类推理失败, 返回空结果"); + } + return ActionResult.success(result); + } catch (Exception e) { + log.error("SswAIRepairController.inferCategory 异常", e); + return ActionResult.fail("分类推理异常: " + e.getMessage()); + } + } } \ No newline at end of file