mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-24 10:19:31 +08:00
返回资源分类的资源数量
This commit is contained in:
parent
cca6d050bc
commit
3b67766ab2
@ -1,5 +1,6 @@
|
|||||||
package xyz.playedu.api.controller.backend;
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.hash.Hash;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -69,7 +70,14 @@ public class CourseController {
|
|||||||
filter.setDepIds(depIds);
|
filter.setDepIds(depIds);
|
||||||
|
|
||||||
PaginationResult<Course> result = courseService.paginate(page, size, filter);
|
PaginationResult<Course> result = courseService.paginate(page, size, filter);
|
||||||
return JsonResponse.data(result);
|
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
data.put("data", result.getData());
|
||||||
|
data.put("total", result.getTotal());
|
||||||
|
data.put("category_count", courseService.getCategoryCount());
|
||||||
|
data.put("pure_total", courseService.total());
|
||||||
|
|
||||||
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
||||||
|
@ -77,6 +77,8 @@ public class ResourceController {
|
|||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("result", result);
|
data.put("result", result);
|
||||||
|
data.put("category_count", resourceService.getCategoryCount(type));
|
||||||
|
data.put("pure_total", resourceService.total(type));
|
||||||
|
|
||||||
if (type.equals(BackendConstant.RESOURCE_TYPE_VIDEO)) {
|
if (type.equals(BackendConstant.RESOURCE_TYPE_VIDEO)) {
|
||||||
List<ResourceVideo> resourceVideos = resourceVideoService.chunksByRids(result.getData().stream().map(Resource::getId).toList());
|
List<ResourceVideo> resourceVideos = resourceVideoService.chunksByRids(result.getData().stream().map(Resource::getId).toList());
|
||||||
|
@ -3,6 +3,9 @@ package xyz.playedu.api.mapper;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import xyz.playedu.api.domain.Course;
|
import xyz.playedu.api.domain.Course;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -13,6 +16,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface CourseMapper extends BaseMapper<Course> {
|
public interface CourseMapper extends BaseMapper<Course> {
|
||||||
|
|
||||||
|
List<CourseCategoryCountMapper> getCategoryCount();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,18 +3,25 @@ package xyz.playedu.api.mapper;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import xyz.playedu.api.domain.Resource;
|
import xyz.playedu.api.domain.Resource;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import xyz.playedu.api.types.mapper.ResourceCategoryCountMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
* @description 针对表【resources】的数据库操作Mapper
|
* @description 针对表【resources】的数据库操作Mapper
|
||||||
* @createDate 2023-03-13 10:25:30
|
* @createDate 2023-03-13 10:25:30
|
||||||
* @Entity xyz.playedu.api.domain.Resource
|
* @Entity xyz.playedu.api.domain.Resource
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ResourceMapper extends BaseMapper<Resource> {
|
public interface ResourceMapper extends BaseMapper<Resource> {
|
||||||
|
|
||||||
|
List<ResourceCategoryCountMapper> getCategoryCount(String type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
|||||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -42,4 +43,8 @@ public interface CourseService extends IService<Course> {
|
|||||||
List<Course> chunks(List<Integer> ids, List<String> fields);
|
List<Course> chunks(List<Integer> ids, List<String> fields);
|
||||||
|
|
||||||
List<Course> chunks(List<Integer> ids);
|
List<Course> chunks(List<Integer> ids);
|
||||||
|
|
||||||
|
Map<Integer, Integer> getCategoryCount();
|
||||||
|
|
||||||
|
Integer total();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import xyz.playedu.api.types.paginate.PaginationResult;
|
|||||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -29,4 +30,7 @@ public interface ResourceService extends IService<Resource> {
|
|||||||
|
|
||||||
List<Resource> chunks(List<Integer> ids, List<String> fields);
|
List<Resource> chunks(List<Integer> ids, List<String> fields);
|
||||||
|
|
||||||
|
Map<Integer, Integer> getCategoryCount(String type);
|
||||||
|
|
||||||
|
Integer total(String type);
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,13 @@ import xyz.playedu.api.service.CourseService;
|
|||||||
import xyz.playedu.api.mapper.CourseMapper;
|
import xyz.playedu.api.mapper.CourseMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.playedu.api.service.internal.ResourceCourseCategoryService;
|
import xyz.playedu.api.service.internal.ResourceCourseCategoryService;
|
||||||
|
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
||||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||||
import xyz.playedu.api.util.HelperUtil;
|
import xyz.playedu.api.util.HelperUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -208,6 +207,16 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
public List<Course> chunks(List<Integer> ids) {
|
public List<Course> chunks(List<Integer> ids) {
|
||||||
return list(query().getWrapper().in("id", ids));
|
return list(query().getWrapper().in("id", ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Integer, Integer> getCategoryCount() {
|
||||||
|
return getBaseMapper().getCategoryCount().stream().collect(Collectors.toMap(CourseCategoryCountMapper::getCid, CourseCategoryCountMapper::getTotal));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer total() {
|
||||||
|
return Math.toIntExact(count());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,15 +14,14 @@ import xyz.playedu.api.mapper.ResourceMapper;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.playedu.api.service.ResourceVideoService;
|
import xyz.playedu.api.service.ResourceVideoService;
|
||||||
import xyz.playedu.api.service.internal.ResourceCategoryRelationService;
|
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.PaginationResult;
|
||||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||||
import xyz.playedu.api.util.HelperUtil;
|
import xyz.playedu.api.util.HelperUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -155,6 +154,16 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
public List<Resource> chunks(List<Integer> ids, List<String> fields) {
|
public List<Resource> chunks(List<Integer> ids, List<String> fields) {
|
||||||
return list(query().getWrapper().in("id", ids).select(fields));
|
return list(query().getWrapper().in("id", ids).select(fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Integer, Integer> getCategoryCount(String type) {
|
||||||
|
return getBaseMapper().getCategoryCount(type).stream().collect(Collectors.toMap(ResourceCategoryCountMapper::getCid, ResourceCategoryCountMapper::getTotal));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer total(String type) {
|
||||||
|
return Math.toIntExact(count(query().getWrapper().eq("type", type)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package xyz.playedu.api.types.mapper;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/15 11:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CourseCategoryCountMapper {
|
||||||
|
|
||||||
|
private Integer cid;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package xyz.playedu.api.types.mapper;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/15 11:11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceCategoryCountMapper {
|
||||||
|
|
||||||
|
private Integer cid;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
}
|
@ -17,8 +17,14 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,title,thumb,
|
id,title,thumb,
|
||||||
charge,class_hour,is_show,
|
charge,class_hour,is_show,
|
||||||
created_at,updated_at,deleted_at
|
created_at,updated_at,deleted_at
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<select id="getCategoryCount" resultType="xyz.playedu.api.types.mapper.CourseCategoryCountMapper">
|
||||||
|
SELECT `resource_course_category`.`cid` as `cid`, count(*) as `total`
|
||||||
|
FROM `resource_course_category`
|
||||||
|
GROUP BY `resource_course_category`.`category_id`;
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
@ -21,10 +21,19 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,admin_id,type,
|
id,admin_id,type,
|
||||||
name,extension,size,
|
name,extension,size,
|
||||||
disk,file_id,path,
|
disk,file_id,path,
|
||||||
url,created_at,parent_id,
|
url,created_at,parent_id,
|
||||||
is_hidden
|
is_hidden
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<select id="getCategoryCount" resultType="xyz.playedu.api.types.mapper.ResourceCategoryCountMapper">
|
||||||
|
SELECT `resource_category`.`cid` as `cid`, count(*) as `total`
|
||||||
|
FROM `resources`
|
||||||
|
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||||
|
WHERE `resources`.`type` = #{type}
|
||||||
|
GROUP BY `resource_category`.`cid`;
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user