| | |
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.moral.entity.Sensor;
|
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.SensorMapper;
|
| | | import com.moral.service.AlarmDailyService;
|
| | |
| | | return Arrays.asList(result);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getAlarmDataByMonth(Map<String, Object> parameters) {
|
| | | LocalDate localDate = LocalDate.now();
|
| | | List<Sensor> sensors = sensorMapper.selectAll();
|
| | | // Iterator<Sensor> iterator = sensors.iterator();
|
| | | // while (iterator.hasNext()) {
|
| | | // if ("warn".equals(iterator.next().getSensorKey())) {
|
| | | // iterator.remove();
|
| | | // }
|
| | | // }
|
| | | parameters.put("start", localDate.with(TemporalAdjusters.firstDayOfMonth()));
|
| | | parameters.put("end", localDate.with(TemporalAdjusters.firstDayOfNextMonth()));
|
| | | parameters.put("sensors", sensors);
|
| | | Map<String, Object> map = alarmDailyMapper.getAlarmDataByMonth(parameters);
|
| | | List<Entry<String, Object>> list = new ArrayList<Entry<String,Object>>(map.entrySet());
|
| | | Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
|
| | | @Override
|
| | | public int compare(Entry<String, Object> o1, Entry<String, Object> o2) {
|
| | | if (o2.getValue().equals(o1.getValue())) {
|
| | | return o1.getKey().compareTo(o2.getKey());
|
| | | //return Integer.compare(Integer.valueOf(o1.getKey().replace("e", "")),Integer.valueOf(o2.getKey().replace("e", "")));
|
| | | } else {
|
| | | return Integer.valueOf(o2.getValue().toString()).compareTo(Integer.valueOf(o1.getValue().toString()));
|
| | | }
|
| | | }
|
| | | });
|
| | | List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
|
| | | for (Entry<String, Object> entry : list) {
|
| | | for (Sensor sensor : sensors) {
|
| | | if (!entry.getValue().toString().equals("0") && entry.getKey().equals(sensor.getSensorKey())) {
|
| | | Map<String, Object> map2 = new HashMap<String, Object>();
|
| | | map2.put(sensor.getDescription(), entry.getValue());
|
| | | resultList.add(map2);
|
| | | sensors.remove(sensor);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | }
|