| | |
| | | package com.gkhy.fourierSpecialGasMonitor.service.impl; |
| | | |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.domain.Result; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.domain.SearchResult; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.model.PageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.GasConcentration; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.GasFlux; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.GasWarnLog; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.GasWarnUser; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.*; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.query.FindGasWarnLogPageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.query.FindGasWarnUserPageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.query.GasAtmospherePageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.query.GasPageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.req.GasConcentrationExportBO; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.req.SummaryStatsReqDTO; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.resp.FindGasWarnUserPageRespDTO; |
| | | import com.gkhy.fourierSpecialGasMonitor.entity.resp.SummaryStatsPageRespDTO; |
| | | import com.gkhy.fourierSpecialGasMonitor.enums.DeleteStatusEnum; |
| | | import com.gkhy.fourierSpecialGasMonitor.repository.GasConcentrationRepository; |
| | | import com.gkhy.fourierSpecialGasMonitor.service.GasConcentrationService; |
| | | import com.gkhy.fourierSpecialGasMonitor.utils.SummaryUtils; |
| | | import io.micrometer.core.instrument.util.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.persistence.criteria.*; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.Year; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | |
| | | List<GasConcentration> result = gasConcentrationRepository.findAll(specification); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public SummaryStats findStats(LocalDateTime startTime,LocalDateTime endTime) { |
| | | return gasConcentrationRepository.findStats(startTime,endTime); |
| | | } |
| | | |
| | | @Override |
| | | public Result gasAtmosphereExtremum(SummaryStatsReqDTO reqDTO) { |
| | | Result success = Result.success(); |
| | | |
| | | // 1. 参数校验 |
| | | SummaryUtils summaryUtils = new SummaryUtils(); |
| | | summaryUtils.validateParams(reqDTO); |
| | | |
| | | String type = reqDTO.getType(); // 气体类型(如 "temp"、"humidity") |
| | | Integer dateType = reqDTO.getDateType(); // 时间粒度(1-日、2-月、3-年) |
| | | String date = reqDTO.getDate(); // 日期(如 "2025-11-10"、"2025-11"、"2025") |
| | | |
| | | // 2. 根据 dateType 解析时间范围 |
| | | LocalDateTime startTime = null; |
| | | LocalDateTime endTime = null; |
| | | String formatDate = null; // 格式化后的日期(用于返回) |
| | | |
| | | switch (dateType) { |
| | | case 1: // 日查询(date格式:yyyy-MM-dd) |
| | | LocalDate day = LocalDate.parse(date); |
| | | startTime = day.atStartOfDay(); // 当天00:00:00 |
| | | endTime = day.atTime(23, 59, 59); // 当天23:59:59 |
| | | formatDate = day.format(DateTimeFormatter.ISO_LOCAL_DATE); |
| | | break; |
| | | case 2: // 月查询(date格式:yyyy-MM) |
| | | YearMonth month = YearMonth.parse(date); |
| | | startTime = month.atDay(1).atStartOfDay(); // 当月1日00:00:00 |
| | | endTime = month.atEndOfMonth().atTime(23, 59, 59); // 当月最后一天23:59:59 |
| | | formatDate = month.format(DateTimeFormatter.ofPattern("yyyy-MM")); |
| | | break; |
| | | case 3: // 年查询(date格式:yyyy) |
| | | Year year = Year.parse(date); |
| | | startTime = year.atDay(1).atStartOfDay(); // 当年1月1日00:00:00 |
| | | endTime = year.atMonth(12).atEndOfMonth().atTime(23, 59, 59); // 当年12月最后一天23:59:59 |
| | | formatDate = year.toString(); |
| | | break; |
| | | default: |
| | | throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"无效的dateType,必须为1(日)、2(月)、3(年)"); |
| | | } |
| | | |
| | | // 3. 动态查询指定类型和时间范围的统计值 |
| | | SummaryStatsPageRespDTO summaryStatsByTypeAndTimeRange = gasConcentrationRepository.findSummaryStatsByTypeAndTimeRange(type, startTime, endTime); |
| | | |
| | | success.setData(summaryStatsByTypeAndTimeRange); |
| | | |
| | | // 5. 返回结果 |
| | | return success; |
| | | } |
| | | } |