From 3ffe33aaa24386337e3638558eca731c62f25521 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 13 九月 2025 13:30:06 +0800
Subject: [PATCH] 修改表格打印的数控程序编号
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ProgramConfirmTableService.java | 433 ++++++++++++++++-------------------------------------
1 files changed, 132 insertions(+), 301 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ProgramConfirmTableService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ProgramConfirmTableService.java
index 5d5b936..fe8af9f 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ProgramConfirmTableService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ProgramConfirmTableService.java
@@ -2,32 +2,26 @@
package org.springblade.mdm.flow.service;
import com.itextpdf.text.*;
-import com.itextpdf.text.pdf.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.flowable.engine.HistoryService;
-import org.flowable.task.api.history.HistoricTaskInstance;
+import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.api.R;
-import org.springblade.core.tool.utils.DateUtil;
-import org.springblade.mdm.basesetting.machine.MachineService;
+import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.basesetting.machine.entity.Machine;
-import org.springblade.mdm.flow.constants.FlowContants;
+import org.springblade.mdm.basesetting.producedivision.entity.QinzheFgb;
+import org.springblade.mdm.basesetting.producedivision.service.QinzheFgbService;
+import org.springblade.mdm.commons.contants.DictBizConstants;
+import org.springblade.mdm.commons.service.ParamService;
+import org.springblade.mdm.commons.support.TemplatedPdfWriter;
import org.springblade.mdm.flow.vo.ApproveTableInfo;
-import org.springblade.mdm.program.entity.NcNode;
-import org.springblade.mdm.program.entity.NcProgramApproved;
import org.springblade.mdm.program.service.NcNodeService;
-import org.springblade.mdm.program.service.NcProgramApprovedService;
+import org.springblade.system.feign.IDictBizClient;
import org.springblade.system.feign.IUserClient;
-import org.springblade.system.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.io.*;
import java.util.*;
-import java.util.List;
/**
* 鏁版帶绋嬪簭纭琛ㄨ緭鍑烘湇鍔�
@@ -38,317 +32,154 @@
@Service
public class ProgramConfirmTableService {
@Autowired
- private FlowCommonService flowCommonService;
+ private QinzheFgbService qinzheFgbService;
+ @Autowired
+ private IDictBizClient dictBizClient;
@Autowired
private NcNodeService ncNodeService;
@Autowired
private MachineService machineService;
@Autowired
- private HistoryService historyService;
+ private OssTemplate ossTemplate;
@Autowired
- private IUserClient useClient;
+ private IUserClient userClient;
@Autowired
- private NcProgramApprovedService programApprovedService;
- private static final String UNCHECK_BOX = "鈽�";
- private static final String CHECKED_BOX = "鈽�";
- static Chunk square = new Chunk("o", new Font(Font.FontFamily.ZAPFDINGBATS, 12)); // 绌烘柟妗�
- static Chunk check = new Chunk("4", new Font(Font.FontFamily.ZAPFDINGBATS, 12)); // 甯﹀嬀鏂规
+ private ParamService paramService;
+ @Autowired
+ private ApproveInfoQueryService approveInfoQueryService;
+ public void exportConfirmTable(FlowProgramProperties props, OutputStream os) throws IOException, DocumentException {
- BaseFont getBaseFont() throws DocumentException, IOException {
- return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+ //byte[] tplBytes = getTemplateBytes();
+ TemplatedPdfWriter pdfWriter = new TemplatedPdfWriter(getTemplateBytes());
+ //generateTempPDF(tplBytes,props,os);
+ pdfWriter.write(getPdfData(props),os);
}
-
- Font getChineseFont() throws DocumentException, IOException {
- BaseFont bfChinese = getBaseFont();
- return new Font(bfChinese, 12, Font.NORMAL);
- }
- public void generateTempPDF()throws Exception {
+ /*
+ void generateTempPDF(byte[] bytes,FlowProgramProperties props,OutputStream outputStream) throws DocumentException, IOException {
PdfReader reader = null;
- PdfStamper ps = null;
- OutputStream fos = null;
- ByteArrayOutputStream bos = null;
- try {
- String fileName = "d:/qrb.pdf";//妯℃澘缁濆璺緞
- reader = new PdfReader(fileName);
- bos = new ByteArrayOutputStream();
- ps = new PdfStamper(reader, bos);
- // 浣跨敤涓枃瀛椾綋
- //BaseFont bf = BaseFont.createFont("sTsong-Light", "uniGB-Ucs2-H", BaseFont.NOT_EMBEDDED);
- BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
- ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
- fontList.add(bf);
- AcroFields fields = ps.getAcroFields();
- fields.setSubstitutionFonts(fontList);
- fillData(fields, data());//鏌�
- //蹇呴』瑕佽皟鐢ㄨ繖涓紝鍚﹀垯鏂囨。涓嶄細鐢熸垚鐨�
- ps.setFormFlattening(true);
- if (ps != null) {
- ps.close();
- }
+ PdfStamper pdfStamper = null;
- //鐢熸垚pdf璺緞瀛樻斁鐨勮矾寰�
- fos = new FileOutputStream("d:/bb2.pdf");
- fos.write(bos.toByteArray());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (fos != null) {
- fos.flush();
- fos.close();
- if (bos != null) {
- bos.close();
- }
- if (reader != null) {
- reader.close();
- }
- }
+ reader = new PdfReader(bytes);
+ pdfStamper = new PdfStamper(reader, outputStream);
+ // 浣跨敤涓枃瀛椾綋
+ BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+ ArrayList<BaseFont> fontList = new ArrayList<>();
+ fontList.add(bf);
+ AcroFields fields = pdfStamper.getAcroFields();
+ fields.setSubstitutionFonts(fontList);
+ fillData(fields, getData(props));//鏌�
+ //蹇呴』瑕佽皟鐢ㄨ繖涓紝鍚﹀垯鏂囨。涓嶄細鐢熸垚鐨�
+ pdfStamper.setFormFlattening(true);
+ pdfStamper.close();
+
+ }
+
+ void fillData(AcroFields fields, Map<String, String> data) throws DocumentException, IOException {
+
+ for (String key : data.keySet()) {
+ String value = data.get(key);
+ // 涓哄瓧娈佃祴鍊�,娉ㄦ剰瀛楁鍚嶇О鏄尯鍒嗗ぇ灏忓啓鐨刦ields.setField(key,value);
+ fields.setField(key,value,true);
+
+ //form.setFieldProperty("fieldName", "clrflags", PdfAnnotation.FLAGS_HIDDEN, null);
+ //fields.setFieldRichValue()
+ }
+
+ }*/
+
+
+
+ /**
+ * 鑾峰彇妯℃澘瀛楄妭鏁扮粍
+ * @return
+ */
+ private byte[] getTemplateBytes() throws IOException {
+ String tplOssName = paramService.confirmTableTemplateOssFileName();
+ try (InputStream inputStream = this.ossTemplate.statFileStream(tplOssName)) {
+ return inputStream.readAllBytes();
}
}
- public void fillData(AcroFields fields, Map<String, String> data) {
- try {
- for (String key : data.keySet()) {
- String value = data.get(key);
- // 涓哄瓧娈佃祴鍊�,娉ㄦ剰瀛楁鍚嶇О鏄尯鍒嗗ぇ灏忓啓鐨刦ields.setField(key,value);
- fields.setField(key,value);
- }
- }catch(Exception e){
- e.printStackTrace();
+ /**
+ * 鑾峰彇鎵撳嵃琛ㄦ牸鐨勬暟鎹�
+ * @param props 娴佺▼灞炴��
+ * @return 鏁版嵁map
+ */
+ Map<String,String> getPdfData(FlowProgramProperties props){
+ Map<String,String> data = new HashMap<>();
+ data.put("pageTotal","1");
+ data.put("pageNo","1");
+ data.put("processNo",props.getProcessNo());
+ data.put("drawingNo",props.getDrawingNo());
+ data.put("drawingNoEdition",props.getDrawingNoEdition());
+ data.put("processName",props.getProcessName());
+ data.put("processEdition",props.getProcessEdition());
+ data.put("machineCode",props.getMachineCode());
+ data.put("productModel",props.getProductModel());
+ data.put("craftEdition",props.getCraftEdition());
+ //闆剁粍浠跺悕绉�
+ data.put("drawingName",getDrawingName(props.getDrawingNo()));
+ data.put("deviation",props.getDeviation()!=null?props.getDeviation():StringUtils.EMPTY);
+
+
+
+ Machine machine = this.machineService.getByCode(props.getMachineCode());
+ data.put("machineMode",machine.getName());
+ R<String> dictSystemResult = dictBizClient.getValue(DictBizConstants.CONTROL_SYSTEM,machine.getControlSystem());
+ if(dictSystemResult.isSuccess()){
+ data.put("controlSystem",dictSystemResult.getData());
}
- }
- Map<String,String> data(){
- Map<String,String> ret = new HashMap<>();
- ret.put("drawingName","涓枃鍥惧悕");
- ret.put("craftEdition","TH0001");
- return ret;
- }
- public void exportConfirmTable(String processInstanceId, OutputStream os) throws DocumentException, IOException {
+ data.put("operator","鏉ユ簮MES/2025-1-1");
+ data.put("jjy","鏉ユ簮MES/2025-1-1");
+ data.put("fuheY","Y");//TODO 鏈� 妫�楠屽憳 鍒欑鍚�
+ data.put("keyongY","Y");//TODO 鏈� 妫�楠屽憳 鍒欑鍚�
- BaseFont bfChinese = getBaseFont();
+ data.put("jly","鏉ユ簮MES/2025-1-1");
+ data.put("jln","鏉ユ簮MES/2025-1-1");
+ ApproveTableInfo approveInfo = approveInfoQueryService.getApproveInfo(props);
+ data.put("programmerName",approveInfo.getProgrammerName());
+ data.put("checkerName",approveInfo.getCheckerName());
+ data.put("seniorName",approveInfo.getSeniorName());
- Document document = new Document(PageSize.B5.rotate());
- PdfWriter.getInstance(document, os);
+ data.put("programNo",approveInfo.getProgramNo());
- document.open();
-
- FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(processInstanceId);
-
- ApproveTableInfo appInfo = getApproveInfo(props);
- Machine machine;
- String machineCode = props.getMachineCode();
- machine = machineService.getByCode(machineCode);
-
- int flag = props.getProcessDefinitionKey().equals(FlowContants.TRY_PROCESS_KEY)?1:2;
- printPage(document, bfChinese, props, machine);
- //document.newPage();
-
-
- //printPage(document, bfChinese, props, machine, 2, appInfo);
-
- document.close();
+ return data;
}
-
-
- void printPage(Document document, BaseFont bfChinese, FlowProgramProperties props, Machine machine) throws DocumentException, IOException {
-
- Font tableFont = new Font(bfChinese, 12, Font.NORMAL);
-
-
- PdfPTable titleTable = new PdfPTable(2);
- titleTable.setWidthPercentage(100);
- titleTable.setSpacingBefore(10f);
- titleTable.setSpacingAfter(10f);
-
- PdfPCell celBh = this.getCell("缂栧彿:",tableFont);
- titleTable.addCell(celBh);
- PdfPCell celYb = this.getCell("鑹鸿〃8",tableFont);
-
- titleTable.addCell(celYb);
-
- document.add(titleTable);
-
-
- //document.add(title);
- // 鍒涘缓琛ㄦ牸锛�4鍒楋級
- PdfPTable table = new PdfPTable(6);
- table.setWidths(new float[]{1, 1.3f, 1f, 1.3f,1, 1.5f});
-
- Font ft = this.getChineseFont();
- // 娣诲姞琛ㄥご
- PdfPCell tempCell = getCell("涓�涓�鍥涘巶",tableFont);
-
- //
- table.addCell(tempCell);
-
- tempCell = getCell("鏁版帶绋嬪簭纭琛�",tableFont);
- table.addCell(tempCell);
- table.addCell(getCell("宸ュ簭鍙�", ft));
- table.addCell(getCell("宸ヨ壓鐗堟", ft));
- table.addCell(getCell("鏈哄簥鍨嬪彿", ft));
- table.addCell(getCell("宸ユ璐熻矗浜�/鍗曞厓璐焅n璐d汉娲惧嚭鏃堕棿", ft));
-
-
- table.addCell(getCell(props.getDrawingNo(), ft));//闆剁粍浠跺彿
-
- table.addCell(getCell(props.getProcessNo(), ft));//宸ュ簭鍙�
-
- table.addCell(getCell(props.getCraftEdition(), ft));//宸ヨ壓鐗堟
- table.addCell(getCell(machine.getName(), ft));//鏈哄簥鍨嬪彿
- table.addCell(getCell("", ft));//璐熻矗浜猴紝宸ユ璐熻矗浜烘淳鍑烘椂闂�
-
- //涓棿澶ф牸
- PdfPCell cell = new PdfPCell();
- cell.setColspan(5);
- cell.setCalculatedHeight(400);
- Paragraph mainPara1 = new Paragraph();
- mainPara1.setLeading(30f, 0f);
- mainPara1.setFont(ft);
- mainPara1.setAlignment(Element.ALIGN_LEFT); // 瀵归綈鏂瑰紡
- mainPara1.setIndentationLeft(20); // 宸︾缉杩�(鍍忕礌)
- mainPara1.setIndentationRight(20); // 鍙崇缉杩�
- mainPara1.setSpacingBefore(10); // 娈靛墠闂磋窛
- mainPara1.setSpacingAfter(10); // 娈靛悗闂磋窛
-
-
- mainPara1.add("鏁版帶绋嬪簭缂栧埗浠诲姟瀹夋帓:\n");
- cell.addElement(mainPara1);
-
- Paragraph line2Para = new Paragraph();
- line2Para.setLeading(30f, 0f);
- line2Para.setFont(ft);
- line2Para.setAlignment(Element.ALIGN_LEFT); // 瀵归綈鏂瑰紡
- line2Para.setIndentationLeft(40); // 宸︾缉杩�(鍍忕礌)
- line2Para.add("璇�");
-
- Font underLineFt = new Font(bfChinese, 12, Font.UNDERLINE);
-
- //String personName = record.getUserNickname();
- Chunk block1 = square;
- Chunk block2 = check;
-
- cell.addElement(line2Para);
-
- Paragraph fangzhen = new Paragraph();
- fangzhen.setAlignment(Element.ALIGN_LEFT); // 瀵归綈鏂瑰紡
- fangzhen.setIndentationLeft(20); // 宸︾缉杩�(鍍忕礌)
- fangzhen.setIndentationRight(20); // 鍙崇缉杩�
- fangzhen.setSpacingBefore(10); // 娈靛墠闂磋窛
- fangzhen.setSpacingAfter(10); // 娈靛悗闂磋窛
- fangzhen.setFont(ft);
- fangzhen.setLeading(30f, 0f);
- fangzhen.add("鏄惁闇�瑕佷豢鐪燂紙鏄�");
- fangzhen.add(check);//鍥哄畾鏄豢鐪�
- fangzhen.add(" 鍚�");
- fangzhen.add(square);
- fangzhen.add("锛塡n\n");
-
- cell.addElement(fangzhen);
- table.addCell(cell);
- //涓嬩竴琛�
- PdfPCell cell21 = getCell("鏁版帶绋嬪簭缂栧彿", ft);// PdfPCell();
- cell21.setColspan(2);
- //cell21.setPhrase(new Phrase("鏁版帶绋嬪簭缂栧彿",ft));
- table.addCell(cell21);
- table.addCell(getCell("缂栧埗/鏃ユ湡", ft));
- table.addCell(getCell("鏍″/鏃ユ湡", ft));
- table.addCell(getCell("鎵瑰噯/鏃ユ湡", ft));
-
- PdfPCell cell2 = getCell("00001", ft);
- cell2.setColspan(2);
-
- //cell2.addElement(new Phrase(programPackageNode.getProgramNo(),ft));//鏁版帶绋嬪簭缂栧彿
- //cell2.addElement(new Phrase("00001",ft));
- table.addCell(cell2);
-
- // 璁剧疆琛ㄦ牸瀹藉害鍗犻〉闈㈠搴︾殑100%
- table.setWidthPercentage(100);
-
- // 娣诲姞琛ㄦ牸鍒版枃妗�
- document.add(table);
-
- Phrase lastPhrase = new Phrase("娉�:宸ユ娲惧伐搴旈鍏堣鍒掋�佸悎鐞嗗畨鎺掓暟鎺х▼搴忕紪鍒躲�傜珛鍔犮�佹暟閾c�佹暟杞︾瓑鍗曢亾宸ュ簭绋嬪簭(涓よ酱绋嬪簭)闇�鎻愬墠1涓伐浣滄棩锛屽崸寮忓姞宸ヤ腑蹇冨崟閬撳伐搴�(鍚杞寸▼搴�)闇�鎻愬墠3涓伐浣滄棩銆� ", ft);
- document.add(lastPhrase);
- }
-
- PdfPCell getCell(String text, Font font) throws DocumentException, IOException {
- PdfPCell cell = new PdfPCell();
- cell.setPadding(10);
- cell.setHorizontalAlignment(Element.ALIGN_CENTER);
- cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
- if (StringUtils.isNotBlank(text)) {
- Phrase p = new Phrase(text, font);
- p.setLeading(25);
- cell.setPhrase(p);
+ /**
+ * 鏌ヨ绋嬪簭缂栧彿
+ * @param nodeId
+ * @return
+ */
+ /*
+ private String queryProgramNo(Long nodeId) {
+ if(nodeId ==null) {
+ return StringUtils.EMPTY;
}
-
- return cell;
- }
-
- ApproveTableInfo getApproveInfo(FlowProgramProperties props){
- //缂栧埗
- R<User> leaderR = useClient.userInfoById(props.getTeamLeaderId());
- String leaderName = "";
- if (leaderR.isSuccess()) {
- leaderName = leaderR.getData().getName();
- }
- //缂栧埗
- R<User> programmerR = useClient.userInfoById(props.getProgrammerId());
- String programmerName = "";
- if (programmerR.isSuccess()) {
- programmerName = programmerR.getData().getName();
- }
- Machine machine;
- String machineCode = props.getMachineCode();
- machine = machineService.getByCode(machineCode);
-
- //鏍″
- R<User> checkerR = useClient.userInfoById(props.getCheckerId());
- String checkerName = "";
- if (checkerR.isSuccess()) {
- checkerName = checkerR.getData().getName();
- }
- //瀹℃牳
- R<User> seniorR = useClient.userInfoById(props.getCheckerId());
- String senioirName = "";
- if (seniorR.isSuccess()) {
- senioirName = seniorR.getData().getName();
- }
- ApproveTableInfo appInfo = new ApproveTableInfo();
- appInfo.setTeamLeaderName(leaderName);
- appInfo.setProgrammerName(programmerName);
- appInfo.setCheckerName(checkerName);
- appInfo.setSeniorName(senioirName);
-
- //鑾峰彇鏃堕棿淇℃伅
- List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery()
- .processInstanceId(props.getProcessInstanceId()).orderByTaskCreateTime().desc().list();
-
- for(HistoricTaskInstance task : hisTasks){
- if(appInfo.getProgrammingDate()== null && task.getTaskDefinitionKey().contains("program")){
- appInfo.setProgrammingDate(task.getEndTime());
- }
-
- if(appInfo.getCheckDate()== null && task.getTaskDefinitionKey().contains("check")){
- appInfo.setCheckDate(task.getEndTime());
- }
-
- if(appInfo.getApproveDate()== null && task.getTaskDefinitionKey().contains("approve")){
- appInfo.setApproveDate(task.getEndTime());
- }
- }
-
- //鏌ヨ鏁版帶绋嬪簭缂栧彿
- Optional<NcProgramApproved> appOpt = programApprovedService.lambdaQuery().eq(NcProgramApproved::getProcessInstanceId, props.getProcessInstanceId()).oneOpt();
- if(appOpt.isEmpty()){
- appInfo.setProgramNo("锛堟湭鐢熸垚锛�");
+ NcNode programPkdNode = this.ncNodeService.getById(nodeId);
+ if (programPkdNode != null) {
+ return programPkdNode.getProgramNo();
}else{
- NcNode programPkgNameNode = this.ncNodeService.getById(appOpt.get().getNcNodeId());
- appInfo.setProgramNo(programPkgNameNode.getProgramNo());
+ return StringUtils.EMPTY;
}
- return appInfo;
+
+ }
+ */
+ /**
+ * 鑾峰彇闆剁粍浠跺悕绉�
+ * @param drawingNo 闆朵欢缂栧彿
+ * @return 闆剁粍浠跺悕绉�
+ */
+ String getDrawingName(String drawingNo){
+ QinzheFgb fgb = qinzheFgbService.getByLjh(drawingNo);
+ if(fgb!= null){
+ return fgb.getLjmc();
+ }else{
+ return StringUtils.EMPTY;
+ }
+
}
}
--
Gitblit v1.9.3