| | |
| | | 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.entity.Machine; |
| | | import org.springblade.mdm.commons.contants.DictBizConstants; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | 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.IDictBizClient; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springblade.system.pojo.entity.UserInfo; |
| | | 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; |
| | | |
| | |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @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; |
| | | |
| | | BaseFont getBaseFont() throws DocumentException, IOException { |
| | | return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); |
| | | public void exportConfirmTable(FlowProgramProperties props, OutputStream os) throws IOException, DocumentException { |
| | | |
| | | byte[] tplBytes = getTemplateBytes(); |
| | | generateTempPDF(tplBytes,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); |
| | | PdfStamper pdfStamper = null; |
| | | |
| | | reader = new PdfReader(bytes); |
| | | pdfStamper = new PdfStamper(reader, outputStream); |
| | | // 使ç¨ä¸æåä½ |
| | | //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>(); |
| | | ArrayList<BaseFont> fontList = new ArrayList<>(); |
| | | fontList.add(bf); |
| | | AcroFields fields = ps.getAcroFields(); |
| | | AcroFields fields = pdfStamper.getAcroFields(); |
| | | fields.setSubstitutionFonts(fontList); |
| | | fillData(fields, data());//æ |
| | | fillData(fields, getData(props));//æ |
| | | //å¿
é¡»è¦è°ç¨è¿ä¸ªï¼å¦åææ¡£ä¸ä¼çæç |
| | | ps.setFormFlattening(true); |
| | | if (ps != null) { |
| | | ps.close(); |
| | | pdfStamper.setFormFlattening(true); |
| | | pdfStamper.close(); |
| | | |
| | | } |
| | | |
| | | //çæ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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | void fillData(AcroFields fields, Map<String, String> data) throws DocumentException, IOException { |
| | | |
| | | public void fillData(AcroFields fields, Map<String, String> data) { |
| | | try { |
| | | for (String key : data.keySet()) { |
| | | String value = data.get(key); |
| | | // ä¸ºåæ®µèµå¼,注æå段åç§°æ¯åºå大å°åçfields.setField(key,value); |
| | | fields.setField(key,value); |
| | | fields.setField(key,value,true); |
| | | |
| | | //form.setFieldProperty("fieldName", "clrflags", PdfAnnotation.FLAGS_HIDDEN, null); |
| | | //fields.setFieldRichValue() |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | |
| | | } |
| | | } |
| | | 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 { |
| | | |
| | | BaseFont bfChinese = getBaseFont(); |
| | | |
| | | Document document = new Document(PageSize.B5.rotate()); |
| | | PdfWriter.getInstance(document, os); |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | |
| | | |
| | | 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è´£äººæ´¾åºæ¶é´", 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("注:工段派工åºé¢å
计åãåçå®ææ°æ§ç¨åºç¼å¶ãç«å ãæ°é£ãæ°è½¦çåéå·¥åºç¨åº(两轴ç¨åº)éæå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.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()); |
| | | /** |
| | | * è·å模æ¿åèæ°ç» |
| | | * @return |
| | | */ |
| | | private byte[] getTemplateBytes() throws IOException { |
| | | String tplOssName = paramService.confirmTableTemplateOssFileName(); |
| | | try (InputStream inputStream = this.ossTemplate.statFileStream(tplOssName)) { |
| | | return inputStream.readAllBytes(); |
| | | } |
| | | } |
| | | |
| | | //æ¥è¯¢æ°æ§ç¨åºç¼å· |
| | | 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()); |
| | | /** |
| | | * è·åæå°è¡¨æ ¼çæ°æ® |
| | | * @param props æµç¨å±æ§ |
| | | * @return æ°æ®map |
| | | */ |
| | | Map<String,String> getData(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("fuheY","Y"); |
| | | data.put("keyongY","Y"); |
| | | 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()); |
| | | } |
| | | return appInfo; |
| | | |
| | | data.put("operator","ä¸æç¡®/2025-1-1"); |
| | | data.put("jjy","ä¸æç¡®/2025-1-1"); |
| | | |
| | | data.put("programmerName",getNameByUserId(props.getProgrammerId())); |
| | | data.put("checkerName",getNameByUserId(props.getCheckerId())); |
| | | data.put("seniorName",getNameByUserId(props.getSeniorId())); |
| | | |
| | | return data; |
| | | } |
| | | |
| | | |
| | | String getNameByUserId(Long userId){ |
| | | if(userId == null){ |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | String name = StringUtils.EMPTY; |
| | | R<User> useInfoResult = userClient.userInfoById(userId); |
| | | if(useInfoResult.isSuccess()){ |
| | | name = useInfoResult.getData().getName(); |
| | | } |
| | | |
| | | return name; |
| | | } |
| | | |
| | | } |