Jelajahi Sumber

Merge branch 'master' of http://124.70.43.205:3000/xieshengjie/sis-background

chenminghua 2 tahun lalu
induk
melakukan
b2bdc0f96d

+ 71 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/DiagnosetrainhistoryController.java

@@ -0,0 +1,71 @@
+package com.gyee.impala.controller.diagnose;
+
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.impala.common.result.JsonResult;
+import com.gyee.impala.common.result.ResultCode;
+import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
+import com.gyee.impala.service.master.diagnose.DiagnosetrainhistoryService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+
+/**
+ * 文件方式训练模型
+ */
+@Slf4j
+@CrossOrigin
+@RestController
+@RequestMapping("/api/history")
+public class DiagnosetrainhistoryController {
+    @Autowired
+    private DiagnosetrainhistoryService diagnosetrainhistoryService;
+
+
+    /**
+     * @param enable 模型是否启用
+     * @param name   模型名称
+     * @param code   模型代码
+     * @return
+     */
+    @GetMapping("/getHistoryList")
+    public JSONObject getDiagnosetrainhistoryList(Boolean enable, String name, String code, String model) {
+        try {
+            List<Diagnosetrainhistory> list = diagnosetrainhistoryService.getList(enable, name, code, model);
+            return JsonResult.successData(ResultCode.SUCCESS, list);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR);
+        }
+    }
+
+
+    @PostMapping("/removeHistory")
+    public JSONObject removeDiagnosetrainhistory(String id) {
+        try {
+            diagnosetrainhistoryService.deleteById(id);
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR_DATA);
+        }
+    }
+
+
+    /**
+     * 编辑最终
+     *
+     * @param history
+     * @return
+     */
+    @PostMapping("/editHistory")
+    public JSONObject editDiagnosetrainhistory(@RequestBody String history) {
+        try {
+            Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
+            diagnosetrainhistoryService.editDiagnosetrainhistory(update);
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR_DATA);
+        }
+    }
+}

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

@@ -304,36 +304,6 @@ public class TrainFileModeController {
     }
 
 
-    /**
-     * 编辑最终
-     *
-     * @param history
-     * @return
-     */
-    @PostMapping("/editHistory")
-    public JSONObject editDiagnosetrainhistory(@RequestBody String history) {
-        try {
-
-            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.getDiagnosetrainhistoryList();
-            return JsonResult.successData(ResultCode.SUCCESS, list);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR);
-        }
-    }
 
     /**
      * 预测评估

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

@@ -8,5 +8,6 @@ public class TrainInfo {
     private String time;
     private String complete;
     private String modelname;
+    private String acc;
 
 }

+ 5 - 25
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/TrainFileModeService.java

@@ -12,8 +12,7 @@ import com.gyee.impala.model.master.diagnose.TrainInfo;
 import com.gyee.impala.service.custom.SftpFileService;
 import com.gyee.impala.service.master.diagnose.DiagnosetrainhistoryService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
+import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
@@ -28,6 +27,9 @@ import java.util.concurrent.LinkedBlockingQueue;
 @Service
 public class TrainFileModeService {
 
+
+    private static Logger logger = Logger.getLogger(TrainFileModeService.class);
+
     @Autowired
     private SftpFileService fileService;
 
@@ -149,7 +151,7 @@ public class TrainFileModeService {
         Diagnosetrainhistory d = JSONObject.parseObject(historys.toString(), Diagnosetrainhistory.class);
         d.setEnable(true);
         diagnosetrainhistoryService.insertItem(d);
-        Diagnosetrainhistory dbhistory = diagnosetrainhistoryService.getHistoryByModel(d.getModel());
+        Diagnosetrainhistory dbhistory = diagnosetrainhistoryService.getHistoryByCode(d.getCode());
         historyQueue.put(dbhistory);
 
     }
@@ -173,28 +175,6 @@ public class TrainFileModeService {
     }
 
 
-    /**
-     * 编辑模型
-     *
-     * @param history
-     * @throws Exception
-     */
-    public void editDiagnosetrainhistory(String history) throws Exception {
-        Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
-        diagnosetrainhistoryService.editDiagnosetrainhistory(update);
-    }
-
-
-    /**
-     * 查询历史模型
-     *
-     * @return
-     */
-    public List<Diagnosetrainhistory> getDiagnosetrainhistoryList() {
-        List<Diagnosetrainhistory> list = diagnosetrainhistoryService.getList();
-        return list;
-    }
-
 
     /**
      * 预估

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

@@ -13,6 +13,7 @@ import com.gyee.impala.model.master.diagnose.AlgorithmType;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
 import com.gyee.impala.service.master.diagnose.DiagnosetrainhistoryService;
 import org.apache.kudu.client.*;
+import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -21,6 +22,8 @@ import java.util.List;
 @Service
 public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<DiagnosetrainhistoryMapper, Diagnosetrainhistory> implements DiagnosetrainhistoryService {
 
+
+    private static Logger logger = Logger.getLogger(DiagnosetrainhistoryServiceImpl.class);
     @Autowired
     private KuduDataSourceConfig kuduConfig;
 
@@ -50,7 +53,14 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     }
 
     @Override
-    public void deleteById(String id) {
+    public void deleteById(String id) throws CustomException{
+
+        Diagnosetrainhistory oriHistory = getHistoryById(id);
+        if (null == oriHistory) {
+            logger.warn("没有查找到此模型[ id = " + id + " ]");
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+
         QueryWrapper<Diagnosetrainhistory> wrapper = new QueryWrapper<>();
         wrapper.eq("id",id);
         try {
@@ -62,11 +72,12 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     }
 
     @Override
-    public Diagnosetrainhistory getHistoryByModel(String model) {
-        QueryWrapper<Diagnosetrainhistory> wrapper = new QueryWrapper<>();
+    public List<Diagnosetrainhistory> getHistoryByModel(String id,String model) {
+        ExcludeQueryWrapper<Diagnosetrainhistory> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.ne("id",id);
         wrapper.eq("model",model);
         try{
-            return baseMapper.selectList(wrapper).get(0);
+            return baseMapper.selectList(wrapper);
         } catch (Exception e){
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);
@@ -75,9 +86,44 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
 
     @Override
     public void editDiagnosetrainhistory(Diagnosetrainhistory history) {
-        try{
+        try {
+            List<Diagnosetrainhistory> historyByModel = getHistoryByModel(history.getId(), history.getModel());
+            if (null != historyByModel && historyByModel.size() > 0 && history.isEnable()) {
+                for (Diagnosetrainhistory h : historyByModel) {
+                    h.setEnable(false);
+                    baseMapper.updateById(h);
+                }
+            }
             baseMapper.updateById(history);
             initialRunner.cacheKnowCategory();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+    @Override
+        public List<Diagnosetrainhistory> getList(Boolean enable, String name, String code,String model) {
+        ExcludeQueryWrapper<Diagnosetrainhistory> wrapper = new ExcludeQueryWrapper<>();
+
+        wrapper.eq("enable", enable);
+        wrapper.eq("name", name);
+        wrapper.eq("code", code);
+        wrapper.eq("model",model);
+        try{
+            return baseMapper.selectList(wrapper);
+        } catch (Exception e){
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+    @Override
+    public Diagnosetrainhistory getHistoryById(String historyId) {
+       ExcludeQueryWrapper<Diagnosetrainhistory> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.eq("id",historyId);
+        try{
+            return baseMapper.selectById(historyId);
         } catch (Exception e){
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);
@@ -85,11 +131,11 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     }
 
     @Override
-    public List<Diagnosetrainhistory> getList() {
+    public Diagnosetrainhistory getHistoryByCode(String code) {
         QueryWrapper<Diagnosetrainhistory> wrapper = new QueryWrapper<>();
-//        wrapper.eq("model",model);
+        wrapper.eq("code",code);
         try{
-            return baseMapper.selectList(wrapper);
+            return baseMapper.selectList(wrapper).get(0);
         } catch (Exception e){
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);

+ 24 - 3
gyee-sample-impala/src/main/java/com/gyee/impala/service/master/diagnose/DiagnosetrainhistoryService.java

@@ -1,6 +1,7 @@
 package com.gyee.impala.service.master.diagnose;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.impala.common.exception.CustomException;
 import com.gyee.impala.model.master.diagnose.AlgorithmType;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
 
@@ -26,13 +27,15 @@ public interface DiagnosetrainhistoryService extends IService<Diagnosetrainhisto
      * 通过id删除
      * @param id
      */
-    void deleteById(String id);
+    void deleteById(String id) throws CustomException;
 
     /**
+     *
      * 通过mode获取模型
+     * @param id
      * @param model
      */
-    Diagnosetrainhistory getHistoryByModel(String model);
+    List<Diagnosetrainhistory> getHistoryByModel(String id,String model);
 
 
     /**
@@ -44,8 +47,26 @@ public interface DiagnosetrainhistoryService extends IService<Diagnosetrainhisto
 
     /**
      * 获取训练历史结果
+     *
+     * @param enable 模型是否启用
+     * @param name   模型名称
+     * @param code   模型代码
      * @return
      */
-    List<Diagnosetrainhistory> getList();
+    List<Diagnosetrainhistory> getList(Boolean enable, String name, String code,String model);
+
+    /**
+     * 通过id获取模型
+     * @param historyId
+     */
+    Diagnosetrainhistory getHistoryById(String historyId);
+
+    /**
+     * 通过code获取模型(唯一)
+     * @param code
+     */
+    Diagnosetrainhistory getHistoryByCode(String code);
+
+
 
 }