From ebc552900444d25b1158bf53d07f24c9ee36cc75 Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期一, 20 一月 2025 14:40:57 +0800
Subject: [PATCH] 预警配置

---
 src/views/model/pre/item/MmPredictItemForm.vue |  255 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 178 insertions(+), 77 deletions(-)

diff --git a/src/views/model/pre/item/MmPredictItemForm.vue b/src/views/model/pre/item/MmPredictItemForm.vue
index 11d9120..2ee0b2e 100644
--- a/src/views/model/pre/item/MmPredictItemForm.vue
+++ b/src/views/model/pre/item/MmPredictItemForm.vue
@@ -1,11 +1,11 @@
 <template>
-  <Dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
+  <Dialog v-model="dialogVisible" :title="dialogTitle" width="60%">
     <el-form
       ref="formRef"
       v-loading="formLoading"
       :model="dataForm"
       :rules="formRules"
-      label-width="120px"
+      label-width="100px"
     >
       <el-divider content-position="left">基本信息</el-divider>
       <el-row>
@@ -17,7 +17,8 @@
         </el-col>
         <el-col :span="12">
           <el-form-item label="编号" prop="mmPredictItem.itemno">
-            <el-input v-model="dataForm.mmPredictItem.itemno" placeholder="编号" maxlength="50" readonly/>
+            <el-input v-model="dataForm.mmPredictItem.itemno" placeholder="编号" maxlength="50"
+                      readonly/>
           </el-form-item>
         </el-col>
       </el-row>
@@ -39,7 +40,7 @@
           <el-form-item label="粒度" prop="mmPredictItem.granularity">
             <el-select v-model="dataForm.mmPredictItem.granularity" placeholder="请选择">
               <el-option
-                v-for="dict in getIntDictOptions(DICT_TYPE.TIME_GRANULARITY)"
+                v-for="dict in getIntDictOptions(DICT_TYPE.PRED_GRANULARITY)"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
@@ -99,21 +100,6 @@
                              controls-position="right"/>
           </el-form-item>
         </el-col>
-        <el-col :span="12">
-          <el-form-item label="数据点" prop="mmItemOutput.pointid">
-            <el-select
-              v-model="dataForm.mmItemOutput.pointid"
-              filterable
-              @change="changeOutputPoint"
-              placeholder="请选择">
-              <el-option
-                v-for="item in pointList"
-                :key="item.id"
-                :label="item.pointName"
-                :value="item.id"/>
-            </el-select>
-          </el-form-item>
-        </el-col>
       </el-row>
       <el-row v-if="dataForm.itemtypename === 'MergeItem'">
         <el-col :span="12">
@@ -143,6 +129,7 @@
             :on-success="uploadModelSuccess"
             :on-error="uploadModelError"
             :action="uploadUrl"
+            :show-file-list="false"
             :http-request="httpRequest">
             <el-button type="primary" @click="setReplaceModelOnly(false)">
               <Icon icon="ep:upload"/>
@@ -157,14 +144,14 @@
           </el-upload>
         </el-col>
       </el-row>
-      <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
+      <el-row v-if="dataForm.itemtypename === 'NormalItem'">
         <el-col :span="12">
-          <el-form-item label="结果">
-            <el-select v-model="dataForm.mmPredictModel.resultstrid" placeholder="请选择">
+          <el-form-item label="关联项目">
+            <el-select v-model="dataForm.mmPredictModel.mpkprojectid" placeholder="请选择">
               <el-option
-                v-for="item in resultstridList"
+                v-for="item in mpkProjectList"
                 :key="item.id"
-                :label="item.resultstr"
+                :label="item.projectName"
                 :value="item.id"/>
             </el-select>
           </el-form-item>
@@ -211,22 +198,96 @@
           </el-form-item>
         </el-col>
       </el-row>
+      <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型输出
+      </el-divider>
+      <el-button
+        @click="addItemOutput(dataForm.mmItemOutputList)"
+        type="primary"
+        size="small">
+        添加
+      </el-button>
+      <el-table
+        v-if="dataForm.itemtypename === 'NormalItem'"
+        :data="dataForm.mmItemOutputList"
+        border
+        style="width: 100%; margin-top: 5px;">
+        <el-table-column prop="outputorder" label="排序" align="center" width="80px"/>
+        <el-table-column label="结果KEY" align="center" width="150px">
+          <template #default="scope">
+            <el-input v-model="scope.row.resultstr" placeholder="请输入"/>
+          </template>
+        </el-table-column>
+        <el-table-column label="结果类型" align="center" width="150px">
+          <template #default="scope">
+            <el-select
+              v-model="scope.row.resultType"
+              @change="(value) => resultTypeChange(value,scope.row)"
+              filterable
+              placeholder="请选择">
+              <el-option
+                v-for="dict in getIntDictOptions(DICT_TYPE.MODEL_RESULT_TYPE)"
+                :key="dict.value"
+                :label="dict.label"
+                :value="dict.value"/>
+            </el-select>
+          </template>
+        </el-table-column>
+        <el-table-column label="索引" align="center" width="100px">
+          <template #default="scope">
+            <el-input-number style="width:100%;hight:100%" :disabled="scope.row.resultType !== 2"
+                             v-model="scope.row.resultIndex" :min="0" step-strictly
+                             controls-position="right"/>
+          </template>
+        </el-table-column>
+        <el-table-column label="结果名称" align="center" width="150px">
+          <template #default="scope">
+            <el-input v-model="scope.row.resultName" placeholder="请输入"/>
+          </template>
+        </el-table-column>
+        <el-table-column label="数据点" align="center">
+          <template #default="scope">
+            <el-select
+              v-model="scope.row.pointid"
+              filterable
+              @change="(value) => changeOutputPoint(value,scope.row)"
+              placeholder="请选择">
+              <el-option
+                v-for="item in pointList"
+                :key="item.id"
+                :label="item.pointName"
+                :value="item.id"/>
+            </el-select>
+          </template>
+        </el-table-column>
+        <el-table-column prop="" label="操作" width="80" align="center">
+          <template #default="scope">
+            <el-button
+              @click="deleteItemOutput(scope.$index, dataForm.mmItemOutputList)"
+              type="text"
+              size="small">
+              删除
+            </el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+      <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型设置参数
+      </el-divider>
       <el-table
         v-if="dataForm.itemtypename === 'NormalItem'"
         :data="dataForm.mmModelArithSettingsList"
         border
         style="width: 100%; margin-top: 5px;">
-        <el-table-column prop="key" label="键" align="center"/>
-        <el-table-column prop="name" label="名称" align="center"/>
-        <el-table-column prop="valuetype" label="类型" align="center"/>
-        <el-table-column prop="" label="值" align="center" min-width="150">
+        <el-table-column prop="key" label="键" align="center" min-width="150"/>
+        <el-table-column prop="name" label="名称" align="center" min-width="150"/>
+        <el-table-column prop="valuetype" label="类型" align="center" min-width="150"/>
+        <el-table-column prop="" label="值" align="center" min-width="200">
           <template #default="scope">
             <el-input size="mini" v-model="scope.row.value" maxlength="256"
                       style="width:100%;height:100%"/>
           </template>
         </el-table-column>
       </el-table>
-      <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">输入参数
+      <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型输入参数
       </el-divider>
       <el-table
         v-if="dataForm.itemtypename === 'NormalItem'"
@@ -237,7 +298,9 @@
         <el-table-column prop="modelparamorder" label="序号" width="60" align="center"/>
         <el-table-column prop="" label="类型" width="200" align="center">
           <template #default="scope">
-            <el-select v-model="scope.row.modelparamtype" placeholder="请选择">
+            <el-select v-model="scope.row.modelparamtype"
+                       @change="changeModelparamtype(scope.row)"
+                       placeholder="请选择">
               <el-option
                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
                 :key="dict.value"
@@ -269,18 +332,18 @@
                              style="width:100%;hight:100%"/>
           </template>
         </el-table-column>
-        <el-table-column prop="" label="操作" width="140" align="center">
+        <el-table-column prop="" label="操作" width="120" align="center">
           <template #default="scope">
             <el-button
               @click="addRow(scope.$index, dataForm.mmModelParamList)"
               type="text"
-              size="small">
+              size="mini">
               添加
             </el-button>
             <el-button
               @click="deleteRow(scope.$index, dataForm.mmModelParamList)"
               type="text"
-              size="small">
+              size="mini">
               删除
             </el-button>
           </template>
@@ -305,8 +368,8 @@
               <el-option
                 v-for="(item, index) in predictItemList"
                 :key="index"
-                :label="item.name"
-                :value="item.code"/>
+                :label="item.itemname"
+                :value="item.itemno"/>
             </el-select>
           </template>
         </el-table-column>
@@ -319,7 +382,7 @@
           label="运算符"
           align="center">
           <template #default="scope">
-            <el-select v-model="scope.row.operator" placeholder="请选择">
+            <el-select v-model="scope.row.operator" placeholder="请选择" clearable>
               <el-option
                 v-for="item in operatorList"
                 :key="item"
@@ -358,12 +421,12 @@
 </template>
 <script lang="ts" setup>
 import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
-import * as MmPredictItem from '@/api/model/pre/predict'
-import * as MmItemType from '@/api/model/pre/item'
+import * as MmPredictItem from '@/api/model/pre/item'
+import * as MmItemType from '@/api/model/pre/type'
 import * as DmModule from '@/api/model/pre/dm'
-import * as MmResultTable from '@/api/model/pre/result'
+import * as ProjectApi from '@/api/model/mpk/project'
 import * as DaPoint from '@/api/data/da/point'
-import {useUpload} from '@/api/model/pre/predict'
+import {useUpload} from '@/api/model/pre/item'
 import * as ScheduleModelApi from '@/api/model/sche/model'
 
 const {uploadUrl, httpRequest} = useUpload()
@@ -379,7 +442,7 @@
 const itemTypeList = ref([])
 const itemTypeMap = ref({})
 const moduleList = ref([])
-const resultstridList = ref([])
+const mpkProjectList = ref([])
 const pointNoList = ref([])
 const pointList = ref([])
 const pointMap = ref({})
@@ -422,14 +485,7 @@
     status: undefined,
     categoryid: undefined
   },
-  mmItemOutput: {
-    id: undefined,
-    itemid: undefined,
-    pointid: undefined,
-    resulttableid: undefined,
-    tagname: undefined,
-    outputorder: undefined
-  },
+  mmItemOutputList: [],
   mmPredictModel: {
     id: undefined,
     modelno: undefined,
@@ -448,7 +504,8 @@
     methodname: undefined,
     modelparamstructure: undefined,
     resultstrid: undefined,
-    settingmap: undefined
+    settingmap: undefined,
+    mpkprojectid: undefined
   },
   mmPredictMergeItem: {
     id: undefined,
@@ -475,7 +532,6 @@
   'mmPredictItem.status': [{required: true, message: '是否启用不能为空', trigger: 'blur'}],
   'dmModuleItem.moduleid': [{required: true, message: '管网不能为空', trigger: 'blur'}],
   'dmModuleItem.itemorder': [{required: true, message: '排序不能为空', trigger: 'blur'}],
-  'mmItemOutput.pointid': [{required: true, message: '数据点不能为空', trigger: 'blur'}],
 
 })
 const formRef = ref() // 表单 Ref
@@ -489,15 +545,6 @@
   resetForm()
   resetFields(dataForm.value)
   setDefaultFields()
-  // 修改时,设置数据
-  if (id) {
-    formLoading.value = true
-    try {
-      getInfo(id)
-    } finally {
-      /*formLoading.value = false*/
-    }
-  }
 
   // 加载参数列表
   modelparamListMap.value = await ScheduleModelApi.getModelParamList()
@@ -510,23 +557,37 @@
   if (!dataForm.value.id) {
     dataForm.value.mmPredictItem.itemtypeid = itemTypeList.value[0].id
   }
-  dataForm.value.itemtypename = itemTypeMap[dataForm.value.mmPredictItem.itemtypeid]
 
   // 获取管网列表
   moduleList.value = await DmModule.getModuleList()
 
-  // 获取结果字符串列表
-  resultstridList.value = await MmResultTable.getResultstridList()
+  // 获取mpk项目列表
+  mpkProjectList.value = await ProjectApi.list()
+
+  // 获取normal列表
+  predictItemList.value = await MmPredictItem.getMmPredictItemList({
+    itemtypename: 'NormalItem'
+  })
 
   // 获取数据点列表
   pointNoList.value = await DaPoint.getPointList(queryParams)
   if (pointNoList.value.length > 0) {
+    pointList.value = []
     pointNoList.value.forEach(function (value) {
       pointList.value.push(value)
-      pointMap[value.id] = value.pointname
+      pointMap[value.id] = value.pointName
     })
   }
 
+  // 修改时,设置数据
+  if (id) {
+    formLoading.value = true
+    try {
+      getInfo(id)
+    } finally {
+      formLoading.value = false
+    }
+  }
   formLoading.value = false
 }
 defineExpose({open}) // 提供 open 方法,用于打开弹窗
@@ -538,6 +599,22 @@
   if (!formRef) return
   const valid = await formRef.value.validate()
   if (!valid) return
+
+  //校验模型输出
+  if (dataForm.value.mmItemOutputList == undefined || dataForm.value.mmItemOutputList.length <= 0) {
+    message.error("模型输出不为空")
+    return
+  }
+
+  let flag = false
+  dataForm.value.mmItemOutputList.forEach(e => {
+    if (e.resultstr == undefined || e.resultstr === '' || e.resultType == undefined || e.resultType === '' || e.pointid == undefined || e.pointid === '' || (e.resultType === 2 && (e.resultIndex == undefined || e.resultIndex === ''))) {
+      message.error("模型输出数据异常")
+      flag = true
+    }
+  })
+  if (flag) return
+
   // 提交请求
   formLoading.value = true
   try {
@@ -591,6 +668,7 @@
 
 const getInfo = async (id) => {
   dataForm.value = await MmPredictItem.getMmPredictItem(id)
+  dataForm.value.itemtypename = itemTypeMap[dataForm.value.mmPredictItem.itemtypeid]
   expressionList.value = []
   if (dataForm.value.mmPredictMergeItem && dataForm.value.mmPredictMergeItem.expression) {
     let expression = dataForm.value.mmPredictMergeItem.expression
@@ -693,12 +771,12 @@
   dataForm.value.itemtypename = itemTypeMap[value]
 }
 
-function changeModelparamtype(value, row) {
+function changeModelparamtype(row) {
   row.modelparamid = ''
 }
 
-function changeOutputPoint(value) {
-  dataForm.value.mmItemOutput.tagname = pointMap[value]
+function changeOutputPoint(value, row) {
+  row.tagname = pointMap[value]
 }
 
 function deleteExpressionRow(index, rows) {
@@ -725,6 +803,37 @@
   orderRow(rows)
 }
 
+function addItemOutput(list) {
+  list.push({})
+  orderItemOutput(list)
+}
+
+function deleteItemOutput(index: string, rows) {
+  if (!rows || rows.length === 1) {
+    message.error('不能全部删除!')
+    return
+  }
+  rows.splice(index, 1)
+  orderItemOutput(rows)
+}
+
+function orderItemOutput(list) {
+  list.sort((a, b) => a.outputorder - b.outputorder);
+  let outputorder = 1
+  list.forEach(function (value) {
+    value.outputorder = outputorder
+    outputorder++
+  })
+}
+
+function resultTypeChange(value, row) {
+  if (value === 1) {
+    row.resultIndex = undefined
+  } else if (value === 2) {
+    row.resultIndex = 0
+  }
+}
+
 function orderRow(rows) {
   let modelparamorder = 0
   let modelparamportorder = 0
@@ -749,8 +858,7 @@
   dataForm.value.mmPredictModel.trainsamplength = 60
   dataForm.value.mmPredictModel.isonlinetrain = 0
   dataForm.value.mmPredictModel.status = 1
-  dataForm.value.mmItemOutput.outputorder = 1
-  dataForm.value.mmItemOutput.resulttableid = '3cc2b483-3a01-40f7-a419-0c260210d8eb'
+  dataForm.value.mmItemOutputList = []
   expressionList.value = [{
     point: '',
     operator: ''
@@ -788,14 +896,7 @@
       status: 1,
       categoryid: ''
     },
-    mmItemOutput: {
-      id: '',
-      itemid: '',
-      pointid: '',
-      resulttableid: '3cc2b483-3a01-40f7-a419-0c260210d8eb',
-      tagname: '',
-      outputorder: 1
-    },
+    mmItemOutputList: [],
     mmPredictModel: {
       id: '',
       modelno: '',

--
Gitblit v1.9.3