From 60eac16e1519c4529b5277b52b167b753805dae9 Mon Sep 17 00:00:00 2001
From: ZhuDongming <zdm773644075@hotmail.com>
Date: Fri, 01 May 2020 00:34:06 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/task/HistoryTableInsertTask.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 111 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/moral/task/HistoryTableInsertTask.java b/src/main/java/com/moral/task/HistoryTableInsertTask.java
index 645006c..ca7e19c 100644
--- a/src/main/java/com/moral/task/HistoryTableInsertTask.java
+++ b/src/main/java/com/moral/task/HistoryTableInsertTask.java
@@ -17,18 +17,20 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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;
import com.xxl.job.core.log.XxlJobLogger;
-//@Component
+@Component
public class HistoryTableInsertTask {
private static transient Logger logger = LoggerFactory.getLogger(HistoryTableInsertTask.class);
@@ -39,6 +41,9 @@
private DeviceService deviceService;
@Resource
+ private HistoryService historyService;
+
+ @Resource
private HistoryMinutelyService historyMinutelyService;
@Resource
@@ -47,7 +52,7 @@
@Resource
private HistoryDailyService historyDailyService;
- //@XxlJob("historyMinutely")
+ @XxlJob("historyMinutely")
public ReturnT insertHistoryMinutelyTable(String params) {
LocalDateTime time = LocalDateTime.now();
int year = time.getYear();
@@ -100,11 +105,24 @@
return returnT;
}
- //@XxlJob("historyHourly")
+ @XxlJob("historyHourly")
public ReturnT insertHistoryHourlyTable(String params) {
LocalDateTime time = LocalDateTime.now();
int year = time.getYear();
int month = time.getMonthValue();
+ int day = time.getDayOfMonth();
+ int hour = time.getHour();
+ int minute = time.getMinute();
+ if (day == 1) {
+ if (hour == 0 && minute == 0) {
+ 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);
@@ -132,8 +150,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);
}
}
@@ -156,7 +179,7 @@
return returnT;
}
- //@XxlJob("historyDaily")
+ @XxlJob("historyDaily")
public ReturnT insertHistoryDailyTable(String params) {
LocalDateTime time = LocalDateTime.now();
LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
@@ -211,4 +234,86 @@
ReturnT returnT = new ReturnT(500, "������������������");
return returnT;
}
+
+ @XxlJob("historyMinutelyDelay")
+ public ReturnT insertHistoryMinutelyTableDelay(String params) {
+ Map macMap = JSON.parseObject(params);
+ List<String> macList = (List<String>) macMap.get("mac");
+ LocalDateTime time = LocalDateTime.now();
+ int year = time.getYear();
+ int month = time.getMonthValue();
+ String monthStr = month < 10 ? ("0" + month) : month + "";
+ String yearAndMonth = year + monthStr;
+ LocalDateTime value = time.truncatedTo(ChronoUnit.MINUTES);
+ LocalDateTime startTime = value.minusMinutes(31);
+ LocalDateTime endTime = value.minusMinutes(30);
+ List<String> sensorKeys = sensorService.getSensorKeys();
+ Map<String, Object> devices = new HashMap<>();
+ devices.put("sensorKeys", sensorKeys);
+ devices.put("macList", macList);
+ devices.put("start", startTime);
+ devices.put("end", endTime);
+ try {
+ List<Map<String, Object>> minutelyData = deviceService.getSensorDataByMac(devices);
+ XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
+ List<Map<String, Object>> minutelyDataList = new ArrayList<>();
+ for (Map<String, Object> deviceData : minutelyData) {
+ if (!ObjectUtils.isEmpty(deviceData)) {
+ Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
+ JSONObject jo = new JSONObject(true);
+ minutelyDataMap.put("mac", deviceData.get("mac"));
+ minutelyDataMap.put("time", startTime);
+ JSONArray jsonArray = new JSONArray();
+ for (String key : deviceData.keySet()) {
+ if (!key.equals("mac") && !key.startsWith("M")) {
+ List<Object> date = new ArrayList<>();
+ date.add(deviceData.get(key));
+ date.add(deviceData.get("MIN" + key));
+ date.add(deviceData.get("MAX" + key));
+ jo.put(key, date);
+ }
+ }
+ jsonArray.add(jo);
+ minutelyDataMap.put("json", jsonArray.get(0).toString());
+ minutelyDataList.add(minutelyDataMap);
+ }
+ }
+ if (!CollectionUtils.isEmpty(minutelyDataList)) {
+ historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
+ ReturnT returnT = new ReturnT(200, "���������������������");
+ return returnT;
+ }
+ } catch (Exception e) {
+ XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
+ logger.error(e.getMessage());
+ e.printStackTrace();
+ }
+ ReturnT returnT = new ReturnT(500, "���������������������");
+ 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();
+ Map<String, Object> devices = new HashMap<>();
+ devices.put("macList", macList);
+ devices.put("time", value);
+ try {
+ int count = historyService.insertHistorySpecialTable(devices);
+ XxlJobLogger.log("insertHistorySpecialTable:" + count);
+ if (count > 0) {
+ 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