Explorar el Código

统计接口完成

FanXiaoyu hace 6 años
padre
commit
5ffdda11c6

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

@@ -1,5 +1,6 @@
 package com.sagacloud.route;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.rjeschke.txtmark.Processor;
 import com.sagacloud.pojos.DPSelectPropertyResult;
@@ -142,30 +143,35 @@ public class Route extends ExceptionHandlerBaseRoute {
                 .consumes(MediaType.APPLICATION_JSON)
                 .produces(MediaType.APPLICATION_JSON)
                 .route()
+                .process(exchange -> {
+                    String jsonStr = exchange.getIn().getBody(String.class);
+                    JSONObject json = JSONObject.parseObject(jsonStr);
+                    JSONArray projectArr = json.getJSONArray("project");
+                    List<String> projectList = projectArr.toJavaList(String.class);
+                    exchange.setProperty("projectList",projectList);
+                })
                 .to("direct:buildVenderMap");
 
         from("direct:buildVenderMap")
-                .process(exchange -> {
-                    Object temp = exchange.getIn().getBody();
-                    exchange.setProperty("tempBody",temp);
-                    exchange.getIn().setHeader(Exchange.HTTP_URI, Const.venders+"/auxiliary/vender/query_detail?method=POST");
-                })
-                .to(Const.venders+"/auxiliary/vender/query_detail")
+//                .process(exchange -> {
+//                    exchange.getIn().setHeader(Exchange.HTTP_URI, Const.venders+"/auxiliary/vender/query_detail?method=POST");
+//                })
+                .to(Const.venders+"/auxiliary/vender/query_detail?bridgeEndpoint=true&method=POST")
                 .process(new VenderMapProcessor())
                 .split(body()).parallelProcessing()
                 .process(exchange -> {
                     String projectId = exchange.getIn().getBody(String.class);
                     JSONObject json = new JSONObject();
                     json.put("projectId",projectId);
-                    exchange.setProperty("projectId",projectId);
+                    exchange.setProperty("projectId"+exchange.getExchangeId(),projectId);
                     exchange.getIn().setBody(json.toString());
                 })
                 .to("direct:getPropertiesByPj")
                 .process(exchange -> {
                     String jsonStr = exchange.getIn().getBody(String.class);
                     DPSelectPropertyResult dpResult = JSONObject.parseObject(jsonStr, DPSelectPropertyResult.class);
-                    exchange.setProperty("propertyData",dpResult);
-                    exchange.getIn().setBody(exchange.getProperty("projectId"));
+                    exchange.setProperty("propertyData"+exchange.getExchangeId(),dpResult);
+                    exchange.getIn().setBody(exchange.getProperty("projectId"+exchange.getExchangeId()));
                 })
                 .to("direct:getPropertyStatisticsByProject");
     }

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

@@ -25,7 +25,8 @@ public class StatisticsProcessor implements Processor {
     @Override
     public void process(Exchange exchange) throws Exception {
         String projectId = exchange.getIn().getBody(String.class);
-        DPSelectPropertyResult propertyData = (DPSelectPropertyResult) exchange.getProperty("propertyData");
+        System.out.println("这里是Project:" + projectId);
+        DPSelectPropertyResult propertyData = (DPSelectPropertyResult) exchange.getProperty("propertyData" + exchange.getExchangeId());
         Map<String, Map<String, String>> infoValueMap = (Map<String, Map<String, String>>) exchange.getProperty("map");  // 信息点Code --> (厂商库在该信息点的值value --> vender DPID)
         List<Map<String, Object>> propertyList = propertyData.getContent();
         Map<String, VenderStatistics> venderStatisticsMap = new HashMap<>();
@@ -41,7 +42,9 @@ public class StatisticsProcessor implements Processor {
         addContractCount(venderStatisticsMap, contracts);
         addContractCount(venderStatisticsMap, warranties);
         ProjectStatistics ps = new ProjectStatistics();
-        ps.setCriterias((List<VenderStatistics>) venderStatisticsMap.values());
+        if(venderStatisticsMap.size() == 0)
+            return;
+        ps.setCriterias(new ArrayList<>(venderStatisticsMap.values()));
         ps.setProjectId(projectId);
         exchange.getIn().setBody(JSONObject.toJSONString(ps));
         exchange.getIn().setHeader(Exchange.HTTP_URI, String.join("", InitEnvRoute.venders, "/auxiliary/property/create_by_project?method=POST"));

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

@@ -30,7 +30,7 @@ public class VenderMapProcessor implements Processor {
         AllVender venders = JSONObject.parseObject(content.toString(), AllVender.class);
         buildNameMap(venders,nameMap);
         exchange.setProperty("map",nameMap);
-        exchange.getIn().setBody(exchange.getProperty("tempBody"));
+        exchange.getIn().setBody(exchange.getProperty("projectList"));
     }
 
     public void buildNameMap(AllVender venders, Map<String, Map> nameMap) {