|
@@ -27,7 +27,6 @@ public class EbaUtils {
|
|
|
|
|
|
private static Integer SUCCESS_CODE = 200;
|
|
|
private static MongoTemplate mongoTemplate;
|
|
|
- private static List<Map> initEmptyList;
|
|
|
public static String token;
|
|
|
public static JSONObject project;
|
|
|
public static JSONObject deviceSystem;
|
|
@@ -38,20 +37,6 @@ public class EbaUtils {
|
|
|
public static JSONObject realDataDevice;
|
|
|
public static JSONObject crmProjectInfo;
|
|
|
|
|
|
- static {
|
|
|
- // 初始化模板
|
|
|
- List<Map> monthList = new ArrayList<>();
|
|
|
- Integer monthDays = LeviUtils.getMonthDays(LocalDateTime.now().getMonthValue());
|
|
|
- for (int b = 1; b <= monthDays; b++) {
|
|
|
- List<Map> dayList = new ArrayList<>();
|
|
|
- for (int c = 0; c <= 23; c++) {
|
|
|
- dayList.add(Levi.by("hour", c).set("data", new ArrayList<>()));
|
|
|
- }
|
|
|
- monthList.add(Levi.by("day", b).set("data", dayList));
|
|
|
- }
|
|
|
- initEmptyList = monthList;
|
|
|
- }
|
|
|
-
|
|
|
@Autowired
|
|
|
public void setMongoTemplate(MongoTemplate mongoTemplate) {
|
|
|
EbaUtils.mongoTemplate = mongoTemplate;
|
|
@@ -67,6 +52,20 @@ public class EbaUtils {
|
|
|
return SUCCESS_CODE.equals(JSON.parseObject(result).getInteger("code"));
|
|
|
}
|
|
|
|
|
|
+ public static List<Map> getEmptyTemplate() {
|
|
|
+ // 初始化模板
|
|
|
+ List<Map> monthList = new ArrayList<>();
|
|
|
+ Integer monthDays = LeviUtils.getMonthDays(LocalDateTime.now().getMonthValue());
|
|
|
+ for (int b = 1; b <= monthDays; b++) {
|
|
|
+ List<Map> dayList = new ArrayList<>();
|
|
|
+ for (int c = 0; c <= 23; c++) {
|
|
|
+ dayList.add(Levi.by("hour", c).set("data", new ArrayList<>()));
|
|
|
+ }
|
|
|
+ monthList.add(Levi.by("day", b).set("data", dayList));
|
|
|
+ }
|
|
|
+ return monthList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用于存储数据(不带统计数字)
|
|
|
*
|
|
@@ -84,7 +83,7 @@ public class EbaUtils {
|
|
|
int hour = now.getHour();
|
|
|
Map monthMap = mongoTemplate.findById(pkId + "_" + year + "_" + month, Map.class, collectionName);
|
|
|
if (MapUtil.isEmpty(monthMap)) {
|
|
|
- monthMap = Levi.by("_id", pkId + "_" + year + "_" + month).set("data", LeviUtils.deepCopy(initEmptyList));
|
|
|
+ monthMap = Levi.by("_id", pkId + "_" + year + "_" + month).set("data", getEmptyTemplate());
|
|
|
}
|
|
|
List<Map> dayList = (List<Map>) monthMap.get("data");
|
|
|
Map dayMap = dayList.get(day - 1);
|
|
@@ -119,7 +118,7 @@ public class EbaUtils {
|
|
|
List<Map> objList = (List<Map>) obj;
|
|
|
Map monthMap = mongoTemplate.findById(pkId + "_" + year + "_" + month, Map.class, collectionName);
|
|
|
if (MapUtil.isEmpty(monthMap)) {
|
|
|
- monthMap = Levi.by("_id", pkId + "_" + year + "_" + month).set("data", LeviUtils.deepCopy(initEmptyList));
|
|
|
+ monthMap = Levi.by("_id", pkId + "_" + year + "_" + month).set("data", getEmptyTemplate());
|
|
|
}
|
|
|
List<Map> dayList = (List<Map>) monthMap.get("data");
|
|
|
Map dayMap = dayList.get(day - 1);
|