|
|
@@ -11,7 +11,6 @@ import {
|
|
|
type S8DimensionNode,
|
|
|
type S8ExceptionTypeConfigRow,
|
|
|
type S8MonitorObjectOption,
|
|
|
- type S8WatchRuleCreatePayload,
|
|
|
type S8WizardDraftDetail,
|
|
|
} from '../../api/s8ConfigApi';
|
|
|
import InlineCreateExceptionTypeDialog from './InlineCreateExceptionTypeDialog.vue';
|
|
|
@@ -411,75 +410,6 @@ function nextStep() {
|
|
|
}
|
|
|
function prevStep() { if (step.value > 0) step.value -= 1; }
|
|
|
|
|
|
-function ruleTypeFromMechanism(mech: string): string {
|
|
|
- if (mech === 'DATE') return 'TIMEOUT';
|
|
|
- return 'OUT_OF_RANGE';
|
|
|
-}
|
|
|
-
|
|
|
-function buildParamsJson(): string {
|
|
|
- const obj = selectedObject.value;
|
|
|
- const m = selectedMetric.value;
|
|
|
- const objectLabel = obj?.objectLabel ?? '';
|
|
|
- const metricLabel = m?.metricLabel ?? '';
|
|
|
- const exceptionTypeCode = form.exceptionTypeCode;
|
|
|
- const common = {
|
|
|
- objectIdField: 'source_object_id',
|
|
|
- objectCodeField: 'related_object_code',
|
|
|
- objectNameField: 'related_object_name',
|
|
|
- exceptionTypeCode,
|
|
|
- objectLabel,
|
|
|
- metricLabel,
|
|
|
- };
|
|
|
- if (form.mechanism === 'DATE') {
|
|
|
- const states = form.completedStates.split(/[,\s]+/).map((s) => s.trim()).filter(Boolean);
|
|
|
- return JSON.stringify({
|
|
|
- ...common,
|
|
|
- dueAtField: m?.dueAtField ?? 'due_at',
|
|
|
- statusField: m?.statusField ?? 'status',
|
|
|
- completedStates: states,
|
|
|
- graceMinutes: Number(form.graceMinutes) || 0,
|
|
|
- unit: form.unit || '分钟',
|
|
|
- thresholdDisplay: thresholdDisplay.value,
|
|
|
- });
|
|
|
- }
|
|
|
- if (form.mechanism === 'VALUE_RANGE') {
|
|
|
- const params: Record<string, unknown> = {
|
|
|
- ...common,
|
|
|
- measuredValueField: m?.measuredValueField ?? 'measured_value',
|
|
|
- unit: form.unit,
|
|
|
- thresholdDisplay: thresholdDisplay.value,
|
|
|
- };
|
|
|
- if (form.lowerBound != null) params.lowerBound = form.lowerBound;
|
|
|
- if (form.upperBound != null) params.upperBound = form.upperBound;
|
|
|
- if (form.toleranceAbs > 0) params.toleranceAbs = form.toleranceAbs;
|
|
|
- if (form.toleranceRatioPct > 0) params.toleranceRatio = form.toleranceRatioPct / 100;
|
|
|
- return JSON.stringify(params);
|
|
|
- }
|
|
|
- if (form.mechanism === 'RATIO') {
|
|
|
- return JSON.stringify({
|
|
|
- ...common,
|
|
|
- measuredValueField: m?.measuredValueField ?? 'measured_value',
|
|
|
- lowerBound: Number(form.targetRatio),
|
|
|
- unit: '%',
|
|
|
- thresholdDisplay: thresholdDisplay.value,
|
|
|
- });
|
|
|
- }
|
|
|
- return JSON.stringify(common);
|
|
|
-}
|
|
|
-
|
|
|
-function buildExpression(): string {
|
|
|
- if (form.mechanism === 'DATE') {
|
|
|
- return "SELECT 'DEMO-OBJECT-001' AS related_object_code, 'DEMO-OBJECT-001' AS source_object_id, 'DEMO-OBJECT-001' AS related_object_name, DATE_SUB(NOW(), INTERVAL 1 HOUR) AS due_at, 'PENDING' AS status WHERE 1=0";
|
|
|
- }
|
|
|
- return "SELECT 'DEMO-OBJECT-001' AS related_object_code, 'DEMO-OBJECT-001' AS source_object_id, 'DEMO-OBJECT-001' AS related_object_name, 0 AS measured_value WHERE 1=0";
|
|
|
-}
|
|
|
-
|
|
|
-function pickDataSourceId(): number | null {
|
|
|
- if (!props.dataSources || props.dataSources.length === 0) return null;
|
|
|
- const enabledOne = props.dataSources.find((d) => d.enabled);
|
|
|
- return (enabledOne ?? props.dataSources[0]).id;
|
|
|
-}
|
|
|
-
|
|
|
// CONFIG-WIZARD-DRAFT-FRONTEND-1:序列化 / 反序列化向导态。
|
|
|
function serializeWizardState(): string {
|
|
|
const obj = selectedObject.value;
|
|
|
@@ -642,34 +572,6 @@ async function saveDraft(): Promise<boolean> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function buildRulePayload(): S8WatchRuleCreatePayload | null {
|
|
|
- const dataSourceId = pickDataSourceId();
|
|
|
- if (dataSourceId == null) { ElMessage.error('缺少数据源,无法生成规则'); return null; }
|
|
|
- const obj = selectedObject.value;
|
|
|
- if (!obj) { ElMessage.warning('监控对象异常'); return null; }
|
|
|
- return {
|
|
|
- tenantId: props.tenantId ?? 1,
|
|
|
- factoryId: props.factoryId ?? 1,
|
|
|
- ruleCode: form.ruleCode.trim(),
|
|
|
- sceneCode: form.stageCode,
|
|
|
- dataSourceId,
|
|
|
- watchObjectType: obj.objectType,
|
|
|
- ruleType: ruleTypeFromMechanism(form.mechanism),
|
|
|
- ruleMechanism: form.mechanism,
|
|
|
- stageCode: form.stageCode,
|
|
|
- orderFlowCode: form.orderFlowCode || null,
|
|
|
- exceptionTypeCode: form.exceptionTypeCode,
|
|
|
- severity: form.severity || 'FOLLOW',
|
|
|
- pollIntervalSeconds: form.pollIntervalSeconds,
|
|
|
- triggerCountRequired: form.triggerCountRequired,
|
|
|
- recoverCountRequired: form.recoverCountRequired,
|
|
|
- consecutiveFailureCount: 0,
|
|
|
- enabled: false,
|
|
|
- paramsJson: buildParamsJson(),
|
|
|
- expression: buildExpression(),
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
function validateGenerate(): boolean {
|
|
|
if (!form.mechanism || isManualReport.value) { ElMessage.warning('未选择报警机制'); return false; }
|
|
|
if (!form.stageCode) { ElMessage.warning('阶段维度未选择'); return false; }
|