lizijie
2022-05-12 b4304bac2268701dfc89bb62646748ef3eeb08d6
src/main/java/com/moral/task/HistoryTableInsertTask.java
@@ -27,6 +27,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -59,6 +60,8 @@
    @Resource
    private WeatherUtil weatherUtil;
    @Resource
    RedisTemplate redisTemplate;
    @XxlJob("historyMinutely")
    public ReturnT insertHistoryMinutelyTable(String params) {
@@ -94,21 +97,19 @@
            for (Map<String, Object> deviceData : minutelyData) {
                if (!ObjectUtils.isEmpty(deviceData)) {
                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
                    JSONObject jo = new JSONObject(true);
                    Map<String, Object> map = new HashMap<>();
                    minutelyDataMap.put("mac", deviceData.get("mac"));
                    minutelyDataMap.put("time", endTime.toString());
                    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);
                            map.put(key, date);
                        }
                    }
                    jsonArray.add(jo);
                    minutelyDataMap.put("json", jsonArray.get(0).toString());
                    minutelyDataMap.put("json", JSONObject.toJSONString(map));
                    minutelyDataList.add(minutelyDataMap);
                }
            }
@@ -125,6 +126,9 @@
            ReturnT returnT = new ReturnT(500, e.getMessage());
            return returnT;
        }
        List record = new ArrayList();
        record.add("repairMinutelyData_"+endTimeDate.getTime()/1000);
        redisTemplate.opsForList().leftPushAll("unrepair_data", record);
        ReturnT returnT = new ReturnT(500, "插入分钟表失败");
        return returnT;
    }
@@ -199,6 +203,9 @@
            e.printStackTrace();
        }
        ReturnT returnT = new ReturnT(500, "插入小时表失败");
        List record = new ArrayList();
        record.add("repairHourlyData_"+endTimeDate.getTime()/1000);
        redisTemplate.opsForList().leftPushAll("unrepair_data", record);
        return returnT;
    }