mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-29 08:55:23 +08:00
排序优化
This commit is contained in:
parent
86d507cc98
commit
b4db9d67b2
@ -45,8 +45,8 @@ public class CourseController {
|
|||||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
String sortField = MapUtils.getString(params, "sort_field");
|
||||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||||
String title = MapUtils.getString(params, "title");
|
String title = MapUtils.getString(params, "title");
|
||||||
String depIds = MapUtils.getString(params, "dep_ids");
|
String depIds = MapUtils.getString(params, "dep_ids");
|
||||||
String categoryIds = MapUtils.getString(params, "category_ids");
|
String categoryIds = MapUtils.getString(params, "category_ids");
|
||||||
|
@ -39,8 +39,8 @@ public class ResourceController {
|
|||||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
String sortField = MapUtils.getString(params, "sort_field");
|
||||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||||
String name = MapUtils.getString(params, "name");
|
String name = MapUtils.getString(params, "name");
|
||||||
String categoryIdsStr = MapUtils.getString(params, "category_ids");
|
String categoryIdsStr = MapUtils.getString(params, "category_ids");
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ public class UserController {
|
|||||||
String createdAtStr = MapUtils.getString(params, "created_at");
|
String createdAtStr = MapUtils.getString(params, "created_at");
|
||||||
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
||||||
|
|
||||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
String sortField = MapUtils.getString(params, "sort_field");
|
||||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||||
|
|
||||||
UserPaginateFilter filter = new UserPaginateFilter();
|
UserPaginateFilter filter = new UserPaginateFilter();
|
||||||
filter.setSortAlgo(sortAlgo);
|
filter.setSortAlgo(sortAlgo);
|
||||||
|
@ -61,10 +61,18 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.getSortAlgo().equals("desc")) {
|
String sortFiled = filter.getSortField();
|
||||||
wrapper.orderByDesc(filter.getSortField());
|
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
||||||
|
sortFiled = "id";
|
||||||
|
}
|
||||||
|
String sortAlgo = filter.getSortAlgo();
|
||||||
|
if (sortAlgo == null || sortAlgo.trim().length() == 0) {
|
||||||
|
sortAlgo = "desc";
|
||||||
|
}
|
||||||
|
if ("desc".equals(sortAlgo)) {
|
||||||
|
wrapper.orderByDesc(sortFiled);
|
||||||
} else {
|
} else {
|
||||||
wrapper.orderByAsc(filter.getSortField());
|
wrapper.orderByAsc(sortFiled);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPage<Course> pageObj = new Page<>(page, size);
|
IPage<Course> pageObj = new Page<>(page, size);
|
||||||
|
@ -20,7 +20,7 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
|||||||
implements ResourceCategoryService {
|
implements ResourceCategoryService {
|
||||||
@Override
|
@Override
|
||||||
public List<ResourceCategory> getByType(String type) {
|
public List<ResourceCategory> getByType(String type) {
|
||||||
return list(query().getWrapper().eq("type", type).orderByAsc("id"));
|
return list(query().getWrapper().eq("type", type).orderByAsc("sort"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,11 +40,18 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
wrapper.in("category_id", Arrays.asList(filter.getCategoryIds()));
|
wrapper.in("category_id", Arrays.asList(filter.getCategoryIds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 排序
|
String sortFiled = filter.getSortField();
|
||||||
if (filter.getSortAlgo().equals("desc")) {
|
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
||||||
wrapper.orderByDesc(filter.getSortField());
|
sortFiled = "id";
|
||||||
|
}
|
||||||
|
String sortAlgo = filter.getSortAlgo();
|
||||||
|
if (sortAlgo == null || sortAlgo.trim().length() == 0) {
|
||||||
|
sortAlgo = "desc";
|
||||||
|
}
|
||||||
|
if ("desc".equals(sortAlgo)) {
|
||||||
|
wrapper.orderByDesc(sortFiled);
|
||||||
} else {
|
} else {
|
||||||
wrapper.orderByAsc(filter.getSortField());
|
wrapper.orderByAsc(sortFiled);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPage<Resource> adminPage = new Page<>(page, size);
|
IPage<Resource> adminPage = new Page<>(page, size);
|
||||||
|
@ -78,10 +78,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
wrapper.in("id", userIds);
|
wrapper.in("id", userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.getSortAlgo().equals("desc")) {
|
String sortFiled = filter.getSortField();
|
||||||
wrapper.orderByDesc(filter.getSortField());
|
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
||||||
|
sortFiled = "id";
|
||||||
|
}
|
||||||
|
String sortAlgo = filter.getSortAlgo();
|
||||||
|
if (sortAlgo == null || sortAlgo.trim().length() == 0) {
|
||||||
|
sortAlgo = "desc";
|
||||||
|
}
|
||||||
|
if ("desc".equals(sortAlgo)) {
|
||||||
|
wrapper.orderByDesc(sortFiled);
|
||||||
} else {
|
} else {
|
||||||
wrapper.orderByAsc(filter.getSortField());
|
wrapper.orderByAsc(sortFiled);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPage<User> userPage = new Page<>(page, size);
|
IPage<User> userPage = new Page<>(page, size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user