From da74a124e24d110b4bd15c2fab24e11d39fbf0f9 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Tue, 6 Sep 2022 14:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9F=90=E6=9C=88=E5=BD=93?= =?UTF-8?q?=E5=A4=A9=E7=A7=AF=E6=B0=B4=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaterPointController.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java index 9f4703d..4453995 100644 --- a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java +++ b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java @@ -310,4 +310,61 @@ public class WaterPointController { return Result.success(jdbcTemplate.queryForList(sql)); } + /** + * 查询积水点当年某月每天积水时间 + * + * @param water_point_id + * @param year + * @return + */ + @GetMapping("selectWaterPondingHoursInMonth") + @ApiOperation("查询积水点当年某月每天积水时间") + public Result selectWaterPondingHoursInMonth(@RequestParam String water_point_id, @RequestParam String year, @RequestParam String month) { + if (StringUtils.isEmpty(water_point_id)) { + return Result.error("未提供积水点id"); + } + if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month)) { + return Result.error("未提供日期"); + } + + String sql = String.format("SELECT " + + " `year`, " + + " `month`, " + + " `day`, " + + " COUNT( `hour` ) AS `hours` " + + "FROM " + + " ( " + + " SELECT DISTINCT YEAR " + + " ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `year`, " + + " MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `month`, " + + " DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `day`, " + + " HOUR ( " + + " STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' )) AS `hour` " + + " FROM " + + " water_point_sensor " + + " WHERE " + + " water_point_sensor.water_point_id = '%s' " + + " AND water_point_sensor.updated_date != '0.00' " + + " AND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " + + " AND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " + + " GROUP BY " + + " `year`, " + + " `month`, " + + " `day`, " + + " `hour` " + + " ORDER BY " + + " `year` DESC, " + + " `month` DESC, " + + " `day` DESC " + + " ) AS temp " + + "GROUP BY " + + " `year`, " + + " `month`, " + + " `day` " + + "ORDER BY " + + " `month`, " + + " `day`;", water_point_id, year, month); + return Result.success(jdbcTemplate.queryForList(sql)); + } + }