From 603e4c7f06c99323d60a32de28a4e3df3db69f4f Mon Sep 17 00:00:00 2001 From: zhc077 <565291854@qq.com> Date: Fri, 22 Nov 2024 17:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=94=9F=E6=88=90=E5=90=88?= =?UTF-8?q?=E5=B9=B6=2011.22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/controller/ProjectController.java | 3 + .../service/impl/Project4WordServiceImpl.java | 59 ++++++++++++++----- .../src/main/resources/application-prod.yml | 1 + .../kejigongguan/xiangmushu/ZhengWenDemo.vue | 4 +- .../zhengwen/ProjectFile4ZhengWen.data.ts | 4 +- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java index 97fe1bc..2482889 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java @@ -608,6 +608,9 @@ public class ProjectController extends JeecgController log.setProjectStatus("6"); log.setBudgetStatus("6"); log.setOperationMark("申请人提交项目书,申请人提交预算书"); + + //提交项目时,生成项目书pdf文件 + iProject4WordService.createXiangMuShu4Word(project); } //申请单位审核通过,并向上级提交->科技主管部门待提交(区/县管理员) if ("faren_admin".equals(loginUser.getRoleCode())) { diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java index 8ce6992..2b9491a 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java @@ -18,6 +18,8 @@ import org.jeecg.modules.demo.project.dto.ProjectDto; import org.jeecg.modules.demo.project.entity.Project; import org.jeecg.modules.demo.project.mapper.ProjectMapper; import org.jeecg.modules.demo.project.service.IProject4WordService; +import org.jeecg.modules.demo.projectFile.entity.ProjectFile; +import org.jeecg.modules.demo.projectFile.service.IProjectFileService; import org.jeecg.modules.demo.projectMember.entity.ProjectMember; import org.jeecg.modules.demo.projectMember.service.IProjectMemberService; import org.jeecg.modules.demo.projectType.entity.ProjectType; @@ -33,7 +35,6 @@ import org.jeecg.modules.system.service.impl.SysBaseApiImpl; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; @@ -46,9 +47,11 @@ import java.util.List; import java.util.Map; /** - * @Description: 项目表 + * @Description: 根据模板填充数据生成word文件, + * 合并正文、意见文件 + * 生成pdf文件 * @Author: jeecg-boot - * @Date: 2024-10-17 + * @Date: 2024-11-19 * @Version: V1.0 */ @Service @@ -72,12 +75,18 @@ public class Project4WordServiceImpl extends ServiceImpl @Autowired private IProjectTypeService iProjectTypeService; + @Autowired private IProjectMemberService iProjectMemberService; + @Autowired + private IProjectFileService iProjectFileService; + ProjectDto getData4Xiangmushu(Project req) { - Project project = this.getById("1849284130146025473"); +// Project project = this.getById("1849284130146025473"); + if (ObjectUtils.isEmpty(req.getId())) return null; + Project project = this.getById(req.getId()); if (ObjectUtils.isEmpty(project)) return null; ProjectDto dto = new ProjectDto(); @@ -241,23 +250,25 @@ public class Project4WordServiceImpl extends ServiceImpl return dto; } - @Autowired - private ResourceLoader resourceLoader; - @Value("${jeecg.path.model4word}") private String model4wordPath; + /* @Value("${jeecg.path.upload}") + private String uploadPath;*/ + @Override public Object createXiangMuShu4Word(Project obj) { ProjectDto dto = getData4Xiangmushu(obj); + if (ObjectUtil.isEmpty(dto)) { + return null; + } Map map = BeanUtil.beanToMap(dto); - System.out.println("map = " + JSON.toJSONString(map)); + log.info("--------项目模板填充数据:{}" + JSON.toJSONString(map)); File file = new File(model4wordPath + File.separator); String basePath = file.getPath() + File.separator; -// String modelFilePath = basePath + "baseInfoModel.docx"; -// String modelFilePath = basePath + "model2v.doc"; - String modelFilePath = "C:\\Users\\YX\\Documents\\model3v.docx"; - log.info("the baseInfoModel path:{}", modelFilePath); + log.info("---------------------the basePath:{}", basePath); + String modelFilePath = basePath + "baseInfoModel.docx"; + log.info("---------------------the baseInfoModel path:{}", modelFilePath); String mergeWordFileName = dto.getProjectName() + ".docx"; File outDir = new File(basePath + "pdf"); if (!outDir.exists()) { @@ -269,9 +280,25 @@ public class Project4WordServiceImpl extends ServiceImpl List wordList = new ArrayList<>(); // 文件第一部分 wordList.add(doc); + //正文部门 文件第二部分 - FileInputStream fis = new FileInputStream(basePath + "正文.docx"); - wordList.add(new XWPFDocument(fis)); + ProjectFile projectFile = iProjectFileService.getOne(new LambdaQueryWrapper() + .eq(ProjectFile::getProjectId, dto.getId()) + .eq(ProjectFile::getFileType, "docx") + .orderByDesc(ProjectFile::getCreateTime)); + if (ObjectUtil.isNotEmpty(projectFile)) { + //windwos 下直接写回写路径 + FileInputStream fis = new FileInputStream("F:\\opt\\upFiles\\temp\\" + projectFile.getFileName()); + + + //linux 环境下 +// FileInputStream fis = new FileInputStream(basePath + projectFile.getFileName()); + wordList.add(new XWPFDocument(fis)); + } else { //若正文为空则拼接正文模板 + FileInputStream fis = new FileInputStream(basePath + "shenqingshu.docx"); + wordList.add(new XWPFDocument(fis)); + } + // 意见部分 文件第三部分 FileInputStream fis2 = new FileInputStream(basePath + "yiJianModel.docx"); wordList.add(new XWPFDocument(fis2)); @@ -279,8 +306,8 @@ public class Project4WordServiceImpl extends ServiceImpl XWPFDocument mergeWordObj = WordUtils.mergeWord(wordList); FileOutputStream fos = new FileOutputStream(new File(outDir, mergeWordFileName)); //已合并过的文件,删除 - File oldMergeWord = new File(outDir + File.separator + dto.getProjectName()+".docx"); - File oldPdf = new File(outDir + File.separator + dto.getProjectName()+".pdf"); + File oldMergeWord = new File(outDir + File.separator + dto.getProjectName() + ".docx"); + File oldPdf = new File(outDir + File.separator + dto.getProjectName() + ".pdf"); if (oldMergeWord != null && oldMergeWord.isFile() && oldMergeWord.exists()) { oldMergeWord.delete(); } diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml index 9f70760..1da231e 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml @@ -216,6 +216,7 @@ jeecg: path: #文件上传根目录 设置 upload: /opt/kjj/upload + model4word: /opt/kjj/upload #webapp文件路径 webapp: /opt/kjj/webapp shiro: diff --git a/jeecgboot-vue3/src/views/projectApplication/kejigongguan/xiangmushu/ZhengWenDemo.vue b/jeecgboot-vue3/src/views/projectApplication/kejigongguan/xiangmushu/ZhengWenDemo.vue index 9fe392c..df0aecd 100644 --- a/jeecgboot-vue3/src/views/projectApplication/kejigongguan/xiangmushu/ZhengWenDemo.vue +++ b/jeecgboot-vue3/src/views/projectApplication/kejigongguan/xiangmushu/ZhengWenDemo.vue @@ -2,7 +2,7 @@
下载模板 + @click="downloadFile('temp/shenqingshu.docx')">下载模板
@@ -101,7 +101,7 @@ const schemas2: FormSchema[] = [ }, // label: '富文本', defaultValue: '上传主表信息\n' + - '第一步:下载项目申请书word模板(shenqingshu.doc)。\n' + + '第一步:下载项目申请书word模板(shenqingshu.docx)。\n' + '第二步:打开项目申请书模板,在word中填写项目申请书。\n' + '第三步:将填写完整无误,不再修改的项目申请书(word)上传。', dynamicDisabled: true, diff --git a/jeecgboot-vue3/src/views/projectFile/zhengwen/ProjectFile4ZhengWen.data.ts b/jeecgboot-vue3/src/views/projectFile/zhengwen/ProjectFile4ZhengWen.data.ts index 580eaba..5bc02d4 100644 --- a/jeecgboot-vue3/src/views/projectFile/zhengwen/ProjectFile4ZhengWen.data.ts +++ b/jeecgboot-vue3/src/views/projectFile/zhengwen/ProjectFile4ZhengWen.data.ts @@ -42,9 +42,9 @@ export const formSchema: FormSchema[] = [ field: 'fileUrl', labelLength: 100, component: 'JUpload', - helpMessage: '1次最多上传1个文件,可多次上传', + helpMessage: '只能上传一个申请书模板正文,且格式必须为.docx', componentProps: { - fileType: UploadTypeEnum.all, + fileType: UploadTypeEnum.file, maxCount: 1, }, },