Przeglądaj źródła

refactor: 手动提交采集策略数据

zhanghaijun 3 lat temu
rodzic
commit
cc72635164

+ 5 - 2
src/main/java/com/cec/plugins/service/task/TaskCollectService.java

@@ -48,7 +48,10 @@ public class TaskCollectService {
     private ScheduledFuture<?> future;
 
     public void startReported(DtoPolicy policyDto) {
-        stopReported();
+        if (future != null) {
+            future.cancel(true);
+            log.info("###### 停止上次的上报采集数据定时 ######");
+        }
         long delayMillis = properties.getPlatform().getDelayMillis();
         future = threadPoolTaskScheduler.schedule(() -> {
             log.info("###### 执行上报采集数据 ######");
@@ -58,12 +61,12 @@ public class TaskCollectService {
     }
 
     public void stopReported() {
+        log.info("###### 停止上报采集数据定时 ######");
         if (future != null) {
             future.cancel(true);
         }
         // 删除采集策略
         FileUtil.del(FILE_POLICY);
-        log.info("###### 停止上报采集数据定时 ######");
     }
 
     @Async

+ 3 - 2
web/src/components/DistributePost.vue

@@ -29,9 +29,10 @@ const pops = defineProps({
     default: {},
   },
 });
-const emit = defineEmits<{ (e: "distribute"): void }>();
+const emit = defineEmits<{ (e: "distribute", body: Object): void }>();
 
 const bodyStr = ref<string>(JSON.stringify(pops.body));
+
 const bodyJson = computed(() => {
   try {
     return { ...JSON.parse(bodyStr.value), ...{ instanceId: "instanceId-" + randomString(16) } };
@@ -67,7 +68,7 @@ const sendDistribute = async function () {
   let data = await request({ url: pops.url, method: "POST", data: bodyJson.value });
   loading.value = false;
   resultStr.value = data;
-  emit("distribute");
+  emit("distribute", bodyJson.value);
 };
 </script>
 <style scoped lang="scss">

+ 6 - 15
web/src/pages/GatherPolicy.vue

@@ -1,13 +1,14 @@
 <template>
   <div style="padding-right: 100px; display: flex; flex-direction: row; justify-content: flex-end; align-items: center">
-    <!-- <el-button type="info" @click="body = policy" v-if="existPolicy">重置数据</el-button> -->
-    <el-button type="success" @click="reportedPolicy" :disabled="!existPolicy">采集数据上报</el-button>
-    <span style="color: #dea7b3; margin-left: 6px">{{ existPolicy ? "采集数据手动上报" : "未发现手动采集策略" }}</span>
+    <el-button type="success" @click="reportedPolicy" :disabled="!policyStore.policyExist">采集数据上报</el-button>
+    <span style="color: #dea7b3; margin-left: 6px">{{ policyStore.policyExist ? "采集数据手动上报" : "未发现手动采集策略" }}</span>
   </div>
-  <distribute-post url="/config/api/v1/sendPolicy" :body="body" @distribute="existPolicy = true"></distribute-post>
+  <distribute-post url="/config/api/v1/sendPolicy" :body="body" @distribute="policyStore.getPolicy()"></distribute-post>
 </template>
 <script setup lang="ts">
 import request from "@/api/http";
+import { usePolicyStore } from "@/store/policy";
+const policyStore = usePolicyStore();
 
 const policy = {
   taskId: "518BB5B8-7551-418A-BFDD-A90C1CC66F03",
@@ -92,20 +93,10 @@ const policy = {
   ],
 };
 
-const body = ref<any>(policy);
-const existPolicy = ref<boolean>(false);
+const body = ref<any>(policyStore.policyExist ? policyStore.policyBody : policy);
 
 const reportedPolicy = async function () {
   let data: any = await request({ url: "/config/api/v1/reportedPolicy", method: "GET" });
   data.resp_code == 200 ? ElMessage.success(data.resp_msg || "上报成功") : ElMessage.error(data.resp_msg || "上报失败");
 };
-onMounted(async () => {
-  let { resp_msg }: any = await request({ url: "/config/api/v1/getPolicy", method: "GET" });
-  try {
-    body.value = JSON.parse(resp_msg);
-    existPolicy.value = true;
-  } catch (error) {
-    existPolicy.value = false;
-  }
-});
 </script>

+ 9 - 1
web/src/pages/TaskStatus.vue

@@ -1,7 +1,15 @@
 <template>
-  <distribute-post url="config/api/v1/taskStatus" :body="body"></distribute-post>
+  <distribute-post url="config/api/v1/taskStatus" :body="body" @distribute="distributeBefor"></distribute-post>
 </template>
 <script setup lang="ts">
+import { usePolicyStore } from "@/store/policy";
+const policyStore = usePolicyStore();
+
+const distributeBefor = function (bodyJson: any) {
+  if (bodyJson?.status == 1) {
+    policyStore.getPolicy();
+  }
+};
 const body = {
   taskId: "518BB5B8-7551-418A-BFDD-A90C1CC66F03",
   subtaskId: "9480300E-7BDF-4D7A-BA64-7A059880A694",

+ 27 - 0
web/src/store/policy.ts

@@ -0,0 +1,27 @@
+import request from "@/api/http";
+
+/** 采集策略状态 */
+export const usePolicyStore = defineStore("policy", {
+  state: () => {
+    return {
+      policyBody: {},
+    };
+  },
+  getters: {
+    policyStr: (state) => JSON.stringify(state.policyBody),
+    policyExist: (state) => Object.keys(state.policyBody).length != 0,
+  },
+  actions: {
+    async getPolicy() {
+      let { resp_msg }: any = await request({ url: "/config/api/v1/getPolicy", method: "GET" });
+      try {
+        this.policyBody = JSON.parse(resp_msg);
+      } catch (error) {
+        this.policyBody = {};
+      }
+    },
+  },
+  persist: {
+    key: "pligin:policy",
+  },
+});

+ 34 - 0
web/src/store/task.ts

@@ -0,0 +1,34 @@
+/** 下发请求全局变量 */
+export const useUserStore = defineStore("task", {
+  state: () => {
+    return {
+      taskId: "518BB5B8-7551-418A-BFDD-A90C1CC66F03",
+      subtaskId: "9480300E-7BDF-4D7A-BA64-7A059880A694",
+      xdschemaId: "C4552850-3D50-4934-9C4A-580CD447CECE",
+      ident: "典型轨道交通运行控制网拓扑网络场景",
+    };
+  },
+  getters: {
+    taskId: (state) => state.taskId,
+    subtaskId: (state) => state.subtaskId,
+    xdschemaId: (state) => state.xdschemaId,
+    ident: (state) => state.ident,
+  },
+  actions: {
+    setTtaskId(taskId: string) {
+      this.taskId = taskId;
+    },
+    setSubtaskId(subtaskId: string) {
+      this.subtaskId = subtaskId;
+    },
+    setXdschemaId(xdschemaId: string) {
+      this.xdschemaId = xdschemaId;
+    },
+    setIdent(ident: string) {
+      this.ident = ident;
+    },
+  },
+  persist: {
+    key: "pligin:task",
+  },
+});

+ 2 - 0
web/types/auto-imports.d.ts

@@ -305,6 +305,7 @@ import { UnwrapRef } from 'vue'
 declare module 'vue' {
   interface ComponentCustomProperties {
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
+    readonly ElMessage: UnwrapRef<typeof import('element-plus/es')['ElMessage']>
     readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
     readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
     readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>
@@ -597,6 +598,7 @@ declare module 'vue' {
 declare module '@vue/runtime-core' {
   interface ComponentCustomProperties {
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
+    readonly ElMessage: UnwrapRef<typeof import('element-plus/es')['ElMessage']>
     readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
     readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
     readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>