From 833e909fbb25dd1245ec6aabb0c2cbe4c72d31c7 Mon Sep 17 00:00:00 2001 From: yangys <y_ys79@sina.com> Date: 星期二, 22 七月 2025 14:54:13 +0800 Subject: [PATCH] 审批表打印 --- blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java | 248 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 248 insertions(+), 0 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 new file mode 100644 index 0000000..530f8b9 --- /dev/null +++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ApproveTableService.java @@ -0,0 +1,248 @@ + +package org.springblade.mdm.flow.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.flowable.task.api.Task; +import org.springblade.core.mp.base.BizServiceImpl; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.mdm.basesetting.machine.MachineService; +import org.springblade.mdm.basesetting.machine.entity.Machine; +import org.springblade.mdm.flow.entity.ApproveRecord; +import org.springblade.mdm.flow.mapper.ApproveRecordMapper; +import org.springblade.mdm.flow.vo.ApproveRecordVO; +import org.springblade.mdm.program.entity.NcProgram; +import org.springblade.mdm.program.entity.ProcessProgRef; +import org.springblade.mdm.program.service.NcProgramService; +import org.springblade.mdm.program.service.ProcessProgRefService; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Date; +import java.util.List; +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.*; +/** + * 瀹℃壒璁板綍锛岀敤浜庢煡璇㈡墽琛岃建杩� + * + * @author yangys + */ +@Slf4j +@Service +@AllArgsConstructor +public class ApproveTableService{ + private final ProcessProgRefService processProgRefService; + private final FlowCommonService flowCommonService; + private final ApproveRecordService approveRecordService; + private final NcProgramService ncProgramService; + private final MachineService machineService; + 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)); // 甯﹀嬀鏂规 + //static SimpleDateFormat + BaseFont getBaseFont() throws DocumentException, IOException { + return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); + } + Font getChineseFont() throws DocumentException, IOException { + BaseFont bfChinese = getBaseFont(); + return new Font(bfChinese, 12, Font.NORMAL); + } + /** + * 瀵煎嚭瀹℃壒纭琛� + * @param processInstanceId + */ + public void exportApproveTable(String processInstanceId, OutputStream os) throws DocumentException, IOException { + + BaseFont bfChinese = getBaseFont(); + + Document document = new Document(PageSize.B5.rotate()); + PdfWriter.getInstance(document,os); + + document.open(); + + List<ApproveRecord> records = approveRecordService.lambdaQuery().eq(ApproveRecord::getProcessInstanceId, processInstanceId).orderByAsc(ApproveRecord::getCreateTime).list(); + for(int i=0;i<records.size();i++){ + ApproveRecord record = records.get(i); + printStep(document,bfChinese,record); + if(i<records.size()-1){ + document.newPage(); + } + } + + document.close(); + } + + void printStep(Document document,BaseFont bfChinese,ApproveRecord record) throws DocumentException, IOException { + NcProgram ncProgram; + Machine machine; + if(record.getNcProgramId() !=null ) { + ncProgram = ncProgramService.getById(record.getNcProgramId()); + machine = machineService.getByCode(ncProgram.getMachineCode()); + }else{ + ncProgram = new NcProgram(); + machine = new Machine(); + } + + + Font titleFont = new Font(bfChinese, 14, Font.NORMAL); + Paragraph title = new Paragraph("鏁版帶绋嬪簭缂栧埗瀹℃壒鍗�",titleFont); + title.setAlignment(Element.ALIGN_CENTER); + + title.setLeading(40f, 0f); + title.setSpacingAfter(10); // 娈靛悗闂磋窛 + document.add(title); + // 鍒涘缓琛ㄦ牸锛�4鍒楋級 + PdfPTable table = new PdfPTable(5); + table.setWidths(new float[]{2,1.2f, 1.2f, 1.2f,2}); + + 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)); + + //PdfPCell cell12 = new PdfPCell(); + //cell12.setColspan(2); + //cell12.addElement(new Phrase(ncProgram.getDrawingNo())); + table.addCell(getCell(ncProgram.getDrawingNo(),ft));//闆剁粍浠跺彿 + + table.addCell(getCell(ncProgram.getProcessNo(),ft));//宸ュ簭鍙� + table.addCell(getCell(ncProgram.getCraftEdition(),ft));//宸ヨ壓鐗堟 + table.addCell(getCell(machine.getName(),ft));//鏈哄簥鍨嬪彿 + table.addCell("");//璐熻矗浜猴紝宸ユ璐熻矗浜烘淳鍑烘椂闂� + + //涓棿澶ф牸 + 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 = square; + Date programDate = null; + Date checkDate = null; + if(StringUtils.equals(record.getTaskDefinitionId(),"programmingTask")){ + block1 = check; + programDate = record.getCreateTime(); + }else if(StringUtils.equals(record.getTaskDefinitionId(),"check")){ + block2 = check; + checkDate = record.getCreateTime(); + } + Phrase p = new Phrase(" "+personName+" ",underLineFt); + + line2Para.add(p); + + Phrase p2 = new Phrase("璐熻矗鏁版帶绋嬪簭锛堢紪鍒�"); + 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(square); + fangzhen.add(";鍚�"); + fangzhen.add(square); + fangzhen.add("锛塡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 = new PdfPCell(); + cell2.setColspan(2); + cell2.addElement(new Phrase(ncProgram.getCode(),ft));//鏁版帶绋嬪簭缂栧彿 + 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"); + } + table.addCell(getCell(pDateStr,ft));//缂栧埗鏃ユ湡 + table.addCell(getCell(checkDateStr,ft)); + table.addCell(getCell(" ",ft)); + + // 璁剧疆琛ㄦ牸瀹藉害鍗犻〉闈㈠搴︾殑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; + } + + +} -- Gitblit v1.9.3