|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.service.DeviceService; | 
|---|
|  |  |  | import com.moral.api.service.HistoryMinutelyService; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.RedisConstants; | 
|---|
|  |  |  | import com.moral.util.DateUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @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"); | 
|---|
|  |  |  | String mac = data.remove("mac").toString(); | 
|---|
|  |  |  | //根据mac获取型号 | 
|---|
|  |  |  | Map<String, Object> deviceInfo = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac); | 
|---|
|  |  |  | Map<String, Object> versionInfo = (Map<String, Object>) deviceInfo.get("version"); | 
|---|
|  |  |  | Integer version = (Integer) versionInfo.get("id"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | result.put("mac", mac); | 
|---|
|  |  |  | result.put("version", ver); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN); | 
|---|
|  |  |  | result.put("time", time); | 
|---|
|  |  |  | result.put("version", version); | 
|---|
|  |  |  | //        String time1 = data.get("time").toString(); | 
|---|
|  |  |  | String time2 = data.remove("time").toString(); | 
|---|
|  |  |  | long l = Long.parseLong(time2); | 
|---|
|  |  |  | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00"); | 
|---|
|  |  |  | String format1 = dateFormat.format(l); | 
|---|
|  |  |  | Date time = DateUtils.getDate(format1, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  | //        Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN); | 
|---|
|  |  |  | result.put("time", DateUtils.getDateOfMin(time, -1)); | 
|---|
|  |  |  | result.put("value", JSONObject.toJSONString(data)); | 
|---|
|  |  |  | String timeUnits = DateUtils.dateToDateString(time, DateUtils.yyyyMM_EN); | 
|---|
|  |  |  | String timeUnits = DateUtils.dateToDateString(DateUtils.getDateOfMin(time, -1), DateUtils.yyyyMM_EN); | 
|---|
|  |  |  | result.put("timeUnits", timeUnits + "_" + Constants.UN_ADJUST); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //原始数据(未校准) | 
|---|
|  |  |  | historyMinutelyMapper.insertHistoryMinutely(result); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //数据校准 | 
|---|
|  |  |  | dataAdjust = deviceService.adjustDeviceData(dataAdjust); | 
|---|
|  |  |  | dataAdjust = deviceService.adjustDeviceData(dataAdjust,"1"); | 
|---|
|  |  |  | result.put("timeUnits", timeUnits); | 
|---|
|  |  |  | result.put("value", JSONObject.toJSONString(dataAdjust)); | 
|---|
|  |  |  | historyMinutelyMapper.insertHistoryMinutely(result); | 
|---|