printer:
增加局域网打印
master
xs 4 months ago
parent dc9e34c642
commit e13ab12bbd

@ -17,7 +17,7 @@ public class RuoYiPrinterApplication
public static void main(String[] args)
{
SpringApplication.run(RuoYiPrinterApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 文件服务模块启动成功 ლ(´ڡ`ლ)゙ \n" +
System.out.println("(♥◠‿◠)ノ゙ 打印服务模块启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +

@ -1,8 +1,10 @@
package com.hw.printer.controller;
import com.hw.common.core.domain.R;
import com.hw.common.core.utils.ip.IpUtils;
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import com.hw.printer.api.domain.vo.PrintContentVo;
import com.hw.printer.api.domain.vo.PrinterVo;
import com.hw.printer.service.IPrinterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,13 +29,21 @@ public class PrinterController {
/**
*
* @param printContents
* @param printerVo
* @return
*/
@PostMapping("/printBarcodes")
public R<MesBaseBarcodeInfo> printBarcodes(@RequestBody List<List<PrintContentVo>> printContents) {
public R<MesBaseBarcodeInfo> printBarcodes(@RequestBody PrinterVo printerVo) {
try {
printerService.printBarcodes(printContents);
String hostIp = IpUtils.getHostIp();
String printType = printerVo.getPrintType();
List<List<PrintContentVo>> printContents = printerVo.getPrintContents();
if(printType.equals(PrinterVo.PRINT_TYPE_RAW_LABEL)){
printerService.printBarcodes(printContents,hostIp);
}else if(printType.equals(PrinterVo.PRINT_TYPE_PRODUCT_LABEL)){
printerService.printProductBarcodes(printContents,hostIp);
}
return R.ok();
} catch (Exception e) {
log.error("打印条码失败", e);
@ -41,7 +51,6 @@ public class PrinterController {
}
}
/**
*
* @param params
@ -50,7 +59,8 @@ public class PrinterController {
@PostMapping("/printLocationLabel")
public R<?> printLocationLabel(@RequestBody HashMap<String, String> params) {
try {
printerService.printLocationLabel(params);
String hostIp = IpUtils.getHostIp();
printerService.printLocationLabel(params,hostIp);
return R.ok();
} catch (Exception e) {
log.error("打印条码失败", e);

@ -15,18 +15,32 @@ import java.util.List;
public interface IPrinterService {
/**
*
*
*
* @param printContents
* @param ipAddress IP
* @return
* @throws Exception
*/
public void printBarcodes(List<List<PrintContentVo>> printContents) throws Exception;
public void printBarcodes(List<List<PrintContentVo>> printContents,String ipAddress) throws Exception;
/**
*
*
* @param printContents
* @param ipAddress IP
* @return
* @throws Exception
*/
public void printProductBarcodes(List<List<PrintContentVo>> printContents,String ipAddress) throws Exception;
/**
*
*
* @param params
* @param ipAddress IP
* @return
*/
public void printLocationLabel(HashMap<String, String> params) throws IOException;
public void printLocationLabel(HashMap<String, String> params,String ipAddress) throws IOException;
}

@ -65,14 +65,15 @@ public class PrinterServiceImpl implements IPrinterService {
/**
*
*
*
* @param printContents
* @param ipAddress IP
* @return
* @throws Exception
*/
@Override
public void printBarcodes(List<List<PrintContentVo>> printContents) throws Exception {
public void printBarcodes(List<List<PrintContentVo>> printContents,String ipAddress) throws Exception {
// HashMap<String, String> params = new HashMap<>();
// params.put("localPrintPath", localPrintPath);
// params.put("pdfTemplatePath", pdfTemplatePath);
@ -81,20 +82,43 @@ public class PrinterServiceImpl implements IPrinterService {
// params.put("batchCode", barcodeInfo.getBatchCode());
// params.put("materialName", barcodeInfo.getMaterialName());
// params.put("date", DateUtils.getDate());
HwPrintUtil.printBarcodes(localPrintPath, pdfTemplatePath,
HwPrintUtil.printBarcodes(ipAddress, pdfTemplatePath,
generatePath, printContents);
}
/**
*
*
* @param printContents
* @param ipAddress IP
* @return
* @throws Exception
*/
@Override
public void printProductBarcodes(List<List<PrintContentVo>> printContents,String ipAddress) throws Exception {
// HashMap<String, String> params = new HashMap<>();
// params.put("localPrintPath", localPrintPath);
// params.put("pdfTemplatePath", pdfTemplatePath);
// params.put("generatePath", generatePath);
// params.put("barcodeInfo", barcodeInfo.getBarcodeInfo());
// params.put("batchCode", barcodeInfo.getBatchCode());
// params.put("materialName", barcodeInfo.getMaterialName());
// params.put("date", DateUtils.getDate());
HwPrintUtil.printBarcodes(ipAddress, productLabelTemplatePath,
generateProductLabelPath, printContents);
}
/**
*
*
* @param params
* @param ipAddress IP
* @return
*/
@Override
public void printLocationLabel(HashMap<String, String> params) throws IOException {
HwPrintUtil.printLocationQRCode(localPrintPath, locationLabelTemplatePath,
public void printLocationLabel(HashMap<String, String> params,String ipAddress) throws IOException {
HwPrintUtil.printLocationQRCode(ipAddress, locationLabelTemplatePath,
generateLocationLabelPath, params);
}

@ -61,9 +61,7 @@ public class HwPrintUtil {
// localPrintPath = "导出";
// localPrintPath = "ZD";
for (PrintService service : printServices) {
System.out.println(service.getName());
if (service.getName().contains(localPrintPath)) {
printService = service;
break;
}
@ -146,6 +144,7 @@ public class HwPrintUtil {
PdfStamper stamper = new PdfStamper(reader, bos);
// 动态地将变量的值填充到PDF表单相应字段
AcroFields form = stamper.getAcroFields();
form.setFieldProperty("materialName", "multiline", true, null);
for (PrintContentVo printContentVo : printContentVos) {
if (printContentVo.getType() == PrintContentVo.TYPE_TEXT) {
form.setField(printContentVo.getKey(), printContentVo.getValue());

Loading…
Cancel
Save