|
@@ -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)));
|
|
|
}
|
|
|
}
|