mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
feat: 课程列表相关接口
增加了“查看置顶课程列表”、“设置置顶”、“置顶排序”、“导出课程列表”接口,部分未完成
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
/**
|
||||
* 服务层返回
|
||||
* @param <T>
|
||||
*/
|
||||
public class ServiceResponse<T> {
|
||||
|
||||
private boolean success;
|
||||
|
||||
private String message;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <V> ServiceResponse<V> success(V data) {
|
||||
ServiceResponse<V> response = new ServiceResponse<>();
|
||||
response.setSuccess(true);
|
||||
response.setData(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static <V> ServiceResponse<V> failure(String message) {
|
||||
ServiceResponse<V> response = new ServiceResponse<>();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,12 @@ package com.xboe.module.course.service;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.module.course.dto.CoursePageQueryDTO;
|
||||
import com.xboe.module.course.dto.ServiceResponse;
|
||||
import com.xboe.module.course.vo.CoursePageVo;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
public interface ICoursePageService {
|
||||
|
||||
@@ -14,4 +19,34 @@ public interface ICoursePageService {
|
||||
* @return
|
||||
*/
|
||||
PageList<CoursePageVo> pageQuery(CurrentUser currentUser, CoursePageQueryDTO coursePageQueryDTO);
|
||||
|
||||
/**
|
||||
* 置顶列表
|
||||
* @return
|
||||
*/
|
||||
List<CoursePageVo> topList();
|
||||
|
||||
/**
|
||||
* 置顶/取消置顶
|
||||
* @param courseId
|
||||
* @param top true代表执行置顶操作,false代表执行取消置顶操作
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
ServiceResponse<Boolean> top(String courseId, boolean top);
|
||||
|
||||
/**
|
||||
* 置顶列表排序修改
|
||||
* @param topList
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
ServiceResponse<List<CoursePageVo>> topListSortChange(List<CoursePageVo> topList);
|
||||
|
||||
/**
|
||||
* 导出课程列表
|
||||
* @param coursePageQueryDTO
|
||||
* @param response
|
||||
*/
|
||||
void exportCourseList(CoursePageQueryDTO coursePageQueryDTO, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.xboe.data.outside.IOutSideDataService;
|
||||
import com.xboe.module.course.dao.CourseDao;
|
||||
import com.xboe.module.course.dao.CourseTeacherDao;
|
||||
import com.xboe.module.course.dto.CoursePageQueryDTO;
|
||||
import com.xboe.module.course.dto.ServiceResponse;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseTeacher;
|
||||
import com.xboe.module.course.service.ICoursePageService;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -42,7 +44,8 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
public PageList<CoursePageVo> pageQuery(CurrentUser currentUser, CoursePageQueryDTO coursePageQueryDTO) {
|
||||
/*
|
||||
* 1. 前置权限过滤
|
||||
* 权限说明:管理员登录后当前页面只可查看本人创建的课程及被授权的课程,其他课程不可见,被赋予查看权的用户可直接引用可查看的课程
|
||||
* 权限说明:管理员端 可查看本人创建的课程及被授权的课程,其他课程不可见,被赋予查看权的用户可直接引用可查看的课程;
|
||||
* 教师端 当前用户创建的课程及具有管理权、查看权的课程清单
|
||||
*/
|
||||
UserOrgIds userOrgIds = outSideDataService.getOrgIds();
|
||||
|
||||
@@ -54,7 +57,7 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
String currentAccountId = currentUser == null ? null : currentUser.getAccountId();
|
||||
|
||||
// 构建查询条件
|
||||
List<IFieldFilter> filters = createFilters(coursePageQueryDTO);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
|
||||
// 自动添加过滤已删除
|
||||
filters.add(FieldFilters.eq("c.deleted", false));
|
||||
@@ -79,6 +82,7 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
filters.add(FieldFilters.or(permissionFilters));
|
||||
}
|
||||
}
|
||||
filters.addAll(createFilters(coursePageQueryDTO));
|
||||
|
||||
QueryBuilder query = QueryBuilder.from(Course.class.getSimpleName() + " c").addFilters(filters);
|
||||
// 处理排序
|
||||
@@ -111,6 +115,69 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CoursePageVo> topList() {
|
||||
// 构建查询条件
|
||||
IFieldFilter fieldFilter = FieldFilters.eq("isTop", true);
|
||||
List<Course> courseList = courseDao.findList(fieldFilter);
|
||||
// 如果有值,查询教师数据
|
||||
List<CourseTeacher> courseTeacherList;
|
||||
if (!courseList.isEmpty()) {
|
||||
List<String> courseIds = courseList.stream()
|
||||
.map(Course::getId)
|
||||
.collect(Collectors.toList());
|
||||
courseTeacherList = getCourseTeacherList(courseIds);
|
||||
} else {
|
||||
courseTeacherList = new ArrayList<>();
|
||||
}
|
||||
return courseList.stream()
|
||||
.map(c -> convertToVo(c, courseTeacherList))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResponse<Boolean> top(String courseId, boolean top) {
|
||||
// 1. 查询课程数据
|
||||
Course course = courseDao.get(courseId);
|
||||
if (top) {
|
||||
// 2. 执行置顶操作
|
||||
// 2.1 目前课程是否已置顶
|
||||
if (course.getIsTop() != null && course.getIsTop()) {
|
||||
// 错误提示:已置顶
|
||||
return ServiceResponse.failure("已置顶");
|
||||
}
|
||||
// 2.2 查看置顶列表数量
|
||||
IFieldFilter fieldFilter = FieldFilters.eq("isTop", true);
|
||||
int topCount = courseDao.count(fieldFilter);
|
||||
if (topCount >= 10) {
|
||||
return ServiceResponse.failure("最多只能置顶10个课程");
|
||||
}
|
||||
// 2.3 设置置顶
|
||||
course.setIsTop(true);
|
||||
courseDao.update(course);
|
||||
} else {
|
||||
// 3. 取消置顶
|
||||
// 3.1 课程是否已置顶
|
||||
if (course.getIsTop() == null || !course.getIsTop()) {
|
||||
return ServiceResponse.failure("未置顶");
|
||||
}
|
||||
// 3.2 取消置顶
|
||||
course.setIsTop(false);
|
||||
course.setSortWeight(9999);
|
||||
courseDao.update(course);
|
||||
}
|
||||
return ServiceResponse.success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResponse<List<CoursePageVo>> topListSortChange(List<CoursePageVo> topList) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportCourseList(CoursePageQueryDTO coursePageQueryDTO, HttpServletResponse response) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成过滤条件
|
||||
*
|
||||
@@ -252,6 +319,9 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
|
||||
OrderCondition sortWeightOc = OrderCondition.asc("c.sortWeight");
|
||||
query.addOrder(sortWeightOc);
|
||||
|
||||
OrderCondition createTimeOc = OrderCondition.desc("c.sysCreateTime");
|
||||
query.addOrder(createTimeOc);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user