Merge branch 'dev'

This commit is contained in:
wangliwen 2022-11-18 13:06:13 +08:00
commit bd46f31eac
1 changed files with 15 additions and 4 deletions

View File

@ -924,13 +924,24 @@ public class ResourceController {
if (params.containsKey("page") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("page").toString())) { if (params.containsKey("page") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("page").toString())) {
page = Integer.parseInt(params.get("page").toString()); page = Integer.parseInt(params.get("page").toString());
} }
String sql = String.format("SELECT * FROM policy_cloud_service LIMIT %d,%d", (page - 1) * pageSize, pageSize); String sql;
long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM policy_cloud_service", Long.class); String sqlRoot = "SELECT * FROM policy_cloud_service ";
String where = " WHERE 1=1 ";
String limit = String.format(" LIMIT %d,%d", (page - 1) * pageSize, pageSize);
long count = 0;
if (params.containsKey("name") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("name").toString())) { if (params.containsKey("name") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("name").toString())) {
sql = String.format("SELECT * FROM policy_cloud_service WHERE service_description LIKE '%s' LIMIT %d,%d", "%" + params.get("name").toString() + "%", (page - 1) * pageSize, pageSize); where = where + String.format(" AND service_description LIKE '%s'", "%" + params.get("name").toString() + "%");
count = jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM policy_cloud_service WHERE service_description LIKE '%s'", "%" + params.get("name").toString() + "%"), Long.class);
} }
if (params.containsKey("type") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("type").toString())) {
where = where + String.format(" AND service_type = '%s'", params.get("type").toString());
}
sql = sqlRoot + where + limit;
logger.info("sql" + sql); logger.info("sql" + sql);
String sqlCount = "SELECT COUNT(*) FROM policy_cloud_service " + where;
count = jdbcTemplate.queryForObject(sqlCount, Long.class);
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql); List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
return new Result<PageData<Map<String, Object>>>().ok(new PageData<>(result, count)); return new Result<PageData<Map<String, Object>>>().ok(new PageData<>(result, count));
} }