|
|
@@ -1,428 +0,0 @@
|
|
|
-package com.zsjz.ai.module.agent.tools;
|
|
|
-
|
|
|
-import com.zsjz.ai.common.base.Query;
|
|
|
-import com.zsjz.ai.common.enums.SymbolEnum;
|
|
|
-import com.zsjz.ai.common.enums.TimeSeriesTypeEnum;
|
|
|
-import com.zsjz.ai.common.model.otg.dto.SearchDTO;
|
|
|
-import com.zsjz.ai.common.model.otg.entity.SpecialDateRecord;
|
|
|
-import com.zsjz.ai.common.model.otg.entity.TimeSeries;
|
|
|
-import com.zsjz.ai.common.model.otg.query.TimeSeriesQuery;
|
|
|
-import com.zsjz.ai.common.utils.Json;
|
|
|
-import com.zsjz.ai.module.agent.sql.SqlResultStore;
|
|
|
-import com.zsjz.ai.module.otg.service.SearchService;
|
|
|
-import com.zsjz.ai.module.otg.service.SpecialDateService;
|
|
|
-import com.zsjz.ai.module.otg.service.TimeSeriesService;
|
|
|
-import io.agentscope.core.message.ToolResultBlock;
|
|
|
-import io.agentscope.core.tool.Tool;
|
|
|
-import io.agentscope.core.tool.ToolParam;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.format.DateTimeParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.LinkedHashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-/**
|
|
|
- * 行为时空 / 全文检索类 Agent 工具集(5 个工具),把 {@code module/otg} 下既有的<b>只读</b>业务方法
|
|
|
- * 暴露给 Agent。
|
|
|
- *
|
|
|
- * <p><b>设计要点:</b>
|
|
|
- * <ul>
|
|
|
- * <li><b>只做适配,不重写业务</b>:全部取数仍走 {@link SearchService} /
|
|
|
- * {@link SpecialDateService} / {@link TimeSeriesService},与前端 HTTP 接口用的是同一套
|
|
|
- * SQL 与同一套口径(例如时间轴 SQL 内置的 {@code limit 20}、跳转的 rowid ±10)。
|
|
|
- * 这样「页面上看到的」与「AI 说的」不会打架。</li>
|
|
|
- * <li><b>写操作一律不封装</b>:{@code SpecialDateService} 的 {@code create} / {@code update} /
|
|
|
- * {@code delete} 会改数据,明确排除在本工具集之外。</li>
|
|
|
- * <li><b>返回形态复用 resultId 分页契约</b>:结果写入 {@link SqlResultStore} 后返回
|
|
|
- * {@code {resultId, columns, rows, page, pageSize, totalRows, totalPages}},
|
|
|
- * 与 {@code execute_sql} 完全一致,前端 {@code DataTableBlock} 直接渲染可翻页表格。</li>
|
|
|
- * <li><b>入参是专用 POJO</b>({@link OtgToolSpecs}):不把 {@code Query} 基类的
|
|
|
- * {@code orderKey}/{@code sort}/{@code tableName} 暴露给模型,避免 ORDER BY 拼接注入面。</li>
|
|
|
- * <li>工具是普通类(非 Spring Bean),由 {@code AgentService#buildAgent} 手工 new 出来注册,
|
|
|
- * 与 {@link CallAnalysisTool} 一致。</li>
|
|
|
- * </ul>
|
|
|
- *
|
|
|
- * <p>数据源:{@link TimeSeriesService} / {@link SpecialDateService} 底下的 mapper 标了
|
|
|
- * {@code @DS("slave")}(当前案件的 DuckDB),与 {@code execute_sql} 同库;{@link SearchService}
|
|
|
- * 走的是案件级 Lucene 索引,无需额外处理。
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-public class OtgAnalysisTool {
|
|
|
-
|
|
|
- /**
|
|
|
- * 单次取数行数上限。
|
|
|
- *
|
|
|
- * <p>与 {@code execute_sql} 的 100000 行硬上限不同,这里刻意压到 1 万:
|
|
|
- * {@link SqlResultStore} 是 LRU 50 条 / TTL 30 分钟的<b>进程级共享</b>缓存,
|
|
|
- * 明细动辄上万行,放太宽会把 {@code execute_sql} 的结果挤掉。
|
|
|
- * 超限时返回可读报错让模型收窄条件,而不是悄悄截断(截断会让模型得出错误结论)。
|
|
|
- */
|
|
|
- private static final int FETCH_LIMIT = 10_000;
|
|
|
-
|
|
|
- private final SearchService searchService;
|
|
|
- private final SpecialDateService specialDateService;
|
|
|
- private final TimeSeriesService timeSeriesService;
|
|
|
- private final SqlResultStore sqlResultStore;
|
|
|
-
|
|
|
- public OtgAnalysisTool(SearchService searchService,
|
|
|
- SpecialDateService specialDateService,
|
|
|
- TimeSeriesService timeSeriesService,
|
|
|
- SqlResultStore sqlResultStore) {
|
|
|
- this.searchService = searchService;
|
|
|
- this.specialDateService = specialDateService;
|
|
|
- this.timeSeriesService = timeSeriesService;
|
|
|
- this.sqlResultStore = sqlResultStore;
|
|
|
- }
|
|
|
-
|
|
|
- // ==================== 工具定义 ====================
|
|
|
-
|
|
|
- /**
|
|
|
- * 案件材料全文检索
|
|
|
- */
|
|
|
- @Tool(name = "search_global",
|
|
|
- description = "对当前案件已建立的全文索引做关键词检索(Lucene 通配模糊匹配),"
|
|
|
- + "用于回答「这个关键词出现在哪些材料里、原文是怎么写的」。"
|
|
|
- + "返回文件名、Sheet 名、来源表名、时间与命中的原文片段,"
|
|
|
- + "其中 content 列里用 <em class=\"search-highlight\"> 标记了命中的关键词。"
|
|
|
- + "★ 问「哪个文件/哪份材料里提到过某某」「某某在原文里出现过吗」时用本工具。"
|
|
|
- + "keyword 必填且不能为空白,支持姓名、号码、卡号等任意文本,按内容模糊匹配(两侧自动加通配符,"
|
|
|
- + "所以关键词越具体越准,不要只传一个字)。"
|
|
|
- + "注意:本工具查的是「原文内容」,不是结构化字段 —— 要按字段条件筛选、聚合、排序、统计时,"
|
|
|
- + "请改用 execute_sql 或对应的业务统计工具。结果以可翻页表格返回(最多 500 行)。",
|
|
|
- readOnly = true)
|
|
|
- public ToolResultBlock searchGlobal(
|
|
|
- @ToolParam(name = "keyword",
|
|
|
- description = "检索关键词(必填,不能为空白);姓名、号码、卡号、地名等均可,按内容模糊匹配",
|
|
|
- required = true)
|
|
|
- String keyword) {
|
|
|
- String text = trimToNull(keyword);
|
|
|
- if (text == null) {
|
|
|
- return ToolResults.error("keyword 不能为空");
|
|
|
- }
|
|
|
- try {
|
|
|
- List<SearchDTO> list = searchService.search(text);
|
|
|
- if (list != null && list.size() > FETCH_LIMIT) {
|
|
|
- return overLimit(list.size());
|
|
|
- }
|
|
|
- return ToolResultTable.store(sqlResultStore, null, list, 1,
|
|
|
- ToolResultTable.normalizePageSize(null));
|
|
|
- } catch (Exception e) {
|
|
|
- return fail("全文检索", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 案件配置的特殊日期清单
|
|
|
- */
|
|
|
- @Tool(name = "list_special_dates",
|
|
|
- description = "列出当前案件配置的全部「特殊日期 / 敏感日期」(用户添加的与内置的都在内)。"
|
|
|
- + "返回每条日期的名称(name)、公历或农历(type:0 公历、1 农历)、前后间隔天数(gap)、"
|
|
|
- + "日期(spDate,MM-dd 形式)、是否为内置(flag:0 内置、1 用户添加)。"
|
|
|
- + "★ 问「案件配置了哪些特殊日期」「敏感日期/节假日有哪些」「某个节日是哪天」时用本工具,"
|
|
|
- + "不要用 execute_sql 去查 special_date_reord 表。"
|
|
|
- + "本工具只读、无入参。"
|
|
|
- + "拿到日期清单后,若要分析这些日期内谁和谁联系过,请接着用 stat_call_sensitive_summary / "
|
|
|
- + "stat_call_sensitive_detail。",
|
|
|
- readOnly = true)
|
|
|
- public ToolResultBlock listSpecialDates() {
|
|
|
- try {
|
|
|
- List<SpecialDateRecord> list = specialDateService.listRecord();
|
|
|
- if (list != null && list.size() > FETCH_LIMIT) {
|
|
|
- return overLimit(list.size());
|
|
|
- }
|
|
|
- return ToolResultTable.store(sqlResultStore, null, list, 1,
|
|
|
- ToolResultTable.normalizePageSize(null));
|
|
|
- } catch (Exception e) {
|
|
|
- return fail("特殊日期列表查询", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 行为时间轴列表
|
|
|
- */
|
|
|
- @Tool(name = "get_time_series",
|
|
|
- description = "查询案件行为时间轴(time_series_info 表):把某人的通话、交易、轨迹等行为按时间排成一条轴,"
|
|
|
- + "返回所属来源表英文名/中文名、人员、行为时间 seriesDateTime 以及 ext1~ext9 扩展字段。"
|
|
|
- + "★ 问「某人的行为时间轴」「某段时间内某人有哪些行为/轨迹点」「行为时空」时用本工具。"
|
|
|
- + "可按 personNames(人员,多个 OR)、types(TRANS 交易 / CALL 通信 / TRACK 轨迹)、"
|
|
|
- + "startDate、endDate、hasLocal(Y 表示只要带本地坐标的记录)筛选。"
|
|
|
- + "本工具一次最多返回 20 行(SQL 内置 limit 20),按时间轴行号升序;"
|
|
|
- + "要往后翻页就把上一页最后一行的 rowId 作为 rowId 传入(rowIdSymbol 默认 GT),向前翻传 LT/LE。"
|
|
|
- + "所有条件都不传只会返回最早 20 行,意义不大,建议至少给出 personNames 或日期范围。"
|
|
|
- + "拿到某行的 id 与 tableNameEn 后,用 get_time_series_detail 看该行完整字段,"
|
|
|
- + "用 jump_time_series 看它前后的相邻行为。",
|
|
|
- readOnly = true)
|
|
|
- public ToolResultBlock getTimeSeries(
|
|
|
- @ToolParam(name = "query", description = "行为时间轴筛选条件,字段全部可选")
|
|
|
- OtgToolSpecs.TimeSeriesListSpec query) {
|
|
|
- OtgToolSpecs.TimeSeriesListSpec spec =
|
|
|
- query == null ? new OtgToolSpecs.TimeSeriesListSpec() : query;
|
|
|
- try {
|
|
|
- TimeSeriesQuery q = new TimeSeriesQuery();
|
|
|
- q.setPersonNames(cleanList(spec.personNames));
|
|
|
- q.setTypes(parseTypes(spec.types));
|
|
|
- q.setHasLocal(parseHasLocal(spec.hasLocal));
|
|
|
- q.setRowId(longOrNull(spec.rowId));
|
|
|
- q.setRowIdSymbol(parseSymbol(spec.rowIdSymbol));
|
|
|
- q.setStartDate(parseDate(spec.startDate, "startDate"));
|
|
|
- q.setEndDate(parseDate(spec.endDate, "endDate"));
|
|
|
- applyFetchWindow(q);
|
|
|
-
|
|
|
- List<TimeSeries> list = timeSeriesService.getTimeSeries(q);
|
|
|
- if (list != null && list.size() > FETCH_LIMIT) {
|
|
|
- return overLimit(list.size());
|
|
|
- }
|
|
|
- return ToolResultTable.store(sqlResultStore, null, list, 1,
|
|
|
- ToolResultTable.normalizePageSize(spec.pageSize));
|
|
|
- } catch (Exception e) {
|
|
|
- return fail("行为时间轴查询", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 行为时间轴相邻记录(跳转)
|
|
|
- */
|
|
|
- @Tool(name = "jump_time_series",
|
|
|
- description = "以时间轴上的某条记录为锚点,返回它在时间轴上前后各 10 条相邻记录(共最多 21 条),"
|
|
|
- + "用于回答「这条行为前后还发生了什么」。"
|
|
|
- + "★ 必须传 id —— 取 get_time_series 结果里的 id 列。"
|
|
|
- + "startDate / endDate 可选,仅用于限定锚点记录的日期;一般不用传,"
|
|
|
- + "传了却在范围内找不到该 id 会返回空结果。"
|
|
|
- + "若要查看某条记录的完整明细字段,请改用 get_time_series_detail。",
|
|
|
- readOnly = true)
|
|
|
- public ToolResultBlock jumpTimeSeries(
|
|
|
- @ToolParam(name = "query", description = "跳转锚点参数,id 必填")
|
|
|
- OtgToolSpecs.TimeSeriesJumpSpec query) {
|
|
|
- OtgToolSpecs.TimeSeriesJumpSpec spec =
|
|
|
- query == null ? new OtgToolSpecs.TimeSeriesJumpSpec() : query;
|
|
|
- try {
|
|
|
- Long id = longOrNull(spec.id);
|
|
|
- if (id == null) {
|
|
|
- return ToolResults.error("id 不能为空:请先用 get_time_series 查询时间轴并取其 id 列");
|
|
|
- }
|
|
|
- TimeSeriesQuery q = new TimeSeriesQuery();
|
|
|
- q.setId(id);
|
|
|
- q.setStartDate(parseDate(spec.startDate, "startDate"));
|
|
|
- q.setEndDate(parseDate(spec.endDate, "endDate"));
|
|
|
- applyFetchWindow(q);
|
|
|
-
|
|
|
- List<TimeSeries> list = timeSeriesService.jumpTimeSeries(q);
|
|
|
- if (list != null && list.size() > FETCH_LIMIT) {
|
|
|
- return overLimit(list.size());
|
|
|
- }
|
|
|
- return ToolResultTable.store(sqlResultStore, null, list, 1,
|
|
|
- ToolResultTable.normalizePageSize(spec.pageSize));
|
|
|
- } catch (Exception e) {
|
|
|
- return fail("行为时间轴跳转查询", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 行为时间轴记录明细
|
|
|
- */
|
|
|
- @Tool(name = "get_time_series_detail",
|
|
|
- description = "查询时间轴上某一条记录在「它所属的来源业务表」里的完整明细,并附带该来源表的中文表头定义。"
|
|
|
- + "★ 必须同时传 tableNameEn 与 id:tableNameEn 取 get_time_series 结果里的 tableNameEn 列"
|
|
|
- + "(如 call_record 通话、trans_record 交易、hotel_stay_info 住宿、express_info 快递、"
|
|
|
- + "train_ticket_info 火车票、flight_ticket_info 机票等),id 取同一行的 id 列。"
|
|
|
- + "personName 可选,用于在 id 之外再校验人员,一般不用传。"
|
|
|
- + "返回固定两行两列(key / value):key=head 时 value 是该来源表的中文表头定义"
|
|
|
- + "(JSON 数组,含字段名与中文标题,可据此解释 dt 里的字段);"
|
|
|
- + "key=dt 时 value 是该条记录的完整字段(JSON 对象);记录不存在时 dt 的 value 为 null。"
|
|
|
- + "注意 value 是 JSON 文本,过长时会被截断到 500 字符。"
|
|
|
- + "若要按字段条件批量筛选来源表,请改用 execute_sql。",
|
|
|
- readOnly = true)
|
|
|
- public ToolResultBlock getTimeSeriesDetail(
|
|
|
- @ToolParam(name = "query", description = "明细定位参数,tableNameEn 与 id 必填")
|
|
|
- OtgToolSpecs.TimeSeriesDetailSpec query) {
|
|
|
- OtgToolSpecs.TimeSeriesDetailSpec spec =
|
|
|
- query == null ? new OtgToolSpecs.TimeSeriesDetailSpec() : query;
|
|
|
- try {
|
|
|
- String tableNameEn = trimToNull(spec.tableNameEn);
|
|
|
- if (tableNameEn == null) {
|
|
|
- return ToolResults.error("tableNameEn 不能为空:请先用 get_time_series 查询时间轴并取其 tableNameEn 列");
|
|
|
- }
|
|
|
- Long id = longOrNull(spec.id);
|
|
|
- if (id == null) {
|
|
|
- return ToolResults.error("id 不能为空:请先用 get_time_series 查询时间轴并取其 id 列");
|
|
|
- }
|
|
|
- TimeSeriesQuery q = new TimeSeriesQuery();
|
|
|
- // 该 service 用 tableName 去 TableInfoHelper / GlobalCache 里按「表名」定位实体,
|
|
|
- // 所以这里把模型给的英文表名映射到基类 tableName 上(并不把 tableName 暴露为入参名)。
|
|
|
- q.setTableName(tableNameEn);
|
|
|
- q.setId(id);
|
|
|
- q.setPersonName(trimToNull(spec.personName));
|
|
|
-
|
|
|
- Map<String, Object> detail = timeSeriesService.detailTimeSeries(q);
|
|
|
- return ToolResultTable.store(sqlResultStore, null, flattenDetail(detail), 1,
|
|
|
- ToolResultTable.normalizePageSize(spec.pageSize));
|
|
|
- } catch (Exception e) {
|
|
|
- return fail("行为时间轴明细查询", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ==================== 内部实现 ====================
|
|
|
-
|
|
|
- /**
|
|
|
- * 分页取全量:页大小设为 {@code FETCH_LIMIT + 1},让数据库只回上限内的数据。
|
|
|
- *
|
|
|
- * <p>本组时间轴 SQL 目前内置了 {@code limit 20} / {@code rowid ±10},page/limit 实际不生效,
|
|
|
- * 这里仍按统一约定设置取数窗口,避免日后 XML 支持分页时各工具口径不一致。
|
|
|
- */
|
|
|
- private static void applyFetchWindow(Query query) {
|
|
|
- query.setPage(1);
|
|
|
- query.setLimit(FETCH_LIMIT + 1L);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 把 {@code detailTimeSeries} 返回的 {@code Map} 拍平成两行 {@code key/value} 表格。
|
|
|
- *
|
|
|
- * <p>该接口返回的是 {@code {head: 表头定义, dt: 记录实体}},直接丢给表格组装器只会得到
|
|
|
- * 一个「Map 的字符串形态」,模型读不出结构,所以按 entry 拍平成行。
|
|
|
- */
|
|
|
- private static List<Map<String, Object>> flattenDetail(Map<String, Object> detail) {
|
|
|
- List<Map<String, Object>> rows = new ArrayList<>(2);
|
|
|
- rows.add(detailRow("head", detail == null ? null : detail.get("head")));
|
|
|
- rows.add(detailRow("dt", detail == null ? null : detail.get("dt")));
|
|
|
- return rows;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 单个 entry 转一行:值为 null 时保留 null(而不是字符串 "null"),其余走 JSON 文本
|
|
|
- */
|
|
|
- private static Map<String, Object> detailRow(String key, Object value) {
|
|
|
- Map<String, Object> row = new LinkedHashMap<>(2);
|
|
|
- row.put("key", key);
|
|
|
- row.put("value", value == null ? null : Json.toStr(value));
|
|
|
- return row;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 结果集超限:明确报错而不是截断,否则模型会基于不完整数据下结论
|
|
|
- */
|
|
|
- private static ToolResultBlock overLimit(long total) {
|
|
|
- return ToolResults.error("结果集过大(" + total + " 行,上限 " + FETCH_LIMIT
|
|
|
- + "),请收窄人员、类型或日期范围等条件后重试");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 失败:区分「参数格式错」与「执行错」,后者补一句开案提示
|
|
|
- */
|
|
|
- private static ToolResultBlock fail(String action, Exception e) {
|
|
|
- if (e instanceof IllegalArgumentException) {
|
|
|
- return ToolResults.error(e.getMessage());
|
|
|
- }
|
|
|
- log.warn("{}失败: {}", action, e.getMessage());
|
|
|
- return ToolResults.error(action + "失败: " + e.getMessage()
|
|
|
- + "。若提示数据表不存在,请确认已在客户端打开案件后重试");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据类型解析:枚举名 → 枚举。
|
|
|
- *
|
|
|
- * <p>{@code TimeSeriesTypeEnum} 里每种类型挂着多个来源表名,service 会把它们 flatMap 成
|
|
|
- * 表名列表再拼 {@code tableNameEn IN (...)},所以模型只需给类型名,不用也不该给表名。
|
|
|
- */
|
|
|
- private static List<TimeSeriesTypeEnum> parseTypes(List<String> names) {
|
|
|
- List<String> cleaned = cleanList(names);
|
|
|
- if (cleaned == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<TimeSeriesTypeEnum> types = new ArrayList<>(cleaned.size());
|
|
|
- for (String name : cleaned) {
|
|
|
- try {
|
|
|
- types.add(TimeSeriesTypeEnum.valueOf(name.toUpperCase(Locale.ROOT)));
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- throw new IllegalArgumentException("types 取值不合法(只支持 TRANS / CALL / TRACK):" + name);
|
|
|
- }
|
|
|
- }
|
|
|
- return types;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 游标比较符解析:只认枚举名,转成 {@link SymbolEnum} 后再由 getter 吐符号。
|
|
|
- *
|
|
|
- * <p>SQL 里 {@code rowid} 的比较符是 {@code ${query.rowIdSymbol}} 直接拼接的,
|
|
|
- * 所以这里绝不能把模型给的字符串原样透传 —— 必须经枚举白名单转换。
|
|
|
- */
|
|
|
- private static SymbolEnum parseSymbol(String value) {
|
|
|
- String text = trimToNull(value);
|
|
|
- if (text == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
- return SymbolEnum.valueOf(text.toUpperCase(Locale.ROOT));
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- throw new IllegalArgumentException("rowIdSymbol 取值不合法(只支持 GT / GE / LT / LE / EQ):" + value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 本地坐标标识解析:SQL 只对 {@code "Y"} 分支拼 {@code ext8/ext9 IS NOT NULL},
|
|
|
- * 传错值会静默变成「不过滤」,因此这里显式校验而不是放过。
|
|
|
- */
|
|
|
- private static String parseHasLocal(String value) {
|
|
|
- String text = trimToNull(value);
|
|
|
- if (text == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String upper = text.toUpperCase(Locale.ROOT);
|
|
|
- if (!"Y".equals(upper) && !"N".equals(upper)) {
|
|
|
- throw new IllegalArgumentException("hasLocal 取值不合法(只支持 Y 或 N):" + value);
|
|
|
- }
|
|
|
- return upper;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 日期解析:只接受 {@code yyyy-MM-dd},报错信息带字段名,便于模型自我修正
|
|
|
- */
|
|
|
- private static LocalDate parseDate(String value, String field) {
|
|
|
- String text = trimToNull(value);
|
|
|
- if (text == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
- return LocalDate.parse(text);
|
|
|
- } catch (DateTimeParseException e) {
|
|
|
- throw new IllegalArgumentException(field + " 格式不合法(应为 yyyy-MM-dd,如 2024-01-31):" + value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 清空串/去空白:XML 里部分条件只判 {@code != null},传空串会拼出 {@code = ''} 导致恒空结果,
|
|
|
- * 必须归一成 null。
|
|
|
- */
|
|
|
- private static String trimToNull(String value) {
|
|
|
- if (value == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String trimmed = value.trim();
|
|
|
- return trimmed.isEmpty() ? null : trimmed;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 列表清洗:去空白、去空串、去重保序;空列表归一成 null
|
|
|
- */
|
|
|
- private static List<String> cleanList(List<String> values) {
|
|
|
- if (values == null || values.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- LinkedHashSet<String> cleaned = new LinkedHashSet<>();
|
|
|
- values.stream().map(OtgAnalysisTool::trimToNull)
|
|
|
- .filter(Objects::nonNull).forEach(cleaned::add);
|
|
|
- return cleaned.isEmpty() ? null : new ArrayList<>(cleaned);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数值转 Long:{@code Number} 入参统一在工具内收敛类型
|
|
|
- */
|
|
|
- private static Long longOrNull(Number value) {
|
|
|
- return value == null ? null : value.longValue();
|
|
|
- }
|
|
|
-}
|