From 2554184b0b4c4b458a493c6c84caf9de70543ab4 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Tue, 6 Sep 2022 13:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=A7=AF=E6=B0=B4=E7=82=B9?= =?UTF-8?q?=E5=BD=93=E5=B9=B4=E6=AF=8F=E6=9C=88=E7=A7=AF=E6=B0=B4=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaterPointController.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java index b614f97..2a91b50 100644 --- a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java +++ b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java @@ -259,4 +259,55 @@ public class WaterPointController { return Result.success(jdbcTemplate.queryForList(sql)); } + + /** + * 查询积水点当年每月积水时间 + * + * @param water_point_id + * @param year + * @return + */ + @GetMapping("selectWaterPondingHoursInYear") + @ApiOperation("查询积水点当年每月积水时间") + public Result selectWaterPondingHoursInYear(@RequestParam String water_point_id, @RequestParam String year) { + if (StringUtils.isEmpty(water_point_id)) { + return Result.error("未提供积水点id"); + } + if (StringUtils.isEmpty(year)) { + return Result.error("未提供日期"); + } + + String sql = String.format("SELECT " + + "`year`," + + "`month`," + + "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 " + + " GROUP BY " + + "`year`," + + "`month`," + + "`day`," + + "`hour` " + + " ORDER BY " + + "`year` DESC," + + "`month` DESC," + + "`day` DESC " + + ") AS temp " + + " GROUP BY " + + " `year`," + + " `month` " + + " ORDER BY " + + " `month`", water_point_id, year); + return Result.success(jdbcTemplate.queryForList(sql)); + } + }