This commit is contained in:
wangliwen 2022-09-05 14:41:57 +08:00
parent 5792878b82
commit 1aaeee1bfd
1 changed files with 52 additions and 54 deletions

View File

@ -162,19 +162,19 @@ public class WaterPointController {
if (StringUtils.isEmpty(water_point_id)) { if (StringUtils.isEmpty(water_point_id)) {
return Result.error("未提供积水点id"); return Result.error("未提供积水点id");
} }
String sql = String.format("SELECT DISTINCT\n" + String sql = String.format("SELECT DISTINCT " +
"\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `year`,\n" + "YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) `year`," +
"\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `month`,\n" + "MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) `month`," +
"\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) `day` \n" + "DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) `day` " +
"FROM\n" + " FROM " +
"\twater_point_sensor \n" + "water_point_sensor " +
"WHERE\n" + " WHERE " +
"\twater_point_sensor.water_point_id = '%s' \n" + "water_point_sensor.water_point_id = '%s' " +
"\tAND water_point_sensor.updated_date != '0.00' \n" + "AND water_point_sensor.updated_date != '0.00'" +
"ORDER BY\n" + " ORDER BY " +
"\t`year` DESC,\n" + "`year` DESC," +
"\t`month` DESC,\n" + "`month` DESC," +
"\t`day` DESC;", water_point_id); "`day` DESC;", water_point_id);
return Result.success(jdbcTemplate.queryForList(sql)); return Result.success(jdbcTemplate.queryForList(sql));
} }
@ -197,28 +197,26 @@ public class WaterPointController {
if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month) || StringUtils.isEmpty(day)) { if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month) || StringUtils.isEmpty(day)) {
return Result.error("未提供日期"); return Result.error("未提供日期");
} }
String sql = String.format("SELECT\n" + String sql = String.format("SELECT " +
"\tupdated_date AS depth,\n" + "updated_date AS depth," +
"\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `year`,\n" + "YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `year`," +
"\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `month`,\n" + "MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `month`," +
"\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `day`,\n" + "DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `day`," +
"\tHOUR (\n" + "HOUR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' )) AS `hour`," +
"\tSTR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' )) AS `hour`,\n" + "MINUTE ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' )) AS `minute`" +
"\tMINUTE (\n" + " FROM " +
"\tSTR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' )) AS `minute` \n" + " water_point_sensor " +
"FROM\n" + " WHERE " +
"\twater_point_sensor \n" + "water_point_sensor.water_point_id = '%s' " +
"WHERE\n" + "AND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " +
"\twater_point_sensor.water_point_id = '%s' \n" + "AND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " +
"\tAND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + "AND DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " +
"\tAND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + " ORDER BY " +
"\tAND DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + "`year` DESC," +
"ORDER BY\n" + "`month` DESC," +
"\t`year` DESC,\n" + "`day` DESC," +
"\t`month` DESC,\n" + "`hour`," +
"\t`day` DESC,\n" + "`minute`;", water_point_id, year, month, day);
"\t`hour`,\n" +
"\t`minute`;", water_point_id, year, month, day);
return Result.success(jdbcTemplate.queryForList(sql)); return Result.success(jdbcTemplate.queryForList(sql));
} }
@ -239,25 +237,25 @@ public class WaterPointController {
if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month)) { if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month)) {
return Result.error("未提供日期"); return Result.error("未提供日期");
} }
String sql = String.format("SELECT\n" + String sql = String.format("SELECT " +
"\tMAX( updated_date ) AS depth,\n" + "MAX( updated_date ) AS depth," +
"\tYEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `year`,\n" + "YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `year`," +
"\tMONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `month`,\n" + "MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `month`," +
"\tDAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) AS `day` \n" + "DAY ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) AS `day` " +
"FROM\n" + " FROM " +
"\twater_point_sensor \n" + "water_point_sensor " +
"WHERE\n" + " WHERE " +
"\twater_point_sensor.water_point_id = '%s' \n" + "water_point_sensor.water_point_id = '%s' " +
"\tAND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + "AND YEAR ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " +
"\tAND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%Y-%m-%d %H:%i:%s' ) ) = %s \n" + "AND MONTH ( STR_TO_DATE( water_point_sensor.water_point_area, '%%Y-%%m-%%d %%H:%%i:%%s' ) ) = %s " +
"GROUP BY\n" + " GROUP BY " +
"\t`year`,\n" + "`year`," +
"\t`month`,\n" + "`month`," +
"\t`day` \n" + "`day` " +
"ORDER BY\n" + " ORDER BY " +
"\t`year` DESC,\n" + "`year` DESC," +
"\t`month` DESC,\n" + "`month` DESC," +
"\t`day` DESC;", water_point_id, year, month); "`day` DESC;", water_point_id, year, month);
return Result.success(jdbcTemplate.queryForList(sql)); return Result.success(jdbcTemplate.queryForList(sql));
} }