Ver código fonte

2021/5/26 接口本地化测试

yinhao 4 anos atrás
pai
commit
76fdd8a114

+ 1 - 1
huimv-smart-common/src/main/java/com/huimv/common/utils/TokenUtil.java

@@ -19,7 +19,7 @@ import java.util.Date;
  **/
 public class TokenUtil {
 
-    private static final long EXPIRE_TIME = 24 * 60 * 60 * 1000;  //有效时长
+    private static final long EXPIRE_TIME =  24L * 60L * 60L * 1000L;  //有效时长
     private static final String TOKEN_SECRET = "ben";       // 秘钥
 
     /**

+ 11 - 0
huimv-smart-management/src/main/java/com/huimv/management/HuimvSmartManagementApplication.java

@@ -4,7 +4,13 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
 
+/**
+ * @author yinhao
+ * @since 2021/5/31 15:44
+ */
 @SpringBootApplication
 @MapperScan(value = "com.huimv.management.dao")
 public class HuimvSmartManagementApplication {
@@ -13,4 +19,9 @@ public class HuimvSmartManagementApplication {
         SpringApplication.run(HuimvSmartManagementApplication.class, args);
     }
 
+    @Bean
+    public RestTemplate getRestTemplate(){
+        return new RestTemplate();
+    }
+
 }

+ 76 - 0
huimv-smart-management/src/main/java/com/huimv/management/controller/ApiServiceLocalTestController.java

@@ -0,0 +1,76 @@
+package com.huimv.management.controller;
+
+import com.huimv.common.utils.R;
+import com.huimv.common.validate.ListValue;
+import org.apache.commons.lang3.StringUtils;
+import org.hibernate.validator.constraints.Range;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * <p>
+ * apiService本地测试接口
+ * </p>
+ *
+ * @author yinhao
+ * @date 2021/5/31 15:11
+ */
+@Validated
+@RestController
+@RequestMapping("management/localTest")
+public class ApiServiceLocalTestController {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    private static final String PREFIX = "http://115.238.57.190:8020/pig/";
+
+    @Value("${local.token}")
+    private String accessToken;
+
+    @RequestMapping("/testGetPigInfo")
+    public R testGetPigInfo(@NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
+        return restTemplate.getForObject(PREFIX + "getPigInfo?accessToken=" + accessToken + "&pigEarTagNo=" + pigEarTagNo, R.class);
+    }
+
+    @RequestMapping("/testGetImage")
+    public R testGetImage(@NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
+        return restTemplate.getForObject(PREFIX + "getImage?accessToken=" + accessToken + "&pigEarTagNo=" + pigEarTagNo, R.class);
+    }
+
+    @RequestMapping("/testGetListByBreed")
+    public R testGetListByBreed(@NotBlank(message = "品种名称不能为空!") @RequestParam("breedName") String breedName,
+                                @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
+                                @Range(min = 1, max = 1000, message = "每页条数的范围为1-1000") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
+                                @RequestParam(value = "period", required = false) String period) {
+        String url = PREFIX + "getListByBreed?accessToken=" + accessToken + "&breedName=" + breedName + "&currentPage=" + currentPage + "&pageSize=" + pageSize;
+        if (StringUtils.isNotEmpty(period)) {
+            url = url + "&period=" + period;
+        }
+        return restTemplate.getForObject(url, R.class);
+    }
+
+    @RequestMapping("/testGetIndoorEnv")
+    public R testGetIndoorEnv(@NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
+        return restTemplate.getForObject(PREFIX + "getIndoorEnv?accessToken=" + accessToken + "&pigEarTagNo=" + pigEarTagNo, R.class);
+    }
+
+    @RequestMapping("/testAdopt")
+    public R testAdopt(@NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo) {
+        return restTemplate.getForObject(PREFIX + "adopt?accessToken=" + accessToken + "&pigEarTagNo=" + pigEarTagNo, R.class);
+    }
+
+    @RequestMapping("/testOutFence")
+    public R testOutFence(@NotBlank(message = "耳标号不能为空!") @RequestParam("pigEarTagNo") String pigEarTagNo,
+                          @NotNull(message = "出栏状态不能为空!") @ListValue(vals = {1, 2, 3}) @RequestParam("status") Integer status) {
+        return restTemplate.getForObject(PREFIX + "outFence?accessToken=" + accessToken + "&pigEarTagNo=" + pigEarTagNo + "&status=" + status, R.class);
+    }
+}

+ 4 - 0
huimv-smart-management/src/main/resources/application-dev.yml

@@ -102,3 +102,7 @@ mybatis-plus:
     jdbc-type-for-null: 'null'
 #    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
+
+local:
+  token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsInVzZXJOYW1lIjoiMjAyMTA1MDEiLCJleHAiOjQ3NzgyMDAyMzV9.U6CANYSs3HyvZmnw6SHqNDcNV32PkGc3o6ZcggdeSf0
+  expire: 2121-06-01 13:50:35