| | |
| | | package com.moral.controller;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.moral.common.util.WebUtils;
|
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.DemoMapper;
|
| | | import com.moral.mapper.HistoryMapper;
|
| | |
|
| | |
|
| | | @RestController
|
| | | @RequestMapping("demo")
|
| | |
| | | @Resource
|
| | | private AlarmDailyMapper alarmDailyMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryMapper historyMapper;
|
| | |
|
| | | @GetMapping("list")
|
| | | public List<Map<String, Object>> getDatas(){
|
| | | List<Map<String, Object>> list = demoMapper.getDatas();
|
| | | public List<Map<String, Object>> getDatas(HttpServletRequest request){
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | parameters.put("size", Integer.valueOf(parameters.get("size").toString()));
|
| | | List<Map<String, Object>> list = demoMapper.getDatas(parameters);
|
| | | Collections.sort(list, new Comparator<Map<String, Object>>() {
|
| | | @Override
|
| | | public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
| | |
| | | });
|
| | | return alarmData;
|
| | | }
|
| | | |
| | | @GetMapping("compare")
|
| | | public List<Map<String, Object>> getCompareDatas(HttpServletRequest request){
|
| | | List<Map<String, Object>> thisMonth = getDatas(request);
|
| | | List<Date> timeList = new ArrayList<Date>();
|
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd日HH时");
|
| | | for (Map<String, Object> map : thisMonth) {
|
| | | timeList.add(DateUtils.addMonths((Date)map.get("time"), -1));
|
| | | JSONObject json = JSON.parseObject(map.remove("aqi_json").toString());
|
| | | map.put("this_month_PM2_5",json.get("PM2_5"));
|
| | | map.put("this_month_PM10",json.get("PM10"));
|
| | | map.put("format_time", simpleDateFormat.format((Date)map.get("time")));
|
| | | }
|
| | | Map<String, Object> parameters = new HashMap<String, Object>();
|
| | | parameters.put("timeList", timeList);
|
| | | List<Map<String, Object>> lastMonth = demoMapper.getDatas(parameters);
|
| | | for (Map<String, Object> map : thisMonth) {
|
| | | String formatTime = map.get("format_time").toString();
|
| | | for (Map<String, Object> last : lastMonth) {
|
| | | if (formatTime.equals(simpleDateFormat.format((Date)last.get("time")))) {
|
| | | JSONObject json = JSON.parseObject(last.remove("aqi_json").toString());
|
| | | map.put("last_month_PM2_5",json.get("PM2_5"));
|
| | | map.put("last_month_PM10",json.get("PM10"));
|
| | | lastMonth.remove(last);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | return thisMonth;
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * 功能描述: |
| | | *
|
| | | * @param: startTime 开始时间
|
| | | * @param: endTime 结束时间
|
| | | * @return:
|
| | | * @author: fengxiang
|
| | | * @date: 2018/7/30 11:27
|
| | | */
|
| | | @GetMapping("get-dayaqis")
|
| | | public List<Map<String, Object>> getDayAqis(Date startTime,Date endTime) {
|
| | | return demoMapper.selectByTimeZones(startTime,endTime);
|
| | | }
|
| | | |
| | | @GetMapping("avg")
|
| | | public Map<String, Object> getAvgDatas(HttpServletRequest request){
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e3", "e13"));
|
| | | LocalDateTime now = LocalDateTime.now();
|
| | | parameters.put("start", now.minusHours(1).truncatedTo(ChronoUnit.HOURS));
|
| | | parameters.put("end", now.truncatedTo(ChronoUnit.HOURS));
|
| | | List<Map<String, Object>> avgs = historyMapper.getAreaAllDataByAccount(parameters);
|
| | | if (ObjectUtils.isEmpty(avgs)) {
|
| | | return new HashMap<String, Object>();
|
| | | } else {
|
| | | return avgs.get(0);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|