| | |
| | | import com.moral.api.service.HistorySecondRadarService; |
| | | import com.moral.api.service.RadarHourlySummaryService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.vo.*; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | private static final int PEAK_SEARCH_LIMIT = 200; |
| | | |
| | | private static final DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00:00"); |
| | | private static final DateTimeFormatter DT_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ComparisonResponse getComparison(String location, String time) { |
| | | // 入参时间 → 前一个整点 = current 时刻 |
| | | LocalDateTime inputTime = LocalDateTime.parse(time, DT_FMT); |
| | | LocalDateTime prevHour = inputTime.minusHours(1).withMinute(0).withSecond(0).withNano(0); |
| | | String currentTime = prevHour.format(DT_FMT); |
| | | |
| | | // 30 天范围:currentTime(不含)往前推 30 天 |
| | | String endStr = currentTime; |
| | | String startStr = prevHour.minusDays(30).format(DT_FMT); |
| | | |
| | | ComparisonResponse resp = new ComparisonResponse(); |
| | | resp.setLocation(location); |
| | | resp.setTime(time); |
| | | |
| | | // current: 前一个整点的 a34004_drop_height |
| | | RadarHourlySummaryVO cur = this.baseMapper.getByTime(currentTime); |
| | | resp.setCurrent(cur != null && cur.getA34004DropHeight() != null ? cur.getA34004DropHeight().doubleValue() : 0.0); |
| | | |
| | | // avg30: 720 小时平均 |
| | | Double avg = this.baseMapper.getAvgDropHeightInRange(startStr, endStr); |
| | | resp.setAvg30(avg != null ? avg : 0.0); |
| | | |
| | | // daily30: 按天分组,不含今天 |
| | | List<DailyDropHeightVO> rows = this.baseMapper.getDailyAvgDropHeight(startStr, endStr); |
| | | if(CollectionUtils.isEmpty(rows)){ |
| | | List<DailyDropHeightVO> daily = new ArrayList<>(); |
| | | String todayStr = prevHour.toLocalDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | DailyDropHeightVO dropHeightVO = new DailyDropHeightVO(); |
| | | dropHeightVO.setDate(todayStr); |
| | | dropHeightVO.setDropHeight(0d); |
| | | daily.add(dropHeightVO); |
| | | resp.setDaily30(daily); |
| | | }else { |
| | | resp.setDaily30(rows); |
| | | } |
| | | return resp; |
| | | } |
| | | |
| | | @Override |
| | | public HourlyResponse getHourly5Days(String location, String startTime, String endTime) { |
| | | HourlyResponse resp = new HourlyResponse(); |
| | | resp.setLocation(location); |
| | | resp.setStartTime(startTime); |
| | | resp.setEndTime(endTime); |
| | | |
| | | List<RadarHourlySummaryVO> list = this.baseMapper.queryHourlyByRange(startTime, endTime); |
| | | List<HourlyItemVO> items = new ArrayList<>(); |
| | | for (RadarHourlySummaryVO s : list) { |
| | | HourlyItemVO item = new HourlyItemVO(); |
| | | item.setTime(s.getTimeStr()); |
| | | item.setA34004DropHeight(s.getA34004DropHeight().doubleValue()); |
| | | items.add(item); |
| | | } |
| | | resp.setCount(items.size()); |
| | | resp.setHourly(items); |
| | | return resp; |
| | | } |
| | | |
| | | @Override |
| | | public void processHour(String hourStart) { |
| | | String hourEnd = nextHour(hourStart); |
| | | List<String> rawList = radarService.queryRawDataByHour(hourStart, hourEnd); |