|
@@ -752,6 +752,32 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 将文档按页拆分为多个独立的 Document 对象
|
|
|
+ * @param originalDoc 原始文档
|
|
|
+ * @param pageCount 总页数
|
|
|
+ * @return 拆分后的 Document 数组
|
|
|
+ */
|
|
|
+ public static Document[] splitDocumentByPages(Document originalDoc, int pageCount) {
|
|
|
+ Document[] splitDocs = new Document[pageCount];
|
|
|
+ for (int i = 0; i < pageCount; i++) {
|
|
|
+ try {
|
|
|
+ // 创建一个新的 Document 用于存储当前页内容
|
|
|
+ Document extractedPage = new Document();
|
|
|
+ extractedPage.removeAllChildren();
|
|
|
+ // 获取当前页的节点
|
|
|
+ Document pageNodes = originalDoc.extractPages(i, 1);
|
|
|
+ // 将当前页的节点添加到新文档中
|
|
|
+ for (Node node : (Iterable<Node>) pageNodes) {
|
|
|
+ extractedPage.appendChild(extractedPage.importNode(node, true));
|
|
|
+ }
|
|
|
+ splitDocs[i] = extractedPage;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return splitDocs;
|
|
|
+ }
|
|
|
/**
|
|
|
* 导出文件汇编
|
|
|
* @param map
|
|
@@ -759,6 +785,12 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
*/
|
|
|
@Override
|
|
|
public R exportFile(Map<String, Object> map, HttpServletResponse response) throws Exception {
|
|
|
+ // 前端传来模板id
|
|
|
+ String fileId = "d1b3271ce2ec45c2915f2dbcd819f45a";
|
|
|
+ Object fileIdObj = map.get("fileId");
|
|
|
+ if(Objects.nonNull(fileIdObj)){
|
|
|
+ //fileId = (String) fileIdObj;
|
|
|
+ }
|
|
|
Object projectObj = map.get("projectId");
|
|
|
Object machineNoObj = map.get("machineNo");
|
|
|
Object exportObj = map.get("exportType");
|
|
@@ -767,8 +799,13 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
String machineNo = (String) machineNoObj;
|
|
|
String exportType = (String) exportObj;
|
|
|
ZhcxProjectManageDo projectManageDo = zhcxProjectManageService.getById(projectId);
|
|
|
- SysFileItemDo fileItemDo = sysFileItemService.getById("d1b3271ce2ec45c2915f2dbcd819f45a");
|
|
|
+ // 首页模板地址: d1b3271ce2ec45c2915f2dbcd819f45a
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById(fileId);
|
|
|
final Document[] indexDoc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
|
|
|
+ //Document indexDoc = WordHelpUtils.getDoc(fileItemDo.getFullpath());
|
|
|
+ // 分割文档
|
|
|
+ //Document[] splitDocs = splitDocumentByPages(indexDoc, 2);
|
|
|
+
|
|
|
FormData formData = new FormData();
|
|
|
List<Map<String,Object>> mainDataList = new ArrayList<>();
|
|
|
Map<String,Object> mainMap = new HashMap<>(16);
|
|
@@ -783,14 +820,18 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
mainMap.put("machineNo",machineNo);
|
|
|
mainDataList.add(mainMap);
|
|
|
formData.setMainDataList(mainDataList);
|
|
|
+ // 历史版本
|
|
|
indexDoc[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
|
|
|
+ //splitDocs[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
|
|
|
List<ZhcxCommissionCheckDetailDo> list = zhcxCommissionCheckDetailDao.listData(map);
|
|
|
List<ZhcxCommissionCheckDetailTreeDo> checkTreeList = zhcxCommissionCheckDetailTreeService.listCheckDetailTreeData(map);
|
|
|
Document doc = null;
|
|
|
DocumentBuilder builder = null;
|
|
|
ClassPathResource classPathResource = new ClassPathResource("template/检查内容明细模版.doc");
|
|
|
try {
|
|
|
+ // 历史版本
|
|
|
doc = new Document(classPathResource.getInputStream());
|
|
|
+ //doc = splitDocs[1];
|
|
|
builder = new DocumentBuilder(doc);
|
|
|
} catch (Exception e) {
|
|
|
ExceptionUtils.printExceptionDetail(e,"空模板获取出现异常");
|
|
@@ -1012,8 +1053,10 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
}
|
|
|
// 创建模板A的副本
|
|
|
Document cloneDocA = indexDoc[0].deepClone();
|
|
|
+ //Document cloneDocA = splitDocs[0].deepClone();
|
|
|
// 在副本上合并文档B
|
|
|
cloneDocA.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
|
|
|
+ //cloneDocA.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
|
|
|
if("export".equals(exportType)){
|
|
|
exportWord(cloneDocA, response);
|
|
|
}else {
|