Browse Source

添加天地图接口

liu 1 year ago
parent
commit
ea79f63ee9

+ 4 - 0
src/main/java/com/template/api/HouseOrderAPI.java

@@ -161,5 +161,9 @@ public interface HouseOrderAPI {
     @ApiOperation(value = "账期列表", notes = "账期列表", httpMethod = "GET")
     @ApiOperation(value = "账期列表", notes = "账期列表", httpMethod = "GET")
     CommonResult dateBillType();
     CommonResult dateBillType();
 
 
+    @GetMapping("/tianditu")
+    @ApiOperation(value = "天地图", notes = "天地图", httpMethod = "GET")
+    CommonResult tianditu(@RequestParam String ds,@RequestParam String tk);
+
 }
 }
 
 

+ 2 - 2
src/main/java/com/template/common/result/ResponseStatusEnum.java

@@ -35,8 +35,8 @@ public enum ResponseStatusEnum implements Code{
     SYSTEM_MONGO_TIMEOUT_ERROR(555, false, "Mongo连接超时"),
     SYSTEM_MONGO_TIMEOUT_ERROR(555, false, "Mongo连接超时"),
     SYSTEM_PHONE_ERROR(556,false,"手机号格式错误"),
     SYSTEM_PHONE_ERROR(556,false,"手机号格式错误"),
     SYSTEM_SEND_PHONE_ERROR(557,false,"发送验证码失败"),
     SYSTEM_SEND_PHONE_ERROR(557,false,"发送验证码失败"),
-    SYSTEM_TOKEN_ERROR(558,false,"token为空"),
-    SYSTEM_LOGIN_ERROR(559,false,"无效token,请重新登入"),
+    SYSTEM_TOKEN_ERROR(500,false,"token为空"),
+    SYSTEM_LOGIN_ERROR(500,false,"无效token,请重新登入"),
     PARAM_ERROR(560, false, "参数不能为空!"),
     PARAM_ERROR(560, false, "参数不能为空!"),
     THIRD_PARTY_SERVICE_CALL_FAILED(561,false,"第三方服务调用失败"),
     THIRD_PARTY_SERVICE_CALL_FAILED(561,false,"第三方服务调用失败"),
     EXISTS(999,false,"已存在");
     EXISTS(999,false,"已存在");

+ 235 - 0
src/main/java/com/template/common/utils/HttpClientUtil.java

@@ -0,0 +1,235 @@
+package com.template.common.utils;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.Buffer;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class HttpClientUtil {
+
+    // http请求配置
+    private static RequestConfig config = RequestConfig.custom()
+                                                // 连接超时时间(毫秒)
+                                                .setConnectTimeout(5000)
+                                                // 数据读取超时时间(毫秒)
+                                                .setSocketTimeout(10000)
+                                                // 连接不夠用的等待时间(毫秒)
+                                                .setConnectionRequestTimeout(1000)
+                                                .build();
+
+
+    public static String doGet(String url, Map<String, String> param) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+
+        String resultString = "";
+        CloseableHttpResponse response = null;
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+            httpGet.setConfig(config);
+            // 执行请求
+            response = httpclient.execute(httpGet);
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return resultString;
+    }
+
+    public static String doGet(String url) {
+        return doGet(url, null);
+    }
+
+    public static String doPost(String url, Map<String, String> param) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.setConfig(config);
+            // 创建参数列表
+            if (param != null) {
+                List<NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+
+    public static String doPost(String url) {
+        return doPost(url, null);
+    }
+
+    public static String doPostJson(String url, String json) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.setConfig(config);
+            // 创建请求内容
+            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
+            httpPost.setEntity(entity);
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+
+    /* 发送 post请求 用HTTPclient 发送请求*/
+    public static byte[] post(String URL, String json) {
+        String obj = null;
+        InputStream inputStream = null;
+        Buffer reader = null;
+        byte[] data = null;
+        // 创建默认的httpClient实例.
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        // 创建httppost
+        HttpPost httppost = new HttpPost(URL);
+        httppost.setConfig(config);
+        httppost.addHeader("Content-type", "application/json; charset=utf-8");
+        httppost.setHeader("Accept", "application/json");
+        try {
+            StringEntity s = new StringEntity(json, Charset.forName("UTF-8"));
+            s.setContentEncoding("UTF-8");
+            httppost.setEntity(s);
+            CloseableHttpResponse response = httpclient.execute(httppost);
+            try {
+                // 获取相应实体
+                HttpEntity entity = response.getEntity();
+                if (entity != null) {
+                    inputStream = entity.getContent();
+                    data = readInputStream(inputStream);
+                }
+                return data;
+            } finally {
+                response.close();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭连接,释放资源
+            try {
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return data;
+    }
+
+
+    /**  将流 保存为数据数组
+     * @param inStream
+     * @return
+     * @throws Exception
+     */
+    public static byte[] readInputStream(InputStream inStream) throws Exception {
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+        // 创建一个Buffer字符串
+        byte[] buffer = new byte[1024];
+        // 每次读取的字符串长度,如果为-1,代表全部读取完毕
+        int len = 0;
+        // 使用一个输入流从buffer里把数据读取出来
+        while ((len = inStream.read(buffer)) != -1) {
+            // 用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
+            outStream.write(buffer, 0, len);
+        }
+        // 关闭输入流
+        inStream.close();
+        // 把outStream里的数据写入内存
+        return outStream.toByteArray();
+    }
+
+
+    public static void main(String[] args) {
+        RestTemplate restTemplate = new RestTemplate();
+        try {
+            String baseUrl = "http://api.tianditu.gov.cn/geocoder";
+            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl)
+                    .queryParam("ds", "{\"keyWord\":\"江西省宜春市靖安县墨轩湖大道1号\"}")
+                    .queryParam("tk", "523b39fb1b7a04863f8ff79b204e9dc9");
+            String url = builder.toUriString();
+            ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
+            System.out.println(response.getBody());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 39 - 0
src/main/java/com/template/controller/HouseOrderController.java

@@ -48,6 +48,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
@@ -355,6 +356,9 @@ public class HouseOrderController implements HouseOrderAPI {
 //        房态id
 //        房态id
         houseOrder.setHouseId(houseId);
         houseOrder.setHouseId(houseId);
 //        房间号id(可多个房间id)
 //        房间号id(可多个房间id)
+        if (ObjectUtils.isEmpty(houseNumberIds)) {
+            return CommonResult.fail("房间为空");
+        }
         houseOrder.setHouseNumberId(houseNumberIds);
         houseOrder.setHouseNumberId(houseNumberIds);
         Users users = usersService.getById(userId);
         Users users = usersService.getById(userId);
         if (ObjectUtils.isNotEmpty(users)) {
         if (ObjectUtils.isNotEmpty(users)) {
@@ -3629,6 +3633,7 @@ public class HouseOrderController implements HouseOrderAPI {
     }
     }
 
 
     @Override
     @Override
+    @PassToken
     public CommonResult remainFree(String userId, String liveTime, String leaveTime) {
     public CommonResult remainFree(String userId, String liveTime, String leaveTime) {
         log.info("查询该用户是否能免费订房,userId: " + userId + " liveTime: " + liveTime + " leaveTime: " + leaveTime);
         log.info("查询该用户是否能免费订房,userId: " + userId + " liveTime: " + liveTime + " leaveTime: " + leaveTime);
         Users users = usersService.getById(userId);
         Users users = usersService.getById(userId);
@@ -3768,6 +3773,7 @@ public class HouseOrderController implements HouseOrderAPI {
 
 
 //        获取流程
 //        获取流程
         List<ApplicationProcedureTemporary> aptList = applicationProcedureTemporaryService.getApt(state, end, userId);
         List<ApplicationProcedureTemporary> aptList = applicationProcedureTemporaryService.getApt(state, end, userId);
+//        if (ObjectUtils.isEmpty(aptList) && aptList.size()>0) {
         if (ObjectUtils.isEmpty(aptList)) {
         if (ObjectUtils.isEmpty(aptList)) {
             vo1.setCount(0);
             vo1.setCount(0);
         } else {
         } else {
@@ -3790,6 +3796,7 @@ public class HouseOrderController implements HouseOrderAPI {
                 Integer count2 = Integer.valueOf(houseCount);
                 Integer count2 = Integer.valueOf(houseCount);
                 count2 = count2 - list.size();
                 count2 = count2 - list.size();
                 if(count2==0){
                 if(count2==0){
+                    vo1.setCount(0);
                     break;
                     break;
                 }
                 }
                 aptIdList.add(applicationProcedureTemporary.getId());
                 aptIdList.add(applicationProcedureTemporary.getId());
@@ -3871,6 +3878,38 @@ public class HouseOrderController implements HouseOrderAPI {
         return CommonResult.ok(dateBillTypeList);
         return CommonResult.ok(dateBillTypeList);
     }
     }
 
 
+    @Override
+    public CommonResult tianditu(String ds, String tk) {
+//        String url="http://api.tianditu.gov.cn/geocoder?ds="+ds+"&tk="+tk;
+
+//        JSONObject map = new JSONObject();
+//        map.put("keyWord",ds);
+//
+//        String url="http://api.tianditu.gov.cn/geocoder?ds="+map.toString()+"&tk=" + tk;;
+//        System.out.println("url = " + url);
+//        RestTemplate restTemplate = new RestTemplate();
+//        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
+//        String body = forEntity.getBody();
+//        JSONObject jsonObject = JSONObject.parseObject(body);
+//        System.out.println("jsonObject = " + jsonObject);
+//        return CommonResult.ok(jsonObject);
+
+        String url = "http://api.tianditu.gov.cn/geocoder";
+        Map<String, String> param = new HashMap<>();
+        JSONObject jsonObject2 = new JSONObject();
+        jsonObject2.put("keyWord", ds);
+        param.put("ds", jsonObject2.toJSONString());
+        param.put("tk", tk);
+        String s = HttpClientUtil.doGet(url, param);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        System.out.println("jsonObject = " + jsonObject);
+        String status = jsonObject.getString("status");
+        if ("0".equals(status)) {
+            return CommonResult.ok(jsonObject);
+        }
+        return CommonResult.fail();
+    }
+
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
 //        获取签名
 //        获取签名

+ 1 - 0
src/main/java/com/template/controller/LoginController.java

@@ -197,6 +197,7 @@ public class LoginController implements LoginControllerAPI {
     }
     }
 
 
     @Override
     @Override
+    @PassToken
     public CommonResult menuBar(String permissionSettingId) {
     public CommonResult menuBar(String permissionSettingId) {
         PermissionSetting one = permissionSettingService.getById(permissionSettingId);
         PermissionSetting one = permissionSettingService.getById(permissionSettingId);
 
 

+ 1 - 1
src/main/java/com/template/core/JwtlnterceptorConfig.java

@@ -14,7 +14,7 @@ public class JwtlnterceptorConfig implements WebMvcConfigurer {
         //目前测试下来 使用 /**所有的话,response.sendError浏览器获取不到响应的信息
         //目前测试下来 使用 /**所有的话,response.sendError浏览器获取不到响应的信息
         //默认拦截所有路径
         //默认拦截所有路径
         registry.addInterceptor(authenticationInterceptor())
         registry.addInterceptor(authenticationInterceptor())
-                .addPathPatterns("/auto/**");
+                .addPathPatterns("/auto0/**");
         //endregion
         //endregion
     }
     }