Переглянути джерело

Merge remote-tracking branch 'origin/master'

FanXiaoyu 6 роки тому
батько
коміт
5e07318433

+ 47 - 0
src/main/java/com/sagacloud/pojos/DPSelectPropertyResult.java

@@ -0,0 +1,47 @@
+package com.sagacloud.pojos;
+/*
+ * Author: Jxing
+ * Create Time: 2018/7/12
+ */
+
+import java.util.List;
+import java.util.Map;
+
+public class DPSelectPropertyResult {
+    private String Result;
+    private String ResultMsg;
+    private int Count;
+    private List<Map<String, Object>> Content;
+
+    public String getResult() {
+        return Result;
+    }
+
+    public void setResult(String result) {
+        Result = result;
+    }
+
+    public String getResultMsg() {
+        return ResultMsg;
+    }
+
+    public void setResultMsg(String resultMsg) {
+        ResultMsg = resultMsg;
+    }
+
+    public int getCount() {
+        return Count;
+    }
+
+    public void setCount(int count) {
+        Count = count;
+    }
+
+    public List<Map<String, Object>> getContent() {
+        return Content;
+    }
+
+    public void setContent(List<Map<String, Object>> content) {
+        Content = content;
+    }
+}

+ 1 - 0
src/main/java/com/sagacloud/pojos/WarrantyList.java

@@ -39,6 +39,7 @@ public class WarrantyList {
     }
 
     public class Warrnaty{
+
         private String insuranceNo;
         private String expireDate;
         private String contractFile;

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

@@ -6,6 +6,7 @@ import com.github.rjeschke.txtmark.Processor;
 import com.sagacloud.Exceptions.InvalidPostException;
 import com.sagacloud.route.processors.Insurance.GetInsuranceNoListProcessor;
 import com.sagacloud.route.processors.GetPropByPjProcessor;
+import com.sagacloud.route.processors.Insurance.GetPropertyUnderWarrantyProcessor;
 import com.sagacloud.route.processors.Insurance.HandleWarrantyFromVenderProcessor;
 import com.sagacloud.route.processors.Manufacturer.GetVenderBySpecProcessor;
 import com.sagacloud.utils.Const;
@@ -65,7 +66,7 @@ public class Route extends RouteBuilder {
                 .process(new HandleWarrantyFromVenderProcessor())
                 .to("direct:getPropertiesByPj")
                 //.to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query"))
-                .process(new GetInsuranceNoListProcessor());
+                .process(new GetPropertyUnderWarrantyProcessor());
         // 获取所有保单列表
         rest("/insurance/contract/").post("query")
                 .consumes(MediaType.APPLICATION_JSON)

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

@@ -20,7 +20,6 @@ public class GetInsuranceNoListProcessor implements Processor {
     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);

+ 43 - 9
src/main/java/com/sagacloud/route/processors/Insurance/GetPropertyUnderWarrantyProcessor.java

@@ -4,27 +4,61 @@ package com.sagacloud.route.processors.Insurance;
  * Create Time: 2018/7/12
  */
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.sagacloud.Exceptions.InvalidPostException;
 import com.sagacloud.cache.ProPasCache;
+import com.sagacloud.pojos.DPSelectPropertyResult;
 import com.sagacloud.pojos.InsurancePost;
+import com.sagacloud.pojos.WarrantyList;
 import com.sagacloud.route.InitEnvRoute;
 import com.sagacloud.utils.Const;
+import com.sagacloud.utils.VendersUtil;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
 public class GetPropertyUnderWarrantyProcessor implements Processor {
+    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
     @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())));
+        DPSelectPropertyResult dpResult = JSONObject.parseObject(jsonStr, DPSelectPropertyResult.class);
+        System.out.println(jsonStr);
+        if(dpResult.getResult() == null && !dpResult.getResult().equals("success"))
+            throw new InvalidPostException("数据平台返回异常!");
+
+        HashSet<String> validWarranty = new HashSet<>();
+        List<WarrantyList.Warrnaty> ws = (List<WarrantyList.Warrnaty>) exchange.getProperty("warrantyList");
+        List<Map<String, Object>> propertyList = dpResult.getContent();
+        for(int i = 0; i < ws.size(); ++i){
+            WarrantyList.Warrnaty warrnaty = ws.get(i);
+            try {
+                Date expireDate = sdf.parse(warrnaty.getExpireDate());
+                Date now = new Date();
+                if(now.compareTo(expireDate) > 0 && !validWarranty.contains(warrnaty.getInsuranceNo()))
+                    validWarranty.add(warrnaty.getInsuranceNo());
+            }catch (Exception ignore)
+            {}
+        }
+        if(validWarranty.size() == 0 || propertyList.size() == 0)
+        {
+            exchange.getOut().setBody(VendersUtil.successJsonMsg("", new JSONArray()));
+            return;
+        }
+
+        for(int i = propertyList.size() - 1; i < propertyList.size(); --i){
+            Map<String, Object> property = propertyList.get(i);
+            Map<String, Object> infos = (Map<String, Object>) property.get("infos");
+            if(!validWarranty.contains((String)infos.get(Const.INSUR_ID))){
+                propertyList.remove(i);
+            }
+        }
+        exchange.getOut().setBody(VendersUtil.successJsonMsg("", JSONArray.toJSONString(propertyList)));
     }
 }