Bladeren bron

远程调用重载方法

hanqingsong 3 jaren geleden
bovenliggende
commit
7f286f8b86

+ 6 - 3
src/main/java/com/chinaitop/depot/intelligent/grainsituation/controller/TemperatureRecordController.java

@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Value;
22 22
 import org.springframework.http.MediaType;
23 23
 import org.springframework.util.LinkedMultiValueMap;
24 24
 import org.springframework.util.MultiValueMap;
25
+import org.springframework.validation.annotation.Validated;
25 26
 import org.springframework.web.bind.annotation.RequestBody;
26 27
 import org.springframework.web.bind.annotation.RequestMapping;
27 28
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -29,6 +30,8 @@ import org.springframework.web.bind.annotation.RestController;
29 30
 import org.springframework.web.client.RestTemplate;
30 31
 
31 32
 import javax.annotation.Resource;
33
+import javax.validation.constraints.NotBlank;
34
+import javax.validation.constraints.NotEmpty;
32 35
 import javax.validation.constraints.NotNull;
33 36
 import java.util.*;
34 37
 
@@ -254,7 +257,7 @@ public class TemperatureRecordController {
254 257
         requestEntity.add("storeCode", storeCode);
255 258
         return remoteControlUtil.remoteScan(
256 259
                 String.format("%s%s", url, remoteControlUtil.chooseCFCode),
257
-                requestEntity, "POST", null
260
+                requestEntity
258 261
         );
259 262
     }
260 263
 
@@ -273,7 +276,7 @@ public class TemperatureRecordController {
273 276
         requestEntity.put("tType", tType);
274 277
         return remoteControlUtil.remoteScan(
275 278
                 String.format("%s%s", url, remoteControlUtil.foodAll),
276
-                null, "GET", requestEntity
279
+                requestEntity
277 280
         );
278 281
     }
279 282
 
@@ -300,7 +303,7 @@ public class TemperatureRecordController {
300 303
         requestEntity.add("tType", tType);
301 304
         return remoteControlUtil.remoteScan(
302 305
                 String.format("%s%s", url, remoteControlUtil.foodOnly),
303
-                requestEntity, "POST", null
306
+                requestEntity
304 307
         );
305 308
     }
306 309
 

+ 20 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/RemoteControlUtil.java

@@ -83,6 +83,26 @@ public class RemoteControlUtil {
83 83
     }
84 84
 
85 85
     /**
86
+     * POST 方法重载
87
+     * @param url http
88
+     * @param requestEntity 参数对象
89
+     * @return ResponseEntity
90
+     */
91
+    public ResponseEntity remoteScan(@NotNull String url, MultiValueMap requestEntity) {
92
+        return restTemplate.postForObject(url, requestEntity, ResponseEntity.class);
93
+    }
94
+
95
+    /**
96
+     * GET 方法重载
97
+     * @param url http
98
+     * @param requestMap 参数对象
99
+     * @return ResponseEntity
100
+     */
101
+    public ResponseEntity remoteScan(@NotNull String url, Map requestMap) {
102
+        return restTemplate.getForObject(getForObject(url, requestMap), ResponseEntity.class);
103
+    }
104
+
105
+    /**
86 106
      * 封装的get请求,暂时只支持map传参,并且value只支持基本类型和String
87 107
      *
88 108
      * @param url    库端配置url