管理办法手册插入位置逻辑调整
This commit is contained in:
parent
baaf3f4737
commit
64a5b62b0b
@ -2881,58 +2881,150 @@ public class OutputWordUtil {
|
|||||||
* 判断是否需求合并管理要求
|
* 判断是否需求合并管理要求
|
||||||
* @param uuid
|
* @param uuid
|
||||||
*/
|
*/
|
||||||
public static void mergeMRWord(String filePath, String uuid){
|
public static void mergeMRWord(String filePath, String uuid) {
|
||||||
Map<String, JSONObject> stringJSONObjectMap = PALRepositoryQueryAPIManager.queryRepositoryAttributeById(uuid);
|
Map<String, JSONObject> stringJSONObjectMap = PALRepositoryQueryAPIManager.queryRepositoryAttributeById(uuid);
|
||||||
JSONObject attrJson = stringJSONObjectMap.get("management_requirements_Location");
|
JSONObject attrJson = stringJSONObjectMap.get("management_requirements_Location");
|
||||||
String text = attrJson.getString("text");
|
String text = attrJson.getString("text");
|
||||||
if("不显示管理要求".equals(text)){
|
if ("不显示管理要求".equals(text)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BO mrBO = SDK.getBOAPI().getByKeyField("BO_EU_PROCESS_MR", "FILEUUID", uuid);
|
BO mrBO = SDK.getBOAPI().getByKeyField("BO_EU_PROCESS_MR", "FILEUUID", uuid);
|
||||||
if(null!=mrBO){
|
if (null == mrBO || !"1".equals(mrBO.getString("STATUS"))) {
|
||||||
String status = mrBO.getString("STATUS");
|
return;
|
||||||
if(status.equals("1")){//如果为生效状态
|
}
|
||||||
//先获取管理要求附件
|
|
||||||
List<FormFile> systemfile = SDK.getBOAPI().getFiles(mrBO.getId(), "SYSTEMFILE");
|
List<FormFile> systemfile = SDK.getBOAPI().getFiles(mrBO.getId(), "SYSTEMFILE");
|
||||||
FormFile formFile = systemfile.get(0);
|
if (systemfile.isEmpty()) {
|
||||||
DCContext fileDCContext = SDK.getBOAPI().getFileDCContext(formFile);
|
return;
|
||||||
//开始合并
|
}
|
||||||
Document docs1 = new Document();
|
FormFile formFile = systemfile.get(0);
|
||||||
docs1.loadFromFile(filePath);
|
DCContext fileDCContext = SDK.getBOAPI().getFileDCContext(formFile);
|
||||||
// 加载文档2
|
|
||||||
Document docs2 = new Document();
|
// 加载目标文件和待合并文档2
|
||||||
docs2.loadFromFile(fileDCContext.getFilePath());
|
Document docs1 = new Document();
|
||||||
SectionCollection sections1 = docs1.getSections();
|
docs1.loadFromFile(filePath);
|
||||||
//先确认要找到的段落
|
Document docs2 = new Document();
|
||||||
int targetParagraphIndex = 0;
|
docs2.loadFromFile(fileDCContext.getFilePath());
|
||||||
if("流程图前".equals(text)){
|
|
||||||
for (int i = 1; i < sections1.getCount(); i++) {
|
// 定位插入位置:根据text判断是“流程图前”还是“活动说明后(表格后)”
|
||||||
Section section = sections1.get(i);
|
Paragraph targetPara = null;
|
||||||
for (int j = 0; j < section.getParagraphs().getCount(); j++) {
|
Section targetSection = null;
|
||||||
Paragraph para = section.getParagraphs().get(j);
|
int targetParaIndex = -1;
|
||||||
if (para.getText().contains("流程图")) {
|
if ("流程图前".equals(text)) {
|
||||||
targetParagraphIndex = i;
|
// 保持原有“流程图前”逻辑(适配文件中“# 2. 流程图”)
|
||||||
break;
|
for (Object obj : docs1.getSections()) {
|
||||||
}
|
Section sec = (Section) obj;
|
||||||
}
|
int i = 0;
|
||||||
}
|
for (Object parObj : sec.getParagraphs()) {
|
||||||
}else if("活动说明后".equals(text)){
|
Paragraph para = (Paragraph) parObj;
|
||||||
for (int i = 1; i < sections1.getCount(); i++) {
|
if (para.getText().trim().contains("2. 流程图") || para.getText().trim().equals("流程图")) {
|
||||||
Section section = sections1.get(i);
|
targetPara = para;
|
||||||
for (int j = 0; j < section.getParagraphs().getCount(); j++) {
|
targetSection = sec;
|
||||||
Paragraph para = section.getParagraphs().get(j);
|
targetParaIndex = i;
|
||||||
if (para.getText().contains("流程说明")) {
|
break;
|
||||||
targetParagraphIndex = i+1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (targetPara != null) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
sections1.insert(targetParagraphIndex, docs2.getSections().get(0).deepClone());
|
|
||||||
// 保存文档2
|
|
||||||
docs1.saveToFile(filePath, FileFormat.Docx_2013);
|
|
||||||
docs1.dispose();
|
|
||||||
}
|
}
|
||||||
|
} else if ("活动说明后".equals(text)) {
|
||||||
|
boolean foundProcessDesc = false; // 标记已找到“3. 流程说明”标题
|
||||||
|
int lastTableParaIndex = -1; // 记录流程说明表格最后一行的索引
|
||||||
|
for (Object obj : docs1.getSections()) {
|
||||||
|
Section sec = (Section) obj;
|
||||||
|
int i = 0;
|
||||||
|
for (Object paragraph : sec.getParagraphs()) {
|
||||||
|
Paragraph para = (Paragraph) paragraph;
|
||||||
|
String paraText = para.getText().trim();
|
||||||
|
|
||||||
|
// 修正1:匹配文件中实际的“3. 流程说明”标题(含#和数字)
|
||||||
|
if (paraText.contains("3. 流程说明") || paraText.contains("流程说明")) {
|
||||||
|
foundProcessDesc = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 修正2:在“流程说明”后,持续追踪表格最后一行(含|符号)
|
||||||
|
if (foundProcessDesc) {
|
||||||
|
// 表格行含|(如“|01|线上审批55555|...”)
|
||||||
|
if (paraText.contains("|")) {
|
||||||
|
lastTableParaIndex = i; // 持续更新表格最后一行索引
|
||||||
|
} else {
|
||||||
|
// 遇到非表格内容时,插入位置为表格最后一行的下一行
|
||||||
|
if (lastTableParaIndex != -1) {
|
||||||
|
targetParaIndex = i; // 插入到当前非表格段落前(即表格下方)
|
||||||
|
targetPara = para;
|
||||||
|
targetSection = sec;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (targetPara != null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 未找到目标位置则退出
|
||||||
|
if (targetPara == null || targetSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插入文档2内容(保持格式与文件协调)
|
||||||
|
Section doc2Sec = docs2.getSections().get(0);
|
||||||
|
boolean isFirstPara = true;
|
||||||
|
for (Object obj : doc2Sec.getParagraphs()) {
|
||||||
|
Paragraph doc2Para = (Paragraph) obj;
|
||||||
|
Paragraph clonedPara = (Paragraph) doc2Para.deepClone();
|
||||||
|
ParagraphFormat format = clonedPara.getFormat();
|
||||||
|
|
||||||
|
// 核心格式:确保同页且不挤压
|
||||||
|
format.setPageBreakBefore(false);
|
||||||
|
format.setPageBreakAfter(false);
|
||||||
|
format.setKeepLines(true);
|
||||||
|
format.setKeepFollow(true);
|
||||||
|
format.setLineSpacingRule(LineSpacingRule.At_Least);
|
||||||
|
format.setLineSpacing(12f); // 适配文件中行高
|
||||||
|
|
||||||
|
// 第一段与表格保持6磅间距(避免贴紧表格底部)
|
||||||
|
if (isFirstPara) {
|
||||||
|
float beforeSpacing = format.getBeforeSpacing();
|
||||||
|
format.setBeforeSpacing(beforeSpacing > 0 ? beforeSpacing : 6f);
|
||||||
|
isFirstPara = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插入到目标位置(表格下方)
|
||||||
|
targetSection.getParagraphs().insert(targetParaIndex, clonedPara);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调整后续段落(如矩阵标题)与插入内容的间距
|
||||||
|
ParagraphFormat targetFormat = targetPara.getFormat();
|
||||||
|
targetFormat.setBeforeSpacing(6f); // 与插入内容保持6磅间距
|
||||||
|
targetFormat.setPageBreakBefore(false);
|
||||||
|
|
||||||
|
// 保存文档
|
||||||
|
docs1.saveToFile(filePath, FileFormat.Docx_2013);
|
||||||
|
docs1.dispose();
|
||||||
|
docs2.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增:清除文档中的分页符(针对文档2)
|
||||||
|
private static void clearPageBreaks(Document doc) {
|
||||||
|
for (Object obj : doc.getSections()) {
|
||||||
|
Section section= (Section) obj;
|
||||||
|
// 遍历段落,移除手动分页符(假设分页符以特殊字符或元素存在)
|
||||||
|
for (Object obj1 : section.getParagraphs()) {
|
||||||
|
Paragraph para = (Paragraph) obj1;
|
||||||
|
String paraText = para.getText();
|
||||||
|
if (paraText.contains("\f")) {
|
||||||
|
para.setText(paraText.replace("\f", "")); // 清除分页符字符
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user