mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 16:22:45 +08:00
线上课增加admin_id字段
This commit is contained in:
parent
179a7d5f62
commit
ee1f009966
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package xyz.playedu.api.controller.backend;
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
@ -28,9 +29,11 @@ import xyz.playedu.api.event.CourseDestroyEvent;
|
|||||||
import xyz.playedu.api.request.backend.CourseRequest;
|
import xyz.playedu.api.request.backend.CourseRequest;
|
||||||
import xyz.playedu.common.annotation.BackendPermission;
|
import xyz.playedu.common.annotation.BackendPermission;
|
||||||
import xyz.playedu.common.annotation.Log;
|
import xyz.playedu.common.annotation.Log;
|
||||||
|
import xyz.playedu.common.bus.BackendBus;
|
||||||
import xyz.playedu.common.constant.BPermissionConstant;
|
import xyz.playedu.common.constant.BPermissionConstant;
|
||||||
import xyz.playedu.common.constant.BusinessTypeConstant;
|
import xyz.playedu.common.constant.BusinessTypeConstant;
|
||||||
import xyz.playedu.common.context.BCtx;
|
import xyz.playedu.common.context.BCtx;
|
||||||
|
import xyz.playedu.common.domain.AdminUser;
|
||||||
import xyz.playedu.common.exception.NotFoundException;
|
import xyz.playedu.common.exception.NotFoundException;
|
||||||
import xyz.playedu.common.service.*;
|
import xyz.playedu.common.service.*;
|
||||||
import xyz.playedu.common.types.JsonResponse;
|
import xyz.playedu.common.types.JsonResponse;
|
||||||
@ -71,8 +74,12 @@ public class CourseController {
|
|||||||
|
|
||||||
@Autowired private DepartmentService departmentService;
|
@Autowired private DepartmentService departmentService;
|
||||||
|
|
||||||
|
@Autowired private AdminUserService adminUserService;
|
||||||
|
|
||||||
@Autowired private ApplicationContext ctx;
|
@Autowired private ApplicationContext ctx;
|
||||||
|
|
||||||
|
@Autowired private BackendBus backendBus;
|
||||||
|
|
||||||
@BackendPermission(slug = BPermissionConstant.COURSE)
|
@BackendPermission(slug = BPermissionConstant.COURSE)
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
@Log(title = "线上课-列表", businessType = BusinessTypeConstant.GET)
|
@Log(title = "线上课-列表", businessType = BusinessTypeConstant.GET)
|
||||||
@ -95,6 +102,10 @@ public class CourseController {
|
|||||||
filter.setDepIds(depIds);
|
filter.setDepIds(depIds);
|
||||||
filter.setIsRequired(isRequired);
|
filter.setIsRequired(isRequired);
|
||||||
|
|
||||||
|
if (!backendBus.isSuperAdmin()) {
|
||||||
|
filter.setAdminId(BCtx.getId());
|
||||||
|
}
|
||||||
|
|
||||||
PaginationResult<Course> result = courseService.paginate(page, size, filter);
|
PaginationResult<Course> result = courseService.paginate(page, size, filter);
|
||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
@ -107,6 +118,17 @@ public class CourseController {
|
|||||||
data.put("categories", categoryService.id2name());
|
data.put("categories", categoryService.id2name());
|
||||||
data.put("departments", departmentService.id2name());
|
data.put("departments", departmentService.id2name());
|
||||||
|
|
||||||
|
// 操作人
|
||||||
|
data.put("admin_users", new HashMap<>());
|
||||||
|
if (!result.getData().isEmpty()) {
|
||||||
|
Map<Integer, String> adminUsers =
|
||||||
|
adminUserService
|
||||||
|
.chunks(result.getData().stream().map(Course::getAdminId).toList())
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(AdminUser::getId, AdminUser::getName));
|
||||||
|
data.put("admin_users", adminUsers);
|
||||||
|
}
|
||||||
|
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +156,8 @@ public class CourseController {
|
|||||||
req.getIsRequired(),
|
req.getIsRequired(),
|
||||||
req.getIsShow(),
|
req.getIsShow(),
|
||||||
req.getCategoryIds(),
|
req.getCategoryIds(),
|
||||||
req.getDepIds());
|
req.getDepIds(),
|
||||||
|
BCtx.getId());
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
int classHourCount = 0;
|
int classHourCount = 0;
|
||||||
@ -240,6 +263,10 @@ public class CourseController {
|
|||||||
@Log(title = "线上课-编辑", businessType = BusinessTypeConstant.GET)
|
@Log(title = "线上课-编辑", businessType = BusinessTypeConstant.GET)
|
||||||
public JsonResponse edit(@PathVariable(name = "id") Integer id) throws NotFoundException {
|
public JsonResponse edit(@PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||||
Course course = courseService.findOrFail(id);
|
Course course = courseService.findOrFail(id);
|
||||||
|
if (!backendBus.isSuperAdmin() && !course.getAdminId().equals(BCtx.getId())) {
|
||||||
|
return JsonResponse.error("无权限操作");
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> depIds = courseService.getDepIdsByCourseId(course.getId());
|
List<Integer> depIds = courseService.getDepIdsByCourseId(course.getId());
|
||||||
List<Integer> categoryIds = courseService.getCategoryIdsByCourseId(course.getId());
|
List<Integer> categoryIds = courseService.getCategoryIdsByCourseId(course.getId());
|
||||||
List<CourseChapter> chapters = chapterService.getChaptersByCourseId(course.getId());
|
List<CourseChapter> chapters = chapterService.getChaptersByCourseId(course.getId());
|
||||||
@ -280,6 +307,10 @@ public class CourseController {
|
|||||||
@PathVariable(name = "id") Integer id, @RequestBody @Validated CourseRequest req)
|
@PathVariable(name = "id") Integer id, @RequestBody @Validated CourseRequest req)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
Course course = courseService.findOrFail(id);
|
Course course = courseService.findOrFail(id);
|
||||||
|
if (!backendBus.isSuperAdmin() && !course.getAdminId().equals(BCtx.getId())) {
|
||||||
|
return JsonResponse.error("无权限操作");
|
||||||
|
}
|
||||||
|
|
||||||
courseService.updateWithCategoryIdsAndDepIds(
|
courseService.updateWithCategoryIdsAndDepIds(
|
||||||
course,
|
course,
|
||||||
req.getTitle(),
|
req.getTitle(),
|
||||||
@ -290,15 +321,24 @@ public class CourseController {
|
|||||||
req.getPublishedAt(),
|
req.getPublishedAt(),
|
||||||
req.getCategoryIds(),
|
req.getCategoryIds(),
|
||||||
req.getDepIds());
|
req.getDepIds());
|
||||||
|
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BackendPermission(slug = BPermissionConstant.COURSE)
|
@BackendPermission(slug = BPermissionConstant.COURSE)
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@Log(title = "线上课-删除", businessType = BusinessTypeConstant.DELETE)
|
@Log(title = "线上课-删除", businessType = BusinessTypeConstant.DELETE)
|
||||||
|
@SneakyThrows
|
||||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||||
|
Course course = courseService.findOrFail(id);
|
||||||
|
if (!backendBus.isSuperAdmin() && !course.getAdminId().equals(BCtx.getId())) {
|
||||||
|
return JsonResponse.error("无权限操作");
|
||||||
|
}
|
||||||
|
|
||||||
courseService.removeById(id);
|
courseService.removeById(id);
|
||||||
|
|
||||||
ctx.publishEvent(new CourseDestroyEvent(this, BCtx.getId(), id));
|
ctx.publishEvent(new CourseDestroyEvent(this, BCtx.getId(), id));
|
||||||
|
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,4 +42,6 @@ public class CoursePaginateFiler {
|
|||||||
private Integer pageStart;
|
private Integer pageStart;
|
||||||
|
|
||||||
private Integer pageSize;
|
private Integer pageSize;
|
||||||
|
|
||||||
|
private Integer adminId;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,9 @@ public class Course implements Serializable {
|
|||||||
@JsonProperty("created_at")
|
@JsonProperty("created_at")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
|
|
||||||
|
@JsonProperty("admin_id")
|
||||||
|
private Integer adminId;
|
||||||
|
|
||||||
@JsonIgnore private Date updatedAt;
|
@JsonIgnore private Date updatedAt;
|
||||||
|
|
||||||
@JsonIgnore private Date deletedAt;
|
@JsonIgnore private Date deletedAt;
|
||||||
|
@ -42,7 +42,8 @@ public interface CourseService extends IService<Course> {
|
|||||||
Integer isRequired,
|
Integer isRequired,
|
||||||
Integer isShow,
|
Integer isShow,
|
||||||
Integer[] categoryIds,
|
Integer[] categoryIds,
|
||||||
Integer[] depIds);
|
Integer[] depIds,
|
||||||
|
Integer adminId);
|
||||||
|
|
||||||
void updateWithCategoryIdsAndDepIds(
|
void updateWithCategoryIdsAndDepIds(
|
||||||
Course course,
|
Course course,
|
||||||
|
@ -68,7 +68,8 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
Integer isRequired,
|
Integer isRequired,
|
||||||
Integer isShow,
|
Integer isShow,
|
||||||
Integer[] categoryIds,
|
Integer[] categoryIds,
|
||||||
Integer[] depIds) {
|
Integer[] depIds,
|
||||||
|
Integer adminId) {
|
||||||
// 创建课程
|
// 创建课程
|
||||||
Course course = new Course();
|
Course course = new Course();
|
||||||
course.setTitle(title);
|
course.setTitle(title);
|
||||||
@ -79,6 +80,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
course.setPublishedAt(new Date());
|
course.setPublishedAt(new Date());
|
||||||
course.setCreatedAt(new Date());
|
course.setCreatedAt(new Date());
|
||||||
course.setUpdatedAt(new Date());
|
course.setUpdatedAt(new Date());
|
||||||
|
course.setAdminId(adminId);
|
||||||
save(course);
|
save(course);
|
||||||
// 关联分类
|
// 关联分类
|
||||||
relateCategories(course, categoryIds);
|
relateCategories(course, categoryIds);
|
||||||
|
@ -75,6 +75,9 @@
|
|||||||
<if test="title != null and title != ''">
|
<if test="title != null and title != ''">
|
||||||
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="adminId != null">
|
||||||
|
AND `courses`.`admin_id` = #{adminId}
|
||||||
|
</if>
|
||||||
<if test="isRequired != null">
|
<if test="isRequired != null">
|
||||||
AND `courses`.`is_required` = #{isRequired}
|
AND `courses`.`is_required` = #{isRequired}
|
||||||
</if>
|
</if>
|
||||||
@ -164,6 +167,9 @@
|
|||||||
<if test="title != null and title != ''">
|
<if test="title != null and title != ''">
|
||||||
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="adminId != null">
|
||||||
|
AND `courses`.`admin_id` = #{adminId}
|
||||||
|
</if>
|
||||||
<if test="isRequired != null">
|
<if test="isRequired != null">
|
||||||
AND `courses`.`is_required` = #{isRequired}
|
AND `courses`.`is_required` = #{isRequired}
|
||||||
</if>
|
</if>
|
||||||
|
@ -701,6 +701,18 @@ public class MigrationCheck implements CommandLineRunner {
|
|||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
add(
|
||||||
|
new HashMap<>() {
|
||||||
|
{
|
||||||
|
put("table", "");
|
||||||
|
put("name", "20231113_10_00_add_admin_id_for_courses");
|
||||||
|
put(
|
||||||
|
"sql",
|
||||||
|
"""
|
||||||
|
ALTER TABLE `courses` add `admin_id` int(10) NOT NULL DEFAULT 0 COMMENT '管理员id';
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user