From c534d4ac66958e9f2e9be2d9d7587c55fb3bb42f Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Fri, 17 Apr 2020 11:12:27 +0800
Subject: [PATCH] add 走航车等设备的history表数据重新存一份
---
src/main/java/com/moral/task/HistoryTableInsertTask.java | 79 ++++++++++++++++++++++++++++++++++++---
1 files changed, 72 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/moral/task/HistoryTableInsertTask.java b/src/main/java/com/moral/task/HistoryTableInsertTask.java
index ea5796f..009c19b 100644
--- a/src/main/java/com/moral/task/HistoryTableInsertTask.java
+++ b/src/main/java/com/moral/task/HistoryTableInsertTask.java
@@ -20,10 +20,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.moral.entity.History;
import com.moral.service.DeviceService;
import com.moral.service.HistoryDailyService;
import com.moral.service.HistoryHourlyService;
import com.moral.service.HistoryMinutelyService;
+import com.moral.service.HistoryService;
import com.moral.service.SensorService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
@@ -40,6 +42,9 @@
private DeviceService deviceService;
@Resource
+ private HistoryService historyService;
+
+ @Resource
private HistoryMinutelyService historyMinutelyService;
@Resource
@@ -53,6 +58,15 @@
LocalDateTime time = LocalDateTime.now();
int year = time.getYear();
int month = time.getMonthValue();
+ int day = time.getDayOfMonth();
+ if (day == 1) {
+ if (month == 1) {
+ month = 12;
+ year = year - 1;
+ } else {
+ month = month - 1;
+ }
+ }
String monthStr = month < 10 ? ("0" + month) : month + "";
String yearAndMonth = year + monthStr;
LocalDateTime endTime = time.truncatedTo(ChronoUnit.MINUTES);
@@ -492,6 +506,15 @@
LocalDateTime time = LocalDateTime.now();
int year = time.getYear();
int month = time.getMonthValue();
+ int day = time.getDayOfMonth();
+ if (day == 1) {
+ if (month == 1) {
+ month = 12;
+ year = year - 1;
+ } else {
+ month = month - 1;
+ }
+ }
String monthStr = month < 10 ? ("0" + month) : month + "";
String yearAndMonth = year + monthStr;
LocalDateTime endTime = time.truncatedTo(ChronoUnit.HOURS);
@@ -519,8 +542,13 @@
if (!key.equals("mac") && !key.startsWith("M")) {
List<Object> date = new ArrayList<>();
date.add(deviceData.get(key));
- date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
- date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ if (deviceData.get("MIN" + key) instanceof String) {
+ date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
+ date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ } else if (deviceData.get("MIN" + key) instanceof byte[]) {
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key)))));
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key)))));
+ }
jo.put(key, date);
}
}
@@ -584,8 +612,13 @@
if (!key.equals("mac") && !key.startsWith("M")) {
List<Object> date = new ArrayList<>();
date.add(deviceData.get(key));
- date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
- date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ if (deviceData.get("MIN" + key) instanceof String) {
+ date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
+ date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ } else if (deviceData.get("MIN" + key) instanceof byte[]) {
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key)))));
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key)))));
+ }
jo.put(key, date);
}
}
@@ -643,8 +676,13 @@
if (!key.equals("mac") && !key.startsWith("M")) {
List<Object> date = new ArrayList<>();
date.add(deviceData.get(key));
- date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
- date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ if (deviceData.get("MIN" + key) instanceof String) {
+ date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
+ date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
+ } else if (deviceData.get("MIN" + key) instanceof byte[]) {
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key)))));
+ date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key)))));
+ }
jo.put(key, date);
}
}
@@ -810,7 +848,7 @@
devices.put("start", startTime);
devices.put("end", endTime);
try {
- List<Map<String, Object>> minutelyData = deviceService.getSensorDataByMac(devices);
+ List<Map<String, Object>> minutelyData = deviceService.getSensorDataByMacOnce(devices);
XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
List<Map<String, Object>> minutelyDataList = new ArrayList<>();
for (Map<String, Object> deviceData : minutelyData) {
@@ -848,4 +886,31 @@
return returnT;
}
+ @XxlJob("historySpecial")
+ public ReturnT insertHistorySpecialTable(String params) {
+ Map macMap = JSON.parseObject(params);
+ List<String> macList = (List<String>) macMap.get("mac");
+ LocalDateTime value = LocalDateTime.now();
+ LocalDateTime time = value.truncatedTo(ChronoUnit.SECONDS);
+ LocalDateTime tenSecondsAgo = time.minusSeconds(10);
+ Map<String, Object> devices = new HashMap<>();
+ devices.put("macList", macList);
+ devices.put("time", tenSecondsAgo);
+ try {
+ List<History> historyData = historyService.selectByMacAndTime(devices);
+ if (!CollectionUtils.isEmpty(historyData)) {
+ int count = historyService.insertHistorySpecialTable(devices);
+ XxlJobLogger.log("insertHistorySpecialTable:" + count);
+ ReturnT returnT = new ReturnT(200, "������historySpecial���������");
+ return returnT;
+ }
+ } catch (Exception e) {
+ XxlJobLogger.log("insertHistorySpecialTableException:" + e.getMessage());
+ logger.error(e.getMessage());
+ e.printStackTrace();
+ }
+ ReturnT returnT = new ReturnT(500, "������historySpecial���������");
+ return returnT;
+ }
+
}
--
Gitblit v1.8.0