Browse Source

修改报警预警增删改

zhaoke 1 year ago
parent
commit
280981dccc
2 changed files with 358 additions and 44 deletions
  1. 123 0
      src/api/webApi.ts
  2. 235 44
      src/views/systemSettings/warningEdit/index.vue

+ 123 - 0
src/api/webApi.ts

@@ -61,3 +61,126 @@ export function GeneralDataReception(params): Promise<CommonQueryResult> {
     data: params,
   })
 }
+
+//增/删/改
+export async function dataToChange(
+  id: number,
+  data: any,
+  event: number,
+  key?: string
+) {
+  try {
+    const params = {
+      serviceId: id,
+      dataContent: formatChange(data, event, key),
+      event: `${event}`,
+      // authId: this.AauthId
+    }
+    const { code, message } =
+      event == 1
+        ? await newData(params)
+        : event == 2
+        ? await modifyData(params)
+        : await moveData(params)
+    return { code, message }
+  } catch (error) {
+    return { code: 1, message: error }
+  }
+}
+
+//新增
+function newData(params) {
+  return request({
+    url: '/openApi/newdata',
+    method: 'post',
+    data: params,
+  })
+}
+
+//修改
+function modifyData(params) {
+  return request({
+    url: '/openApi/modifydata',
+    method: 'post',
+    data: params,
+  })
+}
+
+//删除movedata
+function moveData(params) {
+  return request({
+    url: '/openApi/movedata',
+    method: 'post',
+    data: params,
+  })
+}
+
+function formatChange(data, event, key) {
+  const datas: any = []
+  const flag = Array.isArray(data)
+  if (flag) {
+    for (let i = 0; i < data.length; i++) {
+      let obj: any = {}
+      if (event == 1) {
+        obj.Value = data[i]
+      } else if (event == 2) {
+        obj.Value = data[i]
+        obj.filter = {}
+        if (Array.isArray(key)) {
+          const keys = <any>[]
+          const vals = <any>[]
+          obj.filter = []
+          for (let j = 0; j < key.length; j++) {
+            const dep = key[i]
+            keys.push(Object.keys(dep))
+            vals.push(Object.values(dep))
+          }
+          const nobj = {
+            left: '(',
+            column: `${keys[i]}`,
+            comparator: '=',
+            value: `${vals[i]}`,
+            right: ')',
+            connector: 'and',
+          }
+          obj.filter.push(nobj)
+          if (obj.Value.hasOwnProperty(keys[i])) {
+            delete obj.Value[keys[i]]
+          }
+        } else {
+          obj.filter[key] = data[i][key]
+          if (obj.Value[key]) {
+            delete obj.Value[key]
+          }
+        }
+      } else {
+        obj = data[i]
+      }
+      datas.push(obj)
+    }
+  } else {
+    let obj: any = {}
+    if (event == 1) {
+      obj.Value = data
+    } else if (event == 2) {
+      obj.Value = data
+      obj.filter = [
+        {
+          left: '(',
+          column: `${key}`,
+          comparator: '=',
+          value: `${data[key]}`,
+          right: ')',
+          connector: 'and',
+        },
+      ]
+      if (obj.Value[key]) {
+        delete obj.Value[key]
+      }
+    } else {
+      obj = data
+    }
+    datas.push(obj)
+  }
+  return datas
+}

+ 235 - 44
src/views/systemSettings/warningEdit/index.vue

@@ -147,7 +147,12 @@ import _ from "lodash";
 import Minheader from "@/components/minheader/index.vue";
 import DataTable from "@/components/tableTemp/index.vue";
 import Dialog from "@/components/dialog/index.vue";
-import { Query, GeneralDataReception, htQuery } from "@/api/webApi";
+import {
+  Query,
+  GeneralDataReception,
+  htQuery,
+  dataToChange,
+} from "@/api/webApi";
 import { ElMessage } from "element-plus";
 import { onMounted } from "vue";
 const formRules = useElement().formRules;
@@ -231,7 +236,7 @@ const tableBtnGroup = ref([
 const addForm = () => {
   msgTitle.value = "新增报警预警策略";
   flag.value = true;
-  type.value = "";
+  type.value = "add";
   tableForms.event = 1;
 };
 //取消
@@ -249,10 +254,25 @@ const resetForm = () => {
   tableForms.percentage = "";
   delName.value = "";
 };
-const delRemove = () => {
+const delRemove = async () => {
   tableForms.event = 3;
-
-  generalDataReception(tableForms);
+  const { code, message } = await dataToChange(
+    DATACONTENT_ID.sysServiceClId,
+    tableForms,
+    3
+  );
+  if (code == 0) {
+    ElMessage.success(message);
+    resetTable();
+    getQuery();
+    resetForm();
+    flag.value = false;
+    tableObj.value = {};
+  } else {
+    ElMessage.error(message);
+    tableObj.value = {};
+    resetForm();
+  }
 };
 //删除
 const delRest = () => {
@@ -263,10 +283,10 @@ const btnClick = (row, index, param) => {
   if (param === 2) {
     msgTitle.value = "编辑报警预警策略";
     flag.value = true;
-    type.value = "";
+    type.value = "edit";
     const newVal = _.cloneDeep(index);
-    newVal.beginPosition = Number(newVal.beginPosition);
-    newVal.endPosition = Number(newVal.endPosition);
+    // newVal.beginPosition = Number(newVal.beginPosition);
+    // newVal.endPosition = Number(newVal.endPosition);
     newVal.calculationBasis = `${newVal.calculationBasis}`;
     for (const key in tableForms) {
       for (const p in newVal) {
@@ -304,7 +324,6 @@ const sysServiceWarn = async () => {
     if (result.length) {
       const newVal = _.cloneDeep(result[0]);
       for (const key in tableForm) {
-        console.log(key);
         for (const p in newVal) {
           if (key == p) {
             tableForm[key] = newVal[p];
@@ -359,51 +378,191 @@ const getSelectData = async (id, name, dataNme) => {
 //获取表格数据
 const getQuery = async () => {
   try {
-    const { code, returnData } = await Query({
-      id: DATACONTENT_ID.sysServiceStrategyId,
-      needPage: ++page.value,
-      dataContent: [route.query.alarmSceneId],
+    const columnSet = [
+      {
+        queryTemplateColumnSetID: 290,
+        queryTemplateID: 18033,
+        columnName: "alarmStrategyID",
+        columnLabel: "策略编号",
+        columnDescribe: "策略编号",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 0,
+        needGroup: 0,
+        dataType: "int",
+        listqueryTemplateID: null,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 291,
+        queryTemplateID: 18033,
+        columnName: "StrategyName",
+        columnLabel: "策略名称",
+        columnDescribe: "策略名称",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "varchar",
+        listqueryTemplateID: null,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 292,
+        queryTemplateID: 18033,
+        columnName: "calculationBasis",
+        columnLabel: "计算依据",
+        columnDescribe: "计算依据",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "int",
+        listqueryTemplateID: 1803423,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 293,
+        queryTemplateID: 18033,
+        columnName: "warningDuration",
+        columnLabel: "预警时长",
+        columnDescribe: "预警时长",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "number",
+        listqueryTemplateID: null,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 294,
+        queryTemplateID: 18033,
+        columnName: "alarmDuration",
+        columnLabel: "报警时长",
+        columnDescribe: "报警时长",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "number",
+        listqueryTemplateID: null,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 295,
+        queryTemplateID: 18033,
+        columnName: "beginNode",
+        columnLabel: "开始节点",
+        columnDescribe: "开始节点",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "varchar",
+        listqueryTemplateID: 1803424,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 296,
+        queryTemplateID: 18033,
+        columnName: "beginPosition",
+        columnLabel: "开始位置",
+        columnDescribe: "开始位置",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "varchar",
+        listqueryTemplateID: 1803425,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 297,
+        queryTemplateID: 18033,
+        columnName: "endNode",
+        columnLabel: "结束节点",
+        columnDescribe: "结束节点",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "varchar",
+        listqueryTemplateID: 1803424,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 298,
+        queryTemplateID: 18033,
+        columnName: "endPosition",
+        columnLabel: "结束位置",
+        columnDescribe: "结束位置",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 1,
+        needGroup: 0,
+        dataType: "varchar",
+        listqueryTemplateID: 1803425,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+      {
+        queryTemplateColumnSetID: 305,
+        queryTemplateID: 18033,
+        columnName: "alarmSceneId",
+        columnLabel: "场景编号",
+        columnDescribe: "场景编号",
+        needSort: 0,
+        needFilters: 1,
+        needShow: 0,
+        needGroup: 0,
+        dataType: "int",
+        listqueryTemplateID: null,
+        needCount: null,
+        orderNumber: null,
+        needSearch: null,
+      },
+    ];
+    const result: any = await htQuery(DATACONTENT_ID.sysServiceClId, {
+      alarmSceneId: route.query.alarmSceneId,
     });
-    if (code === "0") {
-      if (returnData.listValues.length === 0) {
+    if (result && result.length) {
+      if (result.length === 0) {
         page.value--;
         noMore.value = true;
       }
-      const titleColumn = returnData.columnSet.find(
-        (item) => item.needShow === 1
-      );
+      const titleColumn = columnSet.find((item) => item.needShow === 1);
       if (titleColumn) {
         rowTitle.value = titleColumn.columnName;
       }
-      tableData.value.push(...returnData.listValues);
-      tableCols.value = returnData.columnSet;
-      returnData.columnSet.forEach((item) => {
+      tableData.value.push(...result);
+      tableCols.value = columnSet;
+      columnSet.forEach((item) => {
         if (item.columnName === "calculationBasis") {
           getSelectData(item.listqueryTemplateID, "", "calculationBasis");
         }
-        // if (item.listqueryTemplateID && item.columnName === "beginNode") {
-        //   getSelectData(item.listqueryTemplateID, "", "beginNode");
-        // } else if (
-        //   item.listqueryTemplateID &&
-        //   item.columnName === "beginPosition"
-        // ) {
-        //   getSelectData(item.listqueryTemplateID, null, "beginPosition");
-        //   beginPositionId.value = item.listqueryTemplateID;
-        // } else if (item.listqueryTemplateID && item.columnName === "endNode") {
-        //   getSelectData(item.listqueryTemplateID, "", "endNode");
-        // } else if (
-        //   item.listqueryTemplateID &&
-        //   item.columnName === "endPosition"
-        // ) {
-        //   getSelectData(item.listqueryTemplateID, null, "endPosition");
-        //   endPositionId.value = item.listqueryTemplateID;
-        // }
       });
       tableCols.value.forEach((element) => {
         element.label = element.columnLabel;
         element.key = element.columnName;
       });
-      serviceId.value = returnData.submitID;
     } else {
       page.value--;
     }
@@ -429,9 +588,30 @@ const changeEndPos = (value) => {};
 //确认提交
 const warningEditForm: any = ref(null);
 const submitForm = () => {
-  warningEditForm.value.validate((valid: any) => {
+  warningEditForm.value.validate(async (valid: any) => {
     if (valid) {
-      generalDataReception(tableForms);
+      const event = type.value == "add" ? 1 : 2;
+      const { code, message } =
+        event == 1
+          ? await dataToChange(DATACONTENT_ID.sysServiceClId, tableForms, event)
+          : await dataToChange(
+              DATACONTENT_ID.sysServiceClId,
+              tableForms,
+              event,
+              "alarmSceneId"
+            );
+      if (code == 0) {
+        ElMessage.success(message);
+        resetTable();
+        getQuery();
+        resetForm();
+        flag.value = false;
+        tableObj.value = {};
+      } else {
+        tableObj.value = {};
+        resetForm();
+        ElMessage.error(message);
+      }
     } else {
       return false;
     }
@@ -484,9 +664,20 @@ const generalDataReception = async (data) => {
 //编辑数据
 const warningEditsForm: any = ref(null);
 const preserForm = async () => {
-  warningEditsForm.value.validate((valid: any) => {
+  warningEditsForm.value.validate(async (valid: any) => {
     if (valid) {
-      generalDataReceptions(tableForm);
+      const { code, message } = await dataToChange(
+        DATACONTENT_ID.sysServiceCjId,
+        tableForm,
+        2,
+        "alarmSceneId"
+      );
+      if (code == 0) {
+        ElMessage.success(message);
+        sysServiceWarn();
+      } else {
+        ElMessage.error(message);
+      }
     } else {
       return false;
     }
@@ -533,7 +724,7 @@ const getWzData = async () => {
 onMounted(() => {
   sysServiceWarn();
   getQuery();
-  getSelectDatas(route.query.listqueryTemplateID);
+  // getSelectDatas(route.query.listqueryTemplateID);
   getIaCode();
   getAirpot();
   getJdData();