mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-22 00:39:32 +08:00
课程附件下载重构
This commit is contained in:
parent
d697ded1ec
commit
e28e2e30af
@ -16,10 +16,12 @@
|
|||||||
package xyz.playedu.api.controller.backend;
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import xyz.playedu.api.constant.BPermissionConstant;
|
import xyz.playedu.api.constant.BPermissionConstant;
|
||||||
import xyz.playedu.api.constant.BackendConstant;
|
import xyz.playedu.api.constant.BackendConstant;
|
||||||
import xyz.playedu.api.domain.CourseAttachment;
|
import xyz.playedu.api.domain.CourseAttachment;
|
||||||
@ -62,11 +64,7 @@ public class CourseAttachmentController {
|
|||||||
|
|
||||||
CourseAttachment courseAttachment =
|
CourseAttachment courseAttachment =
|
||||||
attachmentService.create(
|
attachmentService.create(
|
||||||
courseId,
|
courseId, req.getSort(), req.getTitle(), type, req.getRid());
|
||||||
req.getSort(),
|
|
||||||
req.getTitle(),
|
|
||||||
type,
|
|
||||||
req.getRid());
|
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
package xyz.playedu.api.controller.backend;
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
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;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import xyz.playedu.api.annotation.Log;
|
import xyz.playedu.api.annotation.Log;
|
||||||
import xyz.playedu.api.constant.BusinessType;
|
import xyz.playedu.api.constant.BusinessType;
|
||||||
import xyz.playedu.api.domain.*;
|
import xyz.playedu.api.domain.*;
|
||||||
@ -50,7 +52,8 @@ public class CourseAttachmentDownloadLogController {
|
|||||||
Integer courserAttachmentId = MapUtils.getInteger(params, "courser_attachment_id");
|
Integer courserAttachmentId = MapUtils.getInteger(params, "courser_attachment_id");
|
||||||
Integer rid = MapUtils.getInteger(params, "rid");
|
Integer rid = MapUtils.getInteger(params, "rid");
|
||||||
|
|
||||||
CourseAttachmentDownloadLogPaginateFiler filter = new CourseAttachmentDownloadLogPaginateFiler();
|
CourseAttachmentDownloadLogPaginateFiler filter =
|
||||||
|
new CourseAttachmentDownloadLogPaginateFiler();
|
||||||
filter.setUserId(userId);
|
filter.setUserId(userId);
|
||||||
filter.setCourseId(courseId);
|
filter.setCourseId(courseId);
|
||||||
filter.setTitle(title);
|
filter.setTitle(title);
|
||||||
@ -59,7 +62,8 @@ public class CourseAttachmentDownloadLogController {
|
|||||||
filter.setSortField(sortField);
|
filter.setSortField(sortField);
|
||||||
filter.setSortAlgo(sortAlgo);
|
filter.setSortAlgo(sortAlgo);
|
||||||
|
|
||||||
PaginationResult<CourseAttachmentDownloadLog> result = courseAttachmentDownloadLogService.paginate(page, size, filter);
|
PaginationResult<CourseAttachmentDownloadLog> result =
|
||||||
|
courseAttachmentDownloadLogService.paginate(page, size, filter);
|
||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("data", result.getData());
|
data.put("data", result.getData());
|
||||||
|
@ -27,7 +27,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import xyz.playedu.api.BCtx;
|
import xyz.playedu.api.BCtx;
|
||||||
import xyz.playedu.api.annotation.Log;
|
import xyz.playedu.api.annotation.Log;
|
||||||
import xyz.playedu.api.constant.BPermissionConstant;
|
import xyz.playedu.api.constant.BPermissionConstant;
|
||||||
import xyz.playedu.api.constant.BackendConstant;
|
|
||||||
import xyz.playedu.api.constant.BusinessType;
|
import xyz.playedu.api.constant.BusinessType;
|
||||||
import xyz.playedu.api.domain.*;
|
import xyz.playedu.api.domain.*;
|
||||||
import xyz.playedu.api.event.CourseDestroyEvent;
|
import xyz.playedu.api.event.CourseDestroyEvent;
|
||||||
@ -234,13 +233,18 @@ public class CourseController {
|
|||||||
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());
|
||||||
List<CourseHour> hours = hourService.getHoursByCourseId(course.getId());
|
List<CourseHour> hours = hourService.getHoursByCourseId(course.getId());
|
||||||
List<CourseAttachment> attachments = attachmentService.getAttachmentsByCourseId(course.getId());
|
List<CourseAttachment> attachments =
|
||||||
if(null != attachments && attachments.size() > 0){
|
attachmentService.getAttachmentsByCourseId(course.getId());
|
||||||
Map<Integer,String> resourceMap = resourceService.chunks(attachments.stream().map(CourseAttachment::getRid).toList())
|
if (null != attachments && attachments.size() > 0) {
|
||||||
.stream().collect(Collectors.toMap(Resource::getId, Resource::getUrl));
|
Map<Integer, String> resourceMap =
|
||||||
attachments.forEach(courseAttachment -> {
|
resourceService
|
||||||
courseAttachment.setUrl(resourceMap.get(courseAttachment.getRid()));
|
.chunks(attachments.stream().map(CourseAttachment::getRid).toList())
|
||||||
});
|
.stream()
|
||||||
|
.collect(Collectors.toMap(Resource::getId, Resource::getUrl));
|
||||||
|
attachments.forEach(
|
||||||
|
courseAttachment -> {
|
||||||
|
courseAttachment.setUrl(resourceMap.get(courseAttachment.getRid()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 杭州白书科技有限公司
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package xyz.playedu.api.controller.frontend;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import xyz.playedu.api.FCtx;
|
|
||||||
import xyz.playedu.api.domain.*;
|
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
|
||||||
import xyz.playedu.api.service.*;
|
|
||||||
import xyz.playedu.api.types.JsonResponse;
|
|
||||||
import xyz.playedu.api.util.IpUtil;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@Slf4j
|
|
||||||
@RequestMapping("/api/v1/course/{courseId}/attachment/{attachmentId}/resource")
|
|
||||||
public class CourseAttachmentDownloadLogController {
|
|
||||||
|
|
||||||
@Autowired private CourseService courseService;
|
|
||||||
|
|
||||||
@Autowired private CourseAttachmentDownloadLogService courseAttachmentDownloadLogService;
|
|
||||||
|
|
||||||
@PostMapping("/{id}")
|
|
||||||
public JsonResponse store(@PathVariable(name = "courseId") Integer courseId,
|
|
||||||
@PathVariable(name = "attachmentId") Integer attachmentId,
|
|
||||||
@PathVariable(name = "id") Integer id) throws NotFoundException {
|
|
||||||
Course course = courseService.findOrFail(courseId);
|
|
||||||
|
|
||||||
CourseAttachmentDownloadLog courseAttachmentDownloadLog =
|
|
||||||
new CourseAttachmentDownloadLog() {
|
|
||||||
{
|
|
||||||
setUserId(FCtx.getId());
|
|
||||||
setCourseId(course.getId());
|
|
||||||
setTitle(course.getTitle());
|
|
||||||
setCourserAttachmentId(attachmentId);
|
|
||||||
setRid(id);
|
|
||||||
setIp(IpUtil.getIpAddress());
|
|
||||||
setCreatedAt(new Date());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
courseAttachmentDownloadLogService.save(courseAttachmentDownloadLog);
|
|
||||||
return JsonResponse.success();
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,10 +27,11 @@ import xyz.playedu.api.service.*;
|
|||||||
import xyz.playedu.api.types.JsonResponse;
|
import xyz.playedu.api.types.JsonResponse;
|
||||||
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.IpUtil;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +57,8 @@ public class CourseController {
|
|||||||
|
|
||||||
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
|
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
|
||||||
|
|
||||||
|
@Autowired private CourseAttachmentDownloadLogService courseAttachmentDownloadLogService;
|
||||||
|
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||||
@ -78,24 +81,48 @@ public class CourseController {
|
|||||||
|
|
||||||
List<CourseHour> courseHours = hourService.getHoursByCourseId(course.getId());
|
List<CourseHour> courseHours = hourService.getHoursByCourseId(course.getId());
|
||||||
|
|
||||||
List<CourseAttachment> attachments = attachmentService.getAttachmentsByCourseId(course.getId());
|
List<CourseAttachment> attachments =
|
||||||
if(null != attachments && attachments.size() > 0){
|
attachmentService.getAttachmentsByCourseId(course.getId());
|
||||||
Map<Integer,String> resourceMap = resourceService.chunks(attachments.stream().map(CourseAttachment::getRid).toList())
|
|
||||||
.stream().collect(Collectors.toMap(Resource::getId, Resource::getUrl));
|
|
||||||
attachments.forEach(courseAttachment -> {
|
|
||||||
courseAttachment.setUrl(resourceMap.get(courseAttachment.getRid()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("course", course);
|
data.put("course", course);
|
||||||
data.put("chapters", chapterService.getChaptersByCourseId(course.getId()));
|
data.put("chapters", chapterService.getChaptersByCourseId(course.getId()));
|
||||||
data.put("hours", courseHours.stream().collect(Collectors.groupingBy(CourseHour::getChapterId)));
|
data.put(
|
||||||
|
"hours",
|
||||||
|
courseHours.stream().collect(Collectors.groupingBy(CourseHour::getChapterId)));
|
||||||
data.put("learn_record", userCourseRecordService.find(FCtx.getId(), course.getId()));
|
data.put("learn_record", userCourseRecordService.find(FCtx.getId(), course.getId()));
|
||||||
data.put("learn_hour_records",
|
data.put(
|
||||||
|
"learn_hour_records",
|
||||||
userCourseHourRecordService.getRecords(FCtx.getId(), course.getId()).stream()
|
userCourseHourRecordService.getRecords(FCtx.getId(), course.getId()).stream()
|
||||||
.collect(Collectors.toMap(UserCourseHourRecord::getHourId, e -> e)));
|
.collect(Collectors.toMap(UserCourseHourRecord::getHourId, e -> e)));
|
||||||
data.put("attachments", attachments);
|
data.put("attachments", attachments);
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{courseId}/attach/{id}")
|
||||||
|
@SneakyThrows
|
||||||
|
public JsonResponse attachmentDownload(
|
||||||
|
@PathVariable(name = "courseId") Integer courseId,
|
||||||
|
@PathVariable(name = "id") Integer id) {
|
||||||
|
CourseAttachment attachment = attachmentService.findOrFail(id, courseId);
|
||||||
|
Resource resource = resourceService.findOrFail(attachment.getRid());
|
||||||
|
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
data.put("download_url", resource.getUrl());
|
||||||
|
|
||||||
|
courseAttachmentDownloadLogService.save(
|
||||||
|
new CourseAttachmentDownloadLog() {
|
||||||
|
{
|
||||||
|
setUserId(FCtx.getId());
|
||||||
|
setCourseId(attachment.getCourseId());
|
||||||
|
setCourserAttachmentId(attachment.getId());
|
||||||
|
setRid(resource.getId());
|
||||||
|
setTitle(attachment.getTitle());
|
||||||
|
setIp(IpUtil.getIpAddress());
|
||||||
|
setCreatedAt(new Date());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return JsonResponse.data(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -106,7 +107,11 @@ public class CourseAttachmentDownloadLog implements Serializable {
|
|||||||
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
|
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
|
||||||
result = prime * result + ((getCourseId() == null) ? 0 : getCourseId().hashCode());
|
result = prime * result + ((getCourseId() == null) ? 0 : getCourseId().hashCode());
|
||||||
result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
|
result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
|
||||||
result = prime * result + ((getCourserAttachmentId() == null) ? 0 : getCourserAttachmentId().hashCode());
|
result =
|
||||||
|
prime * result
|
||||||
|
+ ((getCourserAttachmentId() == null)
|
||||||
|
? 0
|
||||||
|
: getCourserAttachmentId().hashCode());
|
||||||
result = prime * result + ((getRid() == null) ? 0 : getRid().hashCode());
|
result = prime * result + ((getRid() == null) ? 0 : getRid().hashCode());
|
||||||
result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode());
|
result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode());
|
||||||
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
package xyz.playedu.api.mapper;
|
package xyz.playedu.api.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
||||||
import xyz.playedu.api.types.paginate.CourseAttachmentDownloadLogPaginateFiler;
|
import xyz.playedu.api.types.paginate.CourseAttachmentDownloadLogPaginateFiler;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package xyz.playedu.api.request.backend;
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,6 +17,7 @@ package xyz.playedu.api.request.backend;
|
|||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -16,14 +16,15 @@
|
|||||||
package xyz.playedu.api.service;
|
package xyz.playedu.api.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
||||||
import xyz.playedu.api.types.paginate.CourseAttachmentDownloadLogPaginateFiler;
|
import xyz.playedu.api.types.paginate.CourseAttachmentDownloadLogPaginateFiler;
|
||||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public interface CourseAttachmentDownloadLogService extends IService<CourseAttachmentDownloadLog> {
|
public interface CourseAttachmentDownloadLogService extends IService<CourseAttachmentDownloadLog> {
|
||||||
PaginationResult<CourseAttachmentDownloadLog> paginate(int page, int size, CourseAttachmentDownloadLogPaginateFiler filter);
|
PaginationResult<CourseAttachmentDownloadLog> paginate(
|
||||||
|
int page, int size, CourseAttachmentDownloadLogPaginateFiler filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
package xyz.playedu.api.service.impl;
|
package xyz.playedu.api.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
import xyz.playedu.api.domain.CourseAttachmentDownloadLog;
|
||||||
import xyz.playedu.api.mapper.CourseAttachmentDownloadLogMapper;
|
import xyz.playedu.api.mapper.CourseAttachmentDownloadLogMapper;
|
||||||
import xyz.playedu.api.service.CourseAttachmentDownloadLogService;
|
import xyz.playedu.api.service.CourseAttachmentDownloadLogService;
|
||||||
@ -24,10 +26,12 @@ import xyz.playedu.api.types.paginate.CourseAttachmentDownloadLogPaginateFiler;
|
|||||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CourseAttachmentDownloadLogServiceImpl extends ServiceImpl<CourseAttachmentDownloadLogMapper, CourseAttachmentDownloadLog>
|
public class CourseAttachmentDownloadLogServiceImpl
|
||||||
|
extends ServiceImpl<CourseAttachmentDownloadLogMapper, CourseAttachmentDownloadLog>
|
||||||
implements CourseAttachmentDownloadLogService {
|
implements CourseAttachmentDownloadLogService {
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult<CourseAttachmentDownloadLog> paginate(int page, int size, CourseAttachmentDownloadLogPaginateFiler filter) {
|
public PaginationResult<CourseAttachmentDownloadLog> paginate(
|
||||||
|
int page, int size, CourseAttachmentDownloadLogPaginateFiler filter) {
|
||||||
filter.setPageStart((page - 1) * size);
|
filter.setPageStart((page - 1) * size);
|
||||||
filter.setPageSize(size);
|
filter.setPageSize(size);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user