martin пре 3 година
родитељ
комит
0fbf015ef7

+ 11 - 4
api-common/pom.xml

@@ -14,10 +14,18 @@
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>
+        <jackson-core.version>2.13.1</jackson-core.version>
     </properties>
 
     <dependencies>
 
+        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+            <version>${jackson-core.version}</version>
+        </dependency>
+
         <!-- http 客户端 -->
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
@@ -42,10 +50,9 @@
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-configuration-processor</artifactId>
-        </dependency>
+
+
+
     </dependencies>
 
 </project>

+ 1 - 1
simulation-resource-common/src/main/java/com/css/simulation/resource/common/pojo/parameter/KafkaParameter.java → api-common/src/main/java/api/common/pojo/parameter/KafkaParameter.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.common.pojo.parameter;
+package api.common.pojo.parameter;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;

+ 5 - 1
simulation-resource-common/src/main/java/com/css/simulation/resource/common/pojo/parameter/MinioParameter.java → api-common/src/main/java/api/common/pojo/parameter/MinioParameter.java

@@ -1,16 +1,20 @@
-package com.css.simulation.resource.common.pojo.parameter;
+package api.common.pojo.parameter;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
 public class MinioParameter {
 
+    @NotNull(message = "文件不能")
+    private MultipartFile file;
     @NotBlank(message ="bucket 名称不能为空!")
     private String bucketName;
     @NotBlank(message ="object 名称不能为空!")

+ 1 - 1
simulation-resource-common/src/main/java/com/css/simulation/resource/common/pojo/parameter/RedisParameter.java → api-common/src/main/java/api/common/pojo/parameter/RedisParameter.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.common.pojo.parameter;
+package api.common.pojo.parameter;
 
 
 import lombok.AllArgsConstructor;

+ 1 - 1
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/FileUtil.java → api-common/src/main/java/api/common/util/FileUtil.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.common.util;
+package api.common.util;
 
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.multipart.MultipartFile;

+ 5 - 26
api-common/src/main/java/api/common/util/HttpUtil.java

@@ -6,8 +6,6 @@ import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.util.EntityUtils;
-import org.springframework.boot.configurationprocessor.json.JSONException;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
@@ -30,26 +28,10 @@ import java.util.Map;
  */
 public class HttpUtil {
 
-//    private static final CloseableHttpClient httpClient;
-//    private static final RequestConfig requestConfig = RequestConfig.custom()
-//            .setSocketTimeout(5000)
-//            .setConnectTimeout(5000)
-//            .setConnectionRequestTimeout(5000)
-//            .setRedirectsEnabled(false)
-//            .setExpectContinueEnabled(false)
-//            .build();
-//
-//    static {
-//        PoolingHttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
-//        pool.setMaxTotal(300);
-//        pool.setDefaultMaxPerRoute(300);
-//        httpClient = HttpClients.custom().setConnectionManager(pool).build();
-//    }
-
     /**
      * get 请求的参数在 url 里
      */
-    public static JSONObject get(CloseableHttpClient httpClient, RequestConfig requestConfig, String url, Map<String, String> headers) throws Exception {
+    public static String get(CloseableHttpClient httpClient, RequestConfig requestConfig, String url, Map<String, String> headers) throws Exception {
         //1 创建 post 请求
         HttpGet get = new HttpGet(url);
         //2 设置请求默认配置
@@ -63,8 +45,7 @@ public class HttpUtil {
         //5 处理返回结果,
         //5-1 如果状态码为200,就是正常返回
         if (response.getStatusLine().getStatusCode() == 200) {
-            String result = EntityUtils.toString(response.getEntity());
-            return new JSONObject(result);
+            return EntityUtils.toString(response.getEntity());
             //如果是下载文件,可以用response.getEntity().getContent()返回InputStream
         } else {
             throw new Exception("服务器错误!");
@@ -79,9 +60,8 @@ public class HttpUtil {
      * @param headers       请求头,可为 null
      * @param localFilePath 本地保存的文件路径
      * @throws IOException   异常
-     * @throws JSONException 异常
      */
-    public static InputStream get(CloseableHttpClient httpClient, RequestConfig requestConfig,String url, Map<String, String> headers, String localFilePath) throws IOException, JSONException {
+    public static InputStream get(CloseableHttpClient httpClient, RequestConfig requestConfig,String url, Map<String, String> headers, String localFilePath) throws IOException {
         //1 创建 post 请求
         HttpGet get = new HttpGet(url);
         //2 设置请求默认配置
@@ -105,7 +85,7 @@ public class HttpUtil {
     /**
      * 发送 post 请求
      */
-    public static JSONObject post(CloseableHttpClient httpClient, RequestConfig requestConfig,String url, Map<String, String> headers, Map<String, String> params) throws Exception {
+    public static String post(CloseableHttpClient httpClient, RequestConfig requestConfig,String url, Map<String, String> headers, Map<String, String> params) throws Exception {
         //1 创建 post 请求
         HttpPost post = new HttpPost(url);
         //2 设置请求默认配置
@@ -123,8 +103,7 @@ public class HttpUtil {
         //6 处理返回结果,
         //6-1 如果状态码为200,就是正常返回
         if (response.getStatusLine().getStatusCode() == 200) {
-            String result = EntityUtils.toString(response.getEntity());
-            return new JSONObject(result);
+            return EntityUtils.toString(response.getEntity());
             //如果是下载文件,可以用response.getEntity().getContent()返回InputStream
         } else {
             throw new Exception("服务器错误!");

+ 0 - 109
api-common/src/main/java/api/common/util/JsonUtil.java

@@ -2,17 +2,9 @@ package api.common.util;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.boot.configurationprocessor.json.JSONArray;
-import org.springframework.boot.configurationprocessor.json.JSONException;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
 
 public class JsonUtil {
 
-    // -------------------------------- A --------------------------------
-    // -------------------------------- B --------------------------------
 
     /**
      * bean 转成 json
@@ -25,24 +17,6 @@ public class JsonUtil {
     public static <T> String beanToJson(T bean) throws JsonProcessingException {
         return new ObjectMapper().writeValueAsString(bean);
     }
-    // -------------------------------- C --------------------------------
-    // -------------------------------- D --------------------------------
-    // -------------------------------- F --------------------------------
-    // -------------------------------- G --------------------------------
-    // -------------------------------- H --------------------------------
-    // -------------------------------- I --------------------------------
-    // -------------------------------- J --------------------------------
-
-    /**
-     * json 转成 JSONObject
-     *
-     * @param json json 字符串
-     * @return JSONObject 对象
-     * @throws JSONException 异常
-     */
-    public static JSONObject jsonToJSONObject(String json) throws JSONException {
-        return new JSONObject(json);
-    }
 
     /**
      * json 转成 bean
@@ -57,75 +31,6 @@ public class JsonUtil {
         return new ObjectMapper().readValue(json, tClass);
     }
 
-    /**
-     * JSONObject 转成 bean
-     *
-     * @param jsonObject   jsonObject 对象
-     * @param tClass 返回值类型
-     * @param <T>    声明为泛型方法
-     * @return bean 对象
-     */
-    public static <T> T jsonObjectToBean(JSONObject jsonObject, Class<T> tClass) throws JsonProcessingException {
-        return new ObjectMapper().readValue(jsonObject.toString(), tClass);
-    }
-
-    /**
-     * json 转成 list
-     *
-     * @param arrayJson    json 数组字符串
-     * @param elementClass 列表元素类型
-     * @param <E>          声明为泛型方法
-     * @return 结果列表
-     * @throws JsonProcessingException 异常
-     */
-    public static <E> List<E> jsonToList(String arrayJson, Class<E> elementClass) throws JsonProcessingException, JSONException {
-        List<E> resultList = new ArrayList<>();
-        JSONArray jsonArray = new JSONArray(arrayJson);
-        for (int i = 0; i < jsonArray.length(); i++) {
-            JSONObject jsonObject = jsonArray.getJSONObject(i);
-            String beanJson = jsonObject.toString();
-            E element = jsonToBean(beanJson, elementClass);
-            resultList.add(element);
-        }
-        return resultList;
-    }
-
-//    /**
-//     * json 字符串转成 info 为 list 的 result
-//     *
-//     * @param json         json 字符串
-//     * @param elementClass 列表元素类型
-//     * @param <E>          声明为泛型方法
-//     * @return result 对象
-//     * @throws JsonProcessingException 异常
-//     */
-//    public static <E> Result<List<E>> jsonToResultWithListInfo(String json, Class<E> elementClass) throws JsonProcessingException, JSONException {
-//        Result<?> temporaryResult = jsonToBean(json, Result.class);
-//        String infoJson = beanToJson(temporaryResult.getInfo());
-//        List<E> infoList = jsonToList(infoJson, elementClass);
-//        Result<List<E>> finalResult = new Result<>();
-//        finalResult.setCode(temporaryResult.getCode());
-//        finalResult.setMessage(temporaryResult.getMessage());
-//        finalResult.setInfo(infoList);
-//        return finalResult;
-//    }
-//
-//    /**
-//     * json 字符串转成 info 为 list 的 result
-//     *
-//     * @param jsonObject   JSONObject 对象
-//     * @param elementClass 列表元素类型
-//     * @param <E>          声明为泛型方法
-//     * @return result 对象
-//     * @throws JsonProcessingException 异常
-//     */
-//    public static <E> Result<List<E>> jsonObjectToResultWithListInfo(JSONObject jsonObject, Class<E> elementClass) throws JsonProcessingException, JSONException {
-//        String json = jsonObject.toString();
-//        return jsonToResultWithListInfo(json, elementClass);
-//    }
-    // -------------------------------- K --------------------------------
-    // -------------------------------- L --------------------------------
-
     /**
      * bean 转成 json
      *
@@ -138,19 +43,5 @@ public class JsonUtil {
         return new ObjectMapper().writeValueAsString(list);
     }
 
-    // -------------------------------- M --------------------------------
-    // -------------------------------- N --------------------------------
-    // -------------------------------- O --------------------------------
-    // -------------------------------- P --------------------------------
-    // -------------------------------- Q --------------------------------
-    // -------------------------------- R --------------------------------
-    // -------------------------------- S --------------------------------
-    // -------------------------------- T --------------------------------
-    // -------------------------------- U --------------------------------
-    // -------------------------------- V --------------------------------
-    // -------------------------------- W --------------------------------
-    // -------------------------------- X --------------------------------
-    // -------------------------------- Y --------------------------------
-    // -------------------------------- Z --------------------------------
 
 }

+ 10 - 5
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/SignController.java

@@ -8,12 +8,14 @@ import api.common.util.HttpUtil;
 import api.common.util.JsonUtil;
 import com.css.simulation.oauth.client.configuration.oauth.OauthParameter;
 import com.css.simulation.oauth.client.mapper.UserMapper;
+import com.css.simulation.oauth.client.pojo.parameter.SingleParameter;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.springframework.boot.configurationprocessor.json.JSONObject;
 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.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -69,7 +71,9 @@ public class SignController {
     @RequestMapping("/single")
     @SneakyThrows
     @ResponseBody
-    public ResponseBodyVO<SimulationTokenVO> home(@RequestParam("code") String code, @RequestParam("ticket") String ticket) {
+    public ResponseBodyVO<SimulationTokenVO> home(@RequestBody SingleParameter singleParameter) {
+        String code = singleParameter.getCode();
+        String ticket = singleParameter.getTicket();
         //1 根据统一凭条 code 获取统一平台 access_token
         /*
         响应体
@@ -85,7 +89,7 @@ public class SignController {
                 "&secret=" + oauthParameter.getZoogooyAppSecret() +
                 "&code=" + code +
                 "&grant_type=authorization_code";
-        JSONObject zoogooyToken = HttpUtil.post(closeableHttpClient, requestConfig, zoogooyTokenUrl, null, null);
+        JSONObject zoogooyToken = new JSONObject(HttpUtil.post(closeableHttpClient, requestConfig, zoogooyTokenUrl, null, null));
         String accessToken = zoogooyToken.optString("access_token");
         String openid = zoogooyToken.optString("openid");
         log.info("------- 统一平台令牌信息为:" + zoogooyToken);
@@ -104,7 +108,8 @@ public class SignController {
                 "?access_token=" + accessToken +
                 "&openid=" + openid +
                 "&ticket=" + ticket;
-        JSONObject userInfo = HttpUtil.post(closeableHttpClient, requestConfig, zoogooyUserUrl, null, null);
+        JSONObject userInfo = new JSONObject(HttpUtil.post(closeableHttpClient, requestConfig, zoogooyUserUrl, null, null));
+
 
         String unionid = userInfo.optString("unionid");
         String nickname = userInfo.optString("nickname");
@@ -143,8 +148,8 @@ public class SignController {
                 "&password=" + password;
         String simulationToken = HttpUtil.post(closeableHttpClient, requestConfig, simulationTokenUrl, null, null).toString();
         System.out.println("------- 仿真平台令牌信息为:" + simulationToken);
-        SimulationTokenVO simulationTokenVO = JsonUtil.jsonObjectToBean(new JSONObject(simulationToken),SimulationTokenVO.class);
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,simulationTokenVO);
+        SimulationTokenVO simulationTokenVO = JsonUtil.jsonToBean(simulationToken, SimulationTokenVO.class);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, simulationTokenVO);
     }
 
 }

+ 13 - 0
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/pojo/parameter/SingleParameter.java

@@ -0,0 +1,13 @@
+package com.css.simulation.oauth.client.pojo.parameter;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SingleParameter {
+    private String code;
+    private String ticket;
+}

+ 2 - 2
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -1,8 +1,8 @@
 package com.css.simulation.resource.common.controller;
 
 import api.common.pojo.common.ResponseBodyVO;
-import com.css.simulation.resource.common.pojo.parameter.MinioParameter;
-import com.css.simulation.resource.common.util.FileUtil;
+import api.common.pojo.parameter.MinioParameter;
+import api.common.util.FileUtil;
 import com.css.simulation.resource.common.util.MinioUtil;
 import io.minio.MinioClient;
 import io.minio.errors.*;

+ 0 - 22
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/oauth/MyTokenServices.java

@@ -30,26 +30,4 @@ public class MyTokenServices {
         return services;
     }
 
-//* -------------------------------- 使用 jwt 令牌,无需访问远程授权服务器,也可以两者结合 --------------------------------
-//    /**
-//     * 令牌存储
-//     * <p>
-//     * (推荐)new JwtTokenStore():基于 Jwt
-//     * (推荐)new RedisTokenStore():基于 redis
-//     * new InMemoryTokenStore():基于内存
-//     * new JwkTokenStore():基于 Jwk
-//     * new JdbcTokenStore():基于 Jdbc
-//     */
-//    @Bean
-//    public TokenStore tokenStore() {
-////        return new InMemoryTokenStore();
-//        return new JwtTokenStore(accessTokenConverter());
-//    }
-//
-//    @Bean
-//    public JwtAccessTokenConverter accessTokenConverter() {
-//        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
-//        jwtAccessTokenConverter.setSigningKey("project");
-//        return jwtAccessTokenConverter;
-//    }
 }

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/feign/DemoController.java

@@ -1,7 +1,7 @@
 package com.css.simulation.resource.scheduler.feign;
 
 import api.common.pojo.common.ResponseBodyVO;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
@@ -14,7 +14,7 @@ public class DemoController {
     @Resource
     private DemoService demoService;
 
-    @RequestMapping("/upload")
+    @PostMapping("/upload")
     public ResponseBodyVO<String> upload(
             @RequestParam("file") MultipartFile multipartFile,
             @RequestParam("bucketName") String bucketName,

+ 2 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/feign/fallback/DemoServiceFallback.java

@@ -2,8 +2,10 @@ package com.css.simulation.resource.scheduler.feign.fallback;
 
 import api.common.pojo.common.ResponseBodyVO;
 import com.css.simulation.resource.scheduler.feign.DemoService;
+import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+@Service
 public class DemoServiceFallback implements DemoService {
 
     @Override