| | |
| | | @Transactional |
| | | public void insertHistoryMinutely(Map<String, Object> data) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Object ver = data.remove("ver"); |
| | | |
| | | Map<String, Object> dataAdjust = new HashMap<>(data); |
| | | |
| | | Object mac = data.remove("mac"); |
| | | |
| | | result.put("mac", mac); |
| | | result.put("version", data.remove("ver")); |
| | | result.put("version", ver); |
| | | |
| | | Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN); |
| | | result.put("time", time); |
| | | result.put("value", JSONObject.toJSONString(data)); |
| | | String timeUnits = DateUtils.dateToDateString(time, DateUtils.yyyyMM_EN); |
| | | result.put("timeUnits", tableSuffix(timeUnits, Constants.UN_ADJUST)); |
| | | result.put("timeUnits", timeUnits + "_" + Constants.UN_ADJUST); |
| | | |
| | | //原始数据(未校准) |
| | | historyMinutelyMapper.insertHistoryMinutely(result); |
| | | |
| | | //数据校准 |
| | | dataAdjust = deviceService.adjustDeviceData(dataAdjust); |
| | | dataAdjust.remove("mac"); |
| | | dataAdjust.remove("DataTime"); |
| | | dataAdjust.remove("ver"); |
| | | result.put("timeUnits", timeUnits); |
| | | result.put("value", JSONObject.toJSONString(dataAdjust)); |
| | | historyMinutelyMapper.insertHistoryMinutely(result); |
| | | |
| | | |
| | | } |
| | | |
| | | //表后缀 |
| | | private String tableSuffix(String... keys) { |
| | | StringBuilder key = new StringBuilder(keys[0]); |
| | | for (int i = 1; i < keys.length; i++) { |
| | | key.append("_"); |
| | | key.append(keys[i]); |
| | | } |
| | | return key.toString(); |
| | | } |
| | | } |