kaiyu
2020-11-24 35fa7f327c9a8fc2fa3072af4f734ce793d93582
修改平均风向SQL语句。
2 files modified
37 ■■■■ changed files
src/main/java/com/moral/task/HistoryFiveMinutelyTask.java 28 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/task/HistoryTableInsertTask.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/task/HistoryFiveMinutelyTask.java
@@ -6,6 +6,8 @@
import com.moral.util.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
@@ -20,6 +22,9 @@
    @Resource
    SensorService sensorService;
    @Resource
    RedisTemplate redisTemplate;
    @XxlJob("createHistoryFiveMinutelyTb")
    public ReturnT createHistoryMinutelyTb(String param) {
@@ -43,20 +48,18 @@
     *     10:20:30  插入10:15--10:20的数据*/
    @XxlJob("insertHistoryFiveMinutelyTb")
    public ReturnT insertHistoryFiveMinutely(String param) {
        //获取当前时间
        Date errorDate = new Date();
        try {
        /*根据时间从分钟表数据钟查询五分钟数据的平均值*/
        Map<String, Object> params = getStartAndEndTime();
        List<String> sensorKeys = sensorService.getSensorKeys();
        params.put("sensorKeys", sensorKeys);
        List<Map<String, Object>> fiveMinutesSensorDatas;
        try {
            fiveMinutesSensorDatas = historyFiveMinutelyService.getFiveMinutesSensorData(params);
        } catch (Exception e) {
            return new ReturnT(500, "查询分钟表数据失败");
        }
        /*将得到的数据进行转换*/
        List<Map<String, Object>> insertDatas;
        try {
            insertDatas = new ArrayList<>();
            for (Map<String, Object> data : fiveMinutesSensorDatas) {
                String mac = (String) data.get("mac");
@@ -84,13 +87,20 @@
                insertDataMap.put("json", keyAndValueJson);
                insertDatas.add(insertDataMap);
            }
            /*将数据插入数据库*/
            if (!ObjectUtils.isEmpty(insertDatas)) {
                historyFiveMinutelyService.insertHistoryFiveMinutely(insertDatas, (String) params.get("yearAndMonth"));
                return new ReturnT(200, "插入五分钟数据成功");
            }
        } catch (Exception e) {
            return new ReturnT(500, "数据转换异常");
            XxlJobLogger.log("historyFiveMinutelyException:" + e.getMessage());
            e.printStackTrace();
        }
        /*将数据插入数据库*/
        historyFiveMinutelyService.insertHistoryFiveMinutely(insertDatas, (String) params.get("yearAndMonth"));
        return new ReturnT(200, "插入数据成功");
        List record = new ArrayList();
        record.add("repairFiveMinutelyData_" + errorDate.getTime() / 1000);
        redisTemplate.opsForList().leftPushAll("unrepair_data", record);
        return new ReturnT(500, "插入五分钟数据失败");
    }
    /**
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) {
@@ -125,6 +128,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 +205,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;
    }