Przeglądaj źródła

算法平台接口feign调用

zhaoyan 3 lat temu
rodzic
commit
d6ea884692

+ 1 - 1
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/AlgPlatformCtrl.java

@@ -50,7 +50,7 @@ public class AlgPlatformCtrl {
             String tokenUri = clientDetail.getTokenUri();
             String appid = clientDetail.getAppid();
             String secret = clientDetail.getSecret();
-            String URI = tokenUri + "?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
+            String URI = tokenUri + "&appid=" + appid + "&secret=" + secret;
             String result = HttpUtil.get(HttpUtil.getHttpClient(), HttpUtil.getRequestConfig(), URI);
             JsonNode jsonNode = JsonUtil.readTree(result);
             JsonNode dataNode = jsonNode.path("data");

+ 0 - 6
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java

@@ -155,12 +155,6 @@ public class MinioUtil {
                 .build());
         pis.close();
 
-        // 执行到此表示上传完成了,强者更新redis的值 1
-        RedisParameter redisParameter=new RedisParameter();
-        redisParameter.setKey(DictConstants.ALGORITHM_KEY + objectPath);
-        redisParameter.setValue("1");
-        redisParameter.setMinutes(1);
-        redisController.set(redisParameter);
     }
 
     /**

+ 14 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/ctrl/AlgorithmCtrl.java

@@ -40,10 +40,23 @@ public class AlgorithmCtrl {
      */
     @RequestMapping("selectAlgorithmList")
     @ResponseBody
-    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param) throws IOException {
         return service.selectAlgorithmList(param);
     }
 
+    /**
+     * 查询算法列表-算法平台页面
+     * @param param
+     * @return
+     */
+    @RequestMapping("selectAlgoPlatformList")
+    @ResponseBody
+    public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param) throws IOException {
+        return service.selectAlgoPlatformList(param);
+    }
+
+
+
     /**
      * 查询算法列表-公有页面
      * @param param

+ 2 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/service/AlgorithmService.java

@@ -14,6 +14,8 @@ public interface AlgorithmService {
 
     ResponseBodyVO selectAlgorithmList(AlgorithmParameter param);
 
+    ResponseBodyVO selectAlgoPlatformList(AlgorithmParameter param);
+
     ResponseBodyVO deleteByid(AlgorithmParameter param);
 
     ResponseBodyVO selectDetailsById(AlgorithmParameter param);

+ 63 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/serviceImpl/AlgorithmServiceImpl.java

@@ -4,21 +4,25 @@ import api.common.pojo.param.algorithm.AlgorithmParameter;
 import api.common.pojo.param.system.DictParam;
 import api.common.pojo.po.algorithm.AlgorithmPO;
 import api.common.pojo.constants.DictConstants;
-import api.common.util.JgitUtil;
-import api.common.util.StringUtil;
+import api.common.util.*;
 import api.common.pojo.vo.algorithm.AlgorithmVO;
 import api.common.pojo.vo.algorithm.RunningProjectVO;
-import api.common.util.TimeUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
+import com.css.simulation.resource.feign.AlgoPlatformService;
 import com.css.simulation.resource.system.service.DictService;
 import com.github.pagehelper.PageInfo;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.eclipse.jgit.lib.Ref;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,6 +30,9 @@ import java.util.Map;
 @Service
 public class AlgorithmServiceImpl implements AlgorithmService {
 
+    @Resource
+    AlgoPlatformService algoPlatformService;
+
     @Autowired
     private AlgorithmMapper algorithmMapper;
 
@@ -68,7 +75,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
     }
 
     @Override
-    public ResponseBodyVO selectAlgorithmList(AlgorithmParameter param) {
+    public ResponseBodyVO selectAlgorithmList(AlgorithmParameter param){
         param.setIsDeleted("0");
         param.setCreateUserId(AuthUtil.getCurrentUserId());
         PageUtil.setPageInfo(param);
@@ -79,6 +86,58 @@ public class AlgorithmServiceImpl implements AlgorithmService {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,new PageInfo<>(vos));
     }
 
+    @Override
+    public ResponseBodyVO selectAlgoPlatformList(AlgorithmParameter param){
+        //获取参数
+        String algorithmId = param.getAlgorithmCode();
+        String algorithmName = param.getAlgorithmName();
+        String description = param.getDescription();
+        Integer page = param.getPageNum();
+        Integer size = param.getPageSize();
+        String sort = "algorithmId-desc";
+        String urlParam = "";
+        if (StringUtil.isNotEmpty(algorithmId)){
+            urlParam = urlParam + "&algorithmId=" + algorithmId;
+        }
+        if (StringUtil.isNotEmpty(algorithmName)){
+            urlParam = urlParam + "&algorithmName=" + algorithmName;
+        }
+        if (StringUtil.isNotEmpty(description)){
+            urlParam = urlParam + "&description=" + description;
+        }
+        if (StringUtil.isNotEmpty(page)){
+            urlParam = urlParam + "&page=" + page;
+        }
+        if (StringUtil.isNotEmpty(size)){
+            urlParam = urlParam + "&size=" + size;
+        }
+        urlParam = urlParam + "&sort=" + sort;
+
+        ResponseBodyVO 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);
+            }
+        }
+        PageInfo<AlgorithmVO> objectPageInfo = new PageInfo<>(vos);
+        objectPageInfo.setTotal(totalElements);
+
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,objectPageInfo);
+    }
+
+
     @Override
     public ResponseBodyVO selectSharedAlgorithmList(AlgorithmParameter param) {
         param.setShare("1");

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

@@ -0,0 +1,26 @@
+package com.css.simulation.resource.feign;
+
+import api.common.pojo.common.ResponseBodyVO;
+import com.css.simulation.resource.common.config.FeignConfiguration;
+import com.css.simulation.resource.feign.fallback.AlgoPlatformServiceFallback;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+
+//@FeignClient(name = "test", url = "http://10.15.12.87:8001",path = "/simulation/resource/common", fallback = AlgoPlatformServiceFallback.class, configuration = FeignConfiguration.class)
+@FeignClient(
+        contextId = "algoPlatform",
+        value = "simulation-resource-common",
+        path = "/simulation/resource/common",
+        fallback = AlgoPlatformServiceFallback.class,
+        configuration = FeignConfiguration.class
+)
+public interface AlgoPlatformService {
+
+    @PostMapping(value = "/algPlatform/getAlgorithmList")
+    ResponseBodyVO getAlgorithmList(@RequestBody String param);
+
+
+
+}

+ 11 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/fallback/AlgoPlatformServiceFallback.java

@@ -0,0 +1,11 @@
+package com.css.simulation.resource.feign.fallback;
+
+import api.common.pojo.common.ResponseBodyVO;
+import com.css.simulation.resource.feign.AlgoPlatformService;
+
+public class AlgoPlatformServiceFallback implements AlgoPlatformService {
+    @Override
+    public ResponseBodyVO<String> getAlgorithmList(String param) {
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
+    }
+}