From f8baba8116fa0e718ea1a8bf9f21adf5740f4b55 Mon Sep 17 00:00:00 2001 From: yangwl <1726150332@qq.com> Date: Mon, 17 Jan 2022 14:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E6=89=93=E5=8D=B0=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/FileController.java | 20 ++------ .../common/controller/PrintLogController.java | 33 +++++++++++-- .../common/service/PrintLogService.java | 2 +- .../service/impl/PrintLogServiceImpl.java | 42 +++++++++++++---- .../common/util/DrawPrepareProducts.java | 47 ++++++++++++++----- .../src/main/resources/application-prd.yml | 9 +++- .../src/main/resources/application-qas.yml | 2 +- console/src/main/resources/application.yml | 4 +- .../service/impl/SfcDispatchServiceImpl.java | 5 -- .../impl/ShopOrderReleaseServiceImpl.java | 2 +- 10 files changed, 113 insertions(+), 53 deletions(-) diff --git a/common/src/main/java/com/foreverwin/mesnac/common/controller/FileController.java b/common/src/main/java/com/foreverwin/mesnac/common/controller/FileController.java index 67608964..719ae7b1 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/controller/FileController.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/controller/FileController.java @@ -7,6 +7,7 @@ import com.foreverwin.modular.core.exception.BaseException; import com.foreverwin.modular.core.util.CommonMethods; import com.foreverwin.modular.core.util.R; import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; import org.apache.poi.ss.usermodel.Workbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,26 +139,14 @@ public class FileController { public R getLabelPrintPdf(HttpServletRequest request, HttpServletResponse response, @PathVariable("fileName") String fileName) { InputStream in = null; OutputStream out = null; - String path = request.getParameter("Path").replace('-','/');; - String filepatch=path; try { - FTPClient ftp= new FTPClient(); - ftp.connect("172.16.251.187",8091); //连接ftp服务器 - ftp.login("administrator","mes@123"); //登录ftp服务器 - ftp.changeWorkingDirectory(filepatch); - ftp.storeFile("Label.pdf", in); + //服务器发布 + in = ftpClient.getFtp(path); if(null == in){ in = ftpClient.getFtp(new String(path.getBytes("GBK"), FTPClient.DEFAULT_CONTROL_ENCODING)); } - //本地测试 - /*String newPath = new String(path.getBytes("GBK"), FTPClient.DEFAULT_CONTROL_ENCODING); - in = plmFtpClient.getFtp(newPath); - if(null == in){ - in = plmFtpClient.getFtp(new String(path.getBytes("UTF-8"), FTPClient.DEFAULT_CONTROL_ENCODING)); - }*/ - if(null == in){ throw new BaseException("获取FTP文件路径为:【"+path+"】的文件流失败!"); } @@ -171,8 +160,7 @@ public class FileController { out = response.getOutputStream(); out.write(data); out.flush(); - ftp.logout(); - ftp.disconnect(); + }catch (Exception e){ return R.failed("下载文件失败:文件路径为"+path+":"+e.getMessage()); }finally { diff --git a/common/src/main/java/com/foreverwin/mesnac/common/controller/PrintLogController.java b/common/src/main/java/com/foreverwin/mesnac/common/controller/PrintLogController.java index ab35efa2..b5f97a7f 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/controller/PrintLogController.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/controller/PrintLogController.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.itextpdf.text.Document; import com.itextpdf.text.PageSize; import com.itextpdf.text.pdf.PdfWriter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -36,7 +37,8 @@ public class PrintLogController { @Autowired public PrintLogService printLogService; - + @Value("${exportLabel.filepatch}") + private String filepatch; /** * 查询所有数据 * @@ -93,7 +95,6 @@ public class PrintLogController { if (requestList == null || requestList.size() <= 0) { throw BusinessException.build("请选择至少一笔记录进行操作!"); } - String site = CommonMethods.getSite(); String user = CommonMethods.getUser(); printLogService.labelPrint(site, user, requestList); @@ -104,20 +105,44 @@ public class PrintLogController { return R.ok(); } @ResponseBody - @PostMapping("/exportLabel") + @PostMapping("/generateLabel") public R exportLabel(@RequestBody List requestList){ try { if (requestList == null || requestList.size() <= 0) { throw BusinessException.build("请选择至少一笔记录进行操作!"); } // String filepatch=printLogService.labelExport(requestList); - return R.ok(printLogService.labelExport(requestList)); + printLogService.labelExport(requestList); + return R.ok(); }catch (Exception e){ return R.failed(e.getMessage()); } } + @GetMapping("/exportLabel") + private void download(HttpServletResponse response){ + try { ; + String filepatch="/exportpdf/Label.pdf"; + File file = new File(filepatch); + String filename=file.getName(); + InputStream fis = new BufferedInputStream(new FileInputStream(filepatch)); + byte[] buffer = new byte[fis.available()]; + fis.read(buffer); + fis.close(); + response.reset(); + response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes())); + response.addHeader("Content-Length", "" + file.length()); + OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); + response.setContentType("application/octet-stream"); + toClient.write(buffer); + toClient.flush(); + toClient.close(); + }catch (Exception e){ + throw BusinessException.build("下载错误!"); + } + } + /** * 根据sfc,查询当前sfc的打印信息 diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/PrintLogService.java b/common/src/main/java/com/foreverwin/mesnac/common/service/PrintLogService.java index ab840f44..79ae7772 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/PrintLogService.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/PrintLogService.java @@ -42,7 +42,7 @@ public interface PrintLogService extends IService { * @param printList * */ - String labelExport(List printList) throws Exception; + void labelExport(List printList) throws Exception; /** * 查询标签打印所有数据 diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java index 1257b0d0..7a9496b9 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java @@ -129,25 +129,50 @@ public class PrintLogServiceImpl extends ServiceImpl i } @Override - public String labelExport(List requestList) throws Exception { + public void labelExport(List requestList) throws Exception { // 1.新建document对象 Document document = new Document(PageSize.A4);// 建立一个Document对象 // 2.建立一个书写器(Writer)与document对象关联 - File file = new File(filepatch); + String path="/exportpdf/Label.pdf"; + File file = new File(path); file.createNewFile(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); //3.打开文件 document.open(); for (PrintLog printLog : requestList){ - String s=printLog.getPrintParam(); - System.out.println(s); -// LabelPrintDto labelPrintDto=JSONObject.parseObject(printLog.getPrintParam(),LabelPrintDto.class); + String PrintParam=printLog.getPrintParam(); + System.out.println(PrintParam); + PrintParam=PrintParam.replace("[",""); + PrintParam=PrintParam.replace("]",""); + LabelPrintDto labelPrintDto=JSONObject.parseObject(PrintParam,LabelPrintDto.class); //4.生成二维码 - QRUtils.encode(printLog.getSfc(),qrPath,destPath); + QRUtils.encode(labelPrintDto.getSfc(),qrPath,destPath); + //数量参数 + String Qty; + if (labelPrintDto.getSfcQty()!=null&&labelPrintDto.getQty()!=null){ + Qty=labelPrintDto.getSfcQty().toString()+"/"+labelPrintDto.getQty().toString(); + }else{ + Qty=labelPrintDto.getQty()==null?" ":labelPrintDto.getQty().toString(); + } + String DrawingVersion=" "; + if(labelPrintDto.getDrawingVersion()!=null){ + DrawingVersion=labelPrintDto.getDrawingVersion(); + } //5.绘图 - DrawPrepareProducts.mark(original, finall, - Color.black, "收货方","物料描述","数量","订单号","工序","下料尺寸","产品条码","物料编码"); + DrawPrepareProducts.mark(original, + finall, + Color.black, + labelPrintDto.getWorkOrder()==null?" ":labelPrintDto.getWorkOrder(), + labelPrintDto.getItemDescription()==null?" "+DrawingVersion:DrawingVersion+labelPrintDto.getItemDescription(), + Qty, + labelPrintDto.getShopOrder()==null?" ":labelPrintDto.getShopOrder(), + labelPrintDto.getOperation()==null?" ":labelPrintDto.getOperation(), + labelPrintDto.getBlankingSize()==null?" ":labelPrintDto.getBlankingSize(), + labelPrintDto.getSfc()==null?" ":labelPrintDto.getSfc(), + labelPrintDto.getItemTypeOrder()==null?" ":labelPrintDto.getItemTypeOrder(), + labelPrintDto.getItem()==null?" ":labelPrintDto.getItem()); +// generatePDF(document); Image image = Image.getInstance(finall); image.setAlignment(Image.ALIGN_MIDDLE); image.scalePercent(50); //依照比例缩放 @@ -156,7 +181,6 @@ public class PrintLogServiceImpl extends ServiceImpl i } //关闭文档 document.close(); - return "-pdfdownload"; } @Override diff --git a/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java b/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java index 8405ca23..c66f96de 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java @@ -1,5 +1,7 @@ package com.foreverwin.mesnac.common.util; +import org.springframework.beans.factory.annotation.Value; + import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; @@ -7,6 +9,8 @@ import java.io.File; import java.io.FileOutputStream; public class DrawPrepareProducts { + + /** * * @param srcImgPath @@ -22,7 +26,7 @@ public class DrawPrepareProducts { * @param wlbm */ public static void mark(String srcImgPath, String outImgPath, Color markContentColor, String shf, - String wlms, String sl, String ddh, String gx, String xlcc, String cptm, String wlbm){ + String wlms, String sl, String ddh, String gx, String xlcc, String cptm,String ItemTypeOrder, String wlbm){ try { // 读取原图片信息 File srcImgFile = new File(srcImgPath); @@ -34,20 +38,38 @@ public class DrawPrepareProducts { Graphics2D g = bufImg.createGraphics(); g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null); // Font font = new Font("Courier New", Font.PLAIN, 12); - Font font = new Font("宋体", Font.PLAIN, 30); + Font font = new Font("宋体", Font.PLAIN, 20); g.setColor(markContentColor); // 根据图片的背景设置水印颜色 g.setFont(font); -// g.drawString(shf, 10, 70); -// g.drawString(wlms, 10, 150); -// g.drawString(sl, 10, 230); -// g.drawString(ddh, 420, 230); -// g.drawString(gx, 10, 330); -// g.drawString(xlcc, 10, 440); -// g.drawString(cptm, 10, 520); -// g.drawString(wlbm, 10, 600); + g.drawString(shf, 100, 40); + g.drawString(wlms, 100, 100); + g.drawString(sl, 120, 150); + g.drawString(ddh, 410, 150); + if(gx.length()<=30) + { + g.drawString(gx, 100, 240); + } + if (gx.length()>30&&gx.length()<=60) + { + g.drawString(gx.substring(0,30), 100, 235); + g.drawString(gx.substring(30), 100, 255); + } + if (gx.length()>60&&gx.length()<=90) + { + g.drawString(gx.substring(0,30), 100, 215); + g.drawString(gx.substring(30,60), 100, 235); + g.drawString(gx.substring(60), 100, 255); + }else if (gx.length()>90){ + g.drawString(gx.substring(0,30), 100, 205); + g.drawString(gx.substring(30,60), 100, 225); + g.drawString(gx.substring(60,90), 100, 245); + g.drawString(gx.substring(90), 100, 265); + } + g.drawString("280*360*410", 100, 310); + g.drawString(cptm, 100, 360); + g.drawString("RK", 370, 360); + g.drawString(wlbm, 100, 420); g.dispose(); - //生成二维码图片 -// QRUtils.encode("012345678912","D:\\QRCODE.jpg",false); //插入生成好的二维码图片 QRUtils.insertImage(bufImg,"D:\\img\\QRCODE.jpg",false); // 输出图片 @@ -58,6 +80,5 @@ public class DrawPrepareProducts { } catch (Exception e) { e.printStackTrace(); } -// return outImgPath; } } diff --git a/console/src/main/resources/application-prd.yml b/console/src/main/resources/application-prd.yml index ce75924e..2b451e46 100644 --- a/console/src/main/resources/application-prd.yml +++ b/console/src/main/resources/application-prd.yml @@ -62,4 +62,11 @@ cappftp: username: Administrator password: cappnew@123 uploadDir: - downloadDir: \ No newline at end of file + downloadDir: + +exportLabel: + qrPath: /exportpdf/QRCODE.jpg + destPath: /exportpdf + original: /exportpdf/original.png + finall: /exportpdf/finall.png + filepatch: /exportpdf/Label.pdf \ No newline at end of file diff --git a/console/src/main/resources/application-qas.yml b/console/src/main/resources/application-qas.yml index ea153899..3c76593c 100644 --- a/console/src/main/resources/application-qas.yml +++ b/console/src/main/resources/application-qas.yml @@ -55,7 +55,7 @@ exportLabel: destPath: /exportpdf original: /exportpdf/original.png finall: /exportpdf/finall.png - filepatch: /exportpdf/标签导出.pdf + filepatch: /exportpdf/Label.pdf activeMq: sendWeChatMessage: tcp://localhost:61616?wireFormat.maxInactivityDuration=0 diff --git a/console/src/main/resources/application.yml b/console/src/main/resources/application.yml index e0e0c71d..29ee7c20 100644 --- a/console/src/main/resources/application.yml +++ b/console/src/main/resources/application.yml @@ -35,9 +35,9 @@ spring: time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss profiles: - active: prd +# active: prd # active: qas -# active: local + active: local # active: dev # 文件上传 servlet: diff --git a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SfcDispatchServiceImpl.java b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SfcDispatchServiceImpl.java index efb8fdea..2b38798f 100644 --- a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SfcDispatchServiceImpl.java +++ b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SfcDispatchServiceImpl.java @@ -86,9 +86,6 @@ public class SfcDispatchServiceImpl extends ServiceImpl findSfcDispatch(String site, String sfc, String operation, String stepId) { return sfcDispatchMapper.findSfcDispatch(site, sfc, operation, stepId); @@ -124,9 +121,7 @@ public class SfcDispatchServiceImpl extends ServiceImpl