| | |
| | | package com.moral.controller;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.time.LocalDate;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
|
| | | import com.moral.common.util.WebUtils;
|
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.DemoMapper;
|
| | |
|
| | | @RestController
|
| | |
| | |
|
| | | @Resource
|
| | | private DemoMapper demoMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private AlarmDailyMapper alarmDailyMapper;
|
| | |
|
| | | @GetMapping("list")
|
| | | public List<Map<String, Object>> getDatas(){
|
| | | List<Map<String, Object>> list = demoMapper.getDatas();
|
| | |
| | | });
|
| | | return list;
|
| | | }
|
| | |
|
| | | @GetMapping("pollution")
|
| | | public List<Map<String, Object>> getPollutionDatas(HttpServletRequest request){
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Object sensorKey = parameters.get("sensorKey");
|
| | | parameters.put("sensorKeys", Arrays.asList(sensorKey));
|
| | | parameters.put("start", LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()));
|
| | | parameters.put("end", LocalDate.now().with(TemporalAdjusters.firstDayOfNextMonth()));
|
| | | List<Map<String, Object>> alarmData = alarmDailyMapper.getAlarmData(parameters);
|
| | | Collections.sort(alarmData, new Comparator<Map<String, Object>>() {
|
| | | @Override
|
| | | public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
| | | return ((BigDecimal) o2.get(sensorKey)).compareTo((BigDecimal) o1.get(sensorKey));
|
| | | }
|
| | | });
|
| | | return alarmData;
|
| | | }
|
| | | }
|