Sfoglia il codice sorgente

新增:
通过配置文件获取api

wuweihao 4 anni fa
parent
commit
f0a80815b9

+ 11 - 7
gis_application/src/main/resources/application-dev.properties

@@ -6,11 +6,15 @@ logging.config=classpath:logback-spring.xml
 logging.level.com.gis=debug
 
 
-## 上传文件保存路径
-## 本地保存路径
-#file.path=F:\\test\\ngin\\cms_fdkanzhan_data\\
-#server.domain =http://192.168.0.135/data/
-#
-#oss.file.path=cms_fdkanzhan/
-#oss.domain=http://ossxiaoan.4dage.com/
+# swagger2 \uFFFD\uFFFD\uFFFD\uFFFD\u022B\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u02BD\u03AAutf-8
+swagger.package=com.gis.web.controller
+swagger.title=\u6210\u90FD\u5FB7\u6E90-dev
+swagger.description=${swagger.title}
+swagger.version=1.0
 
+
+# \u5927\u5C4F
+api.screen=https://testlife.eshimin.com
+
+#\u95E8\u7981
+api.door=https://cdpre.tfsmy.com/intelligence-access-control-api

+ 20 - 0
gis_application/src/main/resources/application-pro.properties

@@ -0,0 +1,20 @@
+
+
+#log
+logging.path=/root/user/cms_chengdu_screen_log
+logging.config=classpath:logback-spring.xml
+logging.level.com.gis=debug
+
+
+
+# swagger2 \uFFFD\uFFFD\uFFFD\uFFFD\u022B\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u02BD\u03AAutf-8
+swagger.package=com.gis.web.controller
+swagger.title=\u6210\u90FD\u5FB7\u6E90-pro
+swagger.description=${swagger.title}
+swagger.version=1.0
+
+# \u5927\u5C4F
+api.screen=https://life.eshimin.com
+
+#\u95E8\u7981
+api.door=https://tfsmy.chengdu.gov.cn/intelligence-access-control-api

+ 0 - 9
gis_application/src/main/resources/application-sit.properties

@@ -1,9 +0,0 @@
-
-
-#log
-logging.path=/root/user/cms_chengdu_screen_log
-logging.config=classpath:logback-spring.xml
-logging.level.com.gis=debug
-
-
-

+ 1 - 1
gis_application/src/main/resources/application.properties

@@ -1,6 +1,6 @@
 server.port=8106
 
-spring.profiles.active=dev
+spring.profiles.active=pro
 
 # \u8BBF\u95EE\u9759\u6001\u8D44\u6E90\u8BBE\u7F6E
 spring.resources.static-locations=classpath:templates/,classpath:static/,classpath:web/

+ 39 - 0
gis_common/src/main/java/com/gis/common/config/ConfigConstant.java

@@ -0,0 +1,39 @@
+package com.gis.common.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by owen on 2020/12/31 0031 14:22
+ *
+ * 全局动态参数
+ */
+@Component
+public class ConfigConstant {
+
+    @Value("${swagger.package}")
+    public  String swaggerPackage;
+
+    @Value("${swagger.title}")
+    public  String swaggerTitle;
+
+    @Value("${swagger.description}")
+    public  String swaggerDescription;
+
+    @Value("${swagger.version}")
+    public  String swaggerVersion;
+
+
+    /*********************** 其他参数 ***********************/
+
+    @Value("${api.door}")
+    public  String apiDoor;
+
+    @Value("${api.screen}")
+    public  String apiScreen;
+
+
+
+
+
+}

+ 11 - 4
gis_common/src/main/java/com/gis/common/config/Swagger2.java

@@ -2,6 +2,8 @@ package com.gis.common.config;
 
 import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
 import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import springfox.documentation.builders.ApiInfoBuilder;
@@ -30,16 +32,21 @@ import java.util.List;
  *
  * 2.9.2 不需要字启动类配置注解
  */
+@Slf4j
 @Configuration
 @EnableSwagger2
 @EnableKnife4j
 public class Swagger2 {
+
+    @Autowired
+    ConfigConstant configConstant;
+
     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(apiInfo())
                 .select()
-                .apis(RequestHandlerSelectors.basePackage("com.gis.web.controller"))
+                .apis(RequestHandlerSelectors.basePackage(configConstant.swaggerPackage))
                 .paths(PathSelectors.any())
                 .build()
                 //添加登录认证,可以使用token
@@ -50,9 +57,9 @@ public class Swagger2 {
 
     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
-                .title("德源大屏 APIs")
-                .description("德源大屏 Api接口文档")
-                .version("1.0")
+                .title(configConstant.swaggerTitle)
+                .description(configConstant.swaggerDescription)
+                .version(configConstant.swaggerVersion)
                 .build();
     }
 

+ 12 - 5
gis_common/src/main/java/com/gis/common/deyuan/util/ResultUtils.java

@@ -2,11 +2,14 @@ package com.gis.common.deyuan.util;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.parser.Feature;
+import com.gis.common.config.ConfigConstant;
 import com.gis.common.util.Result;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
@@ -16,11 +19,12 @@ import java.util.Map;
 /**
  * Created by owen on 2020/10/15 0015 9:21
  */
+@Component
 @Log4j2
 public class ResultUtils {
 
     /** 德源ip-测试*/
-    private static final String host = "https://testlife.eshimin.com";
+//    private static final String host = "https://testlife.eshimin.com";
 
     /** 德源ip-正式*/
 //    private static final String host = "https://life.eshimin.com";
@@ -34,8 +38,11 @@ public class ResultUtils {
     /** 应用id,需要向德源申请, ip(我们服务器ip)和appId绑定*/
     private static final String appId = "887b30a6b92345099c726de28c797dda";
 
+    @Autowired
+    ConfigConstant configConstant;
 
-    public static Result doGetResult(String path, Map<String, Object> param){
+
+    public Result doGetResult(String path, Map<String, Object> param){
 
         Map<String, Object> map = new HashMap();
         if (param != null) {
@@ -68,7 +75,7 @@ public class ResultUtils {
         String resultData = null;
 //        log.info("request url: "+ path);
         try {
-            HttpResponse httpResponse = HttpUtils.doGet(host, path, headers, querys);
+            HttpResponse httpResponse = HttpUtils.doGet(configConstant.apiScreen, path, headers, querys);
             String restResult = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
             log.info("restResult: {}", restResult);
             if (StringUtils.isNotEmpty(restResult)) {
@@ -94,7 +101,7 @@ public class ResultUtils {
         return Result.success(JSONObject.parseObject(resultData));
     }
 
-    public static JSONObject doGet(String path, Map<String, Object> param){
+    public  JSONObject doGet(String path, Map<String, Object> param){
 
         Map<String, Object> map = new HashMap();
 
@@ -130,7 +137,7 @@ public class ResultUtils {
         String resultData = null;
 //        log.info("request url: "+ path);
         try {
-            HttpResponse httpResponse = HttpUtils.doGet(host, path, headers, querys);
+            HttpResponse httpResponse = HttpUtils.doGet(configConstant.apiScreen, path, headers, querys);
             String restResult = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
             if (StringUtils.isNotEmpty(restResult)) {
                 JSONObject jsonObject = JSONObject.parseObject(restResult, Feature.IgnoreNotMatch);

+ 14 - 9
gis_web/src/main/java/com/gis/web/controller/DoorController.java

@@ -3,6 +3,7 @@ package com.gis.web.controller;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import com.gis.common.config.ConfigConstant;
 import com.gis.common.util.Result;
 import com.gis.web.dto.PageDateDto;
 import com.gis.common.util.DoorUtils;
@@ -13,6 +14,7 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
@@ -33,7 +35,10 @@ public class DoorController  {
 //    private static String BASE_URL = "https://cdpre.tfsmy.com/intelligence-access-control-api";
 
     // 正式环境请求域名
-    private static String BASE_URL = "https://tfsmy.chengdu.gov.cn/intelligence-access-control-api";
+//    private static String BASE_URL = "https://tfsmy.chengdu.gov.cn/intelligence-access-control-api";
+
+    @Autowired
+    ConfigConstant configConstant;
 
 
     /**
@@ -46,7 +51,7 @@ public class DoorController  {
     @ApiOperation(value = "设备列表信息查询", notes = "测试: code:510124112006001, type:设备名称 1-门禁 2-道闸 3-消防栓 4-井盖 5-一体机 6-投屏显示器 7-路灯 8-人脸卡口 9-人员聚集 10-气象站")
     @GetMapping("findDeviceList/{code}/{type}")
     public Result findVideoInfo(@PathVariable String code, @PathVariable String type) throws Exception {
-        String apiUrl = BASE_URL + "/bi/findDeviceList";
+        String apiUrl = configConstant.apiDoor + "/bi/findDeviceList";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", code);
         reqParam.put("type", type);
@@ -59,7 +64,7 @@ public class DoorController  {
     @ApiOperation("访客总数、近7天每日统计数(测试:510124112006001)")
     @GetMapping("getVisitorCount/{code}")
     public Result getVisitorCount(@PathVariable String code) throws Exception {
-        String apiUrl = BASE_URL + "/bi/getVisitorCount";
+        String apiUrl = configConstant.apiDoor + "/bi/getVisitorCount";
         TreeMap<String, Object> param = new TreeMap<>();
         param.put("code", code);
         return DoorUtils.doPost(apiUrl, param);
@@ -69,7 +74,7 @@ public class DoorController  {
     @ApiOperation("今日进入和外出总数")
     @GetMapping("dailyInOut/{code}")
     public Result dailyInOut(@PathVariable String code) throws Exception {
-        String apiUrl = BASE_URL + "/bi/dailyInOut";
+        String apiUrl = configConstant.apiDoor + "/bi/dailyInOut";
         TreeMap<String, Object> param = new TreeMap<>();
         param.put("code", code);
         return DoorUtils.doGet(apiUrl, param);
@@ -79,7 +84,7 @@ public class DoorController  {
     @ApiOperation("时间段进入和外出")
     @PostMapping("accessRecordsWithDevice")
     public Result accessRecordsWithDevice(@RequestBody PageDateDto param) throws Exception {
-        String apiUrl = BASE_URL + "/bi/accessRecordsWithDevice";
+        String apiUrl = configConstant.apiDoor + "/bi/accessRecordsWithDevice";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", param.getCode());
         reqParam.put("startTime", getTime(param.getStartTime()));
@@ -92,7 +97,7 @@ public class DoorController  {
     @ApiOperation("车辆进出日志(code:510124112006001)")
     @PostMapping("entranceCarLogList")
     public Result entranceCarLogList(@RequestBody PageDto param) throws Exception {
-        String apiUrl = BASE_URL + "/bi/entranceCarLogList";
+        String apiUrl = configConstant.apiDoor + "/bi/entranceCarLogList";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", param.getCode());
         Integer pageSize = param.getPageSize();
@@ -109,7 +114,7 @@ public class DoorController  {
     @ApiOperation("车辆进出统计(按天计算)")
     @PostMapping("entranceCarLogDateAvgData")
     public Result entranceCarLogDateAvgData(@RequestBody PageDateDto param) throws Exception {
-        String apiUrl = BASE_URL + "/bi/entranceCarLogDateAvgData";
+        String apiUrl = configConstant.apiDoor + "/bi/entranceCarLogDateAvgData";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", param.getCode());
         reqParam.put("startTime", getTime(param.getStartTime()));
@@ -121,7 +126,7 @@ public class DoorController  {
     @ApiOperation("车辆进出统计(按小时计算)")
     @PostMapping("entranceCarLogHourAvgData")
     public Result entranceCarLogHourAvgData(@RequestBody PageDateDto param) throws Exception {
-        String apiUrl = BASE_URL + "/bi/entranceCarLogHourAvgData";
+        String apiUrl = configConstant.apiDoor + "/bi/entranceCarLogHourAvgData";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", param.getCode());
         reqParam.put("startTime", param.getStartTime());
@@ -141,7 +146,7 @@ public class DoorController  {
     @ApiOperation("异常时间进出日志(指定查找0点-5点数据)")
     @PostMapping("findInOutLog")
     public Result findInOutLog(@RequestBody PageDateDto param) throws Exception {
-        String apiUrl = BASE_URL + "/bi/findInOutLog";
+        String apiUrl = configConstant.apiDoor + "/bi/findInOutLog";
         TreeMap<String, Object> reqParam = new TreeMap<>();
         reqParam.put("code", param.getCode());
         reqParam.put("dateTime", param.getStartTime());

+ 18 - 15
gis_web/src/main/java/com/gis/web/controller/ScreenController.java

@@ -13,6 +13,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
@@ -28,6 +29,8 @@ import java.util.HashMap;
 @RequestMapping("screen")
 public class ScreenController  {
 
+    @Autowired
+    ResultUtils resultUtils;
 
 
     @ApiOperationSupport(order=1)
@@ -37,7 +40,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/base-data";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=1)
@@ -47,7 +50,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/service-data";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGet(apiUrl, param);
+        return resultUtils.doGet(apiUrl, param);
     }
 
     @ApiOperationSupport(order=1)
@@ -57,7 +60,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/space-data";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGet(apiUrl, param);
+        return resultUtils.doGet(apiUrl, param);
     }
 
     @ApiImplicitParams({
@@ -72,7 +75,7 @@ public class ScreenController  {
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
         param.put("labelType", labelType);
-        return ResultUtils.doGet(apiUrl, param);
+        return resultUtils.doGet(apiUrl, param);
     }
 
 
@@ -84,7 +87,7 @@ public class ScreenController  {
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
         param.put("children", "true");
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=2)
@@ -94,7 +97,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/statistics/interflow";
         HashMap<String, Object> param = new HashMap<>();
         param.put("cityCode", cityCode);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
 
@@ -106,7 +109,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/info-data";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=2)
@@ -118,7 +121,7 @@ public class ScreenController  {
         param.put("group", "5f3de3d925892e0001e10312");
         param.put("cityCode", code);
 
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=2)
@@ -128,7 +131,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/deyuan/activity";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=2)
@@ -138,7 +141,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/community/deyuan/organization";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
     @ApiOperationSupport(order=2)
@@ -148,7 +151,7 @@ public class ScreenController  {
         String apiUrl = "/open/api/v1/deyuan/article";
         HashMap<String, Object> param = new HashMap<>();
         param.put("code", code);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }
 
 
@@ -161,7 +164,7 @@ public class ScreenController  {
         param.put("cityCode", code);
         // 商家分组编码
         param.put("group", "5f3de3d925892e0001e10312");
-        return Result.success(ResultUtils.doGet(apiUrl, param));
+        return Result.success(resultUtils.doGet(apiUrl, param));
     }
 
 
@@ -180,7 +183,7 @@ public class ScreenController  {
         param.put("xzCode", code);
         param.put("xzLevel", xzLevel);
         param.put("topic", "111");
-        return Result.success(ResultUtils.doGet(apiUrl, param));
+        return Result.success(resultUtils.doGet(apiUrl, param));
     }
 
     @ApiImplicitParams({
@@ -197,7 +200,7 @@ public class ScreenController  {
         param.put("xzCode", code);
         param.put("xzLevel", xzLevel);
         param.put("topic", topic);
-        return Result.success(ResultUtils.doGet(apiUrl, param));
+        return Result.success(resultUtils.doGet(apiUrl, param));
     }
 
 
@@ -224,7 +227,7 @@ public class ScreenController  {
         }
         param.put("size", pageSize);
         param.put("page", pageNum);
-        return ResultUtils.doGetResult(apiUrl, param);
+        return resultUtils.doGetResult(apiUrl, param);
     }