|
@@ -4,12 +4,14 @@ package com.sagacloud.route.processors.Maintainance;
|
|
|
* Create Time: 2018/7/13
|
|
|
*/
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sagacloud.Exceptions.InvalidPostException;
|
|
|
import com.sagacloud.pojos.DPSelectPropertyResult;
|
|
|
import com.sagacloud.pojos.InsurancePost;
|
|
|
import com.sagacloud.route.processors.Insurance.GetPropertyUnderWarrantyProcessor;
|
|
|
+import com.sagacloud.route.processors.RecommendProcessor;
|
|
|
import com.sagacloud.utils.Const;
|
|
|
import com.sagacloud.utils.VendersUtil;
|
|
|
import org.apache.camel.Exchange;
|
|
@@ -73,4 +75,121 @@ public class FilterPropertyProcessor implements Processor {
|
|
|
}
|
|
|
exchange.getOut().setBody(VendersUtil.successJsonMsg("", (JSONArray) JSONArray.toJSON(propertyList)));
|
|
|
}
|
|
|
+
|
|
|
+ public static void filterEquip(Exchange exchange) throws InvalidPostException {
|
|
|
+ String jsonStr = exchange.getIn().getBody(String.class);
|
|
|
+ DPSelectPropertyResult dpResult = JSONObject.parseObject(jsonStr, DPSelectPropertyResult.class);
|
|
|
+ if(dpResult.getResult() == null && !dpResult.getResult().equals("success"))
|
|
|
+ throw new InvalidPostException("数据平台返回异常!");
|
|
|
+ List<Map<String, Object>> content = dpResult.getContent();
|
|
|
+ InsurancePost post = (InsurancePost) exchange.getProperty("postParam");
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ a: for(Map<String, Object> singleObject : content){
|
|
|
+ Map<String, Object> infos = (Map<String, Object>)singleObject.get("infos");
|
|
|
+ String objMtnVenderId = (String) infos.get("DPMaintainerID");
|
|
|
+ if(objMtnVenderId == null || objMtnVenderId.equals(post.getVenderId()))
|
|
|
+ continue;
|
|
|
+ List<Map<String, Object>> objMtnVenderIdHis = (List<Map<String, Object>>) infos.get("DPMaintainerID_his");
|
|
|
+ if(objMtnVenderIdHis == null)
|
|
|
+ continue;
|
|
|
+ for(Map<String, Object> singleHis : objMtnVenderIdHis){
|
|
|
+ String value = (String) singleHis.get("value");
|
|
|
+ if(post.getVenderId().equals(value)){
|
|
|
+ processData(infos, post.getVenderId());
|
|
|
+ if(objMtnVenderId.equals(""))
|
|
|
+ singleObject.put("hasMaintainer", false);
|
|
|
+ else
|
|
|
+ singleObject.put("hasMaintainer", true);
|
|
|
+ result.add(singleObject);
|
|
|
+ continue a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonStr = JSON.toJSONString(result);
|
|
|
+ JSONArray array = JSON.parseArray(jsonStr);
|
|
|
+ JSONObject body = JSONObject.parseObject((String)exchange.getProperty("postStr"));
|
|
|
+ List<Object> list = RecommendProcessor.paging(array, body.getJSONObject("limit"));
|
|
|
+ exchange.getOut().setBody(VendersUtil.returnJSONArray(new JSONArray(list), (long)array.size()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void processData(Map<String, Object> infos, String venderId) {
|
|
|
+ List<Map<String, Object>> objMtnVenderIdHis = (List<Map<String, Object>>) infos.get("DPMaintainerID_his");
|
|
|
+ // 最后维护该资产的开始时间
|
|
|
+ String maxBeginTime = null;
|
|
|
+ // 最后维护该资产的结束时间
|
|
|
+ String maxEndTime = null;
|
|
|
+ for(Map<String, Object> singleHis : objMtnVenderIdHis){
|
|
|
+ String value = (String) singleHis.get("value");
|
|
|
+ String time = (String) singleHis.get("time");
|
|
|
+ if(venderId.equals(value)){
|
|
|
+ if(maxBeginTime== null)
|
|
|
+ maxBeginTime = time;
|
|
|
+ else if(maxBeginTime.compareTo(time) < 0)
|
|
|
+ maxBeginTime = time;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(maxBeginTime == null)
|
|
|
+ return;
|
|
|
+ for(Map<String, Object> singleHis : objMtnVenderIdHis){
|
|
|
+ String value = (String) singleHis.get("value");
|
|
|
+ String time = (String) singleHis.get("time");
|
|
|
+ if(!venderId.equals(value) && maxBeginTime.compareTo(time) < 0){
|
|
|
+ if(maxEndTime == null)
|
|
|
+ maxEndTime = time;
|
|
|
+ else if(maxEndTime.compareTo(time) > 0)
|
|
|
+ maxEndTime = time;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(maxEndTime == null)
|
|
|
+ return;
|
|
|
+ // 上面已经计算出最后一次维保的开始和结束时间.
|
|
|
+ // 删除所有当前值节点的信息点
|
|
|
+ removeInfo(infos, false);
|
|
|
+ Map<String, Object> periodInfoValueMap = new HashMap<>();
|
|
|
+ //计算维保期间的信息点的值.
|
|
|
+ for(String singleHis : infos.keySet()){
|
|
|
+ List<Map<String, Object>> hisNode = (List<Map<String, Object>>) infos.get(singleHis);
|
|
|
+ String maxTime = null;
|
|
|
+ Object correspondingValue = null;
|
|
|
+ for(Map<String, Object> singleHisObj : hisNode){
|
|
|
+ Object value = singleHisObj.get("value");
|
|
|
+ String time = (String) singleHisObj.get("time");
|
|
|
+ if(time != null && time.compareTo(maxEndTime) < 0){
|
|
|
+ if(maxTime== null) {
|
|
|
+ maxTime = time;
|
|
|
+ correspondingValue = value;
|
|
|
+ }else if(maxTime.compareTo(time) < 0) {
|
|
|
+ maxTime = time;
|
|
|
+ correspondingValue = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(correspondingValue != null){
|
|
|
+ periodInfoValueMap.put(singleHis.substring(0, singleHis.length() - 4), correspondingValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ infos.clear();
|
|
|
+ infos.putAll(periodInfoValueMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除infos节点内的所有历史节点, 或当前值节点
|
|
|
+ * @param infos
|
|
|
+ * @param delHisCur true是删除历史, false 是删除当前值节点
|
|
|
+ */
|
|
|
+ private static void removeInfo(Map<String, Object> infos, boolean delHisCur) {
|
|
|
+ ArrayList<String> arr = new ArrayList<>();
|
|
|
+ for(String infoCode : infos.keySet()) {
|
|
|
+ if (!infoCode.endsWith("_his") && !delHisCur) {
|
|
|
+ arr.add(infoCode);
|
|
|
+ }else if(infoCode.endsWith("_his") && delHisCur){
|
|
|
+ arr.add(infoCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String infoCode : arr)
|
|
|
+ infos.remove(infoCode);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|