|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.teaching.backend.service.impl.courses; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.word.WordExportUtil; |
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
@ -27,15 +28,18 @@ import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; |
|
|
|
|
import com.teaching.backend.model.vo.courses.CoursesVO; |
|
|
|
|
import com.teaching.backend.service.courses.ICoursesService; |
|
|
|
|
import com.teaching.backend.utils.CourseCode; |
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -255,5 +259,34 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
coursesMapper.updateById(course); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void down(HttpServletResponse response, String id) throws Exception { |
|
|
|
|
File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式
|
|
|
|
|
File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址
|
|
|
|
|
//准备导出数据
|
|
|
|
|
//查询课程通过课程id查--课程简介
|
|
|
|
|
Courses courses = this.getById(id); |
|
|
|
|
System.out.println("课程:"+courses); |
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
|
params.put("name",courses.getName()); |
|
|
|
|
params.put("code",courses.getCode()); |
|
|
|
|
params.put("nature",courses.getNature()); |
|
|
|
|
params.put("credit",courses.getCredit()); |
|
|
|
|
params.put("classhour",courses.getClasshours()); |
|
|
|
|
params.put("description",courses.getDescription()); |
|
|
|
|
|
|
|
|
|
//查询课程目标
|
|
|
|
|
|
|
|
|
|
//根据模板+数据 导出文档
|
|
|
|
|
XWPFDocument xwpfDocument = WordExportUtil.exportWord07(templatePath.getPath(), params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//文件名=课程名+课程标准
|
|
|
|
|
String filename= courses.getName()+"课程标准.docx"; |
|
|
|
|
//设置文件的打开方式和mime类型
|
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
|
response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1")); |
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
|
|
|
|
xwpfDocument.write(outputStream); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|