mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
fixed: 资源的列表无分类筛选 && 分类资源数量计算
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -17,9 +14,7 @@ import xyz.playedu.api.service.internal.ResourceCategoryRelationService;
|
||||
import xyz.playedu.api.types.mapper.ResourceCategoryCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -39,52 +34,13 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
|
||||
@Override
|
||||
public PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter) {
|
||||
QueryWrapper<Resource> wrapper = query().getWrapper().eq("is_hidden", 0);
|
||||
|
||||
if (filter.getName() != null) {
|
||||
wrapper.like("name", "%" + filter.getName() + "%");
|
||||
}
|
||||
if (filter.getDisk() != null) {
|
||||
wrapper.eq("disk", filter.getDisk());
|
||||
}
|
||||
if (filter.getExtension() != null) {
|
||||
wrapper.eq("extension", filter.getExtension());
|
||||
}
|
||||
if (filter.getType() != null) {
|
||||
wrapper.eq("type", filter.getType());
|
||||
}
|
||||
if (filter.getAdminId() != null && !filter.getAdminId().equals(0)) {
|
||||
wrapper.eq("admin_id", filter.getAdminId());
|
||||
}
|
||||
if (filter.getCategoryIds() != null && filter.getCategoryIds().trim().length() > 0) {
|
||||
List<Integer> categoryIds = Arrays.stream(filter.getCategoryIds().split(",")).map(Integer::valueOf).toList();
|
||||
List<Integer> ids = relationService.getRidsByCids(categoryIds);
|
||||
if (ids == null || ids.size() == 0) {
|
||||
ids = HelperUtil.zeroIntegerList();
|
||||
}
|
||||
wrapper.in("id", ids);
|
||||
}
|
||||
|
||||
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(sortFiled);
|
||||
}
|
||||
|
||||
IPage<Resource> adminPage = new Page<>(page, size);
|
||||
adminPage = page(adminPage, wrapper);
|
||||
|
||||
PaginationResult<Resource> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(adminPage.getRecords());
|
||||
pageResult.setTotal(adminPage.getTotal());
|
||||
|
||||
filter.setPageStart((page - 1) * size);
|
||||
filter.setPageSize(size);
|
||||
|
||||
pageResult.setData(getBaseMapper().paginate(filter));
|
||||
pageResult.setTotal(getBaseMapper().paginateCount(filter));
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
@@ -158,13 +114,13 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
@Override
|
||||
public Map<Integer, Integer> getCategoryCount(String type) {
|
||||
Map<Integer, Integer> data = getBaseMapper().getCategoryCount(type).stream().collect(Collectors.toMap(ResourceCategoryCountMapper::getCid, ResourceCategoryCountMapper::getTotal));
|
||||
data.put(0, getBaseMapper().getNoneCategoryCount(type));
|
||||
data.put(0, getBaseMapper().getNunCategoryCount(type));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer total(String type) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("type", type)));
|
||||
return Math.toIntExact(count(query().getWrapper().eq("type", type).eq("is_hidden", 0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user