diff --git a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java index 6a9900b..32d731e 100644 --- a/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java +++ b/src/main/java/com/hisense/monitormanage/controller/WaterPointController.java @@ -15,8 +15,10 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -147,4 +149,116 @@ public class WaterPointController { return success; } + + /** + * 根据积水点查询该点存在积水情况的日期 + * + * @param water_point_id + * @return + */ + @GetMapping("selectWaterPondingDate") + @ApiOperation("查询积水点存在积水的日期") + public Result selectWaterPondingDate(@RequestParam String water_point_id) { + if (StringUtils.isEmpty(water_point_id)) { + return Result.error("未提供积水点id"); + } + String sql = String.format("SELECT DISTINCT\n" + + "\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `year`,\n" + + "\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `month`,\n" + + "\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `day` \n" + + "FROM\n" + + "\twater_point_sensor \n" + + "WHERE\n" + + "\twater_point_sensor.water_point_id = '%s' \n" + + "\tAND water_point_sensor.updated_date != '0.00' \n" + + "ORDER BY\n" + + "\t`year` DESC,\n" + + "\t`month` DESC,\n" + + "\t`day` DESC;", water_point_id); + return Result.success(jdbcTemplate.queryForList(sql)); + } + + + /** + * 查询当天的积水点深度情况 + * + * @param water_point_id + * @param year + * @param month + * @param day + * @return + */ + @GetMapping("selectWaterPondingInDay") + @ApiOperation("查询积水点当天的积水深度") + public Result selectWaterPondingInDay(@RequestParam String water_point_id, @RequestParam String year, @RequestParam String month, @RequestParam String day) { + if (StringUtils.isEmpty(water_point_id)) { + return Result.error("未提供积水点id"); + } + if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month) || StringUtils.isEmpty(day)) { + return Result.error("未提供日期"); + } + String sql = String.format("SELECT\n" + + "\tupdated_date AS depth,\n" + + "\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `year`,\n" + + "\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `month`,\n" + + "\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `day`,\n" + + "\tHOUR (\n" + + "\tSTR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' )) AS `hour`,\n" + + "\tMINUTE (\n" + + "\tSTR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' )) AS `minute` \n" + + "FROM\n" + + "\twater_point_sensor \n" + + "WHERE\n" + + "\twater_point_sensor.water_point_id = '%s' \n" + + "\tAND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + + "\tAND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + + "\tAND DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + + "ORDER BY\n" + + "\t`year` DESC,\n" + + "\t`month` DESC,\n" + + "\t`day` DESC,\n" + + "\t`hour`,\n" + + "\t`minute`;", water_point_id, year, month, day); + return Result.success(jdbcTemplate.queryForList(sql)); + } + + /** + * 查询积水点当月内每天最深深度 + * + * @param water_point_id + * @param year + * @param month + * @return + */ + @GetMapping("selectWaterPondingInMonth") + @ApiOperation("查询积水点当月内最深深度") + public Result selectWaterPondingInMonth(@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\n" + + "\tMAX( updated_date ) AS depth,\n" + + "\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `year`,\n" + + "\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `month`,\n" + + "\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `day` \n" + + "FROM\n" + + "\twater_point_sensor \n" + + "WHERE\n" + + "\twater_point_sensor.water_point_id = '%s' \n" + + "\tAND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + + "\tAND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + + "GROUP BY\n" + + "\t`year`,\n" + + "\t`month`,\n" + + "\t`day` \n" + + "ORDER BY\n" + + "\t`year` DESC,\n" + + "\t`month` DESC,\n" + + "\t`day` DESC;", water_point_id, year, month); + return Result.success(jdbcTemplate.queryForList(sql)); + } + }