czt
2026-01-07 0c8d20900c14651cb50180ade4ccd0e2074796b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.fzzy.common.manager;
 
import com.fzzy.igds.data.ExportWordParam;
import com.fzzy.igds.service.FileService;
import com.fzzy.igds.service.InoutNoticeService;
import com.fzzy.igds.utils.WordUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
 
/**
 * @Description 导出预览下载业务处理
 * @Author CZT
 * @Date 2025/12/29 10:56
 */
@Slf4j
@Component
public class ExportManager {
 
    @Resource
    private FileService fileService;
    @Resource
    private InoutNoticeService noticeService;
 
    /**
     * 渲染模板保存并下载
     * @param param
     * @param response
     */
    public void renderWordDownload(ExportWordParam param, HttpServletResponse response) {
        try {
            if(null == param || StringUtils.isBlank(param.getEntityName())){
                log.error("业务类型为空,不执行导出!");
                return;
            }
 
            String templateName = null;
            //数据封装渲染
            if("InoutNoticeIn".equals(param.getEntityName())){
                templateName = "入库通知单.docx";
            }
            if("InoutNoticeOut".equals(param.getEntityName())){
                templateName = "出库通知单.docx";
            }
 
            if(StringUtils.isBlank(templateName)){
                log.error("模板名称为空,不执行导出!");
                return;
            }
 
            //获取模板路径
            String templatePath = fileService.getFileSavePath("TEMPLATE");
            File file = new File(templatePath + templateName);
            if (!file.exists()) {
                log.error("模板文件不存在,不执行导出!");
                return;
            }
 
            //获取文件保存路径,以库区分开
            String savePath = fileService.getFileSavePath(null);
 
            param.setTemplatePath(templatePath);
            param.setTemplateName(templateName);
            param.setSavePath(savePath);
 
            //数据封装渲染
            if("InoutNoticeIn".equals(param.getEntityName())){
                templateName = "入库通知单.docx";
                param = noticeService.handleInData(param);
            }
            if("InoutNoticeOut".equals(param.getEntityName())){
                templateName = "出库通知单.docx";
                param = noticeService.handleOutData(param);
            }
 
            //保存
            if (null != param.getDataList() && param.getDataList().size() > 1) {
                WordUtil.exportMoreWord(param);
            }else {
                WordUtil.exportWord(param);
            }
 
            // 下载生成的Word文档
            WordUtil.download(savePath, templateName, response);
 
        } catch (Exception e) {
            log.error("下载文件失败", e);
        }
    }
 
}