Browse Source

fix things

wushengzong 6 years ago
parent
commit
2711d62b0a

+ 2 - 0
src/main/java/com/sagacloud/route/Route.java

@@ -259,6 +259,7 @@ public class Route extends ExceptionHandlerBaseRoute {
         rest("/getInsurance").post()
                 .produces(MediaType.APPLICATION_JSON)
                 .route()
+                .process(ContractMethods :: validateDPInsurerID)
                 .process(ContractMethods :: preQueryEq)
                 .to(InitEnvRoute.dataPlatform + "/object/subset_query?bridgeEndpoint=true")
                 .process(ContractMethods :: extractInsuranceNum);
@@ -266,6 +267,7 @@ public class Route extends ExceptionHandlerBaseRoute {
         rest("/getSupplierContractID").post()
                 .produces(MediaType.APPLICATION_JSON)
                 .route()
+                .process(ContractMethods :: validateDPSupplierID)
                 .process(ContractMethods :: preQueryEq)
                 .to(InitEnvRoute.dataPlatform + "/object/subset_query?bridgeEndpoint=true")
                 .process(ContractMethods :: extractSupplierContractIds);

+ 24 - 4
src/main/java/com/sagacloud/route/processors/ContractMethods.java

@@ -1,5 +1,6 @@
 package com.sagacloud.route.processors;
 
+import com.sagacloud.Exceptions.InvalidPostException;
 import org.apache.camel.Exchange;
 import org.json.JSONObject;
 
@@ -15,14 +16,14 @@ public class ContractMethods {
     }
 
     public static void extractSupplierContractIds(Exchange exchange) {
-        extract(exchange, "SupplierContractID");
+        extract(exchange, "SupplierContractID", "DPSupplierID", exchange.getProperty("DPSupplierID", String.class));
     }
 
     public static void extractInsuranceNum(Exchange exchange) {
-        extract(exchange, "InsuranceNum");
+        extract(exchange, "InsuranceNum", "DPInsurerID", exchange.getProperty("DPInsurerID", String.class));
     }
 
-    private static void extract(Exchange exchange, String info){
+    private static void extract(Exchange exchange, String info, String venderInfo, String venderId){
         String inStr = exchange.getIn().getBody(String.class);
         JSONObject json = new JSONObject(inStr);
         if(!json.getString("Result").equalsIgnoreCase("success")){
@@ -31,7 +32,8 @@ public class ContractMethods {
         Set<String> contractIds = new HashSet<>();
         json.getJSONArray("Content").forEach(obj ->{
             JSONObject item = (JSONObject) obj;
-            if(item.getJSONObject("infos").has(info)){
+            JSONObject infos = item.getJSONObject("infos");
+            if(infos.has(venderInfo) && infos.getString(venderInfo).trim().equalsIgnoreCase(venderId) && infos.has(info)){
                 contractIds.add(item.getJSONObject("infos").getString(info));
             }
         });
@@ -39,4 +41,22 @@ public class ContractMethods {
         result.put("content", contractIds);
         exchange.getOut().setBody(result);
     }
+
+    public static void validateDPSupplierID(Exchange exchange) throws InvalidPostException {
+        String inStr = exchange.getIn().getBody(String.class);
+        JSONObject json = new JSONObject(inStr);
+        if(!json.has("DPSupplierID")){
+            throw new InvalidPostException("Need DPSupplierID");
+        }
+        exchange.setProperty("DPSupplierID", json.getString("DPSupplierID"));
+    }
+
+    public static void validateDPInsurerID(Exchange exchange) throws InvalidPostException {
+        String inStr = exchange.getIn().getBody(String.class);
+        JSONObject json = new JSONObject(inStr);
+        if(!json.has("DPInsurerID")){
+            throw new InvalidPostException("Need DPInsurerID");
+        }
+        exchange.setProperty("DPInsurerID", json.getString("DPInsurerID").trim());
+    }
 }

+ 10 - 2
src/main/resources/documentation.md

@@ -261,7 +261,11 @@ post体:
 
     http://<host>:<port>/venders-dp/getInsurance?projectId=Pj110108****&secret=***
     
-post方法, 不需要传Post数据:
+post体:
+
+    {
+    	"DPInsurerID":"V0a6a643c9c6311e8b4acf9fa5a3bd22f"
+    }
 
 返回:
  
@@ -277,7 +281,11 @@ post方法, 不需要传Post数据:
 
     http://<host>:<port>/venders-dp/getSupplierContractID?projectId=Pj110108****&secret=***
     
-post方法, 不需要传Post数据:
+post体:
+
+    {
+    	"DPSupplierID":"V5593c8928a2d11e8a8c0b5b15b013d50"
+    }
 
 返回: