From a3a9933cf1b49006edf470615236f94ebdaa4cb9 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 03 九月 2025 17:04:24 +0800
Subject: [PATCH] 增加车床程序处理;退回改为实际编程员

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java |  348 +++++++--------------------------------------------------
 1 files changed, 43 insertions(+), 305 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java
index 0cb9b19..7336c4b 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java
@@ -3,26 +3,16 @@
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.flowable.engine.HistoryService;
-import org.flowable.engine.history.HistoricProcessInstance;
-import org.flowable.engine.runtime.ProcessInstance;
-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.core.tool.utils.Func;
-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.commons.service.ParamService;
 import org.springblade.mdm.commons.support.TemplatedPdfWriter;
 import org.springblade.mdm.flow.constants.FlowContants;
 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.IUserClient;
-import org.springblade.system.pojo.entity.User;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -30,10 +20,10 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.*;
-import java.util.List;
 
 import com.itextpdf.text.*;
-import com.itextpdf.text.pdf.*;
+import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
+
 /**
  * 瀹℃壒璁板綍锛岀敤浜庢煡璇㈡墽琛岃建杩�
  *
@@ -49,23 +39,23 @@
 	@Autowired
 	private MachineService machineService;
 	@Autowired
-	private HistoryService historyService;
-	@Autowired
 	private IUserClient useClient;
-	@Autowired
-	private NcProgramApprovedService programApprovedService;
 	@Autowired
 	private ParamService paramService;
 	@Autowired
 	private OssTemplate ossTemplate;
 
-	private final String DATE_PATTERN = "yyyy-M-d";
+	@Autowired
+	private ApproveInfoQueryService approveInfoQueryService;
 
-	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)); // 甯﹀嬀鏂规
+	@Autowired
+	private FreeMarkerConfigurer freeMarkerConfigurer;
 
+	//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)); // 甯﹀嬀鏂规
+	/*
 	BaseFont getBaseFont() throws DocumentException, IOException {
 		return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
 	}
@@ -73,12 +63,33 @@
 	Font getChineseFont() throws DocumentException, IOException {
 		BaseFont bfChinese = getBaseFont();
 		return new Font(bfChinese, 12, Font.NORMAL);
-	}
+	}*/
 
 	public void exportApproveTable(String processInstanceId, OutputStream os) throws IOException, DocumentException {
 		FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(processInstanceId);
 
-		ApproveTableInfo approveInfo = getApproveInfo(props);
+		TemplatedPdfWriter pdfWriter = new TemplatedPdfWriter(getTemplateBytes());
+		pdfWriter.write(getPdfData(props),os);
+	}
+
+	/**
+	 * 鑾峰彇pdf妯℃澘鐨勫瓧鑺傛暟缁�
+	 * @return 妯℃澘瀛楄妭鏁扮粍
+	 * @throws IOException
+	 */
+	private byte[] getTemplateBytes() throws IOException {
+		String tplOssName = paramService.approveTableTemplateOssFileName();
+		try (InputStream inputStream = this.ossTemplate.statFileStream(tplOssName)) {
+			return inputStream.readAllBytes();
+		}
+	}
+
+	/**
+	 * 鑾峰彇濉厖鏁版嵁
+	 */
+
+	Map<String,String> getPdfData(FlowProgramProperties props){
+		ApproveTableInfo approveInfo = approveInfoQueryService.getApproveInfo(props);
 		Machine machine;
 		String machineCode = props.getMachineCode();
 		machine = machineService.getByCode(machineCode);
@@ -88,6 +99,8 @@
 		pdfData.put("processNo",props.getProcessNo());
 		pdfData.put("craftEdition",props.getCraftEdition());
 		pdfData.put("machineMode",machine.getName());
+
+		String DATE_PATTERN = "yyyy-M-d";
 
 		String dispatchDateStr = " ";
 		if (approveInfo.getDispatchDate() != null) {
@@ -100,10 +113,12 @@
 			pdfData.put("fuzeren",approveInfo.getCheckerName());
 			pdfData.put("checkY","Y");//鍥哄寲锛屽睘浜庢牎瀵逛换鍔�
 		}else{
-			pdfData.put("fuzeren",approveInfo.getProgrammerName());
+			pdfData.put("fuzeren",approveInfo.getProgrammerName());//璐熻矗浜�
 			pdfData.put("programY","Y");//鍏朵粬锛屽睘浜庣紪鍒朵换鍔�
 		}
 		pdfData.put("fangzhenY","Y");
+
+		pdfData.put("programNo",approveInfo.getProgramNo());
 
 		Date programDate = approveInfo.getCheckDate();
 		Date checkDate = approveInfo.getCheckDate();
@@ -128,17 +143,10 @@
 
 		pdfData.put("sendDir",machine.getProgSendDir()!=null?machine.getProgSendDir():"");
 
-		TemplatedPdfWriter pdfWriter = new TemplatedPdfWriter(getTemplateBytes());
-
-		pdfWriter.write(pdfData,os);
-	}
-	private byte[] getTemplateBytes() throws IOException {
-		String tplOssName = paramService.approveTableTemplateOssFileName();
-		try (InputStream inputStream = this.ossTemplate.statFileStream(tplOssName)) {
-			return inputStream.readAllBytes();
-		}
+		return pdfData;
 	}
 
+	/*
 	public void exportApproveTableOld(String processInstanceId, OutputStream os) throws DocumentException, IOException {
 
 		BaseFont bfChinese = getBaseFont();
@@ -164,277 +172,7 @@
 
 		document.close();
 	}
+	*/
 
-
-
-	/**
-	 * 鎵撳嵃涓�涓楠わ紙缂栧埗/鏍″锛�
-	 * @param document
-	 * @param bfChinese
-	 * @param props
-	 * @param machine
-	 * @param flag
-	 * @param approveInfo
-	 * @throws DocumentException
-	 * @throws IOException
-	 */
-	void printPage(Document document, BaseFont bfChinese, FlowProgramProperties props, Machine machine, int flag, ApproveTableInfo approveInfo) throws DocumentException, IOException {
-		Font tipFont = new Font(bfChinese, 10, Font.NORMAL);
-		Paragraph tip = new Paragraph("鑹鸿〃6", tipFont);
-		tip.setAlignment(Element.ALIGN_RIGHT);
-		tip.setSpacingAfter(-5); // 娈靛悗闂磋窛
-		tip.setIndentationRight(220f);
-
-		// 璁剧疆琛岃窛锛堣闂磋窛锛�
-		//mixedParagraph.setLeading(24f); // 缁濆琛岃窛
-		//mixedParagraph.setLeading(1.5f, 2f);
-		// 涔熷彲浠ヤ娇鐢ㄧ浉瀵硅璺濓細mixedParagraph.setLeading(1.5f, 24f);
-		// 绗竴涓弬鏁版槸鏂囨湰楂樺害鐨勫�嶆暟锛岀浜屼釜鍙傛暟鏄澶栫殑鍥哄畾琛岃窛
-
-		Font titleFont = new Font(bfChinese, 14, Font.NORMAL);
-		Paragraph title = new Paragraph("鏁版帶绋嬪簭瀹℃壒鍗�", titleFont);
-		//title.setLeading(40f, 0f);
-		tip.setSpacingBefore(-0.5f);
-		title.setSpacingAfter(10); // 娈靛悗闂磋窛
-		title.setAlignment(Element.ALIGN_CENTER);
-		title.setPaddingTop(-0.6f);
-
-		Paragraph mixedParagraph = new Paragraph();
-		mixedParagraph.add(tip);
-		mixedParagraph.add(title);
-		mixedParagraph.setSpacingAfter(10);
-		document.add(mixedParagraph);
-
-
-		//document.add(title);
-		// 鍒涘缓琛ㄦ牸锛�4鍒楋級
-		PdfPTable table = new PdfPTable(5);
-		table.setWidths(new float[]{1.5f, 1.4f, 1.4f, 1.4f, 1.5f});
-
-		Font ft = this.getChineseFont();
-		// 娣诲姞琛ㄥご
-		PdfPCell tempCell = new PdfPCell();//getCell("闆剁粍浠跺彿");
-		tempCell.setHorizontalAlignment(Element.ALIGN_CENTER);
-		tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
-
-		Phrase pt1 = new Phrase("闆剁粍浠跺彿", ft);
-		tempCell.setPhrase(pt1);
-		//tempCell.addElement(pt1);
-		//
-		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(approveInfo.getTeamLeaderName(), 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;
-		Date programDate = approveInfo.getProgrammingDate(); //TODO 鏌ヨ鏃堕棿
-		Date checkDate = approveInfo.getCheckDate();
-
-		Phrase p;
-		if (1 == flag) {
-			p = new Phrase("       " + approveInfo.getProgrammerName() + "        ", underLineFt);
-		} else {
-			p = new Phrase("       " + approveInfo.getCheckerName() + "        ", underLineFt);
-		}
-		line2Para.add(p);
-
-		Phrase p2 = new Phrase("璐熻矗鏁版帶绋嬪簭锛堢紪鍒�");
-		if (flag == 1) {
-			p2.add(block2);
-			p2.add(new Chunk("   鏍″", ft));
-			p2.add(block1);
-		} else {
-			p2.add(block1);
-			p2.add(new Chunk("   鏍″", ft));
-			p2.add(block2);
-		}
-
-		p2.add(new Chunk("锛�", ft));
-		line2Para.add(p2);
-
-		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);
-
-
-		table.addCell(cell2);
-
-		String pDateStr = " ";
-		if (programDate != null) {
-			pDateStr = DateUtil.format(programDate, "yyyy-MM-dd");
-		}
-		String checkDateStr = " ";
-		if (checkDate != null) {
-			checkDateStr = DateUtil.format(programDate, "yyyy-MM-dd");
-		}
-
-		String approveDateStr = " ";
-		if (approveInfo.getApproveDate() != null) {
-			approveDateStr = DateUtil.format(approveInfo.getApproveDate(), "yyyy-MM-dd");
-		}
-		table.addCell(getCell(approveInfo.getProgrammerName()+" " +pDateStr, ft));//缂栧埗/鏃ユ湡
-		table.addCell(getCell(approveInfo.getCheckerName()+" " +checkDateStr, ft));
-		table.addCell(getCell(approveInfo.getSeniorName()+" " +approveDateStr, ft));
-
-		PdfPCell sendPathCell = getCell("鏁版帶绋嬪簭浼犺緭璺緞锛�" + (machine.getProgSendDir() == null ? "" : machine.getProgSendDir()), ft);// PdfPCell();
-		sendPathCell.setHorizontalAlignment(Element.ALIGN_LEFT);
-		sendPathCell.setColspan(5);
-		table.addCell(sendPathCell);
-
-		// 璁剧疆琛ㄦ牸瀹藉害鍗犻〉闈㈠搴︾殑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);
-		}
-
-		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.getDispatchDate()== null && task.getTaskDefinitionKey().contains("teamLeaderTask")){
-				appInfo.setDispatchDate(task.getEndTime());
-			}
-
-			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("锛堟湭鐢熸垚锛�");
-		}else{
-			NcNode programPkgNameNode = this.ncNodeService.getById(appOpt.get().getNcNodeId());
-			appInfo.setProgramNo(programPkgNameNode.getProgramNo());
-		}
-		return appInfo;
-	}
 
 }

--
Gitblit v1.9.3