mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
feat:增加查询资源学习列表的contentName字段
This commit is contained in:
@@ -133,15 +133,15 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
*
|
||||
* @param pager 分页参数
|
||||
* @param courseId 25.11.25新增
|
||||
*
|
||||
* @param contentName 资源名称
|
||||
*/
|
||||
@RequestMapping(value = "/pagelist-resource", method = {RequestMethod.GET, RequestMethod.POST})
|
||||
public JsonResponse<PageList<CourseFinishCountDto>> findPageResource(Pagination pager, String courseId) {
|
||||
public JsonResponse<PageList<CourseFinishCountDto>> findPageResource(Pagination pager, String courseId, String contentName) {
|
||||
if (StringUtil.isBlank(courseId)) {
|
||||
return error("课程id不能为空");
|
||||
}
|
||||
try {
|
||||
PageList<CourseFinishCountDto> courseFinishCountDTOs = service.findPageResource(pager.getPageIndex(), pager.getPageSize(), courseId);
|
||||
PageList<CourseFinishCountDto> courseFinishCountDTOs = service.findPageResource(pager.getPageIndex(), pager.getPageSize(), courseId, contentName);
|
||||
return success(courseFinishCountDTOs);
|
||||
} catch (Exception e) {
|
||||
log.error("查询课程学习记录错误:{}", e.getMessage());
|
||||
|
||||
@@ -18,9 +18,10 @@ public class CourseStatDao extends BaseDao<StudyCourse> {
|
||||
* @param startIndex 分页开始索引
|
||||
* @param pageSize 分页大小
|
||||
* @param courseId 课程ID
|
||||
* @param contentName 资源名称
|
||||
* @return 课程完成人数统计DTO集合
|
||||
*/
|
||||
public List<CourseFinishCountDto> findFinishCountPage(int startIndex, int pageSize, String courseId) {
|
||||
public List<CourseFinishCountDto> findFinishCountPage(int startIndex, int pageSize, String courseId, String contentName) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ")
|
||||
// 课程名(和DTO字段对应)
|
||||
@@ -42,6 +43,13 @@ public class CourseStatDao extends BaseDao<StudyCourse> {
|
||||
sql.append("AND c.course_id = ? ");
|
||||
params.add(courseId);
|
||||
}
|
||||
// 25.12.1修改 新增:contentName模糊查询(粗略匹配)
|
||||
if (StringUtils.isNotBlank(contentName)) {
|
||||
// 实现“包含contentName”的模糊查询
|
||||
sql.append("AND c.content_name LIKE ? ");
|
||||
// 通配符%拼接在参数上防注入,表示“前后任意字符包含contentName”
|
||||
params.add("%" + contentName + "%");
|
||||
}
|
||||
// 分组+排序+分页(聚合函数必须分组,排序参考第一个代码的desc id)
|
||||
sql.append("GROUP BY c.content_id, c.content_name, cc.content_type ")
|
||||
.append("ORDER BY c.content_id DESC ")
|
||||
@@ -64,8 +72,14 @@ public class CourseStatDao extends BaseDao<StudyCourse> {
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
// 查总条数(返回int类型,匹配PageList的count字段)
|
||||
public int findFinishCountTotal(String courseId) {
|
||||
/**
|
||||
* 查询课程完成人数
|
||||
*
|
||||
* @param courseId 课程ID
|
||||
* @param contentName 资源名称
|
||||
* @return 课程完成人数
|
||||
*/
|
||||
public int findFinishCountTotal(String courseId, String contentName) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ")
|
||||
// 总条数=去重后的人数
|
||||
@@ -80,6 +94,13 @@ public class CourseStatDao extends BaseDao<StudyCourse> {
|
||||
sql.append("AND c.course_id = ? ");
|
||||
params.add(courseId);
|
||||
}
|
||||
// 25.12.1修改 新增:contentName模糊查询(粗略匹配)
|
||||
if (StringUtils.isNotBlank(contentName)) {
|
||||
// 实现“包含contentName”的模糊查询
|
||||
sql.append("AND c.content_name LIKE ? ");
|
||||
// 通配符%拼接在参数上防注入,表示“前后任意字符包含contentName”
|
||||
params.add("%" + contentName + "%");
|
||||
}
|
||||
// 用sqlCount替代sqlFindObject,直接返回int类型结果
|
||||
// sqlCount会执行SQL并返回COUNT的结果,无需手动转换Object
|
||||
return this.sqlCount(sql.toString(), params.toArray());
|
||||
|
||||
@@ -69,8 +69,9 @@ public interface IStudyCourseService {
|
||||
* @param pageIndex 页码
|
||||
* @param pageSize 每页数据条数
|
||||
* @param courseId 课程id
|
||||
* @param contentName 资源名称
|
||||
*/
|
||||
PageList<CourseFinishCountDto> findPageResource(int pageIndex, int pageSize, String courseId);
|
||||
PageList<CourseFinishCountDto> findPageResource(int pageIndex, int pageSize, String courseId, String contentName);
|
||||
|
||||
/**
|
||||
* 热度榜
|
||||
|
||||
@@ -233,15 +233,24 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
}
|
||||
return studyCoursePageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询课程的资源名称以及资源学习完成人数
|
||||
*
|
||||
* @param pageIndex 页码
|
||||
* @param pageSize 每页数据条数
|
||||
* @param courseId 课程id
|
||||
* @param contentName 资源名称
|
||||
*/
|
||||
@Override
|
||||
public PageList<CourseFinishCountDto> findPageResource(int pageIndex, int pageSize, String courseId) {
|
||||
public PageList<CourseFinishCountDto> findPageResource(int pageIndex, int pageSize, String courseId, String contentName) {
|
||||
// 1. 手动计算分页偏移量(数据库分页必需)
|
||||
// pageIndex<1时设为0,避免数据库LIMIT偏移量为负数
|
||||
int startIndex = (pageIndex < 1) ? 0 : (pageIndex - 1) * pageSize;
|
||||
// 2. 调用Dao层:查当前页数据(传入偏移量、每页条数、courseId条件)
|
||||
List<CourseFinishCountDto> dtoList = courseStatDao.findFinishCountPage(startIndex, pageSize, courseId);
|
||||
List<CourseFinishCountDto> dtoList = courseStatDao.findFinishCountPage(startIndex, pageSize, courseId,contentName);
|
||||
// 3. 调用Dao层:查总条数(对应PageList的count字段,用int类型,和PageList一致)
|
||||
int totalCount = courseStatDao.findFinishCountTotal(courseId);
|
||||
int totalCount = courseStatDao.findFinishCountTotal(courseId,contentName);
|
||||
// 4. 按PageList构造函数创建对象(只传list和count)
|
||||
PageList<CourseFinishCountDto> pageList = new PageList<>(dtoList, totalCount);
|
||||
// 5. 设置pageSize(覆盖默认10,确保总页数计算正确)
|
||||
|
||||
Reference in New Issue
Block a user