虚拟打印完成

master
yangwl 3 years ago
parent fbd2eb3f29
commit f8baba8116

@ -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 {

@ -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<PrintLog> 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("下载错误!");
}
}
/**
* sfcsfc

@ -42,7 +42,7 @@ public interface PrintLogService extends IService<PrintLog> {
* @param printList
*
*/
String labelExport(List<PrintLog> printList) throws Exception;
void labelExport(List<PrintLog> printList) throws Exception;
/**
*

@ -129,25 +129,50 @@ public class PrintLogServiceImpl extends ServiceImpl<PrintLogMapper, PrintLog> i
}
@Override
public String labelExport(List<PrintLog> requestList) throws Exception {
public void labelExport(List<PrintLog> 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<PrintLogMapper, PrintLog> i
}
//关闭文档
document.close();
return "-pdfdownload";
}
@Override

@ -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;
}
}

@ -62,4 +62,11 @@ cappftp:
username: Administrator
password: cappnew@123
uploadDir:
downloadDir:
downloadDir:
exportLabel:
qrPath: /exportpdf/QRCODE.jpg
destPath: /exportpdf
original: /exportpdf/original.png
finall: /exportpdf/finall.png
filepatch: /exportpdf/Label.pdf

@ -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

@ -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:

@ -86,9 +86,6 @@ public class SfcDispatchServiceImpl extends ServiceImpl<SfcDispatchMapper, SfcDi
private ProductionCalendarService productionCalendarService;
@Autowired
private SfcDispatchEmployeeService sfcDispatchEmployeeService;
@Autowired
private CappFtpClient cappFtpClient;
@Override
public List<SfcDispatch> 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<SfcDispatchMapper, SfcDi
}
}
}
GetDrawingVersionUtil getDrawingVersionUtil=new GetDrawingVersionUtil();
//登录Capp的FTP文件服务器
FTPClient connect = null;
// try {
// connect = cappFtpClient.login();
// for (SfcDispatchDto sfcDispatch : list) {

@ -237,7 +237,7 @@ public class ShopOrderReleaseServiceImpl implements ShopOrderReleaseService {
}
String sfc = sfcModel.getSfc();
String itemBo=sfcModel.getItemBo();
String itemBo=shopOrderModel.getPlannedItemBo();
String shopOrder = shopOrderModel.getShopOrder();
String stepId = "";
String nextStepBo = "";

Loading…
Cancel
Save