From e4af7e0784508446df18076388a8119fb5564ef2 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 17 Dec 2025 13:35:24 +0800 Subject: [PATCH] =?UTF-8?q?perf(X-Pack):=20=E9=98=88=E5=80=BC=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=20#17526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/ChartViewThresholdManage.java | 113 ++++++++++++++++-- .../resources/db/migration/V2.10.19__ddl.sql | 6 + core/core-frontend/src/locales/en.ts | 5 +- core/core-frontend/src/locales/tw.ts | 5 +- core/core-frontend/src/locales/zh-CN.ts | 5 +- .../system/parameter/basic/BasicEdit.vue | 13 ++ .../chart/request/ThresholdCheckRequest.java | 4 + .../api/communicate/dto/MessageDTO.java | 2 + .../api/threshold/dto/ThresholdCreator.java | 2 + .../constant/XpackSettingConstants.java | 1 + .../io/dataease/utils/SystemSettingUtils.java | 3 +- 11 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 core/core-backend/src/main/resources/db/migration/V2.10.19__ddl.sql diff --git a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartViewThresholdManage.java b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartViewThresholdManage.java index 740e3f87fe..c8ce28385c 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartViewThresholdManage.java +++ b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartViewThresholdManage.java @@ -35,6 +35,7 @@ public class ChartViewThresholdManage { @Resource private ChartViewManege chartViewManege; + public String convertThresholdRules(Long chartId, String thresholdRules, String resourceTable) { ChartViewDTO details = chartViewManege.getDetails(chartId, resourceTable); return convertThresholdRules(details, thresholdRules); @@ -277,30 +278,103 @@ public class ChartViewThresholdManage { Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); Matcher matcher = pattern.matcher(thresholdTemplate); StringBuilder sb = new StringBuilder(); + + boolean withThresholdData = false; + int thresholdRecordCount = request.getThresholdLimit(); while (matcher.find()) { long id = Long.parseLong(matcher.group(1)); + if (id == 2L) { + withThresholdData = true; + } // 根据id从map中获取替换文本 DatasetTableFieldDTO fieldDTO = fieldMap.get(id); if (ObjectUtils.isEmpty(fieldDTO)) continue; + String dataeaseName = fieldDTO.getDataeaseName(); String fieldDTOName = fieldDTO.getName(); - /*String dataeaseName = fieldDTO.getDataeaseName(); - String replacement = null; - if (fieldDTO.getDeType().equals(DeTypeConstants.DE_FLOAT) || fieldDTO.getDeType().equals(DeTypeConstants.DE_INT)) { - List valueList = rows.stream().map(row -> ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : stripTrailingZeros2String(row.get(dataeaseName))).collect(Collectors.toList()); - replacement = fieldDTOName + ": " + JsonUtil.toJSONString(valueList); - } else { - List valueList = rows.stream().map(row -> ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : row.get(dataeaseName).toString()).collect(Collectors.toList()); - replacement = fieldDTOName + ": " + JsonUtil.toJSONString(valueList); + + if (rows.size() > thresholdRecordCount) { + rows = rows.subList(0, thresholdRecordCount); + } + if (request.isShowFieldValue()) { + String replacement = null; + if (fieldDTO.getDeType().equals(DeTypeConstants.DE_FLOAT) || fieldDTO.getDeType().equals(DeTypeConstants.DE_INT)) { + List valueList = rows.stream().map(row -> ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : stripTrailingZeros2String(row.get(dataeaseName))).collect(Collectors.toList()); + replacement = fieldDTOName + ": " + JsonUtil.toJSONString(valueList); + } else { + List valueList = rows.stream().map(row -> ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : row.get(dataeaseName).toString()).collect(Collectors.toList()); + replacement = fieldDTOName + ": " + JsonUtil.toJSONString(valueList); + } + matcher.appendReplacement(sb, replacement); + } else { + matcher.appendReplacement(sb, fieldDTOName); } - - // 替换文本 - matcher.appendReplacement(sb, replacement);*/ - matcher.appendReplacement(sb, fieldDTOName); } - matcher.appendTail(sb); + matcher.appendTail(sb); // 输出替换后的HTML内容 String result = sb.toString(); + + if (withThresholdData) { + Set thresholdFieldIdSet = new HashSet<>(); + getThresholdFieldIdList(filterTreeObj, thresholdFieldIdSet); + List> thresholdTableList = rows.stream().map(row -> thresholdFieldIdSet.stream().map(fieldId -> { + DatasetTableFieldDTO fieldDTO = fieldMap.get(fieldId); + if (ObjectUtils.isEmpty(fieldDTO)) return ""; + String dataeaseName = fieldDTO.getDataeaseName(); + Integer deType = fieldDTO.getDeType(); + String value = null; + + if (deType.equals(DeTypeConstants.DE_FLOAT) || deType.equals(DeTypeConstants.DE_INT)) { + value = ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : stripTrailingZeros2String(row.get(dataeaseName)); + } else { + value = ObjectUtils.isEmpty(row.get(dataeaseName)) ? null : row.get(dataeaseName).toString(); + } + return value; + }).collect(Collectors.toList())).collect(Collectors.toList()); + List tableHeadList = thresholdFieldIdSet.stream().map(i -> fieldMap.get(i).getName()).collect(Collectors.toList()); + tableHeadList.addFirst("NO"); + thresholdTableList.addFirst(tableHeadList); + StringBuilder tableHtml = new StringBuilder(""); + + for (int i = 0; i < thresholdTableList.size(); i++) { + List row = thresholdTableList.get(i); + if (i == 0) { + StringBuilder theadHtmlBuild = new StringBuilder(""); + row.forEach(item -> { + theadHtmlBuild.append(""); + }); + theadHtmlBuild.append(""); + tableHtml.append(theadHtmlBuild); + continue; + } + row.addFirst(String.valueOf(i)); + if (i == 1) { + tableHtml.append(""); + } + + StringBuilder trHtmlBuild = new StringBuilder(""); + row.forEach(item -> { + trHtmlBuild.append(""); + }); + trHtmlBuild.append(""); + tableHtml.append(trHtmlBuild); + + if (i == thresholdTableList.size() - 1) { + tableHtml.append("
").append(item).append("
").append(item).append("
"); + } + + } + + String thresholdDataRex = "]*?style=\"([^\"]*?)\"[^>]*?>\\s*]*?data-mce-content=\"\\[告警数据\\]\"[^>]*?>\\[告警数据\\]\\s*"; + + Pattern thresholdDataPattern = Pattern.compile(thresholdDataRex, Pattern.DOTALL); + Matcher thresholdDataMatcher = thresholdDataPattern.matcher(result); + if (thresholdDataMatcher.find()) { + String originStyle = thresholdDataMatcher.group(2); + String tableStyleHtml = tableHtml.toString().replace("min-width:35%;", originStyle + "min-width:35%;"); + result = thresholdDataMatcher.replaceAll(tableStyleHtml); + } + } return new ThresholdCheckVO(true, result, null, null); } catch (Exception e) { LogUtil.error(e.getMessage(), new Throwable(e)); @@ -316,6 +390,18 @@ public class ChartViewThresholdManage { return ((BigDecimal) value).stripTrailingZeros().toPlainString(); } + private void getThresholdFieldIdList(FilterTreeObj conditionTree, Set fieldIdSet) { + List items = conditionTree.getItems(); + items.forEach(item -> { + if (!StringUtils.equals("item", item.getType())) { + getThresholdFieldIdList(item.getSubTree(), fieldIdSet); + } else { + Long fieldId = item.getFieldId(); + fieldIdSet.add(fieldId); + } + }); + } + private void chartDynamicMap(List> rows, FilterTreeObj conditionTree, Map fieldMap) { List items = conditionTree.getItems(); items.forEach(item -> { @@ -603,4 +689,5 @@ public class ChartViewThresholdManage { return valueLong == targetLong; } } + } diff --git a/core/core-backend/src/main/resources/db/migration/V2.10.19__ddl.sql b/core/core-backend/src/main/resources/db/migration/V2.10.19__ddl.sql new file mode 100644 index 0000000000..ac2de5c660 --- /dev/null +++ b/core/core-backend/src/main/resources/db/migration/V2.10.19__ddl.sql @@ -0,0 +1,6 @@ +ALTER TABLE `xpack_threshold_info` + ADD COLUMN `show_field_value` tinyint(1) NOT NULL DEFAULT 0 COMMENT '显示字段值' AFTER `repeat_send`; + +ALTER TABLE `xpack_threshold_info_snapshot` + ADD COLUMN `show_field_value` tinyint(1) NOT NULL DEFAULT 0 COMMENT '显示字段值' AFTER `repeat_send`; + diff --git a/core/core-frontend/src/locales/en.ts b/core/core-frontend/src/locales/en.ts index 25f29abfbb..996713e87e 100644 --- a/core/core-frontend/src/locales/en.ts +++ b/core/core-frontend/src/locales/en.ts @@ -3845,7 +3845,8 @@ export default { loginLimit: 'Limit login', loginLimitRate: 'Limit login failure times (times)', loginLimitTime: 'Limit login failure time (minutes)', - share_disable_tips: 'Dashboard and data screen sharing are invalid after turning on' + share_disable_tips: 'Dashboard and data screen sharing are invalid after turning on', + thresholdLimit: 'Alarm data limitation' }, resource_sort: { time_asc: 'In ascending order by creation time', @@ -4628,6 +4629,7 @@ export default { msg_title: 'Message title', msg_content: 'Message content', repeat_send: 'Repeat send', + show_field_value: 'Show field value', recipient: 'Recipient', choose_recipient: 'Select recipient', trigger_alarm: 'Trigger alarm', @@ -4637,6 +4639,7 @@ export default { recipient_setting: 'Recipient setting', attention_quota_tip: 'The indicators you are following', pay_attention_in_time: '. Please pay attention in time.', + threshold_record: 'Alert Data', msg_preview: 'Message preview', average: 'Average value', next_time: 'Next ', diff --git a/core/core-frontend/src/locales/tw.ts b/core/core-frontend/src/locales/tw.ts index a6bfbffe62..09117f3bc7 100644 --- a/core/core-frontend/src/locales/tw.ts +++ b/core/core-frontend/src/locales/tw.ts @@ -3734,7 +3734,8 @@ export default { loginLimit: '限制登入', loginLimitRate: '限制登入失敗次數 (次)', loginLimitTime: '限制登入失敗時間 (分)', - share_disable_tips: '開啟後儀表板以及大屏分享無效' + share_disable_tips: '開啟後儀表板以及大屏分享無效', + thresholdLimit: '告警數據限製' }, resource_sort: { time_asc: '按建立時間升序', @@ -4497,6 +4498,7 @@ export default { msg_title: '消息標題', msg_content: '消息正文', repeat_send: '是否重複發送', + show_field_value: '顯示字段值', recipient: '接收人', choose_recipient: '選擇接收人', trigger_alarm: '觸發告警', @@ -4506,6 +4508,7 @@ export default { recipient_setting: '設置接收人', attention_quota_tip: '您關注的指標', pay_attention_in_time: '。請及時關注。', + threshold_record: '告警數據', msg_preview: '消息預覽', average: '平均值', next_time: '下一', diff --git a/core/core-frontend/src/locales/zh-CN.ts b/core/core-frontend/src/locales/zh-CN.ts index 47e41c40f1..ad47b41bfd 100644 --- a/core/core-frontend/src/locales/zh-CN.ts +++ b/core/core-frontend/src/locales/zh-CN.ts @@ -3740,7 +3740,8 @@ export default { loginLimit: '限制登录', loginLimitRate: '限制登录失败次数 (次)', loginLimitTime: '限制登录失败时间 (分)', - share_disable_tips: '开启后仪表板以及大屏分享无效' + share_disable_tips: '开启后仪表板以及大屏分享无效', + thresholdLimit: '告警数据限制' }, resource_sort: { time_asc: '按创建时间升序', @@ -4502,6 +4503,7 @@ export default { msg_title: '消息标题', msg_content: '消息正文', repeat_send: '是否重复发送', + show_field_value: '显示字段值', recipient: '接收人', choose_recipient: '选择接收人', trigger_alarm: '触发告警', @@ -4511,6 +4513,7 @@ export default { recipient_setting: '设置接收人', attention_quota_tip: '您关注的指标', pay_attention_in_time: '。请及时关注。', + threshold_record: '告警数据', msg_preview: '消息预览', average: '平均值', next_time: '下一', diff --git a/core/core-frontend/src/views/system/parameter/basic/BasicEdit.vue b/core/core-frontend/src/views/system/parameter/basic/BasicEdit.vue index 1d16307b37..c7dac8d530 100644 --- a/core/core-frontend/src/views/system/parameter/basic/BasicEdit.vue +++ b/core/core-frontend/src/views/system/parameter/basic/BasicEdit.vue @@ -337,6 +337,19 @@ defineExpose({ type="number" /> +
+ +