| | |
| | | private static final Pattern LIMIT_PATTERN = Pattern.compile("(前|最近)?(\\d{1,2})条"); |
| | | private static final Pattern DATE_PATTERN = Pattern.compile("(\\d{4}-\\d{2}-\\d{2})"); |
| | | private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+(?:\\.\\d+)?)"); |
| | | private static final Pattern RECENT_RANGE_PATTERN = Pattern.compile("近\\d+(天|周|个月|月|年)"); |
| | | private static final Pattern HALF_RANGE_PATTERN = Pattern.compile("(最近|近)?半(个)?(月|年)"); |
| | | private static final Pattern EXPLICIT_RANGE_PATTERN = Pattern.compile(".*(到|至).*"); |
| | | |
| | | private final ApproveTodoTools approveTodoTools; |
| | | |
| | |
| | | String text = message.trim(); |
| | | String approveId = extractApproveId(text); |
| | | |
| | | if (containsAny(text, "统计", "分析", "图表", "趋势", "占比")) { |
| | | if (isStatsIntent(text)) { |
| | | return approveTodoTools.getTodoStats( |
| | | memoryId, |
| | | extractStartDate(text), |
| | |
| | | extractTimeRange(text) |
| | | ); |
| | | } |
| | | if (containsAny(text, "流转", "进度", "节点", "日志")) { |
| | | if (containsAny(text, "流转", "进度", "节点", "日志", "卡在", "卡到", "当前审批人", "处理记录")) { |
| | | return StringUtils.hasText(approveId) |
| | | ? approveTodoTools.getTodoProgress(memoryId, approveId) |
| | | : missingApproveId("todo_progress", "查询审批进度需要提供流程编号。"); |
| | |
| | | ? approveTodoTools.getTodoDetail(memoryId, approveId) |
| | | : missingApproveId("todo_detail", "查询审批详情需要提供流程编号。"); |
| | | } |
| | | if (containsAny(text, "取消审核", "撤销审核", "回退审核")) { |
| | | if (containsAny(text, "取消审核", "撤销审核", "回退审核", "撤销审批", "撤回审批") |
| | | || (containsAny(text, "撤销", "撤回") && containsAny(text, "审批操作", "审核操作"))) { |
| | | return StringUtils.hasText(approveId) |
| | | ? approveTodoTools.cancelReviewTodo(memoryId, approveId, extractTail(text, "原因")) |
| | | ? approveTodoTools.cancelReviewTodo(memoryId, approveId, firstNonBlank(extractTail(text, "原因"), extractTail(text, "备注"))) |
| | | : missingApproveId("cancel_review_action", "取消审核需要提供流程编号。"); |
| | | } |
| | | if (containsAny(text, "删除")) { |
| | | if (containsAny(text, "删除", "移除")) { |
| | | return StringUtils.hasText(approveId) |
| | | ? approveTodoTools.deleteTodo(memoryId, approveId) |
| | | : missingApproveId("delete_action", "删除审批单需要提供流程编号。"); |
| | | } |
| | | if (containsAny(text, "驳回", "拒绝")) { |
| | | return StringUtils.hasText(approveId) |
| | | ? approveTodoTools.reviewTodo(memoryId, approveId, "reject", extractTail(text, "原因")) |
| | | ? approveTodoTools.reviewTodo(memoryId, approveId, "reject", firstNonBlank(extractTail(text, "原因"), extractTail(text, "备注"))) |
| | | : missingApproveId("review_action", "驳回审批需要提供流程编号。"); |
| | | } |
| | | if (containsAny(text, "审核通过", "审批通过", "通过审批", "同意审批", "审批同意")) { |
| | |
| | | && !containsAny(text, "未通过", "通过率", "审批通过率", "审核通过率")) { |
| | | return approveTodoTools.reviewTodo(memoryId, approveId, "approve", extractTail(text, "备注")); |
| | | } |
| | | if (containsAny(text, "修改")) { |
| | | if (containsAny(text, "修改", "更新", "变更")) { |
| | | return StringUtils.hasText(approveId) |
| | | ? approveTodoTools.updateTodo( |
| | | memoryId, |
| | |
| | | extractValue(text, "备注")) |
| | | : missingApproveId("update_action", "修改审批单需要提供流程编号。"); |
| | | } |
| | | if (containsAny(text, "列表", "待办", "查询审批")) { |
| | | if (containsAny(text, "列表", "待办", "查询审批", "单据", "流程", "审批批")) { |
| | | return approveTodoTools.listTodos( |
| | | memoryId, |
| | | extractStatus(text), |
| | | extractApproveType(text), |
| | | extractKeyword(text), |
| | | extractLimit(text)); |
| | | extractLimit(text), |
| | | extractScope(text)); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private boolean isStatsIntent(String text) { |
| | | if (containsAny(text, "统计", "分析", "图表", "趋势", "占比", "汇总", "总量", "分布", "各有多少", "有多少")) { |
| | | return true; |
| | | } |
| | | boolean hasQueryWord = containsAny(text, "查询", "查看", "看下", "看看", "获取"); |
| | | boolean hasDataWord = containsAny(text, "数据", "报表", "情况", "数量", "金额"); |
| | | boolean hasTimeWord = containsAny(text, "今天", "昨日", "昨天", "本周", "上周", "本月", "上月", "本年", "今年", "去年") |
| | | || DATE_PATTERN.matcher(text).find() |
| | | || RECENT_RANGE_PATTERN.matcher(text).find() |
| | | || HALF_RANGE_PATTERN.matcher(text).find() |
| | | || EXPLICIT_RANGE_PATTERN.matcher(text).matches(); |
| | | return hasQueryWord && hasDataWord && hasTimeWord; |
| | | } |
| | | |
| | | private boolean containsAny(String text, String... keywords) { |
| | |
| | | if (containsAny(text, "待审核", "待审批")) { |
| | | return "pending"; |
| | | } |
| | | if (containsAny(text, "审核中")) { |
| | | if (containsAny(text, "审核中", "处理中", "处理中的", "办理中")) { |
| | | return "processing"; |
| | | } |
| | | if (containsAny(text, "已通过", "审核完成")) { |
| | | if (containsAny(text, "已通过", "通过", "审核完成", "审批完成")) { |
| | | return "approved"; |
| | | } |
| | | if (containsAny(text, "未通过", "驳回")) { |
| | | if (containsAny(text, "未通过", "驳回", "已驳回", "拒绝")) { |
| | | return "rejected"; |
| | | } |
| | | if (containsAny(text, "重新提交")) { |
| | |
| | | private String extractKeyword(String text) { |
| | | String cleaned = text |
| | | .replace("查询", "") |
| | | .replace("查看", "") |
| | | .replace("列出", "") |
| | | .replace("帮我", "") |
| | | .replace("审批", "") |
| | | .replace("单据", "") |
| | | .replace("待办", "") |
| | | .replace("列表", "") |
| | | .replace("前10条", "") |
| | |
| | | } |
| | | |
| | | private String extractValue(String text, String fieldName) { |
| | | Pattern pattern = Pattern.compile(fieldName + "(改为|修改为|是)?[::]?[\\s]*([^,,。;;\\s]+)"); |
| | | Pattern pattern = Pattern.compile(fieldName + "(改为|修改为|是)[::]?[\\s]*([^,,。;;\\s]+)"); |
| | | Matcher matcher = pattern.matcher(text); |
| | | return matcher.find() ? matcher.group(2) : null; |
| | | } |
| | |
| | | if (containsAny(text, "今天", "昨日", "昨天", "本周", "上周", "本月", "上月", "本年", "今年", "去年")) { |
| | | return text; |
| | | } |
| | | if (Pattern.compile("近\\d+(天|周|个月|月|年)").matcher(text).find()) { |
| | | if (RECENT_RANGE_PATTERN.matcher(text).find()) { |
| | | return text; |
| | | } |
| | | if (Pattern.compile("最近\\d+(天|周|个月|月|年)").matcher(text).find()) { |
| | | if (HALF_RANGE_PATTERN.matcher(text).find()) { |
| | | return text; |
| | | } |
| | | if (text.contains("到") || text.contains("至")) { |
| | | if (EXPLICIT_RANGE_PATTERN.matcher(text).matches()) { |
| | | return text; |
| | | } |
| | | return null; |
| | |
| | | if (!text.contains(fieldName)) { |
| | | return null; |
| | | } |
| | | Matcher matcher = Pattern.compile(fieldName + "(改为|修改为|是)?[::]?[\\s]*(\\d{1,2})").matcher(text); |
| | | Matcher matcher = Pattern.compile(fieldName + "(改为|修改为|是)[::]?[\\s]*(\\d{1,2})").matcher(text); |
| | | return matcher.find() ? Integer.parseInt(matcher.group(2)) : null; |
| | | } |
| | | |
| | |
| | | return matcher.find() ? matcher.group(2).trim() : null; |
| | | } |
| | | |
| | | private String extractScope(String text) { |
| | | if (containsAny(text, "我发起", "我提交", "我申请", "申请人是我")) { |
| | | return "applicant"; |
| | | } |
| | | if (containsAny(text, "待我审批", "待我审核", "我处理", "我审批", "当前待我", "需要我处理")) { |
| | | return "approver"; |
| | | } |
| | | return "related"; |
| | | } |
| | | |
| | | private String firstNonBlank(String first, String second) { |
| | | return StringUtils.hasText(first) ? first : second; |
| | | } |
| | | |
| | | private String missingApproveId(String type, String description) { |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("success", false); |