查询积水点当年每月积水时间
This commit is contained in:
parent
66f6f73db3
commit
2554184b0b
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue