diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java index 328fb86..f81578a 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java @@ -204,10 +204,12 @@ public class StudyFormFillController extends BaseController { List jcgjList = new ArrayList<>(); Integer noExport=999; Boolean jcgj=false; - if (form.getJcgjlx() != null && form.getJcgjlx().intValue() > 0&&!form.getJcgjlx().equals(noExport)) { + if (form.getJcgjlx() != null &&!form.getJcgjlx().equals(noExport)) { QueryWrapper studyFormFillJcgjQueryWrapper = Wrappers.query(); studyFormFillJcgjQueryWrapper.eq("form_id", studyFormFill.getId()); - studyFormFillJcgjQueryWrapper.eq("jcgjlx", form.getJcgjlx()); + if(form.getJcgjlx()>0){ + studyFormFillJcgjQueryWrapper.eq("jcgjlx", form.getJcgjlx()); + } studyFormFillJcgjQueryWrapper.orderByDesc("create_time"); jcgjList = studyFormFillJcgjService.list(studyFormFillJcgjQueryWrapper); jcgj=true; @@ -231,6 +233,27 @@ public class StudyFormFillController extends BaseController { } /** + * 导出 + */ + @RequiresPermissions(value = {"business:studyFormFill:bj", "business:studyFormFill:xz", + "business:nonTrialFormFill:bj", "business:nonTrialFormFill:xz", + "business:drugFormFill:bj", "business:drugFormFill:xz"}, logical = Logical.OR) + @GetMapping(value = "/exportTbByFileUrl") + public AjaxResult exportTbByFileUrl(StudyFormFillExportForm form) { + StudyFormFill studyFormFill = studyFormFillService.queryInfo(form.getStudyFormFillId()); + Study study = studyService.getById(studyFormFill.getStudyId()); + String fileUrl = form.getUrl(); + fileUrl = fileUrl.replaceFirst(localFilePrefix, ""); + int indexOf = fileUrl.lastIndexOf("/"); + String path = fileUrl.substring(0, indexOf); + String exportFileName = StudyFormFillUtil.exportTb(form.getVersion(), form.getLang(), study.getName() + "(" + study.getSn() + ") " + studyFormFill.getBdmc(), + localFilePath + fileUrl, localFilePath + File.separator + path); + + return AjaxResult.success(localFilePrefix + path + File.separator + exportFileName); + } + + + /** * 加签 */ @PostMapping("/jq") diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java index 44f4325..b293bc1 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java @@ -143,6 +143,71 @@ public class StudyFormFillUtil { } /** + * 导出table + * + * @param headerText + * @param fileDir + * @return + */ + public static String exportTb(String version,String lang, String headerText, String srcPdf, String fileDir) { + language = lang; + Document document = null; + FileOutputStream fos = null; + String filePath = ""; + String fileName = ""; + try { + // 1. 生成文件名 + fileName = generateFileName(); + // 2. 确保目录存在 + File dir = new File(fileDir); + if (!dir.exists()) { + dir.mkdirs(); + } + // 3. 完整文件路径 + filePath = Paths.get(fileDir, fileName).toString(); + // 创建PDF文档 设置文档边距,避免内容遮挡页眉页脚 + // 1. 读取原有PDF,获取页面尺寸(保证新文档与原文档格式一致) + PdfReader srcReader = new PdfReader(srcPdf); + // 取第一页尺寸作为新文档尺寸 + Rectangle pageSize = srcReader.getPageSize(1); + // 2. 初始化Document(iText 5的核心高层类) + document = new Document(pageSize); + fos = new FileOutputStream(filePath); + // 3. 关联PdfWriter,绑定Document和输出流(5.5.11必须先创建Writer再open Document) + PdfWriter writer = PdfWriter.getInstance(document, fos); + // 设置页面事件,每页添加文字页眉 + String sign = "hxhq"; + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (loginUser != null) { + sign = loginUser.getSysUser().getNickName() + " " + DateUtils.getTime(); + } + writer.setPageEvent(new TextHeaderEvent(sign+" "+version+" ", headerText, false)); + // 4. 设置PDF属性 + document.addTitle("华西海圻"); + document.addAuthor("华西海圻"); + document.addCreator("华西海圻"); + document.addCreationDate(); + document.open(); + // 5. 复制原有PDF的所有页面到新Document中 + copyOriginalPagesToDocument(document, writer, srcReader); + } catch (Exception e) { + throw new RuntimeException("生成失败: " + e.getMessage()); + } finally { + if (document != null) { + document.close(); + } + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + log.error("关闭文件流失败", e); + } + } + } + return fileName; + } + + /** * 签名信息 * 申请表单 *