1
0
Просмотр исходного кода

远程调用方法增加header请求post方法

chenendian 5 дней назад
Родитель
Сommit
9c830c7c10

+ 0 - 34
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/third/OfferDataController.java

@@ -98,40 +98,6 @@ public class OfferDataController extends BaseController {
     }
 
 
-    /**
-     * 国有建设用地使用权首次登记
-     * 不动产土地登记完成后入参使用
-     */
-    @PostMapping("/third/landFirstRegistration")
-    public R<Map<String, Object>> landFirstRegistration(@RequestBody LandFirstParamVo body) {
-        try {
-            Map<String, Object> map = offerDataService.landFirstRegistration(body);
-            map.put("id", map.get("id"));
-            return R.ok(map);
-        } catch (Exception e) {
-            return R.fail(e.getMessage());
-        }
-    }
-
-
-    /**
-     *
-     * 国有建设用地使用权及房屋所有权首次登记
-     * landFirstParamVo
-     * houseFirstParamVo
-     * 不动产土地登记完成后入参使用
-     */
-    @PostMapping("/third/houseFirstRegistration")
-    public R<Map<String, Object>> houseFirstRegistration(@RequestBody HouseFirstParamVo body) {
-        try {
-            Map<String, Object> map = offerDataService.houseFirstRegistration(body);
-            map.put("id", map.get("id"));
-            return R.ok(map);
-        } catch (Exception e) {
-            return R.fail(e.getMessage());
-        }
-    }
-
 
     /**
      * 按ID查询

+ 24 - 26
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/third/TakeDataController.java

@@ -1,7 +1,6 @@
 package com.siwei.apply.controller.third;
 
-import com.siwei.apply.domain.LandOneCode;
-import com.siwei.apply.domain.vo.TakeDataAddVo;
+import com.siwei.apply.domain.vo.ThirdRecordStatusParamVo;
 import com.siwei.apply.service.third.TakeDataService;
 import com.siwei.common.core.domain.R;
 import com.siwei.common.core.utils.StringUtils;
@@ -11,7 +10,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -44,25 +42,19 @@ public class TakeDataController extends BaseController {
         }
     }
 
-    /**
-     * 按ID查询
-     */
-    @GetMapping("{id}")
-    public R<LandOneCode> getById(@PathVariable String id) {
-        try {
-            return R.ok();
-        } catch (Exception e) {
-            return R.fail(e.getMessage());
-        }
-    }
+
+
 
     /**
-     * 更新(按ID)
+     * 国有建设用地使用权首次登记
+     * 不动产土地登记完成后入参使用
      */
-    @PutMapping("zzz")
-    public R<Void> update(@RequestBody LandOneCode body) {
+    @PostMapping("/third/landFirstRegistration")
+    public R<Map<String, Object>> landFirstRegistration(@RequestBody ThirdRecordStatusParamVo body) {
         try {
-            return R.ok(null);
+            Map<String, Object> map = takeDataService.remoteLandFirstRegistration(body);
+            map.put("id", map.get("id"));
+            return R.ok(map);
         } catch (Exception e) {
             return R.fail(e.getMessage());
         }
@@ -70,17 +62,17 @@ public class TakeDataController extends BaseController {
 
 
     /**
-     * 添加数据
      *
-     * @param takeDataAddVo
-     * @return
+     * 国有建设用地使用权及房屋所有权首次登记
+     * landFirstParamVo
+     * houseFirstParamVo
+     * 不动产土地登记完成后入参使用
      */
-    @PostMapping("add")
-    public R<Map<String, String>> add(@RequestBody TakeDataAddVo takeDataAddVo) {
+    @PostMapping("/third/houseFirstRegistration")
+    public R<Map<String, Object>> houseFirstRegistration(@RequestBody ThirdRecordStatusParamVo  body) {
         try {
-            String id = takeDataService.add(takeDataAddVo);
-            Map<String, String> map = new HashMap<>();
-            map.put("id", id);
+            Map<String, Object> map = takeDataService.remoteHouseFirstRegistration(body);
+            map.put("id", map.get("id"));
             return R.ok(map);
         } catch (Exception e) {
             return R.fail(e.getMessage());
@@ -100,4 +92,10 @@ public class TakeDataController extends BaseController {
 
 
 
+
+
+
+
+
+
 }

+ 47 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/StorageServiceImpl.java

@@ -244,6 +244,29 @@ public class StorageServiceImpl {
         double totalArea = completeList.stream().mapToDouble(item -> item.getMjMu().doubleValue()).sum();
         totalCompleted.setArea(totalArea);
 
+        totalCompleted.setMethod1(0);
+        totalCompleted.setMethod2(0);
+        totalCompleted.setOtherMethod(0);
+
+        //这里处理收储的方式
+        Map<String, List<TdgyStatisticsRes>> resultMap = completeList.stream()
+                .collect(Collectors.groupingBy(item -> {
+                    String gyfs = item.getGyfs();
+                    //为空赋值“其它”
+                    if (StringUtils.isBlank(gyfs)) {
+                        return "其它";
+                    }
+                    return gyfs;
+                }));
+        if(resultMap.containsKey("收购")){
+            totalCompleted.setMethod1(resultMap.get("收购").size());
+        }
+        if(resultMap.containsKey("征收")){
+            totalCompleted.setMethod2(resultMap.get("征收").size());
+        }
+        if(resultMap.containsKey("其它")){
+            totalCompleted.setOtherMethod(resultMap.get("其它").size());
+        }
 
         //这里处理计划的数据
         LandStorageReportDTO.PlanDTO totalPlan = new LandStorageReportDTO.PlanDTO();
@@ -255,6 +278,30 @@ public class StorageServiceImpl {
         //这里计算面积
         totalArea = planList.stream().mapToDouble(item -> item.getMjMu().doubleValue()).sum();
         totalPlan.setArea(totalArea);
+
+        totalPlan.setMethod1(0);
+        totalPlan.setMethod2(0);
+        totalPlan.setOtherMethod(0);
+
+        resultMap = planList.stream()
+                .collect(Collectors.groupingBy(item -> {
+                    String gyfs = item.getGyfs();
+                    //为空赋值“其它”
+                    if (StringUtils.isBlank(gyfs)) {
+                        return "其它";
+                    }
+                    return gyfs;
+                }));
+        if(resultMap.containsKey("收购")){
+            totalPlan.setMethod1(resultMap.get("收购").size());
+        }
+        if(resultMap.containsKey("征收")){
+            totalPlan.setMethod2(resultMap.get("征收").size());
+        }
+        if(resultMap.containsKey("其它")){
+            totalPlan.setOtherMethod(resultMap.get("其它").size());
+        }
+
         String progress = String.format("%.2f%%", (totalCompleted.getCount()*100.0 / totalPlan.getCount()));
         total.setProgress(progress);
         total.setCompleted(totalCompleted);
@@ -266,7 +313,6 @@ public class StorageServiceImpl {
 
 
 
-
     //统计分析
     public List<TrendStatisticsData> getData1() {
         List<Map<String, Object>> statsList = gjShijiShouchuMapper.getStatsByYear();

+ 1 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/OfferDataServiceImpl.java

@@ -184,7 +184,7 @@ public class OfferDataServiceImpl implements OfferDataService {
             //todo 需要进行数据的抓取,并且需要异步处理,否则下载文件会阻塞接口的返回,导致超时。
             CompletableFuture.supplyAsync(()-> {
                 if("1".equals(ywlx)){ //土地首次登记
-                    //takeDataService.remoteLandFirstRegistration(body);
+                    takeDataService.remoteLandFirstRegistration(body);
                 }else if("2".equals(ywlx)){ //房屋首次登记
                     //takeDataService.remoteHouseFirstRegistration(body);
                 }

+ 9 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/TakeDataServiceImpl.java

@@ -194,6 +194,14 @@ public class TakeDataServiceImpl implements TakeDataService {
         //todo 这里进行远程请求,获取相关数据,解析后入库
         LandFirstParamVo body = new LandFirstParamVo(); //这里需要调整
         List<String> geomsList = body.getGeoms();
+
+
+
+
+
+
+
+
         if (CollectionUtils.isEmpty(geomsList)) {
             throw new ServiceException("geom信息为空");
         }
@@ -233,11 +241,11 @@ public class TakeDataServiceImpl implements TakeDataService {
         }
         //todo 同步完成之后,需要修改t_third_record_status 表的状态值,同步完成;
 
-
         return null;
     }
 
 
+
     @Override
     public Map<String, Object> remoteHouseFirstRegistration(ThirdRecordStatusParamVo paramVo) {
         String yfbdcdyh = paramVo.getYfbdcdyh();

+ 50 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/HttpClientUtil.java

@@ -177,4 +177,54 @@ public class HttpClientUtil {
         }
         return resultString;
     }
+
+    /**
+     * 传送json类型的post请求,支持自定义请求头
+     *
+     * @param url
+     * @param json
+     * @param headers
+     * @return String
+     */
+    public static String doPostJson(String url, String json, Map<String, String> headers) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = null;
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 设置自定义请求头
+            if (headers != null) {
+                for (String key : headers.keySet()) {
+                    httpPost.setHeader(key, headers.get(key));
+                }
+            }
+            // 创建请求内容
+            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
+            entity.setContentEncoding("UTF-8");
+            httpPost.setEntity(entity);
+            RequestConfig requestConfig = RequestConfig.custom()
+                    .setConnectionRequestTimeout(10000)
+                    .setConnectTimeout(10000)
+                    .setSocketTimeout(30000).build();
+            httpPost.setConfig(requestConfig);
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            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;
+    }
+
 }

+ 68 - 5
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceUtil.java

@@ -1,22 +1,34 @@
 package com.siwei.apply.utils;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.siwei.apply.domain.NodeAttachment;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.net.URI;
 import java.security.MessageDigest;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
+import static com.siwei.common.core.utils.RsaUtil.decryptByPrivateKey;
+import static com.siwei.common.core.utils.RsaUtil.encryptByPublicKey;
+
 /**
  * 服务类工具
  */
 public class ServiceUtil {
-
     private static final long EXPIRY_TIME = 10 * 60 * 1000;  // 10 minutes in milliseconds
     private static final String SECRET_KEY = "siwei";  // Secret key for signature
     private static final String TIME_KEY = "?time=";  // time
     private static final String DOMAIN = "http://192.168.60.219/prod-api/apply";  // doman
+    private static final String THIRD_API_PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAI1O4yrVG7/Eg1M0G1f/bRDV1ABUpRSSBxvfAxh4dL2W7ApMCz+Krs3xushcQzTOsVuxPGAjgXB906iUEyUJoefnixiKthYV56kzVeXtIw+J1Tbnc1ujTvhWNUkaJYxLCTw+8Z/kASL0XNKImSgzNsB6YQ/ZlYa0kBUEFrs0RBStAgMBAAECgYAxOrqJwZTZSm02H4EnNyWYJ+aj9tlMQVOYsikx7UU+h8XUEIoaqQYdWYnpI7uGOjwv5Z9THwuJVUzX/j5tON3el/eMeOCdnRaSzprY90ceKPr13TezIy6PvyZbH0JRua7Qwu+Klh8GL/6s5lZfs3VAM3qImSE+O86SlL+GbdLiAQJBANF5zA/a8KGkm7yremftARqvfOTy+PQxXXXE7tbWqE5P/t4/feZI45OKoNNId1EGFs4nIS/G+p99AEO80sQNnVUCQQCssUV6h6ddEp3SAVfDSB1Ss0i35kd5GRZT5v+atA9ETAyP37o8ZqnFln1blG95Afp7qy0NcP+ltGCZZftOBdn5AkAv+SXbx7duPYWRKvBolqW3F9ORl3eebSPLUeOk/hojfTyQZ5gMwkqkQo5cdO8mdi+I3PtDtt0042rJGJhoX/nVAkEAqJekGdxHgzDCjJws/wPvRKatDoQtMMdSKfUxgunYobeQ6ADmQ0OC6NhjZ73BGiTZUlSp9h5kJnSzfe626dQCmQJBAM7heHLxlzNY65ziyTp5RkShxmp/yEi6d4cFzZ5/UyFDWW/vphrbKezsKK5rpbFmQjNhFcAk61+O+70J0V8Yoh8=";  // doman
+    private static final String THIRD_API_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCoVP+LpSUfIL6r2nvN/TYOmBGGJT/6vB2Us8Qhk/4ZhmPIo1PE/8ovpdFcNXaYGbtd6/32dkotxFgMxiLdHFHii3EaBL6PXUYHiZWnIRz79gmttHQGDXhOVRGbldNHOZXWBBrek8/GWDk6Z5jgUFhi3K5853JU5fIc8w5TGyVs7wIDAQAB";
+    private static final String THIRD_API_BASE_URL = "http://10.224.1.228:10001/dsp-register-server/dspRegisterService/proxyService/proxyThirdPlatformService";
+
+
+    protected static final Logger logger = LoggerFactory.getLogger(ServiceUtil.class);
 
     /**
      * 获取指定目录下的子children list
@@ -85,10 +97,10 @@ public class ServiceUtil {
                     List<Map<String, String>> list = (List<Map<String, String>>) childMap.get("children");
                     for (Map<String, String> map : list) {
                         String fileName = map.get("name");
-                        if(StringUtils.isNotBlank(fileName)){
+                        if (StringUtils.isNotBlank(fileName)) {
                             String SignedUrl = attachmentId + "/" + childName + "/" + fileName;
                             String signedRes = fileUrlSigned(SignedUrl, timestamp);
-                            String path =  DOMAIN+ "/public/offer/download/"+signedRes+"/"+timestamp+"/"+attachmentId+"/"+childName+"/"+fileName;
+                            String path = DOMAIN + "/public/offer/download/" + signedRes + "/" + timestamp + "/" + attachmentId + "/" + childName + "/" + fileName;
                             map.put("path", path);
                         }
                     }
@@ -98,8 +110,6 @@ public class ServiceUtil {
     }
 
 
-
-
     // Validate the URL by checking its timestamp and signature
     public static boolean isUrlValid222(String url, long originalTimestamp) {
         try {
@@ -175,4 +185,57 @@ public class ServiceUtil {
     }
 
 
+    /**
+     * 使用HttpClient 获取远程加解密数据
+     *
+     * @throws Exception
+     */
+    public static String getRemoteDataByHttpClient(String queryMethod, Map<String, Object> paramMap) throws Exception {
+        // 1. 公钥私钥
+        String privateKey = THIRD_API_PRIVATE_KEY;
+        String publicKey = THIRD_API_PUBLIC_KEY;
+
+        // 2. 三方提供其公钥(这里用我方公钥模拟三方公钥,联调时替换为真实三方公钥)
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String time = sdf.format(new Date());
+
+        // 3. 组装业务数据
+        Map<String, Object> dataMap = new HashMap<>(4);
+        dataMap.putAll(paramMap);
+//        dataMap.put("ywbh", "");
+//        dataMap.put("bdcdyh", "360122011006GB00318F00010001");
+
+        // 4. 对象转 JSON ->  公钥加密  -> URLEncode
+        ObjectMapper mapper = new ObjectMapper();
+        String json = mapper.writeValueAsString(dataMap);
+        logger.info("入参:{} ", json);
+        String encrypted = encryptByPublicKey(publicKey, json);
+        //System.out.println("密文: " + encrypted);
+        logger.info("密文:{} ", encrypted);
+        String payload = encrypted;
+
+        // 6. 设置header参数(含 M方法参数 x-method)
+        Map<String, String> headers = new HashMap<>(16);
+        headers.put("Content-Type", "application/json; charset=UTF-8");
+        headers.put("Accept", "application/json");
+        headers.put("x-area-code", "360100");
+        headers.put("x-industry-code", "FC");
+        headers.put("x-method", queryMethod);
+        headers.put("x-sender-id", "YMGD20260709");
+        headers.put("x-version", "1.0");
+        headers.put("x-timestamp", time);
+        headers.put("x-format", "json");
+
+        // 7. 使用HttpClientUtil 发起远程POST请求
+        String resp = HttpClientUtil.doPostJson(THIRD_API_BASE_URL, payload, headers);
+        //System.out.println("响应原文: " + resp);
+        logger.info("响应原文:{} ", resp);
+        // 8. 用我方私钥解密响应密文
+        String plain = decryptByPrivateKey(privateKey, resp);
+        //System.out.println("响应解密明文: " + plain);
+        logger.info("响应解密明文:{} ", plain);
+        return plain;
+    }
+
+
 }