master
wenyu441069198 5 months ago
parent c3c27f479f
commit c5b4c8829d
  1. 24
      src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java
  2. 4
      src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java
  3. 31
      src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java
  4. 2
      src/main/java/com/teaching/backend/service/impl/ResourcesRelationshipServiceImpl.java
  5. 93
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  6. 4
      src/main/java/com/teaching/backend/service/resource/CourseResourcesService.java
  7. 3
      src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java

@ -6,6 +6,7 @@ import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.service.impl.CourseResourcesServiceImpl; import com.teaching.backend.service.impl.CourseResourcesServiceImpl;
import io.swagger.annotations.ApiOperation;
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.*;
@ -17,12 +18,14 @@ import java.util.List;
public class CourseResourceController { public class CourseResourceController {
@Autowired @Autowired
private CourseResourcesServiceImpl courseResourcesService; private CourseResourcesServiceImpl courseResourcesService;
@ApiOperation("查询全部课程资源记录")
@GetMapping("/all") @GetMapping("/all")
public BaseResponse<List<CourseResources>> All(){ public BaseResponse<List<CourseResources>> All(){
System.out.println("学习记录:"+courseResourcesService.list()); System.out.println("学习记录:"+courseResourcesService.list());
return ResultUtils.success(courseResourcesService.list()); return ResultUtils.success(courseResourcesService.list());
} }
@ApiOperation("按type查询课程资源")
@GetMapping("/getall") @GetMapping("/getall")
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, @RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
@ -42,10 +45,11 @@ public class CourseResourceController {
} }
/** /**
* 根据id删除 * 根据ids删除
* @param ids * @param ids
* @return * @return
*/ */
@ApiOperation("根据ids删除")
@DeleteMapping("/delete") @DeleteMapping("/delete")
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){ public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
// courseResourcesService.removeCourseResources(ids); // courseResourcesService.removeCourseResources(ids);
@ -58,9 +62,23 @@ public class CourseResourceController {
* @param courseResources * @param courseResources
* @return * @return
*/ */
@GetMapping("/save") @ApiOperation("新增课程资源")
@PostMapping("/save")
public BaseResponse<String> saveCourseResource(@RequestBody CourseResources courseResources){ public BaseResponse<String> saveCourseResource(@RequestBody CourseResources courseResources){
courseResourcesService.save(courseResources); System.out.println(courseResources);
courseResourcesService.saveCourseResource(courseResources);
return ResultUtils.success("添加成功!"); return ResultUtils.success("添加成功!");
} }
/**
* 编辑
* @param resourceId
* @return
*/
@ApiOperation("编辑课程资源")
@PostMapping("/edit")
public BaseResponse<CourseResources> editCourseResource(@RequestParam String resourceId){
System.out.println(resourceId);
return ResultUtils.success(courseResourcesService.editCourseResource(resourceId));
}
} }

@ -8,6 +8,7 @@ import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.entity.records.LearningRecords; import com.teaching.backend.model.entity.records.LearningRecords;
import com.teaching.backend.model.vo.records.LearningRecordsVo; import com.teaching.backend.model.vo.records.LearningRecordsVo;
import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl; import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -29,6 +30,7 @@ public class LearningRecordsController {
* @param pagesize * @param pagesize
* @return * @return
*/ */
@ApiOperation("根据用户id查询学习记录")
@GetMapping("/getall") @GetMapping("/getall")
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, @RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
@ -53,6 +55,7 @@ public class LearningRecordsController {
return ResultUtils.success(pageInfo); return ResultUtils.success(pageInfo);
} }
@ApiOperation("查询所有")
@GetMapping("/all") @GetMapping("/all")
public BaseResponse<List<LearningRecords>> All(){ public BaseResponse<List<LearningRecords>> All(){
System.out.println("学习记录:"+learningRecordsService.list()); System.out.println("学习记录:"+learningRecordsService.list());
@ -65,6 +68,7 @@ public class LearningRecordsController {
* @param learningRecords * @param learningRecords
* @return * @return
*/ */
@ApiOperation("添加学习记录")
@PostMapping("/saverecords") @PostMapping("/saverecords")
public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){ public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){
System.out.println(learningRecords); System.out.println(learningRecords);

@ -140,6 +140,37 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
// this.remove(lambdaQueryWrapper); // this.remove(lambdaQueryWrapper);
} }
@Override
public void saveCourseResource(CourseResources courseResources) {
//将状态设置为1
courseResources.setStatus(1);
//设置默认图片
switch (courseResources.getType()){
case 1 : courseResources.setImg("src\\assets\\icons\\ppt (2).png");//ppt的默认图片
break;
// case 2 : courseResources.setImg(""); //图片
// break;
case 3 : courseResources.setImg("src\\assets\\images\\video.png"); //视频
break;
case 4 : courseResources.setImg("src\\assets\\images\\PDF .png"); //pdf
break;
case 5 : courseResources.setImg("src\\assets\\images\\test.png"); //文件
break;
case 6 : courseResources.setImg("src\\assets\\images\\audio.png"); //音频
break;
default: courseResources.setImg(""); //暂无默认图片
}
}
@Override
public CourseResources editCourseResource(String resourceId) {
//根据id查数据
CourseResources courseResources = this.getById(resourceId);
return courseResources;
}
} }

@ -2,6 +2,7 @@ package com.teaching.backend.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.resource.ResourcesRelationshipMapper; import com.teaching.backend.mapper.resource.ResourcesRelationshipMapper;
import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship; import com.teaching.backend.model.entity.ResourceRelationship;
import com.teaching.backend.service.resource.ResourcesRelationshipService; import com.teaching.backend.service.resource.ResourcesRelationshipService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -18,4 +19,5 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ResourcesRelationshipServiceImpl extends ServiceImpl<ResourcesRelationshipMapper, ResourceRelationship> implements ResourcesRelationshipService { public class ResourcesRelationshipServiceImpl extends ServiceImpl<ResourcesRelationshipMapper, ResourceRelationship> implements ResourcesRelationshipService {
} }

@ -344,16 +344,10 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式 File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式
File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址 File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址
FileInputStream template1; // // 加载Word模板------------------路径换成服务器里文件的绝对路径(要是相对路径也行也OK)
try { // FileInputStream template = new FileInputStream("D:\\Users\\Desktop\\teaching-backend\\src\\main\\resources\\templates\\courses.docx");
template1 = new FileInputStream(templatePath); // new XWPFDocument(template);
} catch (FileNotFoundException e) { XWPFDocument document;
e.printStackTrace();
throw new Exception("模板文件未找到");
}
// 加载Word模板------------------路径换成服务器里文件的绝对路径(要是相对路径也行也OK)
FileInputStream template = new FileInputStream("D:\\IDEA\\AAATEA\\teaching-backend\\src\\main\\resources\\templates\\courses.docx");
XWPFDocument document = new XWPFDocument(template);
//准备导出数据 //准备导出数据
//查询课程通过课程id查--课程简介 //查询课程通过课程id查--课程简介
@ -413,11 +407,18 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
document = WordExportUtil.exportWord07(templatePath.getPath(), params); document = WordExportUtil.exportWord07(templatePath.getPath(), params);
//----------------修改表格模版在导入参数之后
//获取第2个表格----------
XWPFTable table = document.getTables().get(1); XWPFTable table = document.getTables().get(1);
for (int i = 0; i < course_number - 1; i++) { for (int i = 0; i < course_number - 1; i++) {
//新增一行单元格 //新增一行单元格
XWPFTableRow newRow = table.createRow(); XWPFTableRow newRow = table.createRow();
newRow.getCell(0).setText("课程目标" + (i + 2)); newRow.getCell(0).setText("课程目标" + (i + 2));
newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
} }
//获取第5个表格 //获取第5个表格
@ -428,16 +429,21 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
XWPFTableRow newRow = table5.createRow(); XWPFTableRow newRow = table5.createRow();
newRow.getCell(0).setText(Integer.valueOf(i+2).toString()); newRow.getCell(0).setText(Integer.valueOf(i+2).toString());
newRow.getCell(0).getParagraphArray(0).setIndentationLeft(0); newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).getParagraphArray(0).setIndentationHanging(0); newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
newRow.getCell(1).setText(" 课程目标" + (i + 2)); //课程目标
newRow.getCell(1).setText("课程目标" + (i + 2));
newRow.getCell(1).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//扩四列 //扩四列
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
newRow.createCell(); newRow.createCell();
} }
} }
table5.setTableAlignment(TableRowAlign.CENTER);
String filename= courses.getName()+"课程标准.docx"; String filename= courses.getName()+"课程标准.docx";
//设置文件的打开方式和mime类型 //设置文件的打开方式和mime类型
@ -447,65 +453,6 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
document.write(outputStream); document.write(outputStream);
} }
// public static void insertRow(XWPFTable table, int copyrowIndex, int newrowIndex) {
// // 在表格中指定的位置新增一行
// XWPFTableRow targetRow = table.insertNewTableRow(newrowIndex);
// // 获取需要复制行对象
// XWPFTableRow copyRow = table.getRow(copyrowIndex);
// //复制行对象给新增的行对象
// targetRow.getCtRow().setTrPr(copyRow.getCtRow().getTrPr());
// //获取需要复制行对象的列
// List<XWPFTableCell> copyCells = copyRow.getTableCells();
// //新增的对象的列
// XWPFTableCell targetCell = null;
// //遍历复制行对象的列
// for (int i = 0; i < copyCells.size(); i++) {
// //复制行对象的列
// XWPFTableCell copyCell = copyCells.get(i);
// //新增的行对象创建一列
// targetCell = targetRow.addNewTableCell();
// //格式复制
// targetCell.getCTTc().setTcPr(copyCell.getCTTc().getTcPr());
// if (copyCell.getParagraphs() != null && copyCell.getParagraphs().size() > 0) {
// targetCell.getParagraphs().get(0).getCTP().setPPr(copyCell.getParagraphs().get(0).getCTP().getPPr());
// if (copyCell.getParagraphs().get(0).getRuns() != null
// && copyCell.getParagraphs().get(0).getRuns().size() > 0) {
// XWPFRun cellR = targetCell.getParagraphs().get(0).createRun();
// cellR.setBold(copyCell.getParagraphs().get(0).getRuns().get(0).isBold());
// }
// }
// }
//
// }
//
// private static void replaceVariable(XWPFDocument document, String variable, String replacement) {
// for (XWPFParagraph paragraph : document.getParagraphs()) {
// for (XWPFRun run : paragraph.getRuns()) {
// String text = run.getText(0);
// if (text != null && text.contains(variable)) {
// text = text.replace(variable, replacement);
// run.setText(text, 0);
// // run.setFontFamily("Arial");
// // run.setFontSize(14);
// }
// }
// }
// }
// private static void replaceVariableInTable(XWPFTable table, String variable, String replacement) {
// for (XWPFTableRow row : table.getRows()) {
// for (XWPFTableCell cell : row.getTableCells()) {
// for (XWPFParagraph paragraph : cell.getParagraphs()) {
// for (XWPFRun run : paragraph.getRuns()) {
// String text = run.getText(0);
// if (text != null && text.contains(variable)) {
// text = text.replace(variable, replacement);
// run.setText(text, 0);
// }
// }
// }
// }
// }
// }
} }

@ -28,4 +28,8 @@ public interface CourseResourcesService extends IService<CourseResources> {
public List<CourseResources> getByType(String type); public List<CourseResources> getByType(String type);
public void removeCourseResources(List<Long> ids); public void removeCourseResources(List<Long> ids);
public void saveCourseResource(CourseResources courseResources);
public CourseResources editCourseResource(String resourceId);
} }

@ -1,6 +1,7 @@
package com.teaching.backend.service.resource; package com.teaching.backend.service.resource;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship; import com.teaching.backend.model.entity.ResourceRelationship;
@ -14,4 +15,6 @@ import com.teaching.backend.model.entity.ResourceRelationship;
* @Version 1.0 * @Version 1.0
*/ */
public interface ResourcesRelationshipService extends IService<ResourceRelationship> { public interface ResourcesRelationshipService extends IService<ResourceRelationship> {
} }

Loading…
Cancel
Save