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); } } /** * 渲染模板保存并下载 * * @param response */ public void downloadInoutExcel(HttpServletResponse response) { try { String savePath = fileService.getFileSavePath("TEMPLATE"); String templateName = "出入库数据模板.xlsx"; //下载文档 WordUtil.download(savePath, templateName, response); } catch (Exception e) { log.error("下载文件失败", e); } } }