查询某月当天积水时间

This commit is contained in:
wangliwen 2022-09-06 14:13:57 +08:00
parent 737c255035
commit da74a124e2
1 changed files with 57 additions and 0 deletions

View File

@ -310,4 +310,61 @@ public class WaterPointController {
return Result.success(jdbcTemplate.queryForList(sql)); 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));
}
} }