diff --git a/pom.xml b/pom.xml index 1a986a2..76417a1 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,11 @@ com.fasterxml.jackson.core jackson-databind - + + org.docx4j + docx4j-JAXB-ReferenceImpl + 8.3.11 + com.microsoft.sqlserver diff --git a/src/main/java/com/heai/modules/base/utils/wordTest.java b/src/main/java/com/heai/modules/base/utils/wordTest.java new file mode 100644 index 0000000..070c59f --- /dev/null +++ b/src/main/java/com/heai/modules/base/utils/wordTest.java @@ -0,0 +1,116 @@ +package com.heai.modules.base.utils; + +import org.docx4j.openpackaging.packages.WordprocessingMLPackage; +import org.docx4j.wml.*; + +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +public class wordTest { + // 替换Word文档中的占位符为实际值 + public static void replacePlaceholder(WordprocessingMLPackage wordMLPackage, Map replacements) { + // // 遍历文档中的所有段落 + // List content = wordMLPackage.getMainDocumentPart().getContent(); + // for (Object obj : content) { + // // 处理段落 + // if (obj instanceof P) { + // P paragraph = (P) obj; + // replaceTextInParagraph(paragraph, replacements); + // } + // // 处理表格 + // else if (obj instanceof Tbl) { + // Tbl table = (Tbl) obj; + // replaceTextInTable(table, replacements); + // } + // } + + + for (Object obj : wordMLPackage.getMainDocumentPart().getContent()) { + if (obj instanceof P) { + for (Object p : ((P) obj).getContent()) { + if (p instanceof Text) { + Text text = (Text) p; + String currentText = text.getValue(); + // 替换占位符 + for (Map.Entry entry : replacements.entrySet()) { + String placeholder = entry.getKey(); + String replacement = entry.getValue(); + if (currentText.contains(placeholder)) { + currentText = currentText.replace(placeholder, replacement); + text.setValue(currentText); // 更新文本内容 + } + } + } + } + } + } + } + + // 处理段落中的文本替换 + private static void replaceTextInParagraph(P paragraph, Map replacements) { + for (Object content : paragraph.getContent()) { + if (content instanceof R) { + R run = (R) content; + for (Object runContent : run.getContent()) { + if (runContent instanceof Text) { + Text textElement = (Text) runContent; + String currentText = textElement.getValue(); + System.out.println("Before replacement: " + currentText); + // 替换占位符 + for (Map.Entry entry : replacements.entrySet()) { + String placeholder = entry.getKey(); + String replacement = entry.getValue(); + if (currentText.contains(placeholder)) { + currentText = currentText.replace(placeholder, replacement); + textElement.setValue(currentText); // 更新文本内容 + System.out.println("After replacement: " + currentText); + } + } + } + } + } + } + } + + // 处理表格中的文本替换 + private static void replaceTextInTable(Tbl table, Map replacements) { + for (Object tableRow : table.getContent()) { + if (tableRow instanceof Tr) { + Tr row = (Tr) tableRow; + for (Object cell : row.getContent()) { + if (cell instanceof Tc) { + Tc tableCell = (Tc) cell; + for (Object cellContent : tableCell.getContent()) { + if (cellContent instanceof P) { + P cellParagraph = (P) cellContent; + replaceTextInParagraph(cellParagraph, replacements); + } + } + } + } + } + } + } + + + public static void main(String[] args) throws Exception { + // 加载模板文档 + WordprocessingMLPackage template = WordprocessingMLPackage.load(new java.io.File("D:\\java\\模板.docx")); + + // 定义要插入到模板中的数据 + Map data = new HashMap<>(); + data.put("{角色名}", "杨壮壮"); + data.put("{等级}", "99"); + data.put("{职业}", "散修"); + data.put("{特性}", "老当益壮"); + data.put("{境界}", "结丹期"); + data.put("{称号}", "CKP之王"); + data.put("{必杀技}", "老汉推车"); + // 执行替换操作 + replacePlaceholder(template, data); + + // 将结果保存到新文件 + template.save(new java.io.File("D:\\java\\输出结果.docx")); + } +} diff --git a/src/main/java/com/heai/modules/production/entity/ShopOrderRoutingData.java b/src/main/java/com/heai/modules/production/entity/ShopOrderRoutingData.java index 6f2f4aa..bee0854 100644 --- a/src/main/java/com/heai/modules/production/entity/ShopOrderRoutingData.java +++ b/src/main/java/com/heai/modules/production/entity/ShopOrderRoutingData.java @@ -72,6 +72,7 @@ public class ShopOrderRoutingData extends ShopOrderData{ private String materialSplitFlag; private String liuHuaShiJian; private String yangHuaJiType; + private Float lastTime; public String getMaterialSplitFlag() { return materialSplitFlag; } @@ -404,4 +405,12 @@ public class ShopOrderRoutingData extends ShopOrderData{ public void setBanQty(Integer banQty) { this.banQty = banQty; } + + public Float getLastTime() { + return lastTime; + } + + public void setLastTime(Float lastTime) { + this.lastTime = lastTime; + } } diff --git a/src/main/java/com/heai/modules/production/service/impl/DailyPlanServiceImpl.java b/src/main/java/com/heai/modules/production/service/impl/DailyPlanServiceImpl.java index 3e38bed..97b5268 100644 --- a/src/main/java/com/heai/modules/production/service/impl/DailyPlanServiceImpl.java +++ b/src/main/java/com/heai/modules/production/service/impl/DailyPlanServiceImpl.java @@ -721,7 +721,7 @@ public class DailyPlanServiceImpl implements DailyPlanService { closeData.setSeqNo(inData.getSeqNo()); dailyPlanMapper.closeSchedule(closeData); } - //报废率大于5% 自动生成异常单跳转并触发实验室检验 + //报废率大于系统参数 自动生成异常单跳转并触发实验室检验 Double qtyReported=Double.valueOf(inData.getQtyReported()); Double qtyApprove=Double.valueOf(inData.getQtyApprove()); Integer id =null; diff --git a/src/main/resources/mapper/production/DailyPlanMapper.xml b/src/main/resources/mapper/production/DailyPlanMapper.xml index 0872ebf..02a043f 100644 --- a/src/main/resources/mapper/production/DailyPlanMapper.xml +++ b/src/main/resources/mapper/production/DailyPlanMapper.xml @@ -231,7 +231,8 @@ P.Spec+'/'+isnull(P.PartDescription,'') PartDescription,P.Spec,isnull(SL.scheduledQty,0) as scheduledQty,s.workCenterNo,S.qtyReported,S.qtyApprove,S.machSetupTime, S.machRunFactor,S.factorUnit,S.ItemNo,S.OperationDesc,s.Efficiency,isnull(SOP.TotalFinishedQty,0) lastApproveQty,dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo) weightFactor, Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.LotSize,2) weight,dbo.Get_PartPlanQty(a.site,a.PartNo,a.OrderNo) partPlanQty,cod.PlanShipDate, - dbo.Get_LastStartTime( a.site, a.OrderNo,S.ItemNo) LastStartDate,Round(S.DefectiveQty,3) DefectiveQty,dbo.Get_PartValue( a.site,a.PartNo,'CURING METHOD') cuiHuaJi + dbo.Get_LastStartTime( a.site, a.OrderNo,S.ItemNo) LastStartDate,Round(S.DefectiveQty,3) DefectiveQty,dbo.Get_PartValue( a.site,a.PartNo,'CURING METHOD') cuiHuaJi, + Round((a.LotSize- S.qtyReported)/case when s.MachRunFactor=0 then 1000000 else s.MachRunFactor end ,1) lastTime FROM ShopOrder a LEFT JOIN Part P ON P.PartNo=a.PartNo AND a.site=P.Site LEFT JOIN SORouting S on S.site=a.site and S.OrderNo=a.orderNo