From d58fc49be5194dd2ff8c9cef84964fb3a44f0d0e Mon Sep 17 00:00:00 2001 From: hqx <3376194473@qq.com> Date: Tue, 6 Feb 2024 17:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A6=96=E9=A1=B5=E9=9B=A8?= =?UTF-8?q?=E6=83=85=E7=9B=91=E6=B5=8B=E6=9D=BF=E5=9D=97=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E7=9B=91=E6=B5=8B=E8=AE=BE=E5=A4=87=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=8A=B6=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyt/controller/HomePageController.java | 48 +++- .../project/xyt/entity/vo/StPptnVo.java | 30 +++ .../project/xyt/mapper/StPptnRMapper.java | 72 ++++++ .../project/xyt/mapper/StRcvRealMapper.java | 35 ++- .../MonitorEquipmentHealthService.java | 18 ++ .../xyt/service/RainMonitoringService.java | 243 ++++++++++++++++++ 6 files changed, 438 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/gunshi/project/xyt/entity/vo/StPptnVo.java create mode 100644 src/main/java/com/gunshi/project/xyt/mapper/StPptnRMapper.java create mode 100644 src/main/java/com/gunshi/project/xyt/service/RainMonitoringService.java diff --git a/src/main/java/com/gunshi/project/xyt/controller/HomePageController.java b/src/main/java/com/gunshi/project/xyt/controller/HomePageController.java index 12271ab..a50906c 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/HomePageController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/HomePageController.java @@ -3,11 +3,10 @@ package com.gunshi.project.xyt.controller; import com.gunshi.core.annotation.Get; import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.vo.ReservoirLevelVo; +import com.gunshi.project.xyt.entity.vo.StPptnVo; +import com.gunshi.project.xyt.model.StRcvReal; import com.gunshi.project.xyt.model.StResPersonRef; -import com.gunshi.project.xyt.service.MonitorEquipmentHealthService; -import com.gunshi.project.xyt.service.ReservoirLevelService; -import com.gunshi.project.xyt.service.StResPersonRefService; -import com.gunshi.project.xyt.service.WarningInfoService; +import com.gunshi.project.xyt.service.*; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -36,6 +35,8 @@ public class HomePageController { @Resource private ReservoirLevelService reservoirLevelService; @Resource + private RainMonitoringService rainMonitoringService; + @Resource private StResPersonRefService stResPersonRefService; @Resource private WarningInfoService warningInfoService; @@ -82,26 +83,59 @@ public class HomePageController { return R.ok(reservoirLevelService.queryRzHalfYearByResId(resId)); } + @Get(path = "/rainMonitoring/queryTodayDrp",summary = "根据水库ID查询今天降雨量") + public R> queryTodayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ + return R.ok(rainMonitoringService.queryTodayDrpByResId(resId)); + } + + @Get(path = "/rainMonitoring/queryYesterdayDrp",summary = "根据水库ID查询昨天降雨量") + public R> queryYesterdayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ + return R.ok(rainMonitoringService.queryYesterdayDrpByResId(resId)); + } + + @Get(path = "/rainMonitoring/query24HourDrp",summary = "根据水库ID查询24小时内的降雨量") + public R> query24HourDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ + return R.ok(rainMonitoringService.query24HourDrpByResId(resId)); + } + + @Get(path = "/rainMonitoring/query72HourDrp",summary = "根据水库ID查询72小时内的降雨量") + public R> query72HourDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ + return R.ok(rainMonitoringService.query72HourDrpByResId(resId)); + } + + @Get(path = "/rainMonitoring/querySevenDayDrp",summary = "根据水库ID查询七日的降雨量") + public R> querySevenDayDrpByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ + return R.ok(rainMonitoringService.querySevenDayDrpByResId(resId)); + } + @Get(path = "/personInCharge/queryStResPersonRef",summary = "根据水库ID查询责任人信息") public R> queryStResPersonRefByResId(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ return R.ok(stResPersonRefService.queryStResPersonRefByResId(resId)); } - @Get(path = "/WarningInfo/ReservoirExceededLimit",summary = "判断水库超汛限是否正常") + @Get(path = "/warningInfo/reservoirExceededLimit",summary = "判断水库超汛限是否正常") public R ReservoirExceededLimit(@Parameter(description = "水库ID") @RequestParam("resId") String resId){ return R.ok(warningInfoService.ReservoirExceededLimit(resId)); } - @Get(path = "/MonitorEquipmentHealth/queryAllStcdCount",summary = "查看监测设备总数") + @Get(path = "/monitorEquipmentHealth/queryAllStcdCount",summary = "查看监测设备总数") public R queryAllStcdCount(){ return R.ok(monitorEquipmentHealthService.queryAllStcdCount()); } - @Get(path = "/MonitorEquipmentHealth/queryOnlineStcdCount",summary = "查看近一个小时检测设备在线数量") + @Get(path = "/monitorEquipmentHealth/queryOnlineStcdCount",summary = "查看近一个小时检测设备在线数量") public R queryOnlineStcdCount(){ return R.ok(monitorEquipmentHealthService.queryOnlineStcdCount()); } + @Get(path = "/monitorEquipmentHealth/queryOffLineStcd",summary = "查看离线设备清单") + public R> queryOffLineStcd(){ + return R.ok(monitorEquipmentHealthService.queryOffLineStcd()); + } + @Get(path = "/monitorEquipmentHealth/queryOnLineStcd",summary = "查看在线设备清单") + public R> queryOnLineStcd(){ + return R.ok(monitorEquipmentHealthService.queryOnLineStcd()); + } } diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/StPptnVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/StPptnVo.java new file mode 100644 index 0000000..5545aab --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/StPptnVo.java @@ -0,0 +1,30 @@ +package com.gunshi.project.xyt.entity.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.gunshi.core.dateformat.DateFormatString; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * TODO + * + * @ClassName StPptnVo + * @Author Huang Qianxiang + * @Date 2024/2/6 10:48 + */ +@Data +public class StPptnVo { + + /** + * 采集时间 + */ + @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") + private Date time; + + /** + * 时间段内平均水库水位 + */ + private BigDecimal sumDrp; +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/StPptnRMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/StPptnRMapper.java new file mode 100644 index 0000000..e974997 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/mapper/StPptnRMapper.java @@ -0,0 +1,72 @@ +package com.gunshi.project.xyt.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.gunshi.project.xyt.entity.vo.StPptnVo; +import com.gunshi.project.xyt.model.StPptnR; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; +import java.util.List; + +@Mapper +public interface StPptnRMapper extends BaseMapper { + + @Select(""" + + """) + List queryHourTimeQuantumDrpByResId(@Param("resId") String resId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + + @Select(""" + + """) + List queryDayTimeQuantumDrpByResId(@Param("resId") String resId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + + @Select(""" + + """) + List query24HourDrpByResId(@Param("resId") String resId); + + @Select(""" + + """) + List query72HourDrpByResId(@Param("resId") String resId); + +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/StRcvRealMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/StRcvRealMapper.java index f5bbb03..b4707bf 100644 --- a/src/main/java/com/gunshi/project/xyt/mapper/StRcvRealMapper.java +++ b/src/main/java/com/gunshi/project/xyt/mapper/StRcvRealMapper.java @@ -1,15 +1,48 @@ package com.gunshi.project.xyt.mapper; +import com.gunshi.project.xyt.model.StRcvReal; import org.apache.ibatis.annotations.Select; +import java.util.List; + public interface StRcvRealMapper { @Select(""" """) Long queryOnlineStcdCount(); + @Select(""" + + """) + List queryOffLineStcd(); + + @Select(""" + + """) + List queryOnLineStcd(); + } diff --git a/src/main/java/com/gunshi/project/xyt/service/MonitorEquipmentHealthService.java b/src/main/java/com/gunshi/project/xyt/service/MonitorEquipmentHealthService.java index 603c557..ae721ed 100644 --- a/src/main/java/com/gunshi/project/xyt/service/MonitorEquipmentHealthService.java +++ b/src/main/java/com/gunshi/project/xyt/service/MonitorEquipmentHealthService.java @@ -9,6 +9,8 @@ import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.List; + /** * TODO * @@ -41,6 +43,22 @@ public class MonitorEquipmentHealthService { return stRcvRealMapper.queryOnlineStcdCount(); } + /** + * 查看离线设备清单 + * @return + */ + public List queryOffLineStcd(){ + return stRcvRealMapper.queryOffLineStcd(); + } + + /** + * 查看在线设备清单 + * @return + */ + public List queryOnLineStcd(){ + return stRcvRealMapper.queryOnLineStcd(); + } + } diff --git a/src/main/java/com/gunshi/project/xyt/service/RainMonitoringService.java b/src/main/java/com/gunshi/project/xyt/service/RainMonitoringService.java new file mode 100644 index 0000000..7e86925 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/service/RainMonitoringService.java @@ -0,0 +1,243 @@ +package com.gunshi.project.xyt.service; + +import com.gunshi.project.xyt.entity.vo.StPptnVo; +import com.gunshi.project.xyt.mapper.StPptnRMapper; +import com.gunshi.project.xyt.model.StResB; +import com.gunshi.project.xyt.model.StResBAutoDao; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * TODO + * + * @ClassName RainMonitoringService + * @Author Huang Qianxiang + * @Date 2024/2/6 10:44 + */ +@Service +@Slf4j +public class RainMonitoringService { + + @Resource + private StResBAutoDao stResBAutoDao; + @Resource + private StPptnRMapper stPptnRMapper; + + /** + * 根据水库ID查询今天降雨量 + * @param resId 水库ID + * @return + */ + public List queryTodayDrpByResId(String resId){ + StResB stResB = stResBAutoDao.getById(resId); + if (stResB == null){ + throw new IllegalArgumentException("该水库ID不存在"); + } + LocalDateTime now = LocalDateTime.now(); + LocalDateTime startTime = null; + LocalDateTime endTime = null; + if (now.getHour() < 8){ + LocalDateTime time = now.minusDays(1); + //当前时间未到 8:00 + startTime = LocalDateTime.of( + time.getYear(), + time.getMonth(), + time.getDayOfMonth(), + 8, + 0, + 0 + ); + }else { + startTime = LocalDateTime.of( + now.getYear(), + now.getMonth(), + now.getDayOfMonth(), + 8, + 0, + 0 + ); + } + endTime = now; + + return stPptnRMapper.queryHourTimeQuantumDrpByResId( + resId, + Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant()) + ); + } + + + /** + * 根据水库ID查询昨天降雨量 + * @param resId 水库ID + * @return + */ + public List queryYesterdayDrpByResId(String resId){ + StResB stResB = stResBAutoDao.getById(resId); + if (stResB == null){ + throw new IllegalArgumentException("该水库ID不存在"); + } + LocalDateTime now = LocalDateTime.now(); + LocalDateTime startTime = null; + LocalDateTime endTime = null; + if (now.getHour() < 8){ + LocalDateTime time1 = now.minusDays(2); + //当前时间未到 8:00 + startTime = LocalDateTime.of( + time1.getYear(), + time1.getMonth(), + time1.getDayOfMonth(), + 8, + 0, + 0 + ); + LocalDateTime time2 = now.minusDays(1); + endTime = LocalDateTime.of( + time2.getYear(), + time2.getMonth(), + time2.getDayOfMonth(), + 8, + 0, + 0 + ); + }else { + LocalDateTime time = now.minusDays(1); + startTime = LocalDateTime.of( + time.getYear(), + time.getMonth(), + time.getDayOfMonth(), + 8, + 0, + 0 + ); + endTime = LocalDateTime.of( + now.getYear(), + now.getMonth(), + now.getDayOfMonth(), + 8, + 0, + 0 + ); + } + return stPptnRMapper.queryHourTimeQuantumDrpByResId( + resId, + Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant()) + ); + } + + /** + * 根据水库ID查询24小时内的降雨量 + * @param resId 水库ID + * @return + */ + public List query24HourDrpByResId(String resId){ + StResB stResB = stResBAutoDao.getById(resId); + if (stResB == null){ + throw new IllegalArgumentException("该水库ID不存在"); + } + return stPptnRMapper.query24HourDrpByResId(resId); + } + + + /** + * 根据水库ID查询72小时内的降雨量 + * @param resId 水库ID + * @return + */ + public List query72HourDrpByResId(String resId){ + StResB stResB = stResBAutoDao.getById(resId); + if (stResB == null){ + throw new IllegalArgumentException("该水库ID不存在"); + } + return stPptnRMapper.query72HourDrpByResId(resId); + } + + /** + * 根据水库ID查询七日的降雨量 + * @param resId 水库ID + * @return + */ + public List querySevenDayDrpByResId(String resId){ + + StResB stResB = stResBAutoDao.getById(resId); + if (stResB == null){ + throw new IllegalArgumentException("该水库ID不存在"); + } + LocalDateTime now = LocalDateTime.now(); + + LocalDateTime startTime = null; + LocalDateTime endTime = null; + List stPptnVoList = new ArrayList(); + + if (now.getHour() < 8){ + now = now.minusDays(1); + } + + for (int i = 0; i < 7; i++) { + //获取每一天累计降水量 + if (i == 0){ + startTime = LocalDateTime.of( + now.getYear(), + now.getMonth(), + now.getDayOfMonth(), + 8, + 0, + 0 + ); + endTime = now; + }else { + startTime = LocalDateTime.of( + now.getYear(), + now.getMonth(), + now.getDayOfMonth(), + 8, + 0, + 0 + ); + LocalDateTime time = now.plusDays(1); + endTime = LocalDateTime.of( + time.getYear(), + time.getMonth(), + time.getDayOfMonth(), + 8, + 0, + 0 + ); + } + + List stPptnVoList1 = stPptnRMapper.queryDayTimeQuantumDrpByResId( + resId, + Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant()) + ); + + //对结果进行处理 + BigDecimal sumDrp = BigDecimal.valueOf(0); + for (StPptnVo stPptnVo : stPptnVoList1) { + sumDrp = sumDrp.add(stPptnVo.getSumDrp()); + } + + StPptnVo stPptnVo = new StPptnVo(); + stPptnVo.setTime(Date.from( + LocalDateTime.of(now.getYear(),now.getMonth(),now.getDayOfMonth(),0,0,0) + .atZone(ZoneId.systemDefault()) + .toInstant()) + ); + stPptnVo.setSumDrp(sumDrp); + stPptnVoList.add(stPptnVo); + + now = now.minusDays(1); + } + return stPptnVoList; + } + +}