| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moral.api.mapper.HistoryMinutelyMapper; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.moral.api.service.HistoryMinutelyService; |
| | |
| | | private DeviceService deviceService; |
| | | |
| | | @Override |
| | | public void insertHistoryMinutely(Map<String, Object> deviceData) { |
| | | public void insertHistoryMinutely(Map<String, Object> data) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Object mac = deviceData.remove("mac"); |
| | | Map<String, Object> dataAdjust = new HashMap<>(data); |
| | | Object mac = data.remove("mac"); |
| | | result.put("mac", mac); |
| | | result.put("version", deviceData.remove("ver")); |
| | | Date time = new Date((Long) deviceData.remove("DataTime")); |
| | | result.put("time", DateUtils.dateToDateString(time)); |
| | | result.put("value", JSON.toJSONString(deviceData)); |
| | | result.put("version", data.remove("ver")); |
| | | Date time = new Date(new Long((String) data.remove("DataTime"))); |
| | | result.put("time", DateUtils.dataToTimeStampTime(time,DateUtils.yyyy_MM_dd_HH_mm_EN)); |
| | | result.put("value", JSONObject.toJSONString(data)); |
| | | String timeUnits = DateUtils.dateToDateString(time, DateUtils.yyyyMM_EN); |
| | | result.put("timeUnits", tableSuffix(timeUnits, Constants.UN_ADJUST)); |
| | | //未校准 |
| | | |
| | | //原始数据(未校准) |
| | | historyMinutelyMapper.insertHistoryMinutely(result); |
| | | |
| | | //设备信息 |
| | | Map<String, Object> deviceInfo = deviceService.getDeviceByMac(mac.toString()); |
| | | |
| | | //设备数据校准,并存入数据库 |
| | | //数据校准 |
| | | dataAdjust = deviceService.adjustDeviceData(dataAdjust); |
| | | dataAdjust.remove("mac"); |
| | | dataAdjust.remove("DataTime"); |
| | | dataAdjust.remove("ver"); |
| | | result.put("timeUnits", timeUnits); |
| | | deviceData = deviceService.adjustDeviceData(deviceData, deviceInfo); |
| | | result.put("value", JSON.toJSONString(deviceData)); |
| | | result.put("value", JSONObject.toJSONString(dataAdjust)); |
| | | historyMinutelyMapper.insertHistoryMinutely(result); |
| | | |
| | | //判断设备状态 |
| | | Map<String, Object> deviceState = deviceService.judgeDeviceState(deviceData, deviceInfo); |
| | | |
| | | } |
| | | |
| | | //表后缀 |
| | |
| | | } |
| | | return key.toString(); |
| | | } |
| | | |
| | | } |