| | |
| | | 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), |
| | |
| | | extractLimit(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) { |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |