jinpengyong
2021-08-17 6f4e852b84c577454a4876f83c7085bd360fe4fb
screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -37,37 +37,31 @@
    @Override
    @Transactional
    public void insertHistoryHourly(Map<String, Object> data) {
        Integer version = (Integer) data.remove("ver");
        Map<String, Object> dataAdjust = new HashMap<>(data);
        String mac = data.remove("mac").toString();
        Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN);
        Integer version = (Integer) data.remove("ver");
        Map<String, Object> result = new HashMap<>();
        result.put("mac", mac);
        result.put("time", time);
        result.put("version", version);
        result.put("timeUnits", Constants.UN_ADJUST);
        result.put("value", JSONObject.toJSONString(data));
        //原始数据(未校准)
        historyHourlyMapper.insertHistoryHourlyUnAdjust(result);
        //未校准小时表insert
        historyHourlyMapper.insertHistoryHourly(result);
        //数据校准
        dataAdjust = deviceService.adjustDeviceData(dataAdjust);
        dataAdjust.remove("mac");
        dataAdjust.remove("DataTime");
        dataAdjust.remove("ver");
        int count = historyHourlyMapper.getCountByMacAndTime(mac, DateUtils.dateToDateString(time));
        HistoryHourly historyHourly = new HistoryHourly();
        historyHourly.setMac(mac);
        historyHourly.setTime(time);
        historyHourly.setVersion(version);
        historyHourly.setValue(JSONObject.toJSONString(dataAdjust));
        //判断中间表有没有该mac,该小时的数据,有就更新,没有就新增
        if (count == 0) {
            //小时数据校准后存入小时中间表
            result.put("value", JSONObject.toJSONString(dataAdjust));
            //新增
            historyHourlyMapper.insertHistoryHourlyTransition(result);
        } else {
            //更新
            historyHourlyMapper.updateHistoryTransition(mac, DateUtils.dateToDateString(time));
        }
        //校准后小时表insert
        historyHourlyMapper.insert(historyHourly);
    }
}