|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package com.ruoyi.jjh.ent.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
|
|
import cn.hutool.poi.word.Word07Writer;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.jjh.ent.entity.JDevelopmentReport;
|
|
|
|
@ -7,13 +10,29 @@ import com.ruoyi.jjh.ent.entity.response.JTemplateMetricsResponse;
|
|
|
|
|
import com.ruoyi.jjh.ent.service.JDevelopmentReportService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 服务业发展报告(j_template_metrics)表控制层
|
|
|
|
|
*
|
|
|
|
|
* @author du
|
|
|
|
|
* @since 2024/7/31 15:09
|
|
|
|
|
*/
|
|
|
|
@ -23,7 +42,7 @@ import javax.annotation.Resource;
|
|
|
|
|
public class JDevelopmentReportController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
@Autowired
|
|
|
|
|
private JDevelopmentReportService jDevelopmentReportService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,4 +65,72 @@ public class JDevelopmentReportController extends BaseController {
|
|
|
|
|
public AjaxResult getTemplateMetrics(String year) {
|
|
|
|
|
return success(jDevelopmentReportService.getTemplateMetrics(year));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "下载发展模板")
|
|
|
|
|
@GetMapping("/downloadLocal")
|
|
|
|
|
public ResponseEntity<Resource> downloadLocal() {
|
|
|
|
|
String filePath = System.getProperty("user.dir") + "/ruoyi-admin/src/main/resources/template/发展报告模板.docx";
|
|
|
|
|
// 创建文件资源
|
|
|
|
|
Path path = Paths.get(filePath);
|
|
|
|
|
FileSystemResource resource = new FileSystemResource(path.toFile());
|
|
|
|
|
// 设置响应头
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + "moban");
|
|
|
|
|
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
|
// 返回 ResponseEntity
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
|
.headers(headers)
|
|
|
|
|
.body(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @ApiOperation(value = "下载发展模板")
|
|
|
|
|
// @PostMapping("/downloadTemplate")
|
|
|
|
|
// public ResponseEntity<Resource> downloadTemplate(@RequestBody JDevelopmentReport s) {
|
|
|
|
|
// // 定义文件路径
|
|
|
|
|
// ClassPathResource filePath = new ClassPathResource("/template/moban.docx");
|
|
|
|
|
// File touch = filePath.getFile();
|
|
|
|
|
// // 创建 Word07Writer 实例
|
|
|
|
|
// Word07Writer writer = new Word07Writer();
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// // 添加段落(标题)
|
|
|
|
|
// writer.addText(new Font("宋体", Font.PLAIN, 22), s.getTitle());
|
|
|
|
|
//
|
|
|
|
|
// // 添加副标题
|
|
|
|
|
// writer.addText(new Font("宋体", Font.PLAIN, 18), s.getSubheading());
|
|
|
|
|
//
|
|
|
|
|
// // 使用 Jsoup 解析页面内容
|
|
|
|
|
// Document doc = Jsoup.parse(s.getContent(), "UTF-8");
|
|
|
|
|
//
|
|
|
|
|
// // 获取页面内容中的段落
|
|
|
|
|
// Elements paragraphs = doc.select("p");
|
|
|
|
|
// for (Element paragraph : paragraphs) {
|
|
|
|
|
// writer.addText(new Font("仿宋", Font.PLAIN, 16), paragraph.text());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 写出到文件
|
|
|
|
|
// writer.flush(touch);
|
|
|
|
|
//
|
|
|
|
|
// // 设置响应头
|
|
|
|
|
// HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
// headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"发展报告模板1.docx\"");
|
|
|
|
|
// headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
|
//
|
|
|
|
|
// // 封装为 ResponseEntity
|
|
|
|
|
// FileSystemResource resource = new FileSystemResource(touch);
|
|
|
|
|
// return ResponseEntity.ok()
|
|
|
|
|
// .headers(headers)
|
|
|
|
|
// .body(resource);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// // 处理异常情况,例如日志记录或者其他错误处理
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
// } finally {
|
|
|
|
|
// // 关闭资源
|
|
|
|
|
// writer.close();
|
|
|
|
|
// // 删除临时文件
|
|
|
|
|
// FileUtil.del((Path) filePath);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|