root 2 tahun lalu
induk
melakukan
7045fdaeaf

+ 53 - 15
api-common/src/main/java/api/common/util/ObjectUtil.java

@@ -7,19 +7,20 @@ import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.vo.model.VehicleVO;
 import api.common.pojo.vo.system.DictVO;
 import com.fasterxml.jackson.databind.JsonNode;
-import lombok.SneakyThrows;
 import org.springframework.beans.BeanUtils;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.*;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
 
 public class ObjectUtil {
 
     /**
      * 空值判断
      */
-    @SuppressWarnings("all")
     public static boolean isNull(Object obj) {
         boolean isNullFlag = true;
         if (obj != null) {
@@ -34,9 +35,9 @@ public class ObjectUtil {
             } else if (obj instanceof String) {
                 isNullFlag = isNull((String) obj);
             } else if (obj instanceof Integer) {
-                isNullFlag = false;
+                isNullFlag = isNull((Integer) obj);
             } else if (obj instanceof Boolean) {
-                isNullFlag = false;
+                isNullFlag = isNull((Boolean) obj);
             } else if (obj instanceof StringBuffer) {
                 isNullFlag = isNull((StringBuffer) obj);
             } else if (obj instanceof JsonNode) {
@@ -89,7 +90,7 @@ public class ObjectUtil {
     }
 
     public static List<DictVO> DictListToTree(List<DictVO> list) {
-        List<DictVO> treeList = new ArrayList<>();
+        List<DictVO> treeList = new ArrayList<DictVO>();
         for (DictVO dictVO : list) {
             if ("0".equals(dictVO.getPid())) {
                 treeList.add(findChildren(dictVO, list));
@@ -260,20 +261,60 @@ public class ObjectUtil {
         return vehiclePO;
     }
 
+    /**
+     * list转tree结构,
+     *
+     * @param list        List<T>类型数据源
+     * @param rootId      tree的根节点id
+     * @param getId       <T>类型获取id的方法
+     * @param getPid      <T>类型获取父id的方法
+     * @param getChildren <T>类型获取子对象的方法
+     * @param setChildren <T>类型设置子对象的方法
+     * @param <T>         该对象满足父子关系的相关字段:id 和 父id
+     * @param <String>    id的数据类型为String
+     * @return 树形结构的List<T>,多根型
+     */
+    public static <T, String> List<T> listToTree(List<T> list, String rootId, Function<T, String> getId, Function<T, String> getPid, Function<T, List<T>> getChildren, BiConsumer<T, List<T>> setChildren) {
+        List<T> treeList = new ArrayList<T>();
+        for (T node : list) {
+            if (rootId.equals(getPid.apply(node))) {
+                treeList.add(findChildren(node, list, getId, getPid, getChildren, setChildren));
+            }
+        }
+        return treeList;
+    }
+
+    /**
+     * list转tree递归调用
+     */
+    private static <T, String> T findChildren(T parent, List<T> list, Function<T, String> getId, Function<T, String> getPid, Function<T, List<T>> getChildren, BiConsumer<T, List<T>> setChildren) {
+        for (T node : list)
+            if (getId.apply(parent).equals(getPid.apply(node))) {
+                if (getChildren.apply(parent) == null || getChildren.apply(parent).size() == 0) {
+                    setChildren.accept(parent, new ArrayList<T>());
+                }
+                getChildren.apply(parent).add(findChildren(node, list, getId, getPid, getChildren, setChildren));
+            }
+        return parent;
+    }
 
     /**
      * list转tree结构,<T>类型需要在属性上添加注解,标识树形结构:@WId 、@WParentId、 @WChildren;
+     *
+     * @param list
+     * @param <T>
+     * @return
      */
     public static <T> List<T> listToTree(List<T> list) {
         if (isNull(list)) {
-            return new LinkedList<>();
+            return new LinkedList<T>();
         }
         return listToTree(list, "0");
     }
-    @SuppressWarnings("all")
+
     public static <T> List<T> listToTree(List<T> list, String root) {
         try {
-            List<T> treeList = new LinkedList<>();
+            List<T> treeList = new LinkedList<T>();
             Class<?> tClass = null;
             for (T t : list) {
                 tClass = t.getClass();
@@ -304,7 +345,7 @@ public class ObjectUtil {
             }
             //解析列表
             for (T node : list) {
-                if (root.equals(getParentId.invoke(node))) {
+                if (root.equals((String) getParentId.invoke(node))) {
                     treeList.add(findChildren(node, list, getId, getParentId, getChildren, setChildren));
                 }
             }
@@ -318,17 +359,14 @@ public class ObjectUtil {
     /**
      * list转tree递归调用
      */
-    @SneakyThrows
-    @SuppressWarnings("unchecked")
-    private static <T> T findChildren(T parent, List<T> list, Method getId, Method getParentId, Method getChildren, Method setChildren) {
+    private static <T> T findChildren(T parent, List<T> list, Method getId, Method getParentId, Method getChildren, Method setChildren) throws InvocationTargetException, IllegalAccessException {
         for (T node : list) {
             String id = (String) getId.invoke(parent);
             String parentId = (String) getParentId.invoke(node);
             if (id.equals(parentId)) {
-                final Object invoke = getChildren.invoke(parent);
-                List<T> children = (List<T>) invoke;
+                List<T> children = (List<T>) getChildren.invoke(parent);
                 if (ObjectUtil.isNull(children)) {
-                    children = new ArrayList<>();
+                    children = new ArrayList<T>();
                     setChildren.invoke(parent, children);
                 }
                 children.add(findChildren(node, list, getId, getParentId, getChildren, setChildren));

+ 2 - 15
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/controller/AlgorithmController.java

@@ -5,10 +5,9 @@ import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.constants.LogConstants;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
-import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import java.io.IOException;
@@ -17,7 +16,7 @@ import java.util.Map;
 /**
  * 算法库模块
  */
-@Controller
+@RestController
 @RequestMapping(value = "/algorithm",name = LogConstants.MODULE_ALGORITH)
 public class AlgorithmController {
 
@@ -26,7 +25,6 @@ public class AlgorithmController {
 
     //* -------------------------------- Comm删除算法ent --------------------------------
     @RequestMapping("deleteByid")
-    @ResponseBody
     public ResponseBodyVO<String> deleteById(@RequestBody AlgorithmParameter param){
         return algorithmService.deleteById(param);
     }
@@ -37,7 +35,6 @@ public class AlgorithmController {
      * 新增/修改算法
      */
     @RequestMapping("addOrUpdate")
-    @ResponseBody
     public ResponseBodyVO addOrUpdate(@RequestBody AlgorithmParameter param) throws IOException {
         return algorithmService.addOrUpdate(param);
     }
@@ -49,18 +46,14 @@ public class AlgorithmController {
      * @return
      */
     @RequestMapping("selectAlgorithmList")
-    @ResponseBody
     public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param){
         return algorithmService.selectAlgorithmList(param);
     }
 
     /**
      * 查询算法列表-算法平台页面
-     * @param param
-     * @return
      */
     @RequestMapping("selectAlgoPlatformList")
-    @ResponseBody
     public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param){
         return algorithmService.selectAlgoPlatformList(param);
     }
@@ -72,7 +65,6 @@ public class AlgorithmController {
      * @return
      */
     @RequestMapping("selectSharedAlgorithmList")
-    @ResponseBody
     public ResponseBodyVO selectSharedAlgorithmList(@RequestBody AlgorithmParameter param){
         return algorithmService.selectSharedAlgorithmList(param);
     }
@@ -82,7 +74,6 @@ public class AlgorithmController {
      * 删除算法前校验
      */
     @RequestMapping("deleteCheck")
-    @ResponseBody
     public ResponseBodyVO<Map<String,String>> deleteCheck(@RequestBody AlgorithmParameter param){
         return algorithmService.deleteCheck(param);
     }
@@ -93,7 +84,6 @@ public class AlgorithmController {
      * @return
      */
     @RequestMapping("shareAlgorithm")
-    @ResponseBody
     public ResponseBodyVO shareAlgorithm(@RequestBody AlgorithmParameter param){
         return algorithmService.shareAlgorithm(param);
     }
@@ -105,7 +95,6 @@ public class AlgorithmController {
      * @return
      */
     @RequestMapping("selectDetailsById")
-    @ResponseBody
     public ResponseBodyVO selectDetailsById(@RequestBody AlgorithmParameter param){
         String algorithmId = param.getId();
         return algorithmService.selectDetailsById(algorithmId);
@@ -115,7 +104,6 @@ public class AlgorithmController {
      * git测试连接
      */
     @RequestMapping("testConnection")
-    @ResponseBody
     public ResponseBodyVO<String> testConnection(@RequestBody AlgorithmParameter param){
         return algorithmService.testConnection(param);
     }
@@ -124,7 +112,6 @@ public class AlgorithmController {
      * 根据git仓库地址获取版本号
      */
     @RequestMapping("getGitVersion")
-    @ResponseBody
     public ResponseBodyVO<String> getGitVersion(@RequestBody AlgorithmParameter param) {
         String id = param.getId();
         String gitVersion = algorithmService.getGitVersion(id);

+ 34 - 16
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/service/impl/AlgorithmServiceImpl.java

@@ -23,15 +23,18 @@ import com.css.simulation.resource.project.service.SimulationProjectService;
 import com.css.simulation.resource.system.service.DictService;
 import com.github.pagehelper.PageInfo;
 import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+@Slf4j
 @Service
 public class AlgorithmServiceImpl implements AlgorithmService {
 
@@ -42,7 +45,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
     private DictService dictService;
     private GitConfiguration gitConfiguration;
 
-    @Autowired
+    @Resource
     private SimulationProjectService simulationProjectService;
 
     @Autowired
@@ -160,27 +163,42 @@ public class AlgorithmServiceImpl implements AlgorithmService {
         }
         urlParam = urlParam + "&sort=" + sort;
 
-        ResponseBodyVO algorithmList = algoPlatformService.getAlgorithmList(urlParam);
+        ResponseBodyVO<String> algorithmList = algoPlatformService.getAlgorithmList(urlParam);
+
 
-        //解析数据
-        Map jsonMap = JsonUtil.jsonToMap((String) algorithmList.getInfo());
-        Map<String, Object> dataMap = (Map<String, Object>) jsonMap.get("data");
-        List<Map<String, String>> contentList = (List<Map<String, String>>) dataMap.get("content");
-        Integer totalElements = (Integer) dataMap.get("totalElements");
         List<AlgorithmVO> vos = new ArrayList<>();
-        if (totalElements > 0) {
-            for (Map<String, String> content : contentList) {
-                AlgorithmVO vo = new AlgorithmVO();
-                vo.setId(content.get("id"));
-                vo.setAlgorithmCode(content.get("algorithmId"));
-                vo.setAlgorithmName(content.get("algorithmName"));
-                vo.setDescription(content.get("description"));
-                vos.add(vo);
+        int totalElements = 0;
+        //解析数据
+        final String json = algorithmList.getInfo();
+        Map jsonMap = JsonUtil.jsonToMap(json);
+        if (CollectionUtil.isNotEmpty(jsonMap)) {
+            Map<String, Object> dataMap = (Map<String, Object>) jsonMap.get("data");
+            if (CollectionUtil.isNotEmpty(dataMap)) {
+                List<Map<String, String>> contentList = (List<Map<String, String>>) dataMap.get("content");
+                if (CollectionUtil.isNotEmpty(contentList)) {
+                    totalElements = (Integer) dataMap.get("totalElements");
+                    if (totalElements > 0) {
+                        for (Map<String, String> content : contentList) {
+                            AlgorithmVO vo = new AlgorithmVO();
+                            vo.setId(content.get("id"));
+                            vo.setAlgorithmCode(content.get("algorithmId"));
+                            vo.setAlgorithmName(content.get("algorithmName"));
+                            vo.setDescription(content.get("description"));
+                            vos.add(vo);
+                        }
+                    }
+                } else {
+                    log.info("算法列表接口返回值中的 data.content 字段为空:" + contentList);
+                }
+            } else {
+                log.info("算法列表接口返回值中的 data 字段为空:" + dataMap);
             }
+        } else {
+            log.info("算法列表接口返回值为空:" + json);
         }
+
         PageInfo<AlgorithmVO> objectPageInfo = new PageInfo<>(vos);
         objectPageInfo.setTotal(totalElements);
-
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, objectPageInfo);
     }
 

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/AlgoPlatformService.java

@@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 public interface AlgoPlatformService {
 
     @PostMapping(value = "/algPlatform/getAlgorithmList")
-    ResponseBodyVO getAlgorithmList(@RequestBody String param);
+    ResponseBodyVO<String> getAlgorithmList(@RequestBody String param);
 
     @PostMapping(value = "/algPlatform/selectAlgorithmNameByAlgorithmId")
     ResponseBodyVO<String> selectAlgorithmNameByAlgorithmId(@RequestBody String algorithmId);