parent
9789bdbfde
commit
77c9f862cb
64 changed files with 205 additions and 12609 deletions
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.api; |
||||
package com.teaching.backend.common; |
||||
|
||||
public interface CommonConstant { |
||||
|
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.api; |
||||
package com.teaching.backend.common; |
||||
|
||||
/** |
||||
* @auther macrozheng |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.api; |
||||
package com.teaching.backend.common; |
||||
|
||||
/** |
||||
* @auther macrozheng |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.api; |
||||
package com.teaching.backend.common; |
||||
|
||||
/** |
||||
* @auther macrozheng |
@ -1,132 +0,0 @@ |
||||
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<byte[]> 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<String, Object> 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<String, String> params = new HashMap<>(); |
||||
params.put("username", "姜钧瀚"); |
||||
//处理正文
|
||||
|
||||
List<XWPFParagraph> paragraphs = word.getParagraphs(); |
||||
for (XWPFParagraph paragraph : paragraphs) { |
||||
List<XWPFRun> 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()); |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,51 +0,0 @@ |
||||
package com.teaching.backend.controller.know; |
||||
|
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ErrorCode; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.exception.BusinessException; |
||||
|
||||
import com.teaching.backend.model.dto.know.KnowAddRequest; |
||||
|
||||
import com.teaching.backend.service.know.KnowService; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-06-17-11:57 |
||||
* @Description: |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/konw") |
||||
public class KnowController { |
||||
|
||||
@Autowired |
||||
private KnowService knowService; |
||||
|
||||
|
||||
/** |
||||
* 知识点添加 |
||||
* |
||||
*/ |
||||
@PostMapping("/add") |
||||
// 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
public BaseResponse<Boolean> doFavour(@RequestBody KnowAddRequest knowAddRequest) { |
||||
// todo 字段判空 合法
|
||||
|
||||
// todo 字段是否存在
|
||||
|
||||
Boolean result = knowService.add(knowAddRequest); |
||||
|
||||
if(!result) { |
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR); |
||||
} |
||||
|
||||
return ResultUtils.success(result); |
||||
} |
||||
} |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.mapper; |
||||
package com.teaching.backend.mapper.resource; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.teaching.backend.model.entity.CourseResources; |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.mapper; |
||||
package com.teaching.backend.mapper.resource; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.teaching.backend.model.entity.ResourceRelationship; |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.service; |
||||
package com.teaching.backend.service.resource; |
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.service; |
||||
package com.teaching.backend.service.resource; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.teaching.backend.model.entity.ResourceRelationship; |
@ -1,9 +1,80 @@ |
||||
package com.teaching.backend.utils; |
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-06-17-23:15 |
||||
* @Description: |
||||
*/ |
||||
public class ParamOutAspect { |
||||
} |
||||
//package com.teaching.backend.utils;
|
||||
//
|
||||
///**
|
||||
// * @Author:youhang
|
||||
// * @Date:2024-06-17-23:15
|
||||
// * @Description:
|
||||
// */
|
||||
//
|
||||
//
|
||||
//
|
||||
//import cn.hutool.json.JSONObject;
|
||||
//import cn.hutool.json.JSONUtil;
|
||||
//import com.teaching.backend.common.ErrorCode;
|
||||
//import com.teaching.backend.exception.BusinessException;
|
||||
//import org.aspectj.lang.JoinPoint;
|
||||
//import org.aspectj.lang.annotation.Aspect;
|
||||
//import org.aspectj.lang.annotation.Before;
|
||||
//import org.aspectj.lang.reflect.MethodSignature;
|
||||
//import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.lang.reflect.Method;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//
|
||||
//@Component
|
||||
//@Aspect
|
||||
//public class ParamOutAspect {
|
||||
//
|
||||
//
|
||||
// //对包下所有的controller结尾的类的所有方法增强
|
||||
// private final String executeExpr = "execution(public * com.teaching.backend.controller..*.*(..))";
|
||||
//
|
||||
// @Before(executeExpr)
|
||||
// public void processLog(JoinPoint joinPoint) {
|
||||
// Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
||||
// //获取方法名称
|
||||
// String methodName = method.getName();
|
||||
// //获取参数名称
|
||||
// LocalVariableTableParameterNameDiscoverer paramNames = new LocalVariableTableParameterNameDiscoverer();
|
||||
// String[] params = paramNames.getParameterNames(method);
|
||||
//
|
||||
//
|
||||
// //获取参数f
|
||||
// Object[] args = joinPoint.getArgs();
|
||||
// //过滤掉request和response,不能序列化
|
||||
// List<Object> filteredArgs = Arrays.stream(args)
|
||||
// .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse))).collect(Collectors.toList());
|
||||
// final Object[] array = filteredArgs.stream().toArray();
|
||||
//
|
||||
// for (int i = 0; i < array.length; i++) {
|
||||
// System.out.println(array[i]);
|
||||
// String jsonStr = JSONUtil.toJsonStr(array[i]);
|
||||
// System.out.println(jsonStr);
|
||||
// Class<?> myClass = array[i].getClass(); // 获取类的 Class 对象
|
||||
// System.out.println("class "+myClass);
|
||||
// JSONObject entries = JSONUtil.parseObj(jsonStr);
|
||||
// System.out.println(entries);
|
||||
// // 遍历JSONObject的属性
|
||||
// entries.forEach((key, value) -> {
|
||||
// if(value == null || "".equals(value)){
|
||||
// //可以设置为空的字段
|
||||
// if(key.equals( "sortField")||key.equals( "sortOrder")){
|
||||
// }else{
|
||||
// throw new BusinessException(ErrorCode.PARAMS_NULL);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// System.out.println(key + ": " + value);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
|
@ -1,71 +0,0 @@ |
||||
package com.teaching.backend.utils; |
||||
|
||||
import freemarker.template.Configuration; |
||||
import freemarker.template.Template; |
||||
import freemarker.template.TemplateException; |
||||
import lombok.Data; |
||||
|
||||
|
||||
import java.io.*; |
||||
import java.util.Map; |
||||
import java.util.Random; |
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-05-30-18:20 |
||||
* @Description: |
||||
*/ |
||||
@Data |
||||
public class WordUtil { |
||||
|
||||
private Configuration configuration = null; |
||||
private String baseDir; |
||||
private String templateFile; |
||||
private String outputDir; |
||||
private InputStream templateInputStream; // 模板文件输入流
|
||||
|
||||
public WordUtil() { |
||||
configuration = new Configuration(); |
||||
configuration.setDefaultEncoding("UTF-8"); |
||||
} |
||||
|
||||
public void setTemplateInputStream(InputStream templateStream) { |
||||
this.templateInputStream = templateStream; |
||||
} |
||||
|
||||
public String createWord(Map<String,Object> dataMap) { |
||||
configuration.setClassForTemplateLoading(this.getClass(), ""); |
||||
|
||||
Template t = null; |
||||
try { |
||||
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"); |
||||
Writer out = null; |
||||
|
||||
try { |
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile))); |
||||
|
||||
t.process(dataMap, out); |
||||
|
||||
return outFile.getPath(); |
||||
|
||||
} catch (TemplateException | IOException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (out != null) { |
||||
try { |
||||
out.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return "文档生成失败"; |
||||
} |
||||
} |
@ -1,5 +0,0 @@ |
||||
aliyun.oss.endpoint=oss-cn-wuhan-lr.aliyuncs.com |
||||
aliyun.oss.accessKeyId=LTAI5tFkdu3y5WddxbjgaG2F |
||||
aliyun.oss.accessKeySecret=1xUchxUTlmUBoTV5JQIrKsVjSkmsLF |
||||
aliyun.oss.bucketName=ceshi132132 |
||||
filename=123.ftl |
@ -1,76 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
|
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>文件上传下载示例</title> |
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div id="app"> |
||||
<h1>文件上传</h1> |
||||
<form @submit.prevent="upload" enctype="multipart/form-data"> |
||||
<input type="file" name="file"> |
||||
<button type="submit">上传文件</button> |
||||
</form> |
||||
|
||||
<h1>文件下载</h1> |
||||
<button @click="download">点击下载文件</button> |
||||
|
||||
</div> |
||||
|
||||
<!-- 开发环境版本,包含了有帮助的命令行警告 --> |
||||
<script src="../../plugins/vue/vue.js"></script> |
||||
<!-- 引入组件库 --> |
||||
<script src="../../plugins/element-ui/index.js"></script> |
||||
<!-- 引入axios --> |
||||
<script src="../../plugins/axios/axios.min.js"></script> |
||||
<script> |
||||
new Vue({ |
||||
el: '#app', |
||||
data: { |
||||
fileName: '' |
||||
}, |
||||
methods: { |
||||
download() { |
||||
axios.get('/download?fileName=' + this.fileName, { responseType: 'blob' }) |
||||
.then(response => { |
||||
const url = window.URL.createObjectURL(new Blob([response.data])); |
||||
const link = document.createElement('a'); |
||||
link.href = url; |
||||
link.setAttribute('download', this.fileName); |
||||
document.body.appendChild(link); |
||||
link.click(); |
||||
window.URL.revokeObjectURL(url); |
||||
}) |
||||
.catch(error => { |
||||
console.error("出错了", error); |
||||
}); |
||||
}, |
||||
|
||||
upload(event) { |
||||
let formData = new FormData(); |
||||
formData.append('file', event.target.elements.file.files[0]); |
||||
|
||||
axios.post('/upload', formData, { |
||||
headers: { |
||||
'Content-Type': 'multipart/form-data' |
||||
} |
||||
}) |
||||
.then(response => { |
||||
console.log("上传成功,文件名为:" + response.data.data); |
||||
this.fileName = response.data.data; |
||||
}) |
||||
.catch(error => { |
||||
console.error('上传失败', error); |
||||
}); |
||||
} |
||||
} |
||||
}); |
||||
</script> |
||||
</body> |
||||
|
||||
</html> |
@ -1,56 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>视频上传和下载</title> |
||||
</head> |
||||
<body> |
||||
|
||||
|
||||
<div id="app2"> |
||||
<input type="file" ref="fileInput" @change="handleFileChange"> |
||||
<button @click="uploadFile">上传</button> |
||||
</div> |
||||
|
||||
|
||||
<!-- 开发环境版本,包含了有帮助的命令行警告 --> |
||||
<script src="../../plugins/vue/vue.js"></script> |
||||
<!-- 引入组件库 --> |
||||
<script src="../../plugins/element-ui/index.js"></script> |
||||
<!-- 引入axios --> |
||||
<script src="../../plugins/axios/axios.min.js"></script> |
||||
<script> |
||||
|
||||
new Vue({ |
||||
el: '#app', |
||||
data: { |
||||
asd: [] |
||||
}, |
||||
methods: { |
||||
fetchList() { |
||||
const params = { |
||||
resourceIdList: [4], // 传递资源ID列表 |
||||
type: 1 // 资源类型 |
||||
}; |
||||
axios.get('/Favour/get', { |
||||
params: params |
||||
}) |
||||
.then(response => { |
||||
this.asd = response.data.records; // 直接赋值给 asd |
||||
console.log( this.asd ) |
||||
}) |
||||
.catch(error => { |
||||
console.error("出错了", error); |
||||
}); |
||||
}, |
||||
}, |
||||
mounted() { |
||||
this.fetchList(); // 在组件挂载后立即调用fetchList方法获取资源记录 |
||||
} |
||||
}); |
||||
|
||||
|
||||
</script> |
||||
|
||||
|
||||
</body> |
||||
</html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue