generated from youfool-project/youfool-prj-springboot-template
修改保存目录为可配置
This commit is contained in:
parent
6503e8a5d9
commit
b63f3bd0e8
|
|
@ -1,34 +1,32 @@
|
||||||
package com.chinaweal.youfool.course.controller;
|
package com.chinaweal.youfool.course.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.chinaweal.youfool.course.entity.Course;
|
import com.chinaweal.youfool.course.entity.Course;
|
||||||
import com.chinaweal.youfool.course.entity.CourseVideo;
|
|
||||||
import com.chinaweal.youfool.course.entity.CourseAttachment;
|
import com.chinaweal.youfool.course.entity.CourseAttachment;
|
||||||
import com.chinaweal.youfool.course.entity.CourseComment;
|
import com.chinaweal.youfool.course.entity.CourseComment;
|
||||||
import com.chinaweal.youfool.course.service.CourseService;
|
import com.chinaweal.youfool.course.entity.CourseVideo;
|
||||||
import com.chinaweal.youfool.course.service.CourseVideoService;
|
|
||||||
import com.chinaweal.youfool.course.service.CourseAttachmentService;
|
import com.chinaweal.youfool.course.service.CourseAttachmentService;
|
||||||
import com.chinaweal.youfool.course.service.CourseCommentService;
|
import com.chinaweal.youfool.course.service.CourseCommentService;
|
||||||
|
import com.chinaweal.youfool.course.service.CourseService;
|
||||||
|
import com.chinaweal.youfool.course.service.CourseVideoService;
|
||||||
|
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
|
||||||
|
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||||
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
|
||||||
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
|
|
||||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,6 +35,7 @@ import java.util.UUID;
|
||||||
* @author lroyia
|
* @author lroyia
|
||||||
* @since 2025/10/24
|
* @since 2025/10/24
|
||||||
**/
|
**/
|
||||||
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
public class PageController {
|
public class PageController {
|
||||||
|
|
||||||
|
|
@ -52,6 +51,9 @@ public class PageController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CourseCommentService courseCommentService;
|
private CourseCommentService courseCommentService;
|
||||||
|
|
||||||
|
@Value("${file.savePath:}")
|
||||||
|
private String fileSavePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录页面
|
* 登录页面
|
||||||
*
|
*
|
||||||
|
|
@ -103,9 +105,9 @@ public class PageController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public String indexPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
public String indexPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
@RequestParam(required = false) String courseName,
|
@RequestParam(required = false) String courseName,
|
||||||
Model model) {
|
Model model) {
|
||||||
if (!StpUtil.isLogin()) {
|
if (!StpUtil.isLogin()) {
|
||||||
return "redirect:/course/login";
|
return "redirect:/course/login";
|
||||||
}
|
}
|
||||||
|
|
@ -125,15 +127,15 @@ public class PageController {
|
||||||
/**
|
/**
|
||||||
* 课程详情页面
|
* 课程详情页面
|
||||||
*
|
*
|
||||||
* @param id 课程ID
|
* @param id 课程ID
|
||||||
* @param commentPage 评论页码
|
* @param commentPage 评论页码
|
||||||
* @param model 模型对象
|
* @param model 模型对象
|
||||||
* @return 课程详情页面
|
* @return 课程详情页面
|
||||||
*/
|
*/
|
||||||
@GetMapping("/detail/{id}")
|
@GetMapping("/detail/{id}")
|
||||||
public String courseDetail(@PathVariable String id,
|
public String courseDetail(@PathVariable String id,
|
||||||
@RequestParam(defaultValue = "1") Integer commentPage,
|
@RequestParam(defaultValue = "1") Integer commentPage,
|
||||||
Model model) {
|
Model model) {
|
||||||
if (!StpUtil.isLogin()) {
|
if (!StpUtil.isLogin()) {
|
||||||
return "redirect:/course/login";
|
return "redirect:/course/login";
|
||||||
}
|
}
|
||||||
|
|
@ -247,11 +249,11 @@ public class PageController {
|
||||||
/**
|
/**
|
||||||
* 发布课程
|
* 发布课程
|
||||||
*
|
*
|
||||||
* @param courseName 课程名称
|
* @param courseName 课程名称
|
||||||
* @param courseDesc 课程描述
|
* @param courseDesc 课程描述
|
||||||
* @param videoFile 课程视频文件(可选)
|
* @param videoFile 课程视频文件(可选)
|
||||||
* @param attachment 课程附件文件(可选)
|
* @param attachment 课程附件文件(可选)
|
||||||
* @param model 模型对象
|
* @param model 模型对象
|
||||||
* @return 发布结果
|
* @return 发布结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/publish")
|
@PostMapping("/publish")
|
||||||
|
|
@ -313,10 +315,10 @@ public class PageController {
|
||||||
saveUploadFile(attachment, courseId, "attachment");
|
saveUploadFile(attachment, courseId, "attachment");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RestResult.ok(courseId, "课程发布成功");
|
return RestResult.ok(courseId);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("课程发布失败", e);
|
||||||
return RestResult.error(BaseResultCode.BUSINESS_LOGIC_ERROR, "课程发布失败:" + e.getMessage());
|
return RestResult.error(BaseResultCode.BUSINESS_LOGIC_ERROR, "课程发布失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -344,9 +346,7 @@ public class PageController {
|
||||||
String newFileName = UUID.randomUUID().toString() + "." + fileFormat;
|
String newFileName = UUID.randomUUID().toString() + "." + fileFormat;
|
||||||
|
|
||||||
// 创建上传目录
|
// 创建上传目录
|
||||||
String uploadDir = "../uploads/courses/" + LocalDate.now().getYear() + "/" +
|
String uploadDir = fileSavePath + "/" + courseId;
|
||||||
String.format("%02d", LocalDate.now().getMonthValue()) + "/" +
|
|
||||||
String.format("%02d", LocalDate.now().getDayOfMonth());
|
|
||||||
Path uploadPath = Paths.get(uploadDir);
|
Path uploadPath = Paths.get(uploadDir);
|
||||||
if (!uploadPath.toFile().exists()) {
|
if (!uploadPath.toFile().exists()) {
|
||||||
uploadPath.toFile().mkdirs();
|
uploadPath.toFile().mkdirs();
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ server:
|
||||||
context-path: ${COURSE_CONTEXT_PATH:/course}
|
context-path: ${COURSE_CONTEXT_PATH:/course}
|
||||||
port: ${COURSE_PORT:8080}
|
port: ${COURSE_PORT:8080}
|
||||||
|
|
||||||
|
file:
|
||||||
|
savePath: ${FILE_SAVE_PATH:../file}
|
||||||
|
|
||||||
# Sa-Token配置
|
# Sa-Token配置
|
||||||
sa-token:
|
sa-token:
|
||||||
# token名称 (同时也是cookie名称)
|
# token名称 (同时也是cookie名称)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue