Bladeren bron

完成查询指定项目内历史维护资产功能

Jxing 6 jaren geleden
bovenliggende
commit
634d382979

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

@@ -128,6 +128,15 @@ public class Route extends ExceptionHandlerBaseRoute {
                 .to("direct:getEquipmentByPj")
                 .process(new FilterPropertyProcessor());
 
+        // 查询指定项目内合同有效期内的资产/查询指定项目内历史维护资产
+        rest("/maintainance/property/history/").post("query")
+                .consumes(MediaType.APPLICATION_JSON)
+                .produces(MediaType.APPLICATION_JSON)
+                .route()
+                .process(new QueryPropertyProcesspr())
+                .to("direct:getEquipmentAndHistoryByPj")
+                .process(FilterPropertyProcessor::filterEquip);
+
 
         rest("/project/sync").post()
                 .consumes(MediaType.APPLICATION_JSON)
@@ -172,7 +181,11 @@ public class Route extends ExceptionHandlerBaseRoute {
                 .to(InitEnvRoute.dataPlatform + "/property/relation_query?bridgeEndpoint=true&method=POST");
         from("direct:getEquipmentByPj")
                 .process(new GetEquipmentByPjProcessor())
-                .to(Const.dataPlatform + "/object/subset_query");
+                .to(Const.dataPlatform + "/equipment/complex_query");
+
+        from("direct:getEquipmentAndHistoryByPj")
+                .process(GetEquipmentByPjProcessor::getEquipmentHistoryByPj)
+                .to(Const.dataPlatform + "/equipment/complex_query");
 
         // 统计数据平台资产和设备信息(数量)
         from("direct:buildVenderMap").setHeader(Exchange.HTTP_METHOD, constant("POST"))

+ 11 - 0
src/main/java/com/sagacloud/route/processors/GetEquipmentByPjProcessor.java

@@ -22,4 +22,15 @@ public class GetEquipmentByPjProcessor implements Processor {
         exchange.getIn().setHeader(Exchange.HTTP_URI, Const.dataPlatform+"/object/subset_query?method=POST");
         exchange.getIn().setHeader(Exchange.HTTP_QUERY,Const.HEADER_PROJECT + "=" + projectId + "&"+ Const.HEADER_SECRET+ "="+ secret);
     }
+
+    public static void getEquipmentHistoryByPj(Exchange exchange) throws Exception {
+        String jsonStr = exchange.getIn().getBody(String.class);
+        JSONObject json = JSONObject.parseObject(jsonStr);
+        String projectId = json.getString(Const.HEADER_PROJECT);
+        String secret = ProPasCache.getPjSecret(projectId);
+        exchange.getIn().setBody("{\"venderInfo\":true,\"historyInfos\":true,\"criteria\":{}}");
+//        exchange.getIn().setBody("{\"criteria\":{\"family\":[]}}");
+        exchange.getIn().setHeader(Exchange.HTTP_URI, Const.dataPlatform+"/equipment/complex_query?method=POST");
+        exchange.getIn().setHeader(Exchange.HTTP_QUERY,Const.HEADER_PROJECT + "=" + projectId + "&"+ Const.HEADER_SECRET+ "="+ secret);
+    }
 }

+ 119 - 0
src/main/java/com/sagacloud/route/processors/Maintainance/FilterPropertyProcessor.java

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

+ 1 - 0
src/main/java/com/sagacloud/route/processors/Maintainance/QueryPropertyProcesspr.java

@@ -20,5 +20,6 @@ public class QueryPropertyProcesspr implements Processor {
             throw new InvalidPostException("参数错误!");
         exchange.getIn().setBody(jsonStr);
         exchange.setProperty("postParam", post);
+        exchange.setProperty("postStr", jsonStr);
     }
 }

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

@@ -63,7 +63,23 @@ public class RecommendProcessor {
         exchange.getOut().setBody(VendersUtil.returnJSONArray(new JSONArray(finalArr), (long)arr.size()));
     }
 
-    private static List<Object> paging(ArrayList<JSONObject> arr, JSONObject limit) {
+    public static List<Object> paging(ArrayList<JSONObject> arr, JSONObject limit) {
+        List<Object> retArr = new ArrayList<>();
+        Long from = 0L;
+        int count = arr.size();
+        Long limitSkip = limit == null ? null : limit.getLong("skip");
+        Integer limitCount = limit == null ? null : limit.getInteger("count");
+        if (limitSkip != null && limitCount != null) {
+            from = limitSkip;
+            count = limitCount;
+        }
+        for (long i = from; i < arr.size() && (i - from) < count; ++i) {
+            retArr.add(arr.get((int)i));
+        }
+        return retArr;
+    }
+
+    public static List<Object> paging(JSONArray arr, JSONObject limit) {
         List<Object> retArr = new ArrayList<>();
         Long from = 0L;
         int count = arr.size();

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

@@ -183,14 +183,15 @@ post体:
     }
     
 #维修商
-##查询指定项目内合同有效期内的资产/查询指定项目内历史维护资产[辅助服务接口]
+##查询指定项目内合同有效期内的设备[辅助服务接口]
     http://<host>:<port>/venders-dp/maintainance/property/query
 post体:
     
     {
         "venderId":"****",             // String, 必填, 维修商Id
         "projectId":"*****",          // String, 必填, 项目id
-        "expire":true                   //Boolean, 必填. true 查询维护合同过期资产, false 查询在维护期的资产
+        // expire字段已废弃, 使用接口时可不填, 查询历史维护设备请使用venders-dp/maintainance/property/history/query
+        // "expire":true                   //Boolean, 必填. true 查询维护合同过期资产, false 查询在维护期的资产
     }
     
 返回:
@@ -218,7 +219,41 @@ post体:
         "result":"failure",
         "resultMsg":"***"
     }
+##查询指定项目内历史维护资产[辅助服务接口]
+    http://<host>:<port>/venders-dp/maintainance/property/history/query
+post体:
+    
+    {
+        "venderId":"****",             // String, 必填, 维修商Id
+        "projectId":"*****",          // String, 必填, 项目id
+    }
+    
+返回:
 
+    {
+        "result":"success",
+        "resultMsg":"",
+        "content":[
+            {
+                "id":"****",                 //资产id
+                "hasMaintainer":true|false,    // 是否其他厂商正在维保
+                "infos":{
+                    "EquipLocalName":"",               // 本地名称
+                    "EquipLocalId":"",               // 本地编码
+                    "Brand":"",                   // 品牌
+                    "Product":"",                 // 标牌名
+                    "Specification":"",           // 型号
+                    "MaintainDeadline":"",              // 合同截止日期
+                    "MaintainPeriod":100                   // 保养周期
+                }
+            },........
+        ]
+    }
+    
+    {
+        "result":"failure",
+        "resultMsg":"***"
+    }
 # 统计数据平台数据
 ##按项目更新资产统计数据