| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | |
| | | import com.moral.common.util.ParameterUtils;
|
| | | import com.moral.common.util.ReportTimeFormat;
|
| | | import com.moral.common.util.ResourceUtil;
|
| | | import com.moral.common.util.StringUtils;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.Sensor;
|
| | | import com.moral.entity.charts.DataCondition;
|
| | |
| | | import com.moral.entity.charts.TimePeriod;
|
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.HistoryMapper;
|
| | | import com.moral.mapper.HistoryMinutelyMapper;
|
| | | import com.moral.mapper.SensorMapper;
|
| | | import com.moral.service.HistoryMinutelyService;
|
| | | import com.moral.service.SensorService;
|
| | |
|
| | | import lombok.val;
|
| | |
|
| | | @Service
|
| | | @SuppressWarnings({"unchecked", "unused", "rawtypes"})
|
| | |
| | |
|
| | | @Resource
|
| | | private HistoryMinutelyMapper historyMinutelyMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryMapper historyMapper;
|
| | |
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<Map<String, Object>> getSensorData(Map<String, Object> parameters) {
|
| | | List<Sensor> sensors=sensorMapper.getSensorsByMac(parameters);
|
| | | List<String> sensorKeys=new ArrayList<>();
|
| | | for(Sensor sensor:sensors){
|
| | | public List<List<Map<String, Object>>> getSensorData(Map<String, Object> parameters) {
|
| | | String startTime = parameters.get("startTime").toString();
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
| | | LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
|
| | | LocalDate today = LocalDate.now();
|
| | | LocalDate startTimeLocalDate=startTimeLocalDateTime.toLocalDate();
|
| | | Boolean flag=today.isEqual(startTimeLocalDate);
|
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
|
| | | List<String> sensorKeys = new ArrayList<>();
|
| | | for (Sensor sensor : sensors) {
|
| | | sensorKeys.add(sensor.getSensorKey());
|
| | | }
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | List<Map<String, Object>> listMap = historyMinutelyMapper.getSensorData(parameters);
|
| | | List<Map<String, Object>> listMapNew = new ArrayList<>();
|
| | | Map<String, Object> new_map = new LinkedHashMap<>();
|
| | | List<Map<String, Object>> listMap = null;
|
| | | if (flag) {
|
| | | listMap = historyMapper.getSensorDataToday(parameters);
|
| | | } else {
|
| | | listMap = historyMinutelyMapper.getSensorData(parameters);
|
| | | }
|
| | | List<List<Map<String, Object>>> listMaps = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapAvg = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapMin = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapMax = new ArrayList<>();
|
| | | if (CollectionUtils.isNotEmpty(listMap)) {
|
| | | for (Map<String, Object> map : listMap) {
|
| | | new_map.put("时间", map.get("uavDate"));
|
| | | for (String key : map.keySet()) {
|
| | | Map<String, Object> mapAvg = new LinkedHashMap<>();
|
| | | Map<String, Object> mapMin = new LinkedHashMap<>();
|
| | | Map<String, Object> mapMax = new LinkedHashMap<>();
|
| | | mapAvg.put("time", map.get("time"));
|
| | | mapMin.put("time", map.get("time"));
|
| | | mapMax.put("time", map.get("time"));
|
| | | for (Entry<String,Object> entry : map.entrySet()) {
|
| | | for (Sensor sensor : sensors) {
|
| | | if (sensor.getSensorKey().equals(key)) {
|
| | | if("e79".equals(key)||"e80".equals(key)||"e81".equals(key)){
|
| | | new_map.put(sensor.getDescription(), StringUtils.scientificCountingConversion(map.get(key).toString()));
|
| | | }else{
|
| | | new_map.put(sensor.getDescription(), map.get(key));
|
| | | }
|
| | | if (sensor.getSensorKey().equals(entry.getKey())) {
|
| | | mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString()).stripTrailingZeros().toPlainString() + sensor.getUnit());
|
| | | } else if (("min" + sensor.getSensorKey()).equals(entry.getKey())) {
|
| | | mapMin.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
|
| | | } else if (("max" + sensor.getSensorKey()).equals(entry.getKey())) {
|
| | | mapMax.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
|
| | | }
|
| | | }
|
| | | }
|
| | | listMapNew.add(new_map);
|
| | | new_map = new LinkedHashMap<>();
|
| | | listMapAvg.add(mapAvg);
|
| | | listMapMin.add(mapMin);
|
| | | listMapMax.add(mapMax);
|
| | | }
|
| | | listMaps.add(listMapAvg);
|
| | | listMaps.add(listMapMin);
|
| | | listMaps.add(listMapMax);
|
| | | }
|
| | | return listMapNew;
|
| | | return listMaps;
|
| | | }
|
| | |
|
| | | }
|