Selaa lähdekoodia

前后端日志数据处理

wanggaokun 1 vuosi sitten
vanhempi
sitoutus
2c199d29b5

+ 2 - 1
pdaaphm-admin/src/main/java/com/pdaaphm/biz/controller/LogController.java

@@ -33,7 +33,7 @@ public class LogController {
     @Log(title = "算法", businessType = BusinessType.UPDATE)
     @GetMapping(value = "/info/{taskId}")
     public AjaxResult getLogInfo(@PathVariable("taskId") String taskId) throws IOException {
-        return success(redisLogService.getLogInfo(taskId));
+        return success("成功", redisLogService.getLogInfo(taskId));
     }
 
     @GetMapping(value = "/setInfo/{taskId}")
@@ -45,6 +45,7 @@ public class LogController {
         redisLogService.info(taskId,"开始3。。。。。。");
         redisLogService.info(taskId,"开始4。。。。。。");
         redisLogService.error(taskId,"对方同意更换即可。。。。。。");
+        redisLogService.error(taskId,"任务执行完成。。。。");
         return success();
     }
 

+ 2 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/IRedisLogService.java

@@ -1,5 +1,7 @@
 package com.pdaaphm.biz.service;
 
+import java.util.List;
+
 /**
  * @Description IRedisLogService
  * @Author WGK

+ 4 - 5
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RedisLogService.java

@@ -27,12 +27,11 @@ public class RedisLogService implements IRedisLogService {
     public String getLogInfo(String taskId) {
         List<String> logs = redisCache.getCacheList(taskId);
         if(CollectionUtils.isEmpty(logs)) {
-            return "";
+            return null;
         }
-        String logStr = logs.get(0);
-        log.info("GET::{}", logStr);
-        logs.remove(0);
-        return logStr;
+        // 从头删除
+        redisCache.leftPopList(taskId);
+        return logs.get(0);
     }
 
     @Override

+ 49 - 61
pdaaphm-common/src/main/java/com/pdaaphm/common/core/domain/AjaxResult.java

@@ -1,104 +1,102 @@
 package com.pdaaphm.common.core.domain;
 
-import java.util.HashMap;
-import java.util.Objects;
 import com.pdaaphm.common.constant.HttpStatus;
 import com.pdaaphm.common.utils.StringUtils;
 
+import java.util.HashMap;
+import java.util.Objects;
+
 /**
  * 操作消息提醒
- * 
+ *
  * @author Allen
  */
-public class AjaxResult extends HashMap<String, Object>
-{
+public class AjaxResult extends HashMap<String, Object> {
     private static final long serialVersionUID = 1L;
 
-    /** 状态码 */
+    /**
+     * 状态码
+     */
     public static final String CODE_TAG = "code";
 
-    /** 返回内容 */
+    /**
+     * 返回内容
+     */
     public static final String MSG_TAG = "msg";
 
-    /** 数据对象 */
+    /**
+     * 数据对象
+     */
     public static final String DATA_TAG = "data";
 
     /**
      * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
      */
-    public AjaxResult()
-    {
+    public AjaxResult() {
     }
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      */
-    public AjaxResult(int code, String msg)
-    {
+    public AjaxResult(int code, String msg) {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
     }
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      * @param data 数据对象
      */
-    public AjaxResult(int code, String msg, Object data)
-    {
+    public AjaxResult(int code, String msg, Object data) {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
-        if (StringUtils.isNotNull(data))
-        {
+        if (StringUtils.isNotNull(data)) {
             super.put(DATA_TAG, data);
         }
     }
 
     /**
      * 返回成功消息
-     * 
+     *
      * @return 成功消息
      */
-    public static AjaxResult success()
-    {
+    public static AjaxResult success() {
         return AjaxResult.success("操作成功");
     }
 
     /**
      * 返回成功数据
-     * 
+     *
      * @return 成功消息
      */
-    public static AjaxResult success(Object data)
-    {
+    public static AjaxResult success(Object data) {
         return AjaxResult.success("操作成功", data);
     }
 
     /**
      * 返回成功消息
-     * 
+     *
      * @param msg 返回内容
      * @return 成功消息
      */
-    public static AjaxResult success(String msg)
-    {
+    public static AjaxResult success(String msg) {
         return AjaxResult.success(msg, null);
     }
 
     /**
      * 返回成功消息
-     * 
-     * @param msg 返回内容
+     *
+     * @param msg  返回内容
      * @param data 数据对象
      * @return 成功消息
      */
-    public static AjaxResult success(String msg, Object data)
-    {
+    public static AjaxResult success(String msg, Object data) {
         return new AjaxResult(HttpStatus.SUCCESS, msg, data);
     }
 
@@ -108,65 +106,59 @@ public class AjaxResult extends HashMap<String, Object>
      * @param msg 返回内容
      * @return 警告消息
      */
-    public static AjaxResult warn(String msg)
-    {
+    public static AjaxResult warn(String msg) {
         return AjaxResult.warn(msg, null);
     }
 
     /**
      * 返回警告消息
      *
-     * @param msg 返回内容
+     * @param msg  返回内容
      * @param data 数据对象
      * @return 警告消息
      */
-    public static AjaxResult warn(String msg, Object data)
-    {
+    public static AjaxResult warn(String msg, Object data) {
         return new AjaxResult(HttpStatus.WARN, msg, data);
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @return 错误消息
      */
-    public static AjaxResult error()
-    {
+    public static AjaxResult error() {
         return AjaxResult.error("操作失败");
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param msg 返回内容
      * @return 错误消息
      */
-    public static AjaxResult error(String msg)
-    {
+    public static AjaxResult error(String msg) {
         return AjaxResult.error(msg, null);
     }
 
     /**
      * 返回错误消息
-     * 
-     * @param msg 返回内容
+     *
+     * @param msg  返回内容
      * @param data 数据对象
      * @return 错误消息
      */
-    public static AjaxResult error(String msg, Object data)
-    {
+    public static AjaxResult error(String msg, Object data) {
         return new AjaxResult(HttpStatus.ERROR, msg, data);
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      * @return 错误消息
      */
-    public static AjaxResult error(int code, String msg)
-    {
+    public static AjaxResult error(int code, String msg) {
         return new AjaxResult(code, msg, null);
     }
 
@@ -175,8 +167,7 @@ public class AjaxResult extends HashMap<String, Object>
      *
      * @return 结果
      */
-    public boolean isSuccess()
-    {
+    public boolean isSuccess() {
         return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
     }
 
@@ -185,8 +176,7 @@ public class AjaxResult extends HashMap<String, Object>
      *
      * @return 结果
      */
-    public boolean isWarn()
-    {
+    public boolean isWarn() {
         return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
     }
 
@@ -195,21 +185,19 @@ public class AjaxResult extends HashMap<String, Object>
      *
      * @return 结果
      */
-    public boolean isError()
-    {
+    public boolean isError() {
         return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
     }
 
     /**
      * 方便链式调用
      *
-     * @param key 键
+     * @param key   
      * @param value 值
      * @return 数据对象
      */
     @Override
-    public AjaxResult put(String key, Object value)
-    {
+    public AjaxResult put(String key, Object value) {
         super.put(key, value);
         return this;
     }

+ 10 - 0
pdaaphm-common/src/main/java/com/pdaaphm/common/core/redis/RedisCache.java

@@ -132,6 +132,16 @@ public class RedisCache {
         return count == null ? 0 : count;
     }
 
+    /**
+     * 缓存List数据
+     *
+     * @param key      缓存的键值
+     * @return 缓存的对象
+     */
+    public void leftPopList(final String key) {
+        redisTemplate.opsForList().leftPop(key);
+    }
+
     /**
      * 获得缓存的list对象
      *

+ 11 - 14
pdaaphm-ui/src/views/algoManager/algorithm/algoRun.vue

@@ -22,7 +22,7 @@
 </template>
 
 <script>
-import { getAlgorithm, setLog, getLog } from '@/api/algoManager/algorithm'
+import { getAlgorithm, runAlgorithms, getLog } from '@/api/algoManager/algorithm'
 import { registerAction } from 'echarts/core'
 export default {
   name: 'AlgoRun',
@@ -42,12 +42,6 @@ export default {
   created() {
     // this.getData()
   },
-  beforeDestroy() {
-    if (this.timer) {
-      console.log('销毁定时器')
-      clearInterval(this.timer)
-    }
-  },
   activated() {
     this.getData()
     this.show = false
@@ -57,7 +51,6 @@ export default {
     getData() {
       this.loading = true
       let id = this.$route.params.algoID
-      console.log(id)
       getAlgorithm(id).then(response => {
         console.log('response', response)
         this.info = response.data
@@ -66,16 +59,20 @@ export default {
     },
     /** 运行算法按钮操作 */
     handleRun(id) {
+      this.show = true
       const taskId = `TASK-${id}`
-      setLog(taskId).then(res => {
-        this.timer = setInterval(this.getLog(taskId), 2000)
+      runAlgorithms(id).then(res => {
+        this.timer = setInterval(this.getLogInfo, 1000, taskId)
       })
     },
-    getLog(taskId) {
+    getLogInfo(taskId) {
       getLog(taskId).then(response => {
-        this.show = true
-        this.message = response.msg
-        console.log(response)
+        let logData = response.data
+        if (!logData || (logData && logData.includes('任务执行完成')) ) {
+          console.log("定时器销毁");
+          clearInterval(this.timer)
+        }
+        this.message = this.message + logData
       })
     },
   },