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)); + } + }