zhengnaiwen_citu 1 mese fa
parent
commit
fc22ce1158
2 ha cambiato i file con 186 aggiunte e 152 eliminazioni
  1. 27 5
      src/api/dataFactory.js
  2. 159 147
      src/views/dataFactory/productionLineMonitor/index.vue

+ 27 - 5
src/api/dataFactory.js

@@ -465,14 +465,36 @@ export function productionLineLogDetail (params) {
   return http.post('/dataFactory/platform/production/line/log/detail', params)
 }
 
-// 生产线监控
-export function productionLineMonitor (params) {
-  return http.post('/dataFactory/platform/production/line/monitor/statistics', params)
-}
-
 // 生产线监控
 export function productionLineLogPage (params) {
   return http.post('/dataFactory/platform/production/line/log/page', params)
 }
 
 /** ================================= 生产线 END ==================================================== */
+/** ================================= 生产线 监控 START ==================================================== */
+// 生产线监控 数量
+export function productionLineMonitor (data) {
+  return http.get('/dags/exec-results', data)
+  // return http.post('/dataFactory/platform/production/line/monitor/statistics', params)
+}
+
+// 生产线钻取
+export function getProductionLineList (params) {
+  return http.post('/dags/exec-results/all', params)
+}
+
+// 生产线 常规状态钻取
+export function getProductionLineTasks (params) {
+  return http.post('/dags/exec-results/tasks', params)
+}
+
+// 生产线 未调度钻取
+export function getProductionLineUnscheduled (params) {
+  return http.post('/dags/unscheduled-scripts', params)
+}
+
+// 生产线 钻取日志
+export function getProductionLineTasksLogs (params) {
+  return http.post('/dags/exec-results/task-logs', params)
+}
+/** ================================= 生产线 监控 END ==================================================== */

+ 159 - 147
src/views/dataFactory/productionLineMonitor/index.vue

@@ -32,17 +32,6 @@
         :title="item.title"
         :class="item.class"
       >
-        <!-- <template #title>
-          <v-select
-            v-model="item.query"
-            label="时间"
-            placeholder="请选择时间"
-            class="input-width-m default"
-            :items="item.items"
-            :menu-props="{ offsetY: true }"
-            hide-details outlined dense attach clearable
-          ></v-select>
-        </template> -->
         <low-code v-loading="loading" :option="item.option" height="350"></low-code>
       </m-card>
     </div>
@@ -57,12 +46,8 @@
         :elevation="0"
         :show-select="false"
         :is-tools="false"
-        @pageHandleChange="handlePageChange"
       >
         <template #actions="{ item }">
-          <!-- <template v-if="clickItem.key === 'total'">
-            <v-btn text color="primary">查看生产线</v-btn>
-          </template> -->
           <template v-if="clickItem.key === 'unscheduledCount'">
             <v-btn text color="primary">调度</v-btn>
           </template>
@@ -77,7 +62,24 @@
           </template>
         </template>
       </m-table>
-      <m-log v-model="log.drawer" :data="log.data"></m-log>
+      <!-- <m-log v-model="log.drawer" :data="log.data"></m-log> -->
+      <v-navigation-drawer
+        v-model="log.drawer"
+        fixed
+        temporary
+        right
+        width='700'
+        style="z-index: var(--zIndex-dialog);"
+      >
+        <div v-loading="log.loading" style="min-height: 500px;">
+          <div class="pa-3 font-weight-bold white" style="font-size: 18px; position: sticky; top: 0">
+            {{ log.title }}
+          </div>
+          <div v-for="(log, index) in log.data" :key="index" class="pa-3">
+            {{ log }}
+          </div>
+        </div>
+      </v-navigation-drawer>
     </m-dialog>
   </div>
 </template>
@@ -88,24 +90,32 @@ import LowCode from '@/charts/lowCode'
 import MCard from '@/components/MCard'
 import MDialog from '@/components/Dialog'
 import MTable from '@/components/List/table'
-import MLog from '../components/logPage'
+// import MLog from '../components/logPage'
 import {
   productionLineMonitor,
-  productionLineBasePage,
-  productionLineLogPage,
-  productionLineLogDetail,
-  productionLineLog
+  // productionLineBasePage,
+  // productionLineLogPage,
+  // productionLineLogDetail,
+  // productionLineLog,
+  getProductionLineTasksLogs,
+  getProductionLineList,
+  getProductionLineTasks,
+  getProductionLineUnscheduled
 } from '@/api/dataFactory'
+import {
+  dateFormat
+} from '@/utils/date'
 export default {
   name: 'production-line-monitor',
-  components: { MFilter, LowCode, MCard, MDialog, MTable, MLog },
+  components: { MFilter, LowCode, MCard, MDialog, MTable },
   data () {
     return {
       dialogVisible: false,
       dialogTitle: '',
       table: {
         headers: [
-          { text: '名称', value: 'name' },
+          { text: '名称', value: 'target_table' },
+          { text: '状态', value: 'raw_state' },
           { text: '操作', value: 'actions' }
         ],
         items: [],
@@ -118,7 +128,9 @@ export default {
       },
       log: {
         drawer: false,
-        data: null
+        loading: false,
+        title: null,
+        data: []
       },
       list: [
         {
@@ -194,10 +206,9 @@ export default {
         list: [
           {
             type: 'datePicker',
-            key: 'times',
-            value: [],
-            range: true,
-            dateType: 'day',
+            key: 'exec_date',
+            value: dateFormat('YYYY-mm-dd', new Date()),
+            dateType: 'date',
             placeholder: '请选择要查看的日期',
             clearable: true
           }
@@ -205,85 +216,89 @@ export default {
       },
       loading: false,
       query: {
-        times: []
+        exec_date: dateFormat('YYYY-mm-dd', new Date())
       },
       dictList: {
-        normalCount: '1',
-        executingCount: '2',
-        stopCount: '3',
-        exceptionCount: '4',
-        total: null,
-        unscheduledCount: null
+        success: 0,
+        running: 0,
+        stopped: 0,
+        failed: 0,
+        scheduledCount: 0,
+        total: 0,
+        unscheduledCount: 0
       },
-      items: [
+      clickItem: {},
+      taskStatus: []
+    }
+  },
+  computed: {
+    btnTitle () {
+      return `查看${this.clickItem.isLine ? '最新' : ''}日志`
+    },
+    items () {
+      return [
         {
           title: '生产线数量',
           key: 'total',
-          api: productionLineLog,
+          api: getProductionLineList,
           isLine: true,
-          value: 0,
+          value: this.dictList.total,
           icon: 'mdi-chart-timeline-variant',
           color: 'primary'
         },
         {
           title: '正常执行数量',
-          key: 'normalCount',
-          api: productionLineLog,
+          key: 'success',
+          api: getProductionLineTasks,
           isLine: true,
-          value: 0,
+          value: this.dictList.success,
           icon: 'mdi-timer-check-outline',
           color: 'success'
         },
         {
           title: '正在执行数量',
-          key: 'executingCount',
-          api: productionLineLog,
+          key: 'running',
+          api: getProductionLineTasks,
           isLine: true,
-          value: 0,
+          value: this.dictList.running,
           icon: 'mdi-timer-sync-outline',
           color: 'info'
         },
         {
           title: '停止执行数量',
-          key: 'stopCount',
-          api: productionLineLog,
+          key: 'stopped',
+          api: getProductionLineTasks,
           isLine: true,
-          value: 0,
+          value: this.dictList.stopped,
           icon: 'mdi-timer-cancel-outline',
           color: 'warning'
         },
         {
           title: '异常执行数量',
-          key: 'exceptionCount',
-          api: productionLineLog,
+          key: 'failed',
+          api: getProductionLineTasks,
           isLine: true,
-          value: 0,
+          value: this.dictList.failed,
           icon: 'mdi-timer-alert-outline',
           color: 'error'
         },
         {
           title: '调度执行总数量',
-          key: 'dispatchCount',
-          api: productionLineLogDetail,
-          value: 0,
+          key: 'scheduledCount',
+          api: getProductionLineTasks,
+          value: this.dictList.scheduledCount,
           icon: 'mdi-timer-play-outline',
           color: 'primary'
         },
         {
           title: '未调度执行数量',
           key: 'unscheduledCount',
-          value: 0,
+          api: getProductionLineUnscheduled,
+          value: this.dictList.unscheduledCount,
           icon: 'mdi-timer-pause-outline',
           color: 'default'
         }
-      ],
-      clickItem: {},
-      taskStatus: []
-    }
-  },
-  computed: {
-    btnTitle () {
-      return `查看${this.clickItem.isLine ? '最新' : ''}日志`
+      ]
     }
   },
   created () {
@@ -294,48 +309,64 @@ export default {
       this.loading = true
       try {
         const { data } = await productionLineMonitor(this.query)
-        this.items.forEach(_ele => {
-          _ele.value = data[_ele.key] || 0
-        })
-        this.list.forEach(_e => {
-          if (_e.key === 'line') {
-            if (!data.lineChartMap) {
-              _e.option.xAxis[0].data = []
-              _e.option.series = []
-              return
-            }
-            _e.option.xAxis[0].data = data.lineChartMap.title
-            _e.option.series = data.lineChartMap.series.map(_ele => {
-              return {
-                name: _ele.name,
-                type: 'line',
-                stack: 'Total',
-                symbolSize: 12,
-                areaStyle: {},
-                label: {
-                  show: true,
-                  position: 'top'
-                },
-                emphasis: {
-                  focus: 'series'
-                },
-                data: _ele.data
-              }
-            })
-            return
-          }
-          const item = _e.option.series.find(_v => _v.name === '执行成功失败对比')
-          if (!data.ratioMap) {
-            item.data = []
-            return
-          }
-          item.data = Object.keys(data.ratioMap).map(name => {
-            return {
-              value: data.ratioMap[name],
-              name
-            }
-          })
-        })
+        const item = data.find(e => e.dag_id === 'dataops_productline_execute_dag')
+        if (!item.runs.length) {
+          return
+        }
+        item.runs = item.runs.sort((a, b) => new Date(a.local_exec_time).getTime() - new Date(b.local_exec_time).getTime())
+        const _arr = item.runs[0]
+        this.clickItem = item
+        this.dictList = {
+          success: _arr.tasks.success,
+          running: _arr.tasks.running,
+          stopped: _arr.tasks.stopped,
+          failed: _arr.tasks.failed,
+          scheduledCount: _arr.tasks.scheduled_total,
+          total: _arr.total,
+          unscheduledCount: _arr.unscheduled_total
+        }
+        // this.items.forEach(_ele => {
+        //   _ele.value = data[_ele.key] || 0
+        // })
+        // this.list.forEach(_e => {
+        //   if (_e.key === 'line') {
+        //     if (!data.lineChartMap) {
+        //       _e.option.xAxis[0].data = []
+        //       _e.option.series = []
+        //       return
+        //     }
+        //     _e.option.xAxis[0].data = data.lineChartMap.title
+        //     _e.option.series = data.lineChartMap.series.map(_ele => {
+        //       return {
+        //         name: _ele.name,
+        //         type: 'line',
+        //         stack: 'Total',
+        //         symbolSize: 12,
+        //         areaStyle: {},
+        //         label: {
+        //           show: true,
+        //           position: 'top'
+        //         },
+        //         emphasis: {
+        //           focus: 'series'
+        //         },
+        //         data: _ele.data
+        //       }
+        //     })
+        //     return
+        //   }
+        //   const item = _e.option.series.find(_v => _v.name === '执行成功失败对比')
+        //   if (!data.ratioMap) {
+        //     item.data = []
+        //     return
+        //   }
+        //   item.data = Object.keys(data.ratioMap).map(name => {
+        //     return {
+        //       value: data.ratioMap[name],
+        //       name
+        //     }
+        //   })
+        // })
       } catch (error) {
         this.$snackbar.error(error)
       } finally {
@@ -348,36 +379,17 @@ export default {
       this.table.total = 0
       this.table.pageInfo.current = 1
       this.table.items = []
-      this.clickItem = item
-      this.initTable()
-    },
-    async initTable () {
+      if (item.value === 0) {
+        return
+      }
       this.table.loading = true
       try {
-        const query = {
-          times: this.query.times,
-          ...this.table.pageInfo
-        }
-        if (Object.keys(this.dictList).includes(this.clickItem.key)) {
-          Object.assign(query, {
-            type: this.dictList[this.clickItem.key]
-          })
-        }
-        // if (this.clickItem.key === 'dispatchCount') {
-        //   Object.assign(query, {
-        //     runStatus: '1'
-        //   })
-        // }
-        if (this.clickItem.key === 'unscheduledCount') {
-          Object.assign(query, {
-            status: '0'
-          })
-          delete query.times
-        }
-        const subApi = Object.keys(this.dictList).includes(this.clickItem.key) ? productionLineBasePage : productionLineLogPage
-        const { data } = await subApi(query)
-        this.table.total = data.total
-        this.table.items = data.records
+        const { data } = await item.api({
+          dag_id: this.clickItem.dag_id,
+          run_id: this.clickItem.runs[0].run_id
+        })
+        this.table.total = data.tasks.length
+        this.table.items = data.tasks
       } catch (error) {
         this.$snackbar.error(error)
       } finally {
@@ -395,26 +407,26 @@ export default {
       })
       this.init()
     },
-    handlePageChange (index) {
-      this.table.pageInfo.current = index
-      this.initTable()
-    },
     async handleClickTableItem (item) {
-      if (Object.keys(this.dictList).includes(this.clickItem.key)) {
-        // 跳转生产线明细
-      }
-      // console.log(item)
-      if (!this.clickItem.api) {
-        return
-      }
+      this.log.title = item.target_table
+      this.log.data = []
+      setTimeout(() => {
+        this.log.drawer = true
+        this.log.loading = true
+      })
       try {
-        const { data } = await this.clickItem.api({ id: item.id })
-        this.log.data = data
-        setTimeout(() => {
-          this.log.drawer = true
+        const { data } = await getProductionLineTasksLogs({
+          dag_id: this.clickItem.dag_id,
+          run_id: this.clickItem.runs[0].run_id,
+          task_id: item.task_id,
+          try_number: item.try_number
         })
+
+        this.log.data = data.log.split('\n')
       } catch (error) {
         this.$snackbar.error(error)
+      } finally {
+        this.log.loading = false
       }
     }
   }