Explorar o código

编辑模型接口调整

wangchangsheng %!s(int64=2) %!d(string=hai) anos
pai
achega
b128e69c6f

+ 39 - 30
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/TrainFileModeController.java

@@ -1,16 +1,15 @@
 package com.gyee.impala.controller.diagnose;
 
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.gyee.impala.common.result.JsonResult;
 import com.gyee.impala.common.result.ResultCode;
-import com.gyee.impala.model.custom.TokenUser;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
 import com.gyee.impala.model.master.diagnose.TrainInfo;
-import com.gyee.impala.service.custom.SftpFileService;
 import com.gyee.impala.service.custom.ShiroService;
 import com.gyee.impala.service.master.diagnose.TrainFileModeService;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.web.bind.annotation.*;
@@ -29,10 +28,13 @@ import java.util.List;
 @RequestMapping("/api/filemode")
 public class TrainFileModeController {
 
+
+    protected Log log = LogFactory.getLog(getClass());
+
+
     @Autowired
     private ShiroService shiroService;
 
-
     /**
      * 线程池
      */
@@ -72,10 +74,10 @@ public class TrainFileModeController {
         try {
             synchronized (locker) {
                 name1 = name;
-                forecastLabel1= forecastLabel;
-                inputLabel1= inputLabel;
-                host1= host;
-                file1= file;
+                forecastLabel1 = forecastLabel;
+                inputLabel1 = inputLabel;
+                host1 = host;
+                file1 = file;
                 taskExecutor.submit(this::execute);
             }
 
@@ -86,7 +88,6 @@ public class TrainFileModeController {
     }
 
 
-
     private void execute() {
         trainFileModeService.exec(name1, forecastLabel1, inputLabel1, host1, file1);
     }
@@ -121,31 +122,30 @@ public class TrainFileModeController {
 
     /**
      * 训练结果
+     *
      * @param history
      * @return
      */
     @PostMapping("/putHistory")
-    public JSONObject putDiagnosetrainhistory(@RequestBody  String history){
+    public JSONObject putDiagnosetrainhistory(@RequestBody String history) {
         try {
+            log.warn(history);
             trainFileModeService.putDiagnosetrainhistory(history);
             return JsonResult.success(ResultCode.SUCCESS);
         } catch (Exception e) {
+            log.error("请求错误", e);
             return JsonResult.error(ResultCode.ERROR);
         }
     }
 
 
-    /**
-     * 获取最终结果
-     * @param history
-     * @return
-     */
-    @GetMapping("/getHistory")
-    public JSONObject getDiagnosetrainhistory(String history){
+    @PostMapping("/getHistory")
+    public JSONObject getHistory() {
         try {
-            Diagnosetrainhistory d = trainFileModeService.getDiagnosetrainhistory(history);
+            Diagnosetrainhistory d = trainFileModeService.consumeHistory();
             return JsonResult.successData(ResultCode.SUCCESS, d);
         } catch (Exception e) {
+            log.error("请求错误", e);
             return JsonResult.error(ResultCode.ERROR);
         }
     }
@@ -153,36 +153,46 @@ public class TrainFileModeController {
 
     /**
      * 编辑最终
+     *
      * @param history
      * @return
      */
     @PostMapping("/editHistory")
-    public JSONObject editDiagnosetrainhistory(String history){
+    public JSONObject editDiagnosetrainhistory(@RequestBody String history) {
         try {
 
-            int code = trainFileModeService.editDiagnosetrainhistory(history);
-            if(code >0){
-                return JsonResult.success(ResultCode.SUCCESS);
-            }else {
-                return JsonResult.error(ResultCode.ERROR);
-            }
+            trainFileModeService.editDiagnosetrainhistory(history);
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR_DATA);
+        }
+    }
 
+
+    /**
+     * @return
+     */
+    @GetMapping("/getHistoryList")
+    public JSONObject getDiagnosetrainhistoryList() {
+        try {
+            List<Diagnosetrainhistory> list = trainFileModeService.editDiagnosetrainhistoryList();
+            return JsonResult.successData(ResultCode.SUCCESS, list);
         } catch (Exception e) {
             return JsonResult.error(ResultCode.ERROR);
         }
     }
 
-
     /**
      * 预测评估
+     *
      * @param jsonObject
      * @return
      */
     @PostMapping("/forecasts")
-    public JSONObject forecasts(@RequestBody JSONObject jsonObject){
+    public JSONObject forecasts(@RequestBody JSONObject jsonObject) {
         try {
-           String resultvalue =  trainFileModeService.forecasts(jsonObject);
-           return JsonResult.successData(ResultCode.SUCCESS,resultvalue);
+            String resultvalue = trainFileModeService.forecasts(jsonObject);
+            return JsonResult.successData(ResultCode.SUCCESS, resultvalue);
         } catch (Exception e) {
             return JsonResult.error(ResultCode.ERROR);
         }
@@ -190,5 +200,4 @@ public class TrainFileModeController {
     }
 
 
-
 }

+ 2 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/model/master/diagnose/TrainInfo.java

@@ -7,4 +7,6 @@ public class TrainInfo {
     private String log;
     private String time;
     private String complete;
+    private String modelname;
+
 }

+ 19 - 3
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/master/diagnose/DiagnosetrainhistoryServiceImpl.java

@@ -6,7 +6,7 @@ import com.gyee.impala.common.base.ExcludeQueryWrapper;
 import com.gyee.impala.common.config.datasource.KuduDataSourceConfig;
 import com.gyee.impala.common.exception.CustomException;
 import com.gyee.impala.common.result.ResultCode;
-import com.gyee.impala.common.util.DateUtil;
+import com.gyee.impala.common.spring.InitialRunner;
 import com.gyee.impala.common.util.SnowFlakeUtil;
 import com.gyee.impala.mapper.master.diagnose.DiagnosetrainhistoryMapper;
 import com.gyee.impala.model.master.diagnose.AlgorithmType;
@@ -24,6 +24,9 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     @Autowired
     private KuduDataSourceConfig kuduConfig;
 
+    @Autowired
+    private InitialRunner initialRunner;
+
     @Override
     public List<Diagnosetrainhistory> getAll( AlgorithmType type) {
         ExcludeQueryWrapper<Diagnosetrainhistory> wrapper = new ExcludeQueryWrapper<>();
@@ -71,9 +74,22 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     }
 
     @Override
-    public int editDiagnosetrainhistory(Diagnosetrainhistory history) {
+    public void editDiagnosetrainhistory(Diagnosetrainhistory history) {
+        try{
+            baseMapper.updateById(history);
+            initialRunner.cacheKnowCategory();
+        } catch (Exception e){
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+    @Override
+    public List<Diagnosetrainhistory> getList() {
+        QueryWrapper<Diagnosetrainhistory> wrapper = new QueryWrapper<>();
+//        wrapper.eq("model",model);
         try{
-            return baseMapper.updateById(history);
+            return baseMapper.selectList(wrapper);
         } catch (Exception e){
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);

+ 8 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/service/master/diagnose/DiagnosetrainhistoryService.java

@@ -39,6 +39,13 @@ public interface DiagnosetrainhistoryService extends IService<Diagnosetrainhisto
      * 编辑模型
      * @param history
      */
-    int editDiagnosetrainhistory(Diagnosetrainhistory history);
+    void editDiagnosetrainhistory(Diagnosetrainhistory history);
+
+
+    /**
+     * 获取训练历史结果
+     * @return
+     */
+    List<Diagnosetrainhistory> getList();
 
 }

+ 33 - 10
gyee-sample-impala/src/main/java/com/gyee/impala/service/master/diagnose/TrainFileModeService.java

@@ -9,12 +9,13 @@ import com.gyee.impala.common.util.JudeSystem;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
 import com.gyee.impala.model.master.diagnose.TrainInfo;
 import com.gyee.impala.service.custom.SftpFileService;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.*;
 import java.util.concurrent.BlockingQueue;
@@ -24,6 +25,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 public class TrainFileModeService {
 
 
+    protected Log log = LogFactory.getLog(getClass());
     @Autowired
     private SftpFileService fileService;
 
@@ -52,7 +54,6 @@ public class TrainFileModeService {
     BlockingQueue<TrainInfo> infoQueue = new LinkedBlockingQueue<TrainInfo>();
     BlockingQueue<Diagnosetrainhistory> historyQueue = new LinkedBlockingQueue<Diagnosetrainhistory>();
 
-    Map<String, BlockingQueue<TrainInfo>> mapConsole = new HashMap<>();
 
 
     public void exec(String name, String forecastLabel, String[] inputLabel, String host, MultipartFile file) {
@@ -134,27 +135,49 @@ public class TrainFileModeService {
      * @param history
      * @throws Exception
      */
-    public void putDiagnosetrainhistory(String history) throws Exception {
+    public void putDiagnosetrainhistory(String  history) throws Exception {
 
-        Diagnosetrainhistory d = JSONObject.parseObject(history, Diagnosetrainhistory.class);
+
+        String body = JSONObject.toJSONString(history);
+        Object historys =  JSONObject.parse(body);
+
+        Diagnosetrainhistory d = JSONObject.parseObject(historys.toString(), Diagnosetrainhistory.class);
         d.setEnable(true);
         diagnosetrainhistoryService.insertItem(d);
         Diagnosetrainhistory dbhistory = diagnosetrainhistoryService.getHistoryByModel(d.getModel());
         historyQueue.put(dbhistory);
     }
 
-    public Diagnosetrainhistory getDiagnosetrainhistory(String id) throws Exception {
-        Diagnosetrainhistory history = historyQueue.take();
-        return history;
+    public Diagnosetrainhistory consumeHistory() throws Exception {
+
+        Diagnosetrainhistory d = null;
+        try {
+            if(historyQueue.size()>0){
+                d = historyQueue.take();
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        return d;
     }
 
+    public String  getDiagnosetrainhistory1() throws Exception {
 
-    public int editDiagnosetrainhistory(String history) {
+        return "000000";
+    }
+
+
+    public void editDiagnosetrainhistory(String history) throws Exception{
         Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
+        diagnosetrainhistoryService.editDiagnosetrainhistory(update);
+    }
+
+
+    public List<Diagnosetrainhistory>  editDiagnosetrainhistoryList() {
 
-        int code  = diagnosetrainhistoryService.editDiagnosetrainhistory(update);
+        List<Diagnosetrainhistory>  list  = diagnosetrainhistoryService.getList();
 
-        return  code;
+        return  list;
     }