diff --git a/pom.xml b/pom.xml
index ee03296..762daf4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,6 +57,28 @@
+
+
+ org.apache.poi
+ poi
+ 4.1.2
+
+
+
+ org.apache.poi
+ poi-ooxml
+ 4.1.2
+
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 4.1.2
+
+
+
+
+
com.aliyun.oss
aliyun-sdk-oss
@@ -177,6 +199,17 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.6
+
+ UTF-8
+
+ docx
+
+
+
diff --git a/src/main/java/com/teaching/backend/controller/CommonController.java b/src/main/java/com/teaching/backend/controller/CommonController.java
index daceb35..af648df 100644
--- a/src/main/java/com/teaching/backend/controller/CommonController.java
+++ b/src/main/java/com/teaching/backend/controller/CommonController.java
@@ -2,19 +2,19 @@ package com.teaching.backend.controller;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.model.OSSObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
+import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
-import com.teaching.backend.model.entity.FileTable;
-import com.teaching.backend.service.FileTableService;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
+import com.teaching.backend.model.entity.CourseResources;
+import com.teaching.backend.service.CourseResourcesService;
+
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -22,9 +22,8 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
-import java.awt.*;
+
import java.io.*;
import java.nio.file.Paths;
import java.util.Date;
@@ -44,7 +43,7 @@ public class CommonController {
@Resource
- private FileTableService fileTableService;
+ private CourseResourcesService courseResourcesService;
@Value("${aliyun.oss.endpoint}")
private String endpoint;
@@ -60,21 +59,30 @@ public class CommonController {
@PostMapping("/upload")
- public BaseResponse upload(@RequestParam("courseId") String courseId, MultipartFile file) throws IOException {
+ public BaseResponse upload(MultipartFile file) throws IOException {
+// if (file.getSize() > (10)) {
+// return ResultUtils.error(690,"内容太大啦!");
+// }
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
-
+ Integer Filetype;
String subDir;
if (suffix.equalsIgnoreCase(".jpg") || suffix.equalsIgnoreCase(".jpeg") || suffix.equalsIgnoreCase(".png")) {
subDir = "img/";
+ Filetype=1 ;
} else if (suffix.equalsIgnoreCase(".mp4") || suffix.equalsIgnoreCase(".avi") || suffix.equalsIgnoreCase(".mov")) {
subDir = "video/";
- } else {
+ Filetype=2 ;
+ } else if (suffix.equalsIgnoreCase(".mp3") || suffix.equalsIgnoreCase(".wav") || suffix.equalsIgnoreCase(".flac")) {
+ subDir = "video/";
+ Filetype = 3;
+ }else {
subDir = "others/";
+ Filetype=4;
}
@@ -84,9 +92,11 @@ public class CommonController {
ossClient.putObject(bucketName, subDir + fileName, file.getInputStream());
- String objectUrl = ossClient.generatePresignedUrl(bucketName, subDir + fileName, new Date(System.currentTimeMillis() + 3600 * 1000)).toString();
+// String objectUrl = ossClient.generatePresignedUrl(bucketName, subDir + fileName, new Date(System.currentTimeMillis() + 3600 * 1000)).toString();
- fileTableService.updateFile(courseId, fileName, objectUrl); // 更新文件路径为OSS生成的URL
+ String objectUrl = "https://" + bucketName + "." + endpoint + "/" + subDir + fileName;
+ Integer type=Filetype;
+ courseResourcesService.updateFile(type, fileName, objectUrl); // 更新文件路径为OSS生成的URL
ossClient.shutdown();
@@ -97,23 +107,25 @@ public class CommonController {
//文件下载
@GetMapping("/download")
- public BaseResponse download(@RequestParam String courseId, @RequestParam String path, HttpServletResponse response) throws IOException {
+ public BaseResponse download(@RequestParam String Id, @RequestParam String path, HttpServletResponse response) throws IOException {
System.out.println("执行了下载的方法");
- fileTableService.download(courseId,path,response,endpoint,accessKeyId,accessKeySecret,bucketName);
+ courseResourcesService.download(Id,path,response,endpoint,accessKeyId,accessKeySecret,bucketName);
return ResultUtils.success("成功");
}
@GetMapping("/get/record")
- public BaseResponse> pageBaseResponse(int page,int pageSize){
+ public BaseResponse> pageBaseResponse(@RequestParam Integer type, Integer page,Integer pageSize){
+
- Page pageInfo=new Page<>(page,pageSize);
+ Page pageInfo=new Page<>(page,pageSize);
- LambdaQueryWrapper lambdaQueryWrapper=new LambdaQueryWrapper<>();
+ LambdaQueryWrapper lambdaQueryWrapper=new LambdaQueryWrapper<>();
+ lambdaQueryWrapper.eq(type!=null,CourseResources::getType,type);
- fileTableService.page(pageInfo, lambdaQueryWrapper);
+ courseResourcesService.page(pageInfo, lambdaQueryWrapper);
return ResultUtils.success(pageInfo);
diff --git a/src/main/java/com/teaching/backend/controller/FavourInformation/FavourInformationController.java b/src/main/java/com/teaching/backend/controller/FavourInformation/FavourInformationController.java
new file mode 100644
index 0000000..ce6d646
--- /dev/null
+++ b/src/main/java/com/teaching/backend/controller/FavourInformation/FavourInformationController.java
@@ -0,0 +1,53 @@
+package com.teaching.backend.controller.FavourInformation;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.teaching.backend.common.BaseResponse;
+import com.teaching.backend.common.ErrorCode;
+import com.teaching.backend.common.PageRequest;
+import com.teaching.backend.common.ResultUtils;
+import com.teaching.backend.exception.BusinessException;
+import com.teaching.backend.model.dto.favour.resourceFavour.ResourceFavourAddRequest;
+import com.teaching.backend.model.entity.CourseResources;
+import com.teaching.backend.model.entity.favour.SeCourseFavour;
+import com.teaching.backend.model.entity.favour.SeResourceFavour;
+import com.teaching.backend.service.CourseResourcesService;
+import com.teaching.backend.service.favour.SeResourceFavourService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * ClassName: Get
+ * Package: com.teaching.backend.controller.FavourInformation
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/13 18:15
+ * @Version 1.0
+ */
+@RestController
+public class FavourInformationController{
+
+
+ @Resource
+ CourseResourcesService courseResourcesService;
+
+
+
+ @GetMapping("/Favour/get")
+ public BaseResponse> getInformation2(@RequestParam List resourceIdList , @RequestParam Integer type, PageRequest pageRequest) {
+
+ int page=pageRequest.getCurrent();
+ int pageSize=pageRequest.getPageSize();
+
+ Page resourcesPage=courseResourcesService.getresourceRecords(type,resourceIdList,page,pageSize);
+
+ return ResultUtils.success(resourcesPage);
+
+ }
+
+ }
diff --git a/src/main/java/com/teaching/backend/controller/WordController2.java b/src/main/java/com/teaching/backend/controller/WordController2.java
new file mode 100644
index 0000000..c7533bb
--- /dev/null
+++ b/src/main/java/com/teaching/backend/controller/WordController2.java
@@ -0,0 +1,132 @@
+package com.teaching.backend.controller;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.model.GetObjectRequest;
+import com.aliyun.oss.model.OSSObject;
+import com.teaching.backend.utils.WordUtil;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.ResourceUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.*;
+
+@RestController
+public class WordController2 {
+ @Value("${aliyun.oss.endpoint}")
+ private String endpoint;
+
+ @Value("${aliyun.oss.accessKeyId}")
+ private String accessKeyId;
+
+ @Value("${aliyun.oss.accessKeySecret}")
+ private String accessKeySecret;
+
+ @Value("${aliyun.oss.bucketName}")
+ private String bucketName;
+
+ @Value("${filename}")
+ private String templateFileName; // 模板文件名
+
+ @PostMapping("/Word/get")
+ public ResponseEntity createWord(@RequestParam("outputPath") String outputPath) {
+ String filename = "generatedWord.docx";
+
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+
+ InputStream templateStream = null;
+ //获取模版
+ OSSObject ossObject = ossClient.getObject(new GetObjectRequest(bucketName, templateFileName));
+
+ templateStream = ossObject.getObjectContent();
+
+ WordUtil wordUtil = new WordUtil();
+ wordUtil.setTemplateInputStream(templateStream); // 设置模板文件输入流
+
+
+ Map dataMap = new HashMap<>();
+ dataMap.put("username1", "姜钧瀚");
+
+ dataMap.put("img", "src/main/resources/static/3823.png");
+
+
+ // 设置 Word 生成的输出目录
+ wordUtil.setOutputDir(outputPath);
+
+ String generatedFilePath = wordUtil.createWord(dataMap);
+
+ if (generatedFilePath.equals("操作失败")) {
+ System.out.println("操作失败");
+ return ResponseEntity.badRequest().body("操作失败".getBytes());
+ }
+
+ File file = new File(generatedFilePath);
+ byte[] fileContent;
+ try {
+ fileContent = Files.readAllBytes(file.toPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ return ResponseEntity.badRequest().body("文件读取失败".getBytes());
+ }
+
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+ headers.setContentDispositionFormData("attachment", filename);
+
+ //返回文件内容
+ return new ResponseEntity<>(fileContent, headers, HttpStatus.OK);
+ }
+
+ @PostMapping("/Word/get2")
+ private void downWord(HttpServletResponse response) throws IOException {
+
+ // 读取模板文件并创建XWPFDocument对象
+ File rootFile = new File(ResourceUtils.getURL("classpath:").getPath());
+ File templateFile = new File(rootFile, "/word_template/ceshi2.docx");
+
+ try (FileInputStream fileInputStream = new FileInputStream(templateFile)) {
+ XWPFDocument word = new XWPFDocument(fileInputStream);
+
+ // 填充数据等后续处理代码
+
+ Map params = new HashMap<>();
+ params.put("username", "姜钧瀚");
+ //处理正文
+
+ List paragraphs = word.getParagraphs();
+ for (XWPFParagraph paragraph : paragraphs) {
+ List runs = paragraph.getRuns();
+ for (XWPFRun run : runs) {
+ String text = run.getText(0);
+ for (String key : params.keySet()) {
+ if (text.contains(key)) {
+ run.setText(text.replaceAll(key, params.get(key)), 0);
+ }
+ }
+ }
+ }
+ // 导出Word
+ String fileName = "123123123.docx";
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ word.write(response.getOutputStream());
+ }
+ }
+ }
+
diff --git a/src/main/java/com/teaching/backend/mapper/FileTableMapper.java b/src/main/java/com/teaching/backend/mapper/CourseResourcesMapper.java
similarity index 69%
rename from src/main/java/com/teaching/backend/mapper/FileTableMapper.java
rename to src/main/java/com/teaching/backend/mapper/CourseResourcesMapper.java
index 9196283..773bddb 100644
--- a/src/main/java/com/teaching/backend/mapper/FileTableMapper.java
+++ b/src/main/java/com/teaching/backend/mapper/CourseResourcesMapper.java
@@ -1,7 +1,7 @@
package com.teaching.backend.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.teaching.backend.model.entity.FileTable;
+import com.teaching.backend.model.entity.CourseResources;
import org.apache.ibatis.annotations.Mapper;
/**
@@ -14,5 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
* @Version 1.0
*/
@Mapper
-public interface FileTableMapper extends BaseMapper {
+public interface CourseResourcesMapper extends BaseMapper {
}
diff --git a/src/main/java/com/teaching/backend/mapper/ResourcesRelationshipMapper.java b/src/main/java/com/teaching/backend/mapper/ResourcesRelationshipMapper.java
new file mode 100644
index 0000000..ed0286d
--- /dev/null
+++ b/src/main/java/com/teaching/backend/mapper/ResourcesRelationshipMapper.java
@@ -0,0 +1,19 @@
+package com.teaching.backend.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.teaching.backend.model.entity.ResourceRelationship;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.tomcat.websocket.BackgroundProcess;
+
+/**
+ * ClassName: ResourcesRelationshipMapper
+ * Package: com.teaching.backend.mapper
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/12 21:07
+ * @Version 1.0
+ */
+@Mapper
+public interface ResourcesRelationshipMapper extends BaseMapper {
+}
diff --git a/src/main/java/com/teaching/backend/mapper/UserMapper.java b/src/main/java/com/teaching/backend/mapper/UserMapper.java
deleted file mode 100644
index 92f37fc..0000000
--- a/src/main/java/com/teaching/backend/mapper/UserMapper.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.teaching.backend.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.teaching.backend.model.entity.User;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * ClassName: UserMapper
- * Package: com.teaching.backend.mapper
- * Description:
- *
- * @Author 姜钧瀚
- * @Create 2024/6/3 17:47
- * @Version 1.0
- */
-@Mapper
-public interface UserMapper extends BaseMapper {
-}
diff --git a/src/main/java/com/teaching/backend/model/entity/FileTable.java b/src/main/java/com/teaching/backend/model/entity/CourseResources.java
similarity index 59%
rename from src/main/java/com/teaching/backend/model/entity/FileTable.java
rename to src/main/java/com/teaching/backend/model/entity/CourseResources.java
index c33d09a..2bc0915 100644
--- a/src/main/java/com/teaching/backend/model/entity/FileTable.java
+++ b/src/main/java/com/teaching/backend/model/entity/CourseResources.java
@@ -1,5 +1,7 @@
package com.teaching.backend.model.entity;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -21,12 +23,16 @@ import java.util.stream.Stream;
@ToString
@NoArgsConstructor
@AllArgsConstructor
-@TableName("filetable")
-public class FileTable {
+@TableName("Resource")
+public class CourseResources {
+ @TableId(value = "id", type = IdType.AUTO)
private int id;
- private String courseId;
- private String fileName;
- private String filePath;
+
+ private String name;
+ private int type;
+ private int status;
+ private String tags;
+ private String path;
}
diff --git a/src/main/java/com/teaching/backend/model/entity/User.java b/src/main/java/com/teaching/backend/model/entity/ResourceRelationship.java
similarity index 57%
rename from src/main/java/com/teaching/backend/model/entity/User.java
rename to src/main/java/com/teaching/backend/model/entity/ResourceRelationship.java
index 3aa2e7b..e8d9cad 100644
--- a/src/main/java/com/teaching/backend/model/entity/User.java
+++ b/src/main/java/com/teaching/backend/model/entity/ResourceRelationship.java
@@ -6,21 +6,24 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
/**
- * ClassName: User
+ * ClassName: ResourcesRelationship
* Package: com.teaching.backend.model.entity
* Description:
*
* @Author 姜钧瀚
- * @Create 2024/6/3 17:42
+ * @Create 2024/6/12 21:03
* @Version 1.0
*/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
-public class User {
- private int id;
- private int userid;
- private int bokeid;
- private int type;
+public class ResourceRelationship {
+ private String Id;
+ private String courseid;
+ private String chapterid;
+ private String knowid;
+ private String resourceid;
+
+
}
diff --git a/src/main/java/com/teaching/backend/service/CourseResourcesService.java b/src/main/java/com/teaching/backend/service/CourseResourcesService.java
new file mode 100644
index 0000000..72a5082
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/CourseResourcesService.java
@@ -0,0 +1,27 @@
+package com.teaching.backend.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.teaching.backend.model.entity.CourseResources;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * ClassName: FileTableService
+ * Package: com.teaching.backend.service
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/4 11:49
+ * @Version 1.0
+ */
+public interface CourseResourcesService extends IService {
+ void updateFile(Integer type, String fileName, String filePath);
+
+ void download(String id, String path, HttpServletResponse response, String endpoint, String accessKeyId, String accessKeySecret, String bucketName) throws IOException;
+
+
+ Page getresourceRecords(Integer type, List resourceIdList, int page, int pageSize);
+}
diff --git a/src/main/java/com/teaching/backend/service/FileTableService.java b/src/main/java/com/teaching/backend/service/FileTableService.java
deleted file mode 100644
index f00933f..0000000
--- a/src/main/java/com/teaching/backend/service/FileTableService.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.teaching.backend.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.teaching.backend.model.entity.FileTable;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * ClassName: FileTableService
- * Package: com.teaching.backend.service
- * Description:
- *
- * @Author 姜钧瀚
- * @Create 2024/6/4 11:49
- * @Version 1.0
- */
-public interface FileTableService extends IService {
- void updateFile(String courseId, String fileName, String filePath);
-
-
- void download(String courseId, String path, HttpServletResponse response, String endpoint, String accessKeyId, String accessKeySecret, String bucketName) throws IOException;
-}
diff --git a/src/main/java/com/teaching/backend/service/ResourcesRelationshipService.java b/src/main/java/com/teaching/backend/service/ResourcesRelationshipService.java
new file mode 100644
index 0000000..0ffd16b
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/ResourcesRelationshipService.java
@@ -0,0 +1,17 @@
+package com.teaching.backend.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.teaching.backend.model.entity.ResourceRelationship;
+
+
+/**
+ * ClassName: ResourcesRelationshipService
+ * Package: com.teaching.backend.service
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/12 21:04
+ * @Version 1.0
+ */
+public interface ResourcesRelationshipService extends IService {
+}
diff --git a/src/main/java/com/teaching/backend/service/UserService.java b/src/main/java/com/teaching/backend/service/UserService.java
deleted file mode 100644
index 13e2052..0000000
--- a/src/main/java/com/teaching/backend/service/UserService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.teaching.backend.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.teaching.backend.model.entity.User;
-
-/**
- * ClassName: UserService
- * Package: com.teaching.backend.service
- * Description:
- *
- * @Author 姜钧瀚
- * @Create 2024/6/3 17:48
- * @Version 1.0
- */
-public interface UserService extends IService {
-}
diff --git a/src/main/java/com/teaching/backend/service/favour/SeResourceFavourService.java b/src/main/java/com/teaching/backend/service/favour/SeResourceFavourService.java
index 2eab5a8..a342d54 100644
--- a/src/main/java/com/teaching/backend/service/favour/SeResourceFavourService.java
+++ b/src/main/java/com/teaching/backend/service/favour/SeResourceFavourService.java
@@ -1,8 +1,11 @@
package com.teaching.backend.service.favour;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.teaching.backend.model.dto.favour.resourceFavour.ResourceFavourAddRequest;
import com.teaching.backend.model.entity.favour.SeResourceFavour;
+import java.util.List;
+
/**
* @Author:youhang
* @Date:2024-05-30-20:22
@@ -19,4 +22,6 @@ public interface SeResourceFavourService extends IService {
*/
boolean doResourceFavour(String courseId, String resourceId, String userId);
+
+
}
diff --git a/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java
new file mode 100644
index 0000000..50479c6
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java
@@ -0,0 +1,121 @@
+package com.teaching.backend.service.impl;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.model.OSSObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.teaching.backend.mapper.CourseResourcesMapper;
+import com.teaching.backend.model.entity.CourseResources;
+import com.teaching.backend.model.entity.ResourceRelationship;
+import com.teaching.backend.service.CourseResourcesService;
+import com.teaching.backend.service.ResourcesRelationshipService;
+import org.apache.commons.io.FileUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * ClassName: FileTableImpl
+ * Package: com.teaching.backend.service.impl
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/4 11:50
+ * @Version 1.0
+ */
+@Service
+public class CourseResourcesServiceImpl extends ServiceImpl implements CourseResourcesService {
+ @Resource
+ ResourcesRelationshipService resourcesRelationshipService;
+ @Override
+ public void updateFile(Integer type, String fileName, String filePath) {
+
+ CourseResources courseResources = new CourseResources();
+
+ courseResources.setName(fileName);
+ courseResources.setPath(filePath);
+ courseResources.setType(type);
+
+ this.save(courseResources);
+
+ int resourceId=courseResources.getId();
+ System.out.println(resourceId);
+
+ ResourceRelationship resourcesRelationship=new ResourceRelationship();
+
+ resourcesRelationship.setResourceid(String.valueOf(resourceId));
+
+ resourcesRelationshipService.save(resourcesRelationship);
+ }
+
+ @Override
+ public void download(String Id, String path, HttpServletResponse response, String endpoint, String accessKeyId, String accessKeySecret, String bucketName) throws IOException {
+
+
+
+ CourseResources courseResources=getById(Id);
+
+
+ System.out.println(courseResources);
+
+
+ // 创建OSS客户端
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+
+ String key = extractKeyFromFullPath(courseResources.getPath());
+ OSSObject object = ossClient.getObject(bucketName, key);
+
+ String fileName = courseResources.getName();
+
+ // 设置保存文件的路径
+ String savePath = path + "/" + fileName;
+
+ // 获取文件的输入流
+ InputStream inputStream = object.getObjectContent();
+
+ // 设置响应头
+ response.setContentType("application/octet-stream");
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
+
+ // 创建保存文件
+ File saveFile = new File(savePath);
+
+ // 将文件内容复制到保存文件中
+ FileUtils.copyInputStreamToFile(inputStream, saveFile);
+
+ // 关闭输入流和OSS客户端
+ inputStream.close();
+ ossClient.shutdown();
+ }
+
+ @Override
+ public Page getresourceRecords(Integer type, List resourceIdList, int page, int pageSize) {
+ Page pageInfo=new Page<>(page,pageSize);
+
+ LambdaQueryWrapperlambdaQueryWrapper=new LambdaQueryWrapper<>();
+ lambdaQueryWrapper.in(CourseResources::getId,resourceIdList);
+ lambdaQueryWrapper.eq(CourseResources::getType,type);
+
+ return this.page(pageInfo,lambdaQueryWrapper);
+
+ }
+
+
+ private String extractKeyFromFullPath(String filePath) {
+ // 提取存储桶名称
+ String key = filePath.substring(filePath.indexOf("com") + 4, filePath.indexOf("?"));
+ return key;
+ }
+
+}
+
+
+
diff --git a/src/main/java/com/teaching/backend/service/impl/FileTableServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/FileTableServiceImpl.java
deleted file mode 100644
index cecf46d..0000000
--- a/src/main/java/com/teaching/backend/service/impl/FileTableServiceImpl.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.teaching.backend.service.impl;
-
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.model.OSSObject;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.teaching.backend.mapper.FileTableMapper;
-import com.teaching.backend.model.entity.FileTable;
-import com.teaching.backend.service.FileTableService;
-import org.apache.commons.io.FileUtils;
-import org.springframework.stereotype.Service;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * ClassName: FileTableImpl
- * Package: com.teaching.backend.service.impl
- * Description:
- *
- * @Author 姜钧瀚
- * @Create 2024/6/4 11:50
- * @Version 1.0
- */
-@Service
-public class FileTableServiceImpl extends ServiceImpl implements FileTableService {
- @Override
- public void updateFile(String courseId, String fileName, String filePath) {
- System.out.println("执行了service中的方法");
- System.out.println(courseId);
- System.out.println(fileName);
- System.out.println(filePath);
-
- FileTable fileTable = new FileTable();
-
- fileTable.setFileName(fileName);
- fileTable.setFilePath(filePath);
-// fileTable.setCourseId(courseId); // 设置主键值
-//
-// this.save(fileTable); // 使用save方法来添加新的记录
-
- UpdateWrapper fileTableUpdateWrapper = new UpdateWrapper<>();
- fileTableUpdateWrapper.eq("course_id", courseId);
-
- this.update(fileTable, fileTableUpdateWrapper);
-
- }
-
- @Override
- public void download(String courseId, String path, HttpServletResponse response, String endpoint, String accessKeyId, String accessKeySecret, String bucketName) throws IOException {
-
-
- FileTable fileTable = this.getById(courseId);
- System.out.println(fileTable);
-
- // 创建OSS客户端
- OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
-
- String key = extractKeyFromFullPath(fileTable.getFilePath());
- OSSObject object = ossClient.getObject(bucketName, key);
-
- String fileName = fileTable.getFileName();
-
- // 设置保存文件的路径
- String savePath = path + "/" + fileName;
-
- // 获取文件的输入流
- InputStream inputStream = object.getObjectContent();
-
- // 设置响应头
- response.setContentType("application/octet-stream");
- response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
-
- // 创建保存文件
- File saveFile = new File(savePath);
-
- // 将文件内容复制到保存文件中
- FileUtils.copyInputStreamToFile(inputStream, saveFile);
-
- // 关闭输入流和OSS客户端
- inputStream.close();
- ossClient.shutdown();
- }
-
- private String extractKeyFromFullPath(String filePath) {
- // 提取存储桶名称
- String key = filePath.substring(filePath.indexOf("com") + 4, filePath.indexOf("?"));
- return key;
- }
-
-}
-
-
-
diff --git a/src/main/java/com/teaching/backend/service/impl/ResourcesRelationshipServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/ResourcesRelationshipServiceImpl.java
new file mode 100644
index 0000000..15804b8
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/ResourcesRelationshipServiceImpl.java
@@ -0,0 +1,21 @@
+package com.teaching.backend.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.teaching.backend.mapper.ResourcesRelationshipMapper;
+import com.teaching.backend.model.entity.ResourceRelationship;
+import com.teaching.backend.service.ResourcesRelationshipService;
+import org.springframework.stereotype.Service;
+
+/**
+ * ClassName: ResourcesRelationshipServiceImpl
+ * Package: com.teaching.backend.service.impl
+ * Description:
+ *
+ * @Author 姜钧瀚
+ * @Create 2024/6/12 21:05
+ * @Version 1.0
+ */
+@Service
+public class ResourcesRelationshipServiceImpl extends ServiceImpl implements ResourcesRelationshipService {
+
+}
diff --git a/src/main/java/com/teaching/backend/service/impl/UserServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/UserServiceImpl.java
deleted file mode 100644
index 507883c..0000000
--- a/src/main/java/com/teaching/backend/service/impl/UserServiceImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.teaching.backend.service.impl;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.teaching.backend.mapper.UserMapper;
-import com.teaching.backend.model.entity.User;
-import com.teaching.backend.service.UserService;
-import org.springframework.stereotype.Service;
-
-/**
- * ClassName: UserServiceImpl
- * Package: com.teaching.backend.service.impl
- * Description:
- *
- * @Author 姜钧瀚
- * @Create 2024/6/3 17:48
- * @Version 1.0
- */
-@Service
-public class UserServiceImpl extends ServiceImpl implements UserService {
-
-
-
-
-}
diff --git a/src/main/java/com/teaching/backend/service/impl/favour/SeResourceFavourServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/favour/SeResourceFavourServiceImpl.java
index 968d993..314afe8 100644
--- a/src/main/java/com/teaching/backend/service/impl/favour/SeResourceFavourServiceImpl.java
+++ b/src/main/java/com/teaching/backend/service/impl/favour/SeResourceFavourServiceImpl.java
@@ -1,5 +1,6 @@
package com.teaching.backend.service.impl.favour;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
@@ -7,10 +8,13 @@ import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.favour.SeResourceFavourMapper;
+import com.teaching.backend.model.dto.favour.resourceFavour.ResourceFavourAddRequest;
import com.teaching.backend.model.entity.favour.SeResourceFavour;
import com.teaching.backend.service.favour.SeResourceFavourService;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
+import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -62,4 +66,6 @@ public class SeResourceFavourServiceImpl extends ServiceImpl转换成word
- */
- public String createWord(Map dataMap){
+ public void setTemplateInputStream(InputStream templateStream) {
+ this.templateInputStream = templateStream;
+ }
- configuration.setClassForTemplateLoading(this.getClass(), "");//模板文件所在路径
+ public String createWord(Map dataMap) {
+ configuration.setClassForTemplateLoading(this.getClass(), "");
Template t = null;
-
try {
- //得到模板文件
- configuration.setDirectoryForTemplateLoading(new File(baseDir));
- t = configuration.getTemplate(templateFile);
+ t = new Template(templateFile, new InputStreamReader(templateInputStream, "UTF-8"), configuration);
} catch (IOException e) {
e.printStackTrace();
}
- //随机生成
- Random random=new Random();
-
- File outFile = new File(outputDir+ random.nextInt(200) + ".docx"); //导出文件
-
+ Random random = new Random();
+ File outFile = new File(outputDir + random.nextInt(200) + ".docx");
Writer out = null;
+
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- try {
- t.process(dataMap, out); //将填充数据填入模板文件并输出到目标文件
+
+ t.process(dataMap, out);
+
return outFile.getPath();
- } catch (TemplateException e) {
- e.printStackTrace();
- } catch (IOException e) {
+
+ } catch (TemplateException | IOException e) {
e.printStackTrace();
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
+
return "文档生成失败";
}
-
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/teaching/backend/utils/textceshi.java b/src/main/java/com/teaching/backend/utils/textceshi.java
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 27c1ff9..2e0abe0 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -2,4 +2,4 @@ aliyun.oss.endpoint=oss-cn-wuhan-lr.aliyuncs.com
aliyun.oss.accessKeyId=LTAI5tFkdu3y5WddxbjgaG2F
aliyun.oss.accessKeySecret=1xUchxUTlmUBoTV5JQIrKsVjSkmsLF
aliyun.oss.bucketName=ceshi132132
-
+filename=123.ftl
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 317ae7b..e430a37 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,13 +3,16 @@ server:
spring:
application:
name: teaching-backend
+ servlet:
+ multipart:
+ max-file-size: 10MB
+ max-request-size: 10MB
mvc:
pathmatch:
matching-strategy: ant_path_matcher
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://127.0.0.1:3306/teaching_db
-# url: jdbc:mysql://39.106.16.162:3306/teaching_db
+ url: jdbc:mysql://localhost:3306/teaching_db
username: root
password: root
mybatis:
@@ -18,18 +21,18 @@ mybatis:
mapper-locations:
- classpath:mapper/*.xml
- classpath*:com/**/mapper/*.xml
-# 自定义jwt key
+
jwt:
- tokenHeader: Authorization #JWT存储的请求头
- secret: mySecret #JWT加解密使用的密钥
- expiration: 604800 #JWT的超期限时间(60*60*24)一天
- tokenHead: Bearer #JWT负载中拿到开头
+ tokenHeader: Authorization
+ secret: mySecret
+ expiration: 604800
+ tokenHead: Bearer
knife4j:
enable: true
openapi:
- title: 用户管理接口文档
- description: "用户管理接口文档"
+ title: 111
+ description: "123"
concat: zjh
version: v1.0.0
group:
@@ -40,7 +43,7 @@ knife4j:
- com.teaching.backend.controller
secure:
ignored:
- urls: #安全路径白名单
+ urls:
#- /swagger-ui/
- /**
# - /swagger-resources/**
diff --git a/src/main/resources/static/hello2.html b/src/main/resources/static/hello2.html
index 1b285a4..e7ed7aa 100644
--- a/src/main/resources/static/hello2.html
+++ b/src/main/resources/static/hello2.html
@@ -19,30 +19,32 @@