|
@@ -348,14 +348,11 @@ public class ParkSystemServiceImpl implements ParkSystemService {
|
|
|
times.forEach(x -> result.add(Levi.by("time", x).set("in", 0).set("out", 0).set("exception", 0)));
|
|
|
parkCodeList.forEach(code -> {
|
|
|
String format = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN);
|
|
|
- String formatOld = LocalDateTimeUtil.format(LocalDateTimeUtil.offset(LocalDateTime.now(), -1, ChronoUnit.DAYS), DatePattern.PURE_DATE_PATTERN);
|
|
|
JSONObject inObj = mongoTemplate.findById(code + "_" + format, JSONObject.class, ParkType.IN.getCode());
|
|
|
JSONObject outObj = mongoTemplate.findById(code + "_" + format, JSONObject.class, ParkType.OUT.getCode());
|
|
|
JSONObject exceptionObj = mongoTemplate.findById(code + "_" + format, JSONObject.class, ParkType.EXCEPTION.getCode());
|
|
|
JSONObject exceptionData = exceptionObj != null ? exceptionObj.getJSONObject("data") : null;
|
|
|
- JSONObject exceptionObjOld = mongoTemplate.findById(code + "_" + formatOld, JSONObject.class, ParkType.EXCEPTION.getCode());
|
|
|
ParkExceptionType.codeList().forEach(x -> exceptionCountResult.set((exceptionObj == null ? 0 : (exceptionObj.getDouble(x + "Count") == null ? 0 : exceptionObj.getDouble(x + "Count").intValue())) + exceptionCountResult.get()));
|
|
|
- ParkExceptionType.codeList().forEach(x -> exceptionCountOldResult.set((exceptionObjOld == null ? 0 : (exceptionObjOld.getDouble(x + "Count") == null ? 0 : exceptionObjOld.getDouble(x + "Count").intValue())) + exceptionCountOldResult.get()));
|
|
|
System.out.println("当前车场:" + code + " 异常数量:" + exceptionCountResult);
|
|
|
List<Map> exceptionResult = new ArrayList<>();
|
|
|
if (exceptionData != null) {
|
|
@@ -369,26 +366,62 @@ public class ParkSystemServiceImpl implements ParkSystemService {
|
|
|
return;
|
|
|
}
|
|
|
JSONArray inObjList = inObj != null ? inObj.getJSONArray("data") : null;
|
|
|
- JSONObject inObjOld = mongoTemplate.findById(code + "_" + formatOld, JSONObject.class, ParkType.IN.getCode());
|
|
|
JSONArray outObjList = outObj != null ? outObj.getJSONArray("data") : null;
|
|
|
- JSONObject outObjOld = mongoTemplate.findById(code + "_" + formatOld, JSONObject.class, ParkType.OUT.getCode());
|
|
|
Double inCount = inObj == null ? 0 : inObj.getDouble("count");
|
|
|
- Double inCountOld = inObjOld == null ? 0 : inObjOld.getDouble("count");
|
|
|
+ Double inCountOld = getTodayFlowAnalysisCount(Levi.by("parkCode", code).set("type", 1));
|
|
|
Double outCount = outObj == null ? 0 : outObj.getDouble("count");
|
|
|
- Double outCountOld = outObjOld == null ? 0 : outObjOld.getDouble("count");
|
|
|
+ Double outCountOld = getTodayFlowAnalysisCount(Levi.by("parkCode", code).set("type", 2));
|
|
|
+ Double exceptionCountOld = getTodayFlowAnalysisCount(Levi.by("parkCode", code).set("type", 3));
|
|
|
inCountResult.set(inCount.intValue() + inCountResult.get());
|
|
|
inCountOldResult.set(inCountOld.intValue() + inCountOldResult.get());
|
|
|
outCountResult.set(outCount.intValue() + outCountResult.get());
|
|
|
outCountOldResult.set(outCountOld.intValue() + outCountOldResult.get());
|
|
|
+ exceptionCountOldResult.set(exceptionCountOld.intValue() + exceptionCountOldResult.get());
|
|
|
for (int i = 0; i < indexs.size(); i++) {
|
|
|
Levi levi = result.get(i);
|
|
|
levi.set("in", levi.getInt("in") + (inObjList == null ? 0 : inObjList.getJSONObject(indexs.get(i)).getJSONArray("data").size()));
|
|
|
levi.set("out", levi.getInt("out") + (outObjList == null ? 0 : outObjList.getJSONObject(indexs.get(i)).getJSONArray("data").size()));
|
|
|
}
|
|
|
});
|
|
|
+ log.info("昨日入场:{},昨日出场:{},昨日异常:{}", inCountOldResult.get().doubleValue(), outCountOldResult.get().doubleValue(), exceptionCountOldResult.get().doubleValue());
|
|
|
return ResponseBuilder.ok(Levi.by("inCount", inCountResult.get()).set("outCount", outCountResult.get()).set("exceptionCount", exceptionCountResult.get()).set("inPercent", EnergyUtils.getPercent(inCountResult.get().doubleValue(), inCountOldResult.get().doubleValue())).set("outPercent", EnergyUtils.getPercent(outCountResult.get().doubleValue(), outCountOldResult.get().doubleValue())).set("exceptionPercent", EnergyUtils.getPercent(exceptionCountResult.get().doubleValue(), exceptionCountOldResult.get().doubleValue())).set("list", result));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取任意一天当前时间点的数量
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Double getTodayFlowAnalysisCount(Levi params) {
|
|
|
+ String parkCode = params.getStr("parkCode");
|
|
|
+ Integer type = params.getInt("type");
|
|
|
+ if (type != 1 && type != 2 && type != 3) {
|
|
|
+ return 0D;
|
|
|
+ }
|
|
|
+ List<String> parkCodeList = Arrays.asList(parkCode);
|
|
|
+ if (StringUtils.isBlank(parkCode)) {
|
|
|
+ parkCodeList = ParkUtils.getParkCodeList();
|
|
|
+ }
|
|
|
+ String format = LocalDateTimeUtil.format(LocalDateTimeUtil.offset(LocalDateTime.now(), -1, ChronoUnit.DAYS), DatePattern.PURE_DATE_PATTERN);
|
|
|
+ List<Map> results = new ArrayList<>();
|
|
|
+ parkCodeList.forEach(code -> {
|
|
|
+ JSONObject obj = mongoTemplate.findById(code + "_" + format, JSONObject.class, ParkType.getTypeByNo(type).getCode());
|
|
|
+ if (obj == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 异常类型
|
|
|
+ if (CommonConstants.EXCEPTION_TYPE.equals(type)) {
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
+ data.keySet().forEach(x -> results.addAll((List<Map>) data.get(x)));
|
|
|
+ } else {
|
|
|
+ List<Map> maps = obj.getJSONArray("data").toJavaList(Map.class);
|
|
|
+ maps.forEach(x -> results.addAll((List<Map>) x.get("data")));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return ParkUtils.sortDateListCount(results, ParkType.getTypeByNo(type).getSort());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据停车场编号获取当前车场入场数
|
|
|
*
|