Browse Source

服务新增、删除

zhongxiaoyu 2 years ago
parent
commit
5bc747c468

+ 1 - 1
public/demo.js

@@ -104,7 +104,7 @@ const DATACONTENT_ID = {
   sysServiceTopologyTable: 31, //系统设置-服务管理-服务拓扑-查看日志
   sysServiceTopology: 32, //系统设置-服务管理-服务拓扑-根据id获取拓扑图
   sysDataEditId: 57, //系统设置-数据结构-数据项-表格-编辑-id
-  sysServiceNodeListId: 89,
+  sysServiceNodeList: 89, // 系统设置-服务管理-机器列表
   sysServiceaddId: 8013, //新增预警报警场景
   sysServiceStrategyaddId: 8014, //新增预警报警策略
   /***-----进港管理------***/

+ 15 - 15
src/api/webApi.ts

@@ -1,35 +1,35 @@
-import request from "@/utils/axiosReq";
-import { ObjTy } from "~/common";
+import request from '@/utils/axiosReq'
+import { CommonQueryResult } from '~/common'
 
-export function Query(params) {
+export function Query(params): Promise<CommonQueryResult> {
   return request({
-    url: "/openApi/query",
-    method: "post",
+    url: '/openApi/query',
+    method: 'post',
     data: params,
-  });
+  })
 }
 
 export async function myQuery(id, ...dataContent) {
   const params = {
     id,
     dataContent,
-  };
+  }
   try {
-    const result = await Query(params);
+    const result = await Query(params)
     if (Number(result.code) === 0) {
-      return result.returnData.listValues;
+      return result.returnData.listValues
     } else {
-      return Promise.reject(result.message);
+      return Promise.reject(result.message)
     }
   } catch (error) {
-    return Promise.reject(error);
+    return Promise.reject(error)
   }
 }
 
-export function GeneralDataReception(params) {
+export function GeneralDataReception(params): Promise<CommonQueryResult> {
   return request({
-    url: "/openApi/generalDataReception",
-    method: "post",
+    url: '/openApi/generalDataReception',
+    method: 'post',
     data: params,
-  });
+  })
 }

+ 1 - 1
src/views/systemSettings/log/index.vue

@@ -73,7 +73,7 @@
 <script setup lang="ts">
 import DataTable from '@/components/tableTemp/index.vue'
 import { ElMessage } from 'element-plus'
-import { Query } from '@/api/dataIntegration'
+import { Query } from '@/api/webApi'
 
 type TableColumn = {
   label: string

+ 163 - 22
src/views/systemSettings/serviceManagement/index.vue

@@ -35,7 +35,7 @@
         @del-remove="delSubmitHandler"
         @del-rest="delDialogHide"
         @submit-form="serviceSubmitHandler"
-        @reset-form="serviceDialogHide"
+        @reset-form="addServiceDialogHide"
       >
         <el-form
           ref="serviceFormRef"
@@ -172,8 +172,8 @@
                 <el-date-picker
                   v-model="serviceForm.startTime"
                   type="datetime"
-                  format="yyyy-MM-dd HH:mm"
-                  value-format="yyyy-MM-dd HH:mm"
+                  format="YYYY-MM-DD HH:mm"
+                  value-format="YYYY-MM-DD HH:mm"
                   placeholder="请选择启动时间"
                 />
               </el-form-item>
@@ -183,8 +183,8 @@
                 <el-date-picker
                   v-model="serviceForm.stopTime"
                   type="datetime"
-                  format="yyyy-MM-dd HH:mm"
-                  value-format="yyyy-MM-dd HH:mm"
+                  format="YYYY-MM-DD HH:mm"
+                  value-format="YYYY-MM-DD HH:mm"
                   placeholder="请选择停止时间"
                 />
               </el-form-item>
@@ -315,12 +315,13 @@ import DataTable from '@/components/tableTemp/index.vue'
 import MinHeader from '@/components/minheader/index.vue'
 import Dialog from '@/components/dialog/index.vue'
 import { ElMessage, FormInstance } from 'element-plus'
-import { Query } from '@/api/dataIntegration'
 import {
   CommonTableColumn,
   CommonQueryResult,
   SelectOptionQueryResult,
 } from '~/common'
+import request from '@/utils/axiosReq'
+import { Query, GeneralDataReception } from '@/api/webApi'
 
 interface DataSource {
   dataSourceID: string | number
@@ -331,6 +332,8 @@ interface Protocol {
   protocolName: string
 }
 
+const router = useRouter()
+
 // 表格
 const tableColumns = ref<CommonTableColumn[]>([])
 const tableData = ref<any[]>([])
@@ -340,6 +343,12 @@ const rowTitle = ref('')
 onMounted(() => {
   getTableData()
 })
+const resetTable = () => {
+  page.value = 0
+  noMore.value = false
+  tableData.value = []
+  getTableData()
+}
 const getTableData = async () => {
   try {
     const {
@@ -368,9 +377,9 @@ const getTableData = async () => {
       ...column,
     }))
     tableData.value.push(...listValues)
-  } catch (error: any) {
+  } catch (error) {
     page.value--
-    ElMessage.error(error.message)
+    console.error(error)
   }
 }
 const tableBtnGroup = [
@@ -395,41 +404,133 @@ const tableBtnGroup = [
     param: 4,
   },
 ]
-const tableButtonClickHandler = (
-  rowIndex: number,
-  row: object,
-  param: number
-) => {
+const tableButtonClickHandler = (rowIndex: number, row: any, param: number) => {
   switch (param) {
     case 1:
+      router.push({
+        path: '/systemSettings/serviceTopology',
+        query: {
+          serviceID: row['serviceID'],
+          serviceName: row['serviceName'],
+        },
+      })
       break
     case 2:
+      router.push({
+        path: '/systemSettings/serviceTopology',
+        query: {
+          serviceID: row['serviceID'],
+          serviceName: row['serviceName'],
+        },
+      })
       break
     case 3:
+      changeServiceState(row['serviceID'], row['runState'])
       break
     case 4:
+      delID = row['serviceID']
+      delDialogShow(row)
       break
     default:
       break
   }
 }
+const changeServiceState = async (serviceID: number, runState: string) => {
+  const operate = runState === '运行' ? 'stop' : 'start'
+  try {
+    const {
+      code,
+      returnData: { listValues },
+      message,
+    } = await Query({
+      id: DATACONTENT_ID.sysServiceNodeList,
+      dataContent: [serviceID],
+    })
+    if (Number(code) !== 0) {
+      throw new Error(message ?? '失败')
+    }
+    if (!listValues.length) {
+      throw new Error('无部署机器')
+    }
+    Promise.all(
+      listValues.map(node => {
+        request({
+          url: `${node.serviceURL}${operate}`,
+          method: 'post',
+          data: {
+            serviceId: serviceID,
+          },
+        })
+      })
+    )
+      .then((results: any) => {
+        if (results.every(result => Number(result.code) === 0)) {
+          ElMessage.success('操作成功')
+        } else {
+          ElMessage.error('操作失败')
+        }
+      })
+      .catch(error => {
+        throw new Error(error)
+      })
+  } catch (error) {
+    console.error(error)
+  }
+}
 
 // 新增/删除服务-弹窗
 const serviceDialogVisible = ref(false) // 弹窗开关
-const serviceDialogType = ref('del') // 弹窗类型是否删除
+const serviceDialogType = ref('') // 弹窗类型是否删除
 const serviceDialogWidth = computed(() =>
   serviceDialogType.value === 'del' ? '600px' : '878px'
 )
 const delName = ref('') // 删除对象名
-const msgTitle = '新增服务管理' // 新增弹窗-标题
+let delID // 删除对象ID
+const msgTitle = ref('') // 服务弹窗-标题
+const delDialogShow = row => {
+  serviceDialogType.value = 'del'
+  msgTitle.value = '删除服务'
+  delName.value = row['serviceName']
+  serviceDialogVisible.value = true
+}
+const delDialogHide = () => {
+  serviceDialogVisible.value = false
+}
+const delSubmitHandler = async () => {
+  try {
+    await deleteService()
+    delDialogHide()
+    resetTable()
+  } catch (error) {
+    console.error(error)
+  }
+}
+const deleteService = async () => {
+  try {
+    const dataContent = {
+      serviceID: delID,
+      event: 3,
+    }
+    const { code, message } = await GeneralDataReception({
+      serviceID: SERVICE_ID.sysServiceEdit,
+      dataContent: JSON.stringify(dataContent),
+    })
+    if (Number(code) === 0) {
+      ElMessage.success(message ?? '成功')
+    } else {
+      throw new Error(message ?? '失败')
+    }
+  } catch (error) {
+    return Promise.reject(error)
+  }
+}
 const addServiceDialogShow = () => {
   getSelectOptions(DATACONTENT_ID.dataSourceOptions)
   serviceDialogType.value = 'add'
+  msgTitle.value = '新增服务管理'
   serviceDialogVisible.value = true
 }
-const delSubmitHandler = () => {}
-const delDialogHide = () => {}
-const serviceDialogHide = () => {
+const addServiceDialogHide = () => {
   serviceFormRef.value?.resetFields()
   serviceDialogVisible.value = false
 }
@@ -468,7 +569,47 @@ const serviceFormRules = {
 }
 const dataSourceList = ref<DataSource[]>([])
 const serviceSubmitHandler = () => {
-  serviceDialogHide()
+  serviceFormRef.value!.validate(async valid => {
+    if (valid) {
+      try {
+        await createService()
+        addServiceDialogHide()
+        resetTable()
+      } catch (error) {
+        console.error(error)
+      }
+    }
+  })
+}
+const createService = async () => {
+  try {
+    Object.keys(serviceForm).forEach(key => {
+      if (
+        ![
+          'sourceObjectName',
+          'lifeCycleCol',
+          'computingMethod',
+          'validationExpression',
+          'logList',
+        ].includes(key) &&
+        serviceForm[key] === ''
+      ) {
+        serviceForm[key] = null
+      }
+    })
+    const dataContent = { ...serviceForm, event: 1 }
+    const { code, message } = await GeneralDataReception({
+      serviceID: SERVICE_ID.sysServiceEdit,
+      dataContent: JSON.stringify(dataContent),
+    })
+    if (Number(code) === 0) {
+      ElMessage.success(message ?? '成功')
+    } else {
+      throw new Error(message ?? '失败')
+    }
+  } catch (error) {
+    return Promise.reject(error)
+  }
 }
 
 // 新增数据来源-弹窗
@@ -504,7 +645,7 @@ const getSelectOptions = async (id: number) => {
       dataContent: [],
     })
     if (Number(code) !== 0) {
-      throw new Error(message || '失败')
+      throw new Error(message ?? '失败')
     }
     const options = listValues.map(item => ({
       [item.setlabel]: item.k,
@@ -520,8 +661,8 @@ const getSelectOptions = async (id: number) => {
       default:
         break
     }
-  } catch (error: any) {
-    ElMessage.error(error.message)
+  } catch (error) {
+    console.error(error)
   }
 }
 </script>

+ 9 - 191
src/views/systemSettings/serviceManagement/serviceTopology.vue

@@ -109,7 +109,7 @@ import { Ref, provide } from 'vue'
 import * as echarts from 'echarts'
 import _ from 'lodash'
 import { ElMessage } from 'element-plus'
-import { Query } from '@/api/dataIntegration'
+import { Query } from '@/api/webApi'
 import img1 from '@/assets/integr/jiekou_blue.png'
 import img2 from '@/assets/integr/jiekou_red.png'
 import img3 from '@/assets/integr/pull_blue.png'
@@ -119,8 +119,9 @@ import img6 from '@/assets/integr/save_blue.png'
 import img7 from '@/assets/integr/mysql_blue.png'
 import img8 from '@/assets/integr/pull_red.png'
 
-let serviceID: number
-
+const route = useRoute()
+const serviceID = Number(route.query.serviceID)
+const serviceName = String(route.query.serviceName)
 
 provide('echarts', echarts)
 const chartDom = ref<HTMLDivElement | null>(null)
@@ -172,140 +173,6 @@ const nodeDataList = ref([
     symbol: defaultImg,
     symbolSize: 60,
   },
-  // {
-  //   name: "星盟SBH",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 220],
-  //   draggable: false,
-  //   fixed: true,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "局方公共平台",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 190],
-  //   draggable: false,
-  //   symbol: defaultImgError,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "离港高频",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 160],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "WT",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 130],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "特殊及异常行李",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 100],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "SCS",
-  //   linkTargetName: "国航被动接收节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 70],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "ERP",
-  //   linkTargetName: "国航被动接收节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 40],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  // {
-  //   name: "服务质量",
-  //   linkTargetName: "国航被动接收节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "0",
-  //   },
-  //   value: [10, 10],
-  //   draggable: false,
-  //   symbol: defaultImg,
-  //   symbolSize: 30,
-  // },
-  //节点B,C,D ....n
-  // {
-  //   name: "首都机场边缘节点",
-  //   linkTargetName: "国航主动拉取节点",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "1",
-  //   },
-  //   symbol: pullImg,
-  //   symbolSize: 60,
-  //   draggable: false,
-  //   value: [40, 245],
-  // },
-  // {
-  //   name: "国航主动拉取节点",
-  //   linkTargetName: "Kafka",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "2",
-  //   },
-  //   symbol: pullImg,
-  //   symbolSize: 60,
-  //   draggable: false,
-  //   value: [80, 180],
-  // },
-  // {
-  //   name: "国航被动接收节点",
-  //   linkTargetName: "Kafka",
-  //   linkValue: " ",
-  //   coordConfig: {
-  //     level: "2",
-  //   },
-  //   symbol: pullImg,
-  //   symbolSize: 60,
-  //   draggable: false,
-  //   value: [80, 100],
-  // },
   {
     name: 'Kafka',
     linkTargetName: 'BSMBPM报文解析',
@@ -326,58 +193,6 @@ const nodeDataList = ref([
     draggable: false,
     value: [70, 245],
   },
-  // {
-  //   name: "Kafka ",
-  //   linkTargetName: "BPM",
-  //   linkValue: " ",
-  //   coordConfig: { level: "3" },
-  //   symbolSize: 60,
-  //   symbol: kafkaImg,
-  //   draggable: false,
-  //   label: {
-  //     show: false,
-  //   },
-  //   value: [120, 140],
-  // },
-  // {
-  //   name: "Kafka  ",
-  //   linkTargetName: "航班",
-  //   linkValue: " ",
-  //   coordConfig: { level: "3" },
-  //   symbolSize: 60,
-  //   symbol: kafkaImg,
-  //   draggable: false,
-  //   label: {
-  //     show: false,
-  //   },
-  //   value: [120, 140],
-  // },
-  // {
-  //   name: "Kafka   ",
-  //   linkTargetName: "行李投诉",
-  //   linkValue: " ",
-  //   coordConfig: { level: "3" },
-  //   symbolSize: 60,
-  //   symbol: kafkaImg,
-  //   draggable: false,
-  //   label: {
-  //     show: false,
-  //   },
-  //   value: [120, 140],
-  // },
-  // {
-  //   name: "Kafka    ",
-  //   linkTargetName: "旅客",
-  //   linkValue: " ",
-  //   coordConfig: { level: "3" },
-  //   symbolSize: 60,
-  //   symbol: kafkaImg,
-  //   draggable: false,
-  //   label: {
-  //     show: false,
-  //   },
-  //   value: [120, 140],
-  // },
   {
     name: 'BSM',
     linkTargetName: '解析服务',
@@ -582,6 +397,9 @@ const nodeDataList = ref([
   },
 ])
 const options = reactive({
+  title: {
+    text: `当前服务:${serviceName}`,
+  },
   itemStyle: {
     normal: {
       color: '#67C23A',
@@ -594,7 +412,7 @@ const options = reactive({
     fontWeight: 600,
   },
   grid: {
-    top: 20,
+    top: 60,
     bottom: 10,
     left: 0,
     right: 0,
@@ -649,7 +467,7 @@ const options = reactive({
 const getCoordDataList = (): any[] => {
   let coorDataDict = {}
   let defaultConfig = {
-    type: 'lines', //块1,2...n到节点A,B...N
+    type: 'lines', // 块1,2...n到节点A,B...N
     coordinateSystem: 'cartesian2d',
     // animationDelay: 10000,
     z: 1,

+ 1 - 0
typings/global.d.ts

@@ -10,6 +10,7 @@ declare global {
   declare const PLATFROM_CONFIG: any
   declare const LOOP_INTERVAL: any
   declare const DATACONTENT_ID: any
+  declare const SERVICE_ID: any
 }
 
 export {}