فهرست منبع

修改Processor结构

Jxing 6 سال پیش
والد
کامیت
ceac787797

+ 9 - 8
src/main/java/com/sagacloud/route/Route.java

@@ -2,9 +2,9 @@ package com.sagacloud.route;
 
 import com.github.rjeschke.txtmark.Processor;
 import com.sagacloud.Exceptions.InvalidPostException;
-import com.sagacloud.route.processors.GetInsuranceNoListProcessor;
-import com.sagacloud.route.processors.handleWarrantyFromVenderProcessor;
+import com.sagacloud.route.processors.Insurance.GetInsuranceNoListProcessor;
 import com.sagacloud.route.processors.GetPropByPjProcessor;
+import com.sagacloud.route.processors.Insurance.HandleWarrantyFromVenderProcessor;
 import com.sagacloud.utils.Const;
 import com.sagacloud.utils.VendersUtil;
 import org.apache.camel.Exchange;
@@ -49,8 +49,9 @@ public class Route extends RouteBuilder {
                 .route()
                 .process(new GetInsuranceNoListProcessor())
                 .to(String.join("", InitEnvRoute.venders, "/insurance/contract/query"))
-                .process(new GetInsuranceNoListProcessor())
-                .to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query"))
+                .process(new HandleWarrantyFromVenderProcessor())
+                .to("direct:getPropertiesByPj")
+                //.to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query"))
                 .process(new GetInsuranceNoListProcessor());
         // 获取所有保单列表
         rest("/insurance/contract/").post("query")
@@ -74,10 +75,10 @@ public class Route extends RouteBuilder {
         //body位JSONObject,含有projectId字段
         from("direct:getPropertiesByPj")
                 .process(new GetPropByPjProcessor())
-                .to(Const.dataPlatform+"/property/relation_query")
-                .process(exchange -> {
-                    System.out.println(exchange.getIn().getBody(String.class));
-                });
+                .to(Const.dataPlatform+"/property/relation_query");
+//                .process(exchange -> {
+//                    System.out.println(exchange.getIn().getBody(String.class));
+//                });
         rest("/test").post()
                 .consumes(MediaType.APPLICATION_JSON)
                 .produces(MediaType.APPLICATION_JSON)

+ 1 - 1
src/main/java/com/sagacloud/route/processors/GetInsuranceNoListProcessor.java

@@ -1,4 +1,4 @@
-package com.sagacloud.route.processors;
+package com.sagacloud.route.processors.Insurance;
 /*
  * Author: Jxing
  * Create Time: 2018/7/11

+ 30 - 0
src/main/java/com/sagacloud/route/processors/Insurance/GetPropertyUnderWarrantyProcessor.java

@@ -0,0 +1,30 @@
+package com.sagacloud.route.processors.Insurance;
+/*
+ * Author: Jxing
+ * Create Time: 2018/7/12
+ */
+
+import com.alibaba.fastjson.JSONObject;
+import com.sagacloud.Exceptions.InvalidPostException;
+import com.sagacloud.cache.ProPasCache;
+import com.sagacloud.pojos.InsurancePost;
+import com.sagacloud.route.InitEnvRoute;
+import com.sagacloud.utils.Const;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class GetPropertyUnderWarrantyProcessor implements Processor {
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        String jsonStr = exchange.getIn().getBody(String.class);
+        InsurancePost post = JSONObject.parseObject(jsonStr, InsurancePost.class);
+        System.out.println(ProPasCache.getPjSecret(post.getProjectId()));
+        if(post.getVenderId() == null || post.getProjectId() == null || ProPasCache.getPjSecret(post.getProjectId()) == null)
+            throw new InvalidPostException("参数错误!");
+        exchange.getIn().setBody(jsonStr);
+        exchange.setProperty("postParam", post);
+        exchange.getIn().setHeader(Exchange.HTTP_URI, String.join("", InitEnvRoute.venders, "/insurance/contract/query?method=POST"));
+        exchange.getIn().setHeader(Exchange.HTTP_QUERY,String.join("", Const.HEADER_PROJECT , "=", post.getProjectId(),
+                "&", Const.HEADER_SECRET, "=", ProPasCache.getPjSecret(post.getProjectId())));
+    }
+}

+ 5 - 2
src/main/java/com/sagacloud/route/processors/handleWarrantyFromVenderProcessor.java

@@ -1,4 +1,4 @@
-package com.sagacloud.route.processors;
+package com.sagacloud.route.processors.Insurance;
 /*
  * Author: Jxing
  * Create Time: 2018/7/12
@@ -14,7 +14,7 @@ import com.sagacloud.utils.Const;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 
-public class handleWarrantyFromVenderProcessor implements Processor {
+public class HandleWarrantyFromVenderProcessor implements Processor {
     @Override
     public void process(Exchange exchange) throws Exception {
         String jsonStr = exchange.getIn().getBody(String.class);
@@ -23,6 +23,9 @@ public class handleWarrantyFromVenderProcessor implements Processor {
         if(warrantyList.getResult().equals("failure"))
             throw new InvalidPostException(warrantyList.getResultMsg() != null && warrantyList.getResult().length() > 0?
                     String.join("", "厂商库异常:", warrantyList.getResultMsg()) : "厂商库访问出错!");
+        exchange.setProperty("warrantyList", warrantyList.getWarrantyList());
+        InsurancePost post = (InsurancePost) exchange.getProperty("postParam");
+        exchange.getIn().setBody(JSONObject.toJSONString(post));
 //
 //        //exchange.getIn().setBody();
 //        exchange.setProperty("postParam", post);