From bd24c3ba340543fd522df9f05ecfb16cac0ec296 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 11 二月 2023 13:22:56 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/sys/ReportService.java | 83 ++++++++++++++++++++++++++++++++--------- 1 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/lf/server/service/sys/ReportService.java b/src/main/java/com/lf/server/service/sys/ReportService.java index 63c40b0..df5813e 100644 --- a/src/main/java/com/lf/server/service/sys/ReportService.java +++ b/src/main/java/com/lf/server/service/sys/ReportService.java @@ -1,15 +1,17 @@ package com.lf.server.service.sys; import com.lf.server.entity.ctrl.CountEntity; +import com.lf.server.entity.sys.AttachEntity; import com.lf.server.entity.sys.ReportEntity; -import com.lf.server.helper.FileHelper; -import com.lf.server.helper.StringHelper; -import com.lf.server.helper.WordHelper; +import com.lf.server.helper.*; import com.lf.server.mapper.sys.ReportMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -20,6 +22,12 @@ public class ReportService implements ReportMapper { @Autowired ReportMapper reportMapper; + + @Autowired + AttachService attachService; + + @Autowired + PathHelper pathHelper; @Override public Integer selectCount(String name) { @@ -91,68 +99,107 @@ } /** + * 鍒涘缓鎶ュ憡 + */ + public void createReport(ReportEntity re, HttpServletResponse res) throws Exception { + AttachEntity ae = attachService.selectByGuid(re.getGuid()); + if (null == ae) { + return; + } + + String source = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath(); + String targetName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + FileHelper.getExtension(ae.getName()); + String target = pathHelper.getShareFullPath() + File.separator + targetName; + + File sourceFile = new File(source); + if (!sourceFile.exists() || sourceFile.isDirectory()) { + return; + } + generateReport(source, target, re); + + File targetFile = new File(target); + if (!targetFile.exists() || sourceFile.isDirectory()) { + return; + } + + WebHelper.download(target, targetName, res); + } + + /** + * 鐢熸垚鎶ュ憡 + */ + private void generateReport(String source, String target, ReportEntity re) { + if ("1".equals(re.getType())) { + switch (re.getCode()) { + case "countOperates ": + createCountOperatesWord(source, target); + break; + case "countSizes": + createCountSizesWord(source, target); + break; + default: + createCountServicesWord(source, target); + break; + } + } else { + // + } + } + + /** * 鍒涘缓 鐢ㄦ埛娴侀噺缁熻 Word */ - public void createCountOperatesWord() { + public void createCountOperatesWord(String source, String target) { List<CountEntity> list = countOperates(); if (null == list || list.isEmpty()) { return; } int rows = 1; - String inputFile = "D:\\LF\\鐢ㄦ埛娴侀噺缁熻.docx"; - String outPutFile = "D:\\LF\\鐢ㄦ埛娴侀噺缁熻_new.docx"; - ArrayList<String[]> addList = new ArrayList<>(); for (CountEntity ce : list) { String[] strs = new String[]{"" + rows++, ce.getM1(), ce.getM2(), ce.getCount().toString()}; addList.add(strs); } - WordHelper.generateWord(inputFile, outPutFile, null, addList); + WordHelper.generateWord(source, target, null, addList); } /** * 鍒涘缓 鏈嶅姟璋冪敤閲忕粺璁� Word */ - public void createCountServicesWord() { + public void createCountServicesWord(String source, String target) { List<CountEntity> list = countServices(); if (null == list || list.isEmpty()) { return; } int rows = 1; - String inputFile = "D:\\LF\\鏈嶅姟璋冪敤閲忕粺璁�.docx"; - String outPutFile = "D:\\LF\\鏈嶅姟璋冪敤閲忕粺璁new.docx"; - ArrayList<String[]> addList = new ArrayList<>(); for (CountEntity ce : list) { String[] strs = new String[]{"" + rows++, ce.getM1(), ce.getCount().toString()}; addList.add(strs); } - WordHelper.generateWord(inputFile, outPutFile, null, addList); + WordHelper.generateWord(source, target, null, addList); } /** * 鍒涘缓 鏁版嵁閲忕粺璁� Word */ - public void createCountSizesWord() { + public void createCountSizesWord(String source, String target) { List<CountEntity> list = countSizes(); if (null == list || list.isEmpty()) { return; } int rows = 1; - String inputFile = "D:\\LF\\鏁版嵁閲忕粺璁�.docx"; - String outPutFile = "D:\\LF\\鏁版嵁閲忕粺璁new.docx"; - ArrayList<String[]> addList = new ArrayList<>(); for (CountEntity ce : list) { String[] strs = new String[]{"" + rows++, ce.getM1(), FileHelper.getSizes(ce.getSizes())}; addList.add(strs); } - WordHelper.generateWord(inputFile, outPutFile, null, addList); + WordHelper.generateWord(source, target, null, addList); } } -- Gitblit v1.9.3