mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 16:22:45 +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) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
||||
String sortField = MapUtils.getString(params, "sort_field");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
String title = MapUtils.getString(params, "title");
|
||||
String depIds = MapUtils.getString(params, "dep_ids");
|
||||
String categoryIds = MapUtils.getString(params, "category_ids");
|
||||
|
@ -39,8 +39,8 @@ public class ResourceController {
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
||||
String sortField = MapUtils.getString(params, "sort_field");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
String name = MapUtils.getString(params, "name");
|
||||
String categoryIdsStr = MapUtils.getString(params, "category_ids");
|
||||
|
||||
|
@ -63,8 +63,8 @@ public class UserController {
|
||||
String createdAtStr = MapUtils.getString(params, "created_at");
|
||||
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
||||
|
||||
String sortField = MapUtils.getString(params, "sort_field", "id");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo", "desc");
|
||||
String sortField = MapUtils.getString(params, "sort_field");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
|
||||
UserPaginateFilter filter = new UserPaginateFilter();
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
|
@ -61,10 +61,18 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
}
|
||||
}
|
||||
|
||||
if (filter.getSortAlgo().equals("desc")) {
|
||||
wrapper.orderByDesc(filter.getSortField());
|
||||
String sortFiled = 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 {
|
||||
wrapper.orderByAsc(filter.getSortField());
|
||||
wrapper.orderByAsc(sortFiled);
|
||||
}
|
||||
|
||||
IPage<Course> pageObj = new Page<>(page, size);
|
||||
|
@ -20,7 +20,7 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
||||
implements ResourceCategoryService {
|
||||
@Override
|
||||
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
|
||||
|
@ -40,11 +40,18 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
wrapper.in("category_id", Arrays.asList(filter.getCategoryIds()));
|
||||
}
|
||||
|
||||
// 排序
|
||||
if (filter.getSortAlgo().equals("desc")) {
|
||||
wrapper.orderByDesc(filter.getSortField());
|
||||
String sortFiled = 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 {
|
||||
wrapper.orderByAsc(filter.getSortField());
|
||||
wrapper.orderByAsc(sortFiled);
|
||||
}
|
||||
|
||||
IPage<Resource> adminPage = new Page<>(page, size);
|
||||
|
@ -78,10 +78,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
wrapper.in("id", userIds);
|
||||
}
|
||||
|
||||
if (filter.getSortAlgo().equals("desc")) {
|
||||
wrapper.orderByDesc(filter.getSortField());
|
||||
String sortFiled = 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 {
|
||||
wrapper.orderByAsc(filter.getSortField());
|
||||
wrapper.orderByAsc(sortFiled);
|
||||
}
|
||||
|
||||
IPage<User> userPage = new Page<>(page, size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user