浏览代码

Merge branch 'master' of http://124.70.43.205:3000/wangchangsheng/evaluation

chenminghua 1 年之前
父节点
当前提交
09009ebbbb

+ 3 - 3
ims-service/ims-eval/src/main/java/com/ims/eval/controller/DepartmentalPerformanceIndicatorAssessmentController.java

@@ -100,7 +100,7 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
 			path = "/home/dbkp/statement/" ;
 		}
 		String fileName = evaluationDeptBusinessAssessment.getAppraisalYear() + "年度经营业绩完成情况.doc" ;
-		WordUtil.generateWord(dataMap, "template_dbkp.ftl", path + fileName);
+		WordUtil.generateWord(dataMap, "template_dbkp.ftl", path, fileName);
 		return R.ok().data(fileName);
 	}
 
@@ -112,8 +112,8 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
 	 * @param reportName
 	 * @throws IOException
 	 */
-	@GetMapping(value = "/downloadReport")
-	public void downloadReport(HttpServletRequest request, HttpServletResponse response, String reportName) throws IOException {
+	@GetMapping(value = "/downloadReport/{reportName}")
+	public void downloadReport(HttpServletRequest request, HttpServletResponse response, @PathVariable("reportName") String reportName) throws IOException {
 		String os = System.getProperty("os.name");
 		String path;
 		if (os.toLowerCase().startsWith("win")) { //如果是Windows系统

+ 7 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/util/WordUtil.java

@@ -28,7 +28,7 @@ public class WordUtil {
 	 * @param fileName     要输出的文件路径
 	 * @throws Exception 抛出的异常
 	 */
-	public static void generateWord(Map<String, Object> dataMap, String templateName, String fileName) throws Exception {
+	public static void generateWord(Map<String, Object> dataMap, String templateName, String path, String fileName) throws Exception {
 		// 设置FreeMarker的版本和编码格式
 		Configuration configuration = new Configuration(new Version("2.3.28"));
 		configuration.setDefaultEncoding("UTF-8");
@@ -39,8 +39,13 @@ public class WordUtil {
 		configuration.setClassForTemplateLoading(WordUtil.class, "/templates");
 		// 设置FreeMarker生成Word文档所需要的模板
 		Template tem = configuration.getTemplate(templateName, "UTF-8");
+		// 查看路径下是否有存放文档的文件夹 没有就创建
+		File file = new File(path);
+		if (!file.exists()){
+			file.mkdirs();
+		}
 		// 创建一个Word文档的输出流
-		Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(new File(fileName).toPath()), StandardCharsets.UTF_8));
+		Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(new File(path + fileName).toPath()), StandardCharsets.UTF_8));
 		// FreeMarker使用Word模板和数据生成Word文档
 		tem.process(dataMap, out);
 		out.flush();