|  | @ -24,6 +24,7 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |     public static final String BEAN_ID = "ServiceMonitorService";
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MongoOperations mongoOperations;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private DBCollection businessLog;
 | 
	
		
			
				|  |  | //    public Result mapReduce(String beginTime, String endTime) {
 | 
	
		
			
				|  |  | //        DBCollection businessLogDB = mongoOperations.getCollection(mongoOperations
 | 
	
	
		
			
				|  | @ -89,7 +90,7 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |         return businessLog;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public void bandwidth(String beginTime, String endTime) {
 | 
	
		
			
				|  |  |     public void bandwidth(String beginTime, String endTime, List<String> codeList) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         DBObject match = getMatchFields(beginTime, endTime);
 | 
	
		
			
				|  |  |         DBObject flowGroup = getFlowGroupFields();
 | 
	
	
		
			
				|  | @ -98,43 +99,51 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput flowOutput = getBusinessLog().aggregate(match, flowGroup, sort);
 | 
	
		
			
				|  |  |        //流程带宽
 | 
	
		
			
				|  |  |         Integer flowCalls = 0;
 | 
	
		
			
				|  |  |         String routeId = "";
 | 
	
		
			
				|  |  |         Map<String, Integer> bandwidthMapF = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : flowOutput.results()) {
 | 
	
		
			
				|  |  |             Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             routeId = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             if (count >= 2) {
 | 
	
		
			
				|  |  |                 flowCalls++;
 | 
	
		
			
				|  |  |                 if (bandwidthMapF.containsKey(code)) {
 | 
	
		
			
				|  |  |                     Integer flowCalls = bandwidthMapF.get(code);
 | 
	
		
			
				|  |  |                     bandwidthMapF.put(code, ++flowCalls);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     bandwidthMapF.put(code, 1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         long interval = getInterval(beginTime, endTime);
 | 
	
		
			
				|  |  |         BigDecimal flowBandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(flowCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |         saveServiceMetrics(routeId, "bandwidth", flowBandwidth.toString(), endTime);
 | 
	
		
			
				|  |  |         //服务带宽
 | 
	
		
			
				|  |  |        //服务带宽
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput serviceOutput = getBusinessLog().aggregate(match, serviceGroup, sort);
 | 
	
		
			
				|  |  |         Map<String, Integer> bandwidthMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> bandwidthMapS = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : serviceOutput.results()) {
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("code"));
 | 
	
		
			
				|  |  |             if (bandwidthMap.containsKey(code)) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = bandwidthMap.get(code);
 | 
	
		
			
				|  |  |                 bandwidthMap.put(code, ++serviceCalls);
 | 
	
		
			
				|  |  |             if (bandwidthMapS.containsKey(code)) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = bandwidthMapS.get(code);
 | 
	
		
			
				|  |  |                 bandwidthMapS.put(code, ++serviceCalls);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 bandwidthMap.put(code, 1);
 | 
	
		
			
				|  |  |                 bandwidthMapS.put(code, 1);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         for (String code : bandwidthMap.keySet()) {
 | 
	
		
			
				|  |  |             Integer serviceCalls = bandwidthMap.get(code)/2;
 | 
	
		
			
				|  |  |             BigDecimal serviceBandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(serviceCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "bandwidth", serviceBandwidth.toString(), endTime);
 | 
	
		
			
				|  |  |         for (String code : codeList) {
 | 
	
		
			
				|  |  |             BigDecimal bandwidth = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |             long interval = getInterval(beginTime, endTime);
 | 
	
		
			
				|  |  |             if (!StringUtil.isEmpty(bandwidthMapF.get(code))) {
 | 
	
		
			
				|  |  |                 Integer flowCalls = bandwidthMapF.get(code);
 | 
	
		
			
				|  |  |                 bandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(flowCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |             } else if (!StringUtil.isEmpty(bandwidthMapS.get(code))) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = bandwidthMapS.get(code)/2;
 | 
	
		
			
				|  |  |                 bandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(serviceCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "bandwidth", bandwidth.toString(), endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void qps(String beginTime, String endTime) {
 | 
	
		
			
				|  |  |     public void qps(String beginTime, String endTime, List<String> codeList) {
 | 
	
		
			
				|  |  |         DBObject match = getMatchFields(beginTime, endTime);
 | 
	
		
			
				|  |  |         DBObject flowGroup = getFlowGroupFields();
 | 
	
		
			
				|  |  |         DBObject sort = getSortFields();
 | 
	
	
		
			
				|  | @ -142,137 +151,169 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput flowOutput = getBusinessLog().aggregate(match, flowGroup, sort);
 | 
	
		
			
				|  |  |         //流程qps
 | 
	
		
			
				|  |  |         Integer flowCalls = 0;
 | 
	
		
			
				|  |  |         String routeId = "";
 | 
	
		
			
				|  |  |         Map<String, Integer> qpsMapF = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : flowOutput.results()) {
 | 
	
		
			
				|  |  |             Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             routeId = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             if (count >= 2) {
 | 
	
		
			
				|  |  |                 Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
 | 
	
		
			
				|  |  |                 if (total == count/2) {
 | 
	
		
			
				|  |  |                     flowCalls++;
 | 
	
		
			
				|  |  |                     if (qpsMapF.containsKey(code)) {
 | 
	
		
			
				|  |  |                         Integer flowCalls = qpsMapF.get(code);
 | 
	
		
			
				|  |  |                         qpsMapF.put(code, ++flowCalls);
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         qpsMapF.put(code, 1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         long interval = getInterval(beginTime, endTime);
 | 
	
		
			
				|  |  |         BigDecimal flowQps = NumberUtil.divideBigDecimal(BigDecimal.valueOf(flowCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |         saveServiceMetrics(routeId, "qps", flowQps.toString(), endTime);
 | 
	
		
			
				|  |  |         //服务带宽
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput serviceOutput = getBusinessLog().aggregate(match, serviceGroup, sort);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, Integer> qpsMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> qpsMapS = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : serviceOutput.results()) {
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("code"));
 | 
	
		
			
				|  |  |             if (qpsMap.containsKey(code)) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = qpsMap.get(code);
 | 
	
		
			
				|  |  |                 qpsMap.put(code, ++serviceCalls);
 | 
	
		
			
				|  |  |             if (qpsMapS.containsKey(code)) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = qpsMapS.get(code);
 | 
	
		
			
				|  |  |                 qpsMapS.put(code, ++serviceCalls);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 qpsMap.put(code, 1);
 | 
	
		
			
				|  |  |                 qpsMapS.put(code, 1);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         for (String code : qpsMap.keySet()) {
 | 
	
		
			
				|  |  |             if (qpsMap.get(code) > 1) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = qpsMap.get(code)/2;
 | 
	
		
			
				|  |  |                 BigDecimal serviceBandwidth = NumberUtil.divideBigDecimal(BigDecimal.valueOf(serviceCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |                 saveServiceMetrics(code, "qps", serviceBandwidth.toString(), endTime);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (String code : codeList) {
 | 
	
		
			
				|  |  |             BigDecimal qps = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |             long interval = getInterval(beginTime, endTime);
 | 
	
		
			
				|  |  |             if (!StringUtil.isEmpty(qpsMapF.get(code))) {
 | 
	
		
			
				|  |  |                 Integer flowCalls = qpsMapF.get(code);
 | 
	
		
			
				|  |  |                 qps = NumberUtil.divideBigDecimal(BigDecimal.valueOf(flowCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |             } else if (!StringUtil.isEmpty(qpsMapS.get(code))) {
 | 
	
		
			
				|  |  |                 Integer serviceCalls = qpsMapS.get(code)/2;
 | 
	
		
			
				|  |  |                 qps = NumberUtil.divideBigDecimal(BigDecimal.valueOf(serviceCalls), BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "qps", qps.toString(), endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void usage(String beginTime, String endTime) throws JsonProcessingException {
 | 
	
		
			
				|  |  |     public void usage(String beginTime, String endTime, List<String> codeList) throws JsonProcessingException {
 | 
	
		
			
				|  |  |         DBObject match = getMatchFields(beginTime, endTime);
 | 
	
		
			
				|  |  |         DBObject flowGroup = getFlowGroupFields();
 | 
	
		
			
				|  |  |         DBObject sort = getSortFields();
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput flowOutput = getBusinessLog().aggregate(match, flowGroup, sort);
 | 
	
		
			
				|  |  |         Integer successCountF = 0;
 | 
	
		
			
				|  |  |         Integer failureCountF = 0;
 | 
	
		
			
				|  |  |         String routeId = "";
 | 
	
		
			
				|  |  |         Map<String, Integer> usageMapSuccessF = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> usageMapFailF = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : flowOutput.results()) {
 | 
	
		
			
				|  |  |             Integer total = Integer.parseInt(StringUtil.toString(dbObject.get("total")));
 | 
	
		
			
				|  |  |             Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             routeId = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             if (total == count/2) {
 | 
	
		
			
				|  |  |                 successCountF++;
 | 
	
		
			
				|  |  |                 if (usageMapSuccessF.containsKey(code)) {
 | 
	
		
			
				|  |  |                     Integer countTemp = usageMapSuccessF.get(code);
 | 
	
		
			
				|  |  |                     usageMapSuccessF.put(code, ++countTemp);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     usageMapSuccessF.put(code, 1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 failureCountF++;
 | 
	
		
			
				|  |  |                 if (usageMapFailF.containsKey(code)) {
 | 
	
		
			
				|  |  |                     Integer countTemp = usageMapFailF.get(code);
 | 
	
		
			
				|  |  |                     usageMapFailF.put(code, ++countTemp);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     usageMapFailF.put(code, 1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         ObjectMapper objectMapper = new ObjectMapper();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject resultF = new JSONObject();
 | 
	
		
			
				|  |  |         resultF.put("totalCount", successCountF + failureCountF);
 | 
	
		
			
				|  |  |         resultF.put("successCount", successCountF);
 | 
	
		
			
				|  |  |         resultF.put("failureCount", failureCountF);
 | 
	
		
			
				|  |  |         saveServiceMetrics(routeId, "usage", objectMapper.writeValueAsString(resultF.toString()), endTime);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         DBCursor serviceOutput = getBusinessLog().find(getQueryObject(beginTime, endTime));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, Integer> usageMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> usageFailMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, DBObject> serviceMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> usageMapSuccessS = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, Integer> usageMapFailS = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, String> serviceMap = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : serviceOutput.toArray()) {
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(dbObject.get("code"));
 | 
	
		
			
				|  |  |             if (!usageMap.containsKey(code)) {
 | 
	
		
			
				|  |  |                 usageMap.put(code, 0);
 | 
	
		
			
				|  |  |             String order = StringUtil.toString(dbObject.get("order"));
 | 
	
		
			
				|  |  |             String breadcrumbId = StringUtil.toString(dbObject.get("breadcrumbId"));
 | 
	
		
			
				|  |  |             if (serviceMap.containsKey(code + breadcrumbId + order)) {
 | 
	
		
			
				|  |  |                 serviceMap.remove(code + breadcrumbId + order);
 | 
	
		
			
				|  |  |                 if (usageMapSuccessS.containsKey(code)) {
 | 
	
		
			
				|  |  |                     Integer countTemp = usageMapSuccessS.get(code);
 | 
	
		
			
				|  |  |                     usageMapSuccessS.put(code, ++countTemp);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     usageMapSuccessS.put(code, 1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 serviceMap.put(code + breadcrumbId + order, code);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (serviceMap.containsKey(code)) {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 serviceMap.remove(code);
 | 
	
		
			
				|  |  |                 Integer usageTemp = usageMap.get(code);
 | 
	
		
			
				|  |  |                 usageMap.put(code, ++usageTemp);
 | 
	
		
			
				|  |  |                 usageFailMap.put(code, 0);
 | 
	
		
			
				|  |  |         for (String key : serviceMap.keySet()) {
 | 
	
		
			
				|  |  |             String code = serviceMap.get(key);
 | 
	
		
			
				|  |  |             if (usageMapFailS.containsKey(code)) {
 | 
	
		
			
				|  |  |                 Integer count = usageMapFailF.get(code);
 | 
	
		
			
				|  |  |                 usageMapFailF.put(code, ++count);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 serviceMap.put(code, dbObject);
 | 
	
		
			
				|  |  |                 Integer usageTemp = usageMap.get(code);
 | 
	
		
			
				|  |  |                 usageFailMap.put(code, ++usageTemp);
 | 
	
		
			
				|  |  |                 usageMapFailF.put(code, 1);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (String code : usageMap.keySet()) {
 | 
	
		
			
				|  |  |             JSONObject resultS = new JSONObject();
 | 
	
		
			
				|  |  |             resultS.put("totalCount", usageMap.get(code) + usageFailMap.get(code));
 | 
	
		
			
				|  |  |             resultS.put("successCount", usageMap.get(code));
 | 
	
		
			
				|  |  |             resultS.put("failureCount", usageFailMap.get(code));
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "usage", objectMapper.writeValueAsString(resultS.toString()), endTime);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (String code : codeList) {
 | 
	
		
			
				|  |  |             JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |             Integer successCountF = isNull(usageMapSuccessF.get(code));
 | 
	
		
			
				|  |  |             Integer failureCountF = isNull(usageMapFailF.get(code));
 | 
	
		
			
				|  |  |             Integer successCountS= isNull(usageMapSuccessS.get(code));
 | 
	
		
			
				|  |  |             Integer failureCountS = isNull(usageMapFailS.get(code));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (successCountF > 0 || failureCountF > 0) {
 | 
	
		
			
				|  |  |                 result.put("totalCount", successCountF + failureCountF);
 | 
	
		
			
				|  |  |                 result.put("successCount", successCountF);
 | 
	
		
			
				|  |  |                 result.put("failureCount",failureCountF);
 | 
	
		
			
				|  |  |             } else if (successCountS > 0 || failureCountS > 0) {
 | 
	
		
			
				|  |  |                 result.put("totalCount", successCountS + failureCountS);
 | 
	
		
			
				|  |  |                 result.put("successCount", successCountS);
 | 
	
		
			
				|  |  |                 result.put("failureCount",failureCountS);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 result.put("totalCount", 0);
 | 
	
		
			
				|  |  |                 result.put("successCount", 0);
 | 
	
		
			
				|  |  |                 result.put("failureCount",0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             ObjectMapper objectMapper = new ObjectMapper();
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "usage", objectMapper.writeValueAsString(result.toString()), endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void delay(String beginTime, String endTime) {
 | 
	
		
			
				|  |  |     public void delay(String beginTime, String endTime, List<String> codeList) {
 | 
	
		
			
				|  |  |         DBObject match = getMatchFields(beginTime, endTime);
 | 
	
		
			
				|  |  |         DBObject flowGroup = getFlowGroupFields();
 | 
	
		
			
				|  |  |         DBObject sort = getSortFields();
 | 
	
		
			
				|  |  |         // run aggregation
 | 
	
		
			
				|  |  |         AggregationOutput flowOutput = getBusinessLog().aggregate(match, flowGroup, sort);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BigDecimal flowDelay = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |         String routeId = "";
 | 
	
		
			
				|  |  |         Map<String, BigDecimal> delayMapF = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : flowOutput.results()) {
 | 
	
		
			
				|  |  |             Integer count = Integer.parseInt(StringUtil.toString(dbObject.get("count")));
 | 
	
		
			
				|  |  |             BasicDBObject id = (BasicDBObject) dbObject.get("_id");
 | 
	
		
			
				|  |  |             routeId = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(id.get("routeId"));
 | 
	
		
			
				|  |  |             if (count >= 2) {
 | 
	
		
			
				|  |  |                 String begin = StringUtil.toString(dbObject.get("beginTime"));
 | 
	
		
			
				|  |  |                 String end = StringUtil.toString(dbObject.get("endTime"));
 | 
	
		
			
				|  |  |                 long interval = getIntervalExact(begin, end);
 | 
	
		
			
				|  |  |                 flowDelay = flowDelay.add(BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |                 if (delayMapF.containsKey(code)) {
 | 
	
		
			
				|  |  |                     BigDecimal flowDelay = delayMapF.get(code);
 | 
	
		
			
				|  |  |                     delayMapF.put(code, BigDecimal.valueOf(interval).add(flowDelay));
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     delayMapF.put(code, BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         saveServiceMetrics(routeId, "delay", flowDelay.toString(), endTime);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         DBCursor serviceOutput = getBusinessLog().find(getQueryObject(beginTime, endTime));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, BigDecimal> delayMap = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, BigDecimal> delayMapS = new HashMap<>();
 | 
	
		
			
				|  |  |         Map<String, DBObject> serviceMap = new HashMap<>();
 | 
	
		
			
				|  |  |         for (DBObject dbObject : serviceOutput.toArray()) {
 | 
	
		
			
				|  |  |             String code = StringUtil.toString(dbObject.get("code"));
 | 
	
	
		
			
				|  | @ -281,18 +322,24 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |                 String begin = StringUtil.toString(dbObjectTemp.get("fireTimeSource"));
 | 
	
		
			
				|  |  |                 String end = StringUtil.toString(dbObject.get("fireTimeSource"));
 | 
	
		
			
				|  |  |                 long interval = getIntervalExact(begin, end);
 | 
	
		
			
				|  |  |                 if (delayMap.containsKey(code)) {
 | 
	
		
			
				|  |  |                     BigDecimal delayTemp = delayMap.get(code);
 | 
	
		
			
				|  |  |                     delayMap.put(code, delayTemp.add(BigDecimal.valueOf(interval)));
 | 
	
		
			
				|  |  |                 if (delayMapS.containsKey(code)) {
 | 
	
		
			
				|  |  |                     BigDecimal delayTemp = delayMapS.get(code);
 | 
	
		
			
				|  |  |                     delayMapS.put(code, delayTemp.add(BigDecimal.valueOf(interval)));
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     delayMap.put(code, BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |                     delayMapS.put(code, BigDecimal.valueOf(interval));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 serviceMap.put(code, dbObject);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         for (String code : delayMap.keySet()) {
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "delay", delayMap.get(code).toString(), endTime);
 | 
	
		
			
				|  |  |         for (String code : codeList) {
 | 
	
		
			
				|  |  |             BigDecimal delay = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |             if (delayMapF.containsKey(code)) {
 | 
	
		
			
				|  |  |                 delay = delayMapF.get(code);
 | 
	
		
			
				|  |  |             } else if (delayMapS.containsKey(code)) {
 | 
	
		
			
				|  |  |                 delay = delayMapS.get(code);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             saveServiceMetrics(code, "delay", delay.toString(), endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -364,4 +411,11 @@ public class ServiceMonitorService {
 | 
	
		
			
				|  |  |         serviceMetrics.setCreateTime(createTime);
 | 
	
		
			
				|  |  |         mongoOperations.save(serviceMetrics);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Integer isNull(Integer count) {
 | 
	
		
			
				|  |  |         if (count == null) {
 | 
	
		
			
				|  |  |             count = 0;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return count;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |