Browse Source

fix:[模板管理]导出

master
15881625488@163.com 2 weeks ago
parent
commit
3c394570f5
2 changed files with 90 additions and 2 deletions
  1. +25
    -2
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java
  2. +65
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java

+ 25
- 2
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudyFormFillController.java View File

@ -204,10 +204,12 @@ public class StudyFormFillController extends BaseController {
List<StudyFormFillJcgj> jcgjList = new ArrayList<>(); List<StudyFormFillJcgj> jcgjList = new ArrayList<>();
Integer noExport=999; Integer noExport=999;
Boolean jcgj=false; Boolean jcgj=false;
if (form.getJcgjlx() != null && form.getJcgjlx().intValue() > 0&&!form.getJcgjlx().equals(noExport)) {
if (form.getJcgjlx() != null &&!form.getJcgjlx().equals(noExport)) {
QueryWrapper<StudyFormFillJcgj> studyFormFillJcgjQueryWrapper = Wrappers.query(); QueryWrapper<StudyFormFillJcgj> studyFormFillJcgjQueryWrapper = Wrappers.query();
studyFormFillJcgjQueryWrapper.eq("form_id", studyFormFill.getId()); studyFormFillJcgjQueryWrapper.eq("form_id", studyFormFill.getId());
studyFormFillJcgjQueryWrapper.eq("jcgjlx", form.getJcgjlx());
if(form.getJcgjlx()>0){
studyFormFillJcgjQueryWrapper.eq("jcgjlx", form.getJcgjlx());
}
studyFormFillJcgjQueryWrapper.orderByDesc("create_time"); studyFormFillJcgjQueryWrapper.orderByDesc("create_time");
jcgjList = studyFormFillJcgjService.list(studyFormFillJcgjQueryWrapper); jcgjList = studyFormFillJcgjService.list(studyFormFillJcgjQueryWrapper);
jcgj=true; 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") @PostMapping("/jq")

+ 65
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/StudyFormFillUtil.java View File

@ -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. 初始化DocumentiText 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;
}
/**
* 签名信息 * 签名信息
* 申请表单 * 申请表单
* *

Loading…
Cancel
Save