From 4387471d76d54ae9b957af134b23d07dcedfbe9d Mon Sep 17 00:00:00 2001 From: xxx Date: Tue, 29 Aug 2023 14:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E4=B8=8A=E6=9E=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/backend/CourseController.java | 15 ++-- .../controller/frontend/CourseController.java | 20 +---- .../controller/frontend/UserController.java | 20 +++-- .../api/request/backend/CourseRequest.java | 4 + .../src/main/resources/application.yml | 2 +- .../xyz/playedu/course/domain/Course.java | 90 ++----------------- .../playedu/course/service/CourseService.java | 2 + .../service/impl/CourseServiceImpl.java | 6 ++ .../main/resources/mapper/CourseMapper.xml | 3 +- 9 files changed, 41 insertions(+), 121 deletions(-) diff --git a/playedu-api/src/main/java/xyz/playedu/api/controller/backend/CourseController.java b/playedu-api/src/main/java/xyz/playedu/api/controller/backend/CourseController.java index bbfc5f0..2ad8280 100644 --- a/playedu-api/src/main/java/xyz/playedu/api/controller/backend/CourseController.java +++ b/playedu-api/src/main/java/xyz/playedu/api/controller/backend/CourseController.java @@ -138,7 +138,7 @@ public class CourseController { Date now = new Date(); int classHourCount = 0; - if (req.getHours().size() > 0) { // 无章节课时配置 + if (!req.getHours().isEmpty()) { // 无章节课时配置 List insertHours = new ArrayList<>(); final Integer[] chapterSort = {0}; for (CourseRequest.HourItem hourItem : req.getHours()) { @@ -156,12 +156,12 @@ public class CourseController { } }); } - if (insertHours.size() > 0) { + if (!insertHours.isEmpty()) { hourService.saveBatch(insertHours); classHourCount = insertHours.size(); } } else { - if (req.getChapters().size() == 0) { + if (req.getChapters().isEmpty()) { return JsonResponse.error("请配置课时"); } @@ -199,7 +199,7 @@ public class CourseController { }); } } - if (insertHours.size() > 0) { + if (!insertHours.isEmpty()) { hourService.saveBatch(insertHours); classHourCount = insertHours.size(); } @@ -210,7 +210,7 @@ public class CourseController { } // 课程附件 - if (null != req.getAttachments() && req.getAttachments().size() > 0) { + if (null != req.getAttachments() && !req.getAttachments().isEmpty()) { List insertAttachments = new ArrayList<>(); final Integer[] sort = {0}; for (CourseRequest.AttachmentItem attachmentItem : req.getAttachments()) { @@ -226,7 +226,7 @@ public class CourseController { } }); } - if (insertAttachments.size() > 0) { + if (!insertAttachments.isEmpty()) { attachmentService.saveBatch(insertAttachments); } } @@ -245,7 +245,7 @@ public class CourseController { List hours = hourService.getHoursByCourseId(course.getId()); List attachments = attachmentService.getAttachmentsByCourseId(course.getId()); - if (null != attachments && attachments.size() > 0) { + if (null != attachments && !attachments.isEmpty()) { Map resourceMap = resourceService .chunks(attachments.stream().map(CourseAttachment::getRid).toList()) @@ -286,6 +286,7 @@ public class CourseController { req.getShortDesc(), req.getIsRequired(), req.getIsShow(), + req.getPublishedAt(), req.getCategoryIds(), req.getDepIds()); return JsonResponse.success(); diff --git a/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/CourseController.java b/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/CourseController.java index 56f9e2b..b32ded2 100644 --- a/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/CourseController.java +++ b/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/CourseController.java @@ -17,14 +17,11 @@ package xyz.playedu.api.controller.frontend; import lombok.SneakyThrows; -import org.apache.commons.collections4.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import xyz.playedu.common.context.FCtx; import xyz.playedu.common.types.JsonResponse; -import xyz.playedu.common.types.paginate.CoursePaginateFiler; -import xyz.playedu.common.types.paginate.PaginationResult; import xyz.playedu.common.util.IpUtil; import xyz.playedu.course.domain.*; import xyz.playedu.course.service.*; @@ -63,21 +60,6 @@ public class CourseController { @Autowired private CourseAttachmentDownloadLogService courseAttachmentDownloadLogService; - @GetMapping("/index") - public JsonResponse index(@RequestParam HashMap params) { - Integer page = MapUtils.getInteger(params, "page", 1); - Integer size = MapUtils.getInteger(params, "size", 10); - String categoryIds = MapUtils.getString(params, "category_ids"); - - CoursePaginateFiler filer = new CoursePaginateFiler(); - filer.setIsShow(1); - filer.setCategoryIds(categoryIds); - - PaginationResult result = courseService.paginate(page, size, filer); - - return JsonResponse.data(result); - } - @GetMapping("/{id}") @SneakyThrows public JsonResponse detail(@PathVariable(name = "id") Integer id) { @@ -87,7 +69,7 @@ public class CourseController { List attachments = attachmentService.getAttachmentsByCourseId(course.getId()); - if (null != attachments && attachments.size() > 0) { + if (null != attachments && !attachments.isEmpty()) { Map resourceMap = resourceService .chunks(attachments.stream().map(CourseAttachment::getRid).toList()) diff --git a/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/UserController.java b/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/UserController.java index 9994e7f..d154fc8 100644 --- a/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/UserController.java +++ b/playedu-api/src/main/java/xyz/playedu/api/controller/frontend/UserController.java @@ -68,7 +68,7 @@ public class UserController { User user = FCtx.getUser(); List departments = new ArrayList<>(); List depIds = userService.getDepIdsByUserId(user.getId()); - if (depIds != null && depIds.size() > 0) { + if (depIds != null && !depIds.isEmpty()) { departments = departmentService.listByIds(depIds); } @@ -134,17 +134,21 @@ public class UserController { // 全部部门课 List openCourses = courseService.getOpenCoursesAndShow(500, categoryId); // 汇总到一个list中 - if (depCourses != null && depCourses.size() > 0) { + if (depCourses != null && !depCourses.isEmpty()) { courses.addAll(depCourses); } - if (openCourses != null && openCourses.size() > 0) { + if (openCourses != null && !openCourses.isEmpty()) { courses.addAll(openCourses); } // 对结果进行排序->按照课程id倒序 - if (courses.size() > 0) { + if (!courses.isEmpty()) { courses = courses.stream() - .sorted(Comparator.comparing(Course::getId).reversed()) + .sorted( + Comparator.comparing( + Course::getPublishedAt, + Comparator.nullsFirst(Date::compareTo)) + .reversed()) .toList(); } @@ -154,7 +158,7 @@ public class UserController { // -------- 读取学习进度 ---------- Map learnCourseRecords = new HashMap<>(); - if (courses.size() > 0) { + if (!courses.isEmpty()) { learnCourseRecords = userCourseRecordService.chunk(FCtx.getId(), courseIds).stream() .collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e)); @@ -174,7 +178,7 @@ public class UserController { Long learnDuration = userLearnDurationStatsService.userDuration(FCtx.getId()); // 学习总时长 // -------- 学习数据统计 ---------- - if (courses.size() > 0) { + if (!courses.isEmpty()) { for (Course courseItem : courses) { if (courseItem.getIsRequired() == 1) { requiredHourCount += courseItem.getClassHour(); @@ -233,7 +237,7 @@ public class UserController { // 读取当前学员最近100条学习的线上课 List userCourseHourRecords = userCourseHourRecordService.getLatestCourseIds(FCtx.getId(), 100); - if (userCourseHourRecords == null || userCourseHourRecords.size() == 0) { + if (userCourseHourRecords == null || userCourseHourRecords.isEmpty()) { return JsonResponse.data(new ArrayList<>()); } diff --git a/playedu-api/src/main/java/xyz/playedu/api/request/backend/CourseRequest.java b/playedu-api/src/main/java/xyz/playedu/api/request/backend/CourseRequest.java index 7833f3b..d94d981 100644 --- a/playedu-api/src/main/java/xyz/playedu/api/request/backend/CourseRequest.java +++ b/playedu-api/src/main/java/xyz/playedu/api/request/backend/CourseRequest.java @@ -22,6 +22,7 @@ import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.util.Date; import java.util.List; /** @@ -58,6 +59,9 @@ public class CourseRequest { @JsonProperty("category_ids") private Integer[] categoryIds; + @JsonProperty("published_at") + private Date publishedAt; + @Data public static class HourItem { private String name; diff --git a/playedu-api/src/main/resources/application.yml b/playedu-api/src/main/resources/application.yml index cbb6f60..5399cd3 100644 --- a/playedu-api/src/main/resources/application.yml +++ b/playedu-api/src/main/resources/application.yml @@ -34,7 +34,7 @@ spring: max-wait: 30000 # 连接池最大阻塞等待时间(使用负数表示没有限制,默认-1) max-active: 100 # 连接池最大连接数(使用负数表示没有限制,默认8) max-idle: 20 # 连接池中的最大空闲连接(默认8) - min-idle: 5 # 连接池中的最小空闲连接(默认0) + min-idle: 1 # 连接池中的最小空闲连接(默认0) # 线程池配置 task: execution: diff --git a/playedu-course/src/main/java/xyz/playedu/course/domain/Course.java b/playedu-course/src/main/java/xyz/playedu/course/domain/Course.java index e4aa174..0a1f3bc 100644 --- a/playedu-course/src/main/java/xyz/playedu/course/domain/Course.java +++ b/playedu-course/src/main/java/xyz/playedu/course/domain/Course.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import java.io.Serial; import java.io.Serializable; import java.util.Date; @@ -62,6 +63,9 @@ public class Course implements Serializable { @JsonProperty("is_show") private Integer isShow; + @JsonProperty("published_at") + private Date publishedAt; + @JsonProperty("created_at") private Date createdAt; @@ -69,91 +73,7 @@ public class Course implements Serializable { @JsonIgnore private Date deletedAt; + @Serial @TableField(exist = false) private static final long serialVersionUID = 1L; - - @Override - public boolean equals(Object that) { - if (this == that) { - return true; - } - if (that == null) { - return false; - } - if (getClass() != that.getClass()) { - return false; - } - Course other = (Course) that; - return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) - && (this.getTitle() == null - ? other.getTitle() == null - : this.getTitle().equals(other.getTitle())) - && (this.getThumb() == null - ? other.getThumb() == null - : this.getThumb().equals(other.getThumb())) - && (this.getCharge() == null - ? other.getCharge() == null - : this.getCharge().equals(other.getCharge())) - && (this.getClassHour() == null - ? other.getClassHour() == null - : this.getClassHour().equals(other.getClassHour())) - && (this.getIsShow() == null - ? other.getIsShow() == null - : this.getIsShow().equals(other.getIsShow())) - && (this.getIsRequired() == null - ? other.getIsRequired() == null - : this.getIsRequired().equals(other.getIsRequired())) - && (this.getCreatedAt() == null - ? other.getCreatedAt() == null - : this.getCreatedAt().equals(other.getCreatedAt())) - && (this.getUpdatedAt() == null - ? other.getUpdatedAt() == null - : this.getUpdatedAt().equals(other.getUpdatedAt())) - && (this.getDeletedAt() == null - ? other.getDeletedAt() == null - : this.getDeletedAt().equals(other.getDeletedAt())) - && (this.getShortDesc() == null - ? other.getShortDesc() == null - : this.getShortDesc().equals(other.getShortDesc())); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); - result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode()); - result = prime * result + ((getThumb() == null) ? 0 : getThumb().hashCode()); - result = prime * result + ((getCharge() == null) ? 0 : getCharge().hashCode()); - result = prime * result + ((getShortDesc() == null) ? 0 : getShortDesc().hashCode()); - result = prime * result + ((getClassHour() == null) ? 0 : getClassHour().hashCode()); - result = prime * result + ((getIsShow() == null) ? 0 : getIsShow().hashCode()); - result = prime * result + ((getIsRequired() == null) ? 0 : getIsRequired().hashCode()); - result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode()); - result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode()); - result = prime * result + ((getDeletedAt() == null) ? 0 : getDeletedAt().hashCode()); - return result; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(getClass().getSimpleName()); - sb.append(" ["); - sb.append("Hash = ").append(hashCode()); - sb.append(", id=").append(id); - sb.append(", title=").append(title); - sb.append(", thumb=").append(thumb); - sb.append(", charge=").append(charge); - sb.append(", shortDesc=").append(shortDesc); - sb.append(", classHour=").append(classHour); - sb.append(", isShow=").append(isShow); - sb.append(", isRequired=").append(isRequired); - sb.append(", createdAt=").append(createdAt); - sb.append(", updatedAt=").append(updatedAt); - sb.append(", deletedAt=").append(deletedAt); - sb.append(", serialVersionUID=").append(serialVersionUID); - sb.append("]"); - return sb.toString(); - } } diff --git a/playedu-course/src/main/java/xyz/playedu/course/service/CourseService.java b/playedu-course/src/main/java/xyz/playedu/course/service/CourseService.java index 12d2818..f456489 100644 --- a/playedu-course/src/main/java/xyz/playedu/course/service/CourseService.java +++ b/playedu-course/src/main/java/xyz/playedu/course/service/CourseService.java @@ -22,6 +22,7 @@ import xyz.playedu.common.types.paginate.CoursePaginateFiler; import xyz.playedu.common.types.paginate.PaginationResult; import xyz.playedu.course.domain.Course; +import java.util.Date; import java.util.List; import java.util.Map; @@ -50,6 +51,7 @@ public interface CourseService extends IService { String shortDesc, Integer isRequired, Integer isShow, + Date publishedAt, Integer[] categoryIds, Integer[] depIds); diff --git a/playedu-course/src/main/java/xyz/playedu/course/service/impl/CourseServiceImpl.java b/playedu-course/src/main/java/xyz/playedu/course/service/impl/CourseServiceImpl.java index bc7e5ec..b61ac9b 100644 --- a/playedu-course/src/main/java/xyz/playedu/course/service/impl/CourseServiceImpl.java +++ b/playedu-course/src/main/java/xyz/playedu/course/service/impl/CourseServiceImpl.java @@ -76,6 +76,7 @@ public class CourseServiceImpl extends ServiceImpl impleme course.setShortDesc(shortDesc); course.setIsShow(isShow); course.setIsRequired(isRequired); + course.setPublishedAt(new Date()); course.setCreatedAt(new Date()); course.setUpdatedAt(new Date()); save(course); @@ -146,6 +147,7 @@ public class CourseServiceImpl extends ServiceImpl impleme String shortDesc, Integer isRequired, Integer isShow, + Date publishedAt, Integer[] categoryIds, Integer[] depIds) { Course newCourse = new Course(); @@ -156,6 +158,10 @@ public class CourseServiceImpl extends ServiceImpl impleme newCourse.setIsRequired(isRequired); newCourse.setShortDesc(shortDesc); + if (null != publishedAt) { + newCourse.setPublishedAt(publishedAt); + } + updateById(newCourse); resetRelateCategories(newCourse, categoryIds); diff --git a/playedu-course/src/main/resources/mapper/CourseMapper.xml b/playedu-course/src/main/resources/mapper/CourseMapper.xml index 6d86571..779ebd5 100644 --- a/playedu-course/src/main/resources/mapper/CourseMapper.xml +++ b/playedu-course/src/main/resources/mapper/CourseMapper.xml @@ -13,6 +13,7 @@ + @@ -21,7 +22,7 @@ id,title,thumb,short_desc, charge,class_hour,is_show, - is_required,created_at,updated_at, + is_required,published_at,created_at,updated_at, deleted_at