diff --git a/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/RemotePrinterService.java b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/RemotePrinterService.java index e01f6340..fddef47f 100644 --- a/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/RemotePrinterService.java +++ b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/RemotePrinterService.java @@ -4,6 +4,7 @@ import com.hw.common.core.constant.SecurityConstants; import com.hw.common.core.constant.ServiceNameConstants; import com.hw.common.core.domain.R; import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.printer.api.domain.vo.PrintContentVo; import com.hw.printer.api.factory.RemotePrinterFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; @@ -20,10 +21,18 @@ public interface RemotePrinterService { * @return 结果 */ @PostMapping("/printService/printBarCode") - public MesBaseBarcodeInfo printBarCode(@RequestBody MesBaseBarcodeInfo barcodeInfo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); - + public MesBaseBarcodeInfo printBarCode(@RequestBody MesBaseBarcodeInfo barcodeInfo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); + /** + * 打印库位条码信息 + * + * @param printContentVo 打印条码信息 + * @param source 请求来源 + * @return 结果 + */ + @PostMapping("/printService/printLocationLabel") + public R printLocationLabel(@RequestBody PrintContentVo printContentVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); } diff --git a/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/domain/vo/PrintContentVo.java b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/domain/vo/PrintContentVo.java new file mode 100644 index 00000000..c886c0df --- /dev/null +++ b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/domain/vo/PrintContentVo.java @@ -0,0 +1,13 @@ +package com.hw.printer.api.domain.vo; + +import lombok.Data; + +import java.util.HashMap; + +@Data +public class PrintContentVo { + + private String templatePath; + + private HashMap params; +} diff --git a/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/factory/RemotePrinterFallbackFactory.java b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/factory/RemotePrinterFallbackFactory.java index 2946547a..522fb895 100644 --- a/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/factory/RemotePrinterFallbackFactory.java +++ b/hw-api/hw-api-printer/src/main/java/com/hw/printer/api/factory/RemotePrinterFallbackFactory.java @@ -5,6 +5,7 @@ import com.hw.common.core.domain.R; import com.hw.common.core.exception.ServiceException; import com.hw.printer.api.RemotePrinterService; import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.printer.api.domain.vo.PrintContentVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -27,6 +28,11 @@ public class RemotePrinterFallbackFactory implements FallbackFactory printLocationLabel(PrintContentVo printContentVo, String source) { + throw new ServiceException("打印库位条码服务调用异常:" + throwable.getMessage()); + } }; } } diff --git a/hw-common/hw-common-log/src/main/java/com/hw/common/log/enums/BusinessType.java b/hw-common/hw-common-log/src/main/java/com/hw/common/log/enums/BusinessType.java index 571c1a24..8cf7dc26 100644 --- a/hw-common/hw-common-log/src/main/java/com/hw/common/log/enums/BusinessType.java +++ b/hw-common/hw-common-log/src/main/java/com/hw/common/log/enums/BusinessType.java @@ -129,4 +129,8 @@ public enum BusinessType */ CHECK, + /** + * 打印 + */ + PRINT, } diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java index 24230840..d64c6b8d 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java @@ -2,14 +2,14 @@ package com.hw.printer.controller; import com.hw.common.core.domain.R; import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.printer.api.domain.vo.PrintContentVo; import com.hw.printer.service.IPrinterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; /** * 打印机请求处理 @@ -25,7 +25,7 @@ public class PrinterController { private IPrinterService printerService; /** - * 打印条码接口 + * 打印物料条码接口 * @param barcodeInfo * @return */ @@ -39,4 +39,21 @@ public class PrinterController { } } + + /** + * 打印库位条码 + * @param printContentVo + * @return + */ + @PostMapping("/printLocationLabel") + public R printLocationLabel(@RequestBody PrintContentVo printContentVo) { + try { + printerService.printLocationLabel(printContentVo.getParams()); + return R.ok(); + } catch (Exception e) { + log.error("打印条码失败", e); + return R.fail(e.getMessage()); + } + } + } \ No newline at end of file diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java index 4c242b05..0eafb693 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java @@ -1,6 +1,9 @@ package com.hw.printer.service; import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.printer.utils.HwPrintUtil; + +import java.util.HashMap; /** * 打印机服务接口 @@ -16,4 +19,12 @@ public interface IPrinterService { * @throws Exception */ MesBaseBarcodeInfo printBarCode(MesBaseBarcodeInfo barcodeInfo) throws Exception; + + + /** + * 打印库位条码接口 + * @param params + * @return + */ + public void printLocationLabel(HashMap params); } diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java index c63d22cc..7e3c27eb 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java @@ -24,17 +24,44 @@ public class PrinterServiceImpl implements IPrinterService { public String localPrintPath; /** - * PDF模板路径 + * 原材料条码标签PDF模板路径 */ @Value("${print.pdfTemplatePath}") public String pdfTemplatePath; /** - * 生成PDF文件路径 + * 生成原材料条码标签PDF文件路径 */ @Value("${print.generatePath}") public String generatePath; + + /** + * 成品条码标签PDF模板路径 + */ + @Value("${print.productLabelTemplatePath}") + public String productLabelTemplatePath; + + /** + * 生成成品条码标签PDF文件路径 + */ + @Value("${print.generateProductLabelPath}") + public String generateProductLabelPath; + + + /** + * 库位条码标签PDF模板路径 + */ + @Value("${print.locationLabelTemplatePath}") + public String locationLabelTemplatePath; + + /** + * 生成库位条码标签PDF文件路径 + */ + @Value("${print.generateLocationLabelPath}") + public String generateLocationLabelPath; + + /** * 打印条码接口 * @@ -58,4 +85,16 @@ public class PrinterServiceImpl implements IPrinterService { } + /** + * 打印库位条码接口 + * @param params + * @return + */ + @Override + public void printLocationLabel(HashMap params) { + HwPrintUtil.printLocationQRCode(localPrintPath, locationLabelTemplatePath, + generateLocationLabelPath, params); + } + + } diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java index 308ae63b..e3fec8ab 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java @@ -15,6 +15,7 @@ import javax.print.*; import java.awt.print.*; import java.io.*; import java.util.HashMap; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,20 +31,6 @@ public class HwPrintUtil { private static final Logger log = LoggerFactory.getLogger(HwPrintUtil.class); - /** - * 打印机映射路径 - */ - public static String localPrintPath; - - /** - * PDF模板路径 - */ - public static String pdfTemplatePath; - - /** - * 生成PDF文件路径 - */ - public static String generatePath; /** * 打印机List @@ -55,6 +42,33 @@ public class HwPrintUtil { */ private static PrintService printService = null; + /** + * 导出为金山PDF + * 导出为WPS PDF + * 发送至 OneNote 2013 + * Microsoft XPS Document Writer + * Microsoft Print to PDF + * Fax + * \\10.11.43.159\HP LaserJet MFP M129-M134 + * \\10.11.43.159\HP Laser NS 1020 + */ + public static void initPrintService(String localPrintPath) { +// localPrintPath = "导出"; +// localPrintPath = "ZD"; + for (PrintService service : printServices) { + System.out.println(service.getName()); + if (service.getName().contains(localPrintPath)) { + + printService = service; + break; + } + } + if (printService == null) { + throw new ServiceException("打印机配置错误!"); + } + } + + /** * 项目启动时,初始化打印机参数 */ @@ -72,15 +86,15 @@ public class HwPrintUtil { */ public static String printBarCode(HashMap params) { //解析参数生成打印图片 - localPrintPath = params.get("localPrintPath"); - pdfTemplatePath = params.get("pdfTemplatePath"); - generatePath = params.get("generatePath"); + String localPrintPath = params.get("localPrintPath"); + String pdfTemplatePath = params.get("pdfTemplatePath"); + String generatePath = params.get("generatePath"); String barcodeInfo = params.get("barcodeInfo"); String batchCode = params.get("batchCode"); String materialName = params.get("materialName"); String date = params.get("date"); - initPrintService(); - File outputFile = printQRCode(barcodeInfo, batchCode, materialName, date); + initPrintService(localPrintPath); + File outputFile = printQRCode(barcodeInfo, batchCode, materialName, date,pdfTemplatePath,generatePath); try { printPdf(outputFile); log.info("打印条码printBarCode方法,条码内容:" + barcodeInfo); @@ -94,13 +108,13 @@ public class HwPrintUtil { /** * 打印二维码到PDF文件 * - * @param barcodeInfo 条形码信息 - * @param batchCode 批次代码 + * @param barcodeInfo 条形码信息 + * @param batchCode 批次代码 * @param materialName 物料名称 - * @param date 日期 + * @param date 日期 * @return 生成的PDF文件 */ - public static File printQRCode(String barcodeInfo, String batchCode, String materialName, String date) { + public static File printQRCode(String barcodeInfo, String batchCode, String materialName, String date,String pdfTemplatePath,String generatePath) { try { // 生成PDF文件 File generateFile = new File(generatePath); @@ -154,13 +168,13 @@ public class HwPrintUtil { /** * 打印条形码到PDF文件 * - * @param barcodeInfo 条形码信息 - * @param batchCode 批次代码 + * @param barcodeInfo 条形码信息 + * @param batchCode 批次代码 * @param materialName 物料名称 - * @param date 日期 + * @param date 日期 * @return 生成的PDF文件 */ - public static File printBarCode(String barcodeInfo, String batchCode, String materialName, String date) { + public static File printBarCode(String barcodeInfo, String batchCode, String materialName, String date,String pdfTemplatePath,String generatePath) { try { // 生成PDF文件 File generateFile = new File(generatePath); @@ -256,26 +270,166 @@ public class HwPrintUtil { } } + + /** - * 导出为金山PDF - * 导出为WPS PDF - * 发送至 OneNote 2013 - * Microsoft XPS Document Writer - * Microsoft Print to PDF - * Fax - * \\10.11.43.159\HP LaserJet MFP M129-M134 - * \\10.11.43.159\HP Laser NS 1020 + * 打印方法 + * + * @param params + * @return */ - public static void initPrintService() { - for (PrintService service : printServices) { - System.out.println(service.getName()); - if (service.getName().contains(localPrintPath)) { - printService = service; - break; - } - } - if (printService == null) { - throw new ServiceException("打印机配置错误!"); + public static String printLocationQRCode(String localPrintPath, String locationLabelTemplatePath, + String generateLocationLabelPath, + HashMap params) { + //解析参数生成打印图片 + String qrCode = params.get("qrCode"); + initPrintService(localPrintPath); + File outputFile = printLocationLabelContent(params,locationLabelTemplatePath,generateLocationLabelPath); + try { + printQRPdf(outputFile); + log.info("打印条码,条码内容:" + qrCode); + return localPrintPath; + } catch (Exception e) { + log.error("打印条码[" + qrCode + "]异常:" + e); + throw new ServiceException("打印条码[" + qrCode + "]异常:" + e); } } + + + /** + * 打印二维码到文件 + * + * @param params 二维码信息 + * @return 生成的文件 + */ + public static File printLocationLabelContent(HashMap params,String locationLabelTemplatePath,String generateLocationLabelPath) { + try { + // 生成PDF文件 + File generateFile = new File(generateLocationLabelPath); + FileOutputStream out = new FileOutputStream(generateFile); + // 打印模板PDF + PdfReader reader = new PdfReader(locationLabelTemplatePath); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + // 修改PDF文档的PdfStamper实例,将修改后的内容输出到内存中的字节数组 + PdfStamper stamper = new PdfStamper(reader, bos); + // 动态地将变量的值填充到PDF表单相应字段 + AcroFields form = stamper.getAcroFields(); + + form.setField("text", params.get("text")); + + String qrCode = params.get("qrCode"); + //获取位置(左上右下) + AcroFields.FieldPosition fieldPosition = form.getFieldPositions("qrcode").get(0); + // 绘制二维码 + float width = fieldPosition.position.getRight() - fieldPosition.position.getLeft(); + float height = fieldPosition.position.getTop() - fieldPosition.position.getBottom(); + BarcodeQRCode pdf417 = new BarcodeQRCode(qrCode, (int) width, (int) width, null); + // 生成二维码图像 + Image image128 = pdf417.getImage(); + //而PDF的标准单位是点(pt)。1点等于1/72英寸,1英寸等于2.54厘米,大约1点等于0.03527厘米 +// System.out.println("left:" + fieldPosition.position.getLeft() +// + "right:" + fieldPosition.position.getRight() +// + "top:" + fieldPosition.position.getTop() +// + "bottom:" + fieldPosition.position.getBottom() +// + "width:" + width +// + "height:" + height +// +// ); + // 条码位置 + image128.setAbsolutePosition(fieldPosition.position.getLeft(), + fieldPosition.position.getBottom()-15); + // 获取PDF的第一页 + PdfContentByte cb = stamper.getOverContent(1); + cb.addImage(image128); + // 设置表单不可编辑(即将表单字段内容固定到PDF中) + stamper.setFormFlattening(true); + // 关闭PdfStamper + stamper.close(); + // 创建一个新的文档对象 + Document doc = new Document(); + // 创建 PdfCopy 对象,关联到输出流 + PdfCopy copy = new PdfCopy(doc, out); + // 打开文档 + doc.open(); + // 从内存中的字节数组创建一个 PdfImportedPage 对象 + PdfImportedPage importPage = copy.getImportedPage(new PdfReader(bos.toByteArray()), 1); + // 将导入的页面添加到新文档中 + copy.addPage(importPage); + // 关闭文档 + doc.close(); + return generateFile; + } catch (Exception e) { + log.error("打印条码生成PDF异常:" + e); + } + return null; + } + + + /** + * 打印PDF + * + * @param pdfFile 要打印的PDF文件 + * @throws IOException 如果PDF加载或打印失败 + */ + private static void printQRPdf(File pdfFile) throws IOException { + PDDocument document = null; + try { + +// 定义毫米到英寸的转换系数 + double mmToInch = 1 / 25.4; + +// 定义英寸到点的转换系数 + double inchToPoint = 72; + +// 定义纸张尺寸(单位:毫米) + double paperWidthMm = 40; + double paperHeightMm = 30; + +// 将纸张尺寸转换为点 + double paperWidthPoints = paperWidthMm * mmToInch * inchToPoint; + double paperHeightPoints = paperHeightMm * mmToInch * inchToPoint; + + + document = PDDocument.load(pdfFile); + //打印的页面的大小和方向 + PageFormat pageFormat = new PageFormat(); + //设置打印方向 PORTRAIT 竖向 REVERSE_LANDSCAPE 横向 + pageFormat.setOrientation(PageFormat.PORTRAIT); + Paper paper = new Paper(); + // 纸的大小 + paper.setSize(paperWidthPoints, paperHeightPoints); + // Print 区域 + paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); + pageFormat.setPaper(paper); + Book book = new Book(); + PDFPrintable printable = new PDFPrintable(document, Scaling.SCALE_TO_FIT); + book.append(printable, pageFormat, document.getNumberOfPages()); + PrinterJob job = PrinterJob.getPrinterJob(); + job.setPrintService(printService); + job.setPageable(book); + job.defaultPage(); + try { + job.print(); + } catch (PrinterException e) { + throw new IOException("PDF打印失败:", e); + } + } catch (PrinterException e) { + throw new ServiceException("打印机服务错误:" + e); + } finally { + if (document != null) { + try { + document.close(); + } catch (IOException e) { + // 处理关闭文档时可能出现的异常 + e.printStackTrace(); + } + } + } + } + + + + + + } diff --git a/hw-modules/hw-printer/src/main/resources/files/generatefile.pdf b/hw-modules/hw-printer/src/main/resources/files/generatefile.pdf index 3ef6512c..89449065 100644 Binary files a/hw-modules/hw-printer/src/main/resources/files/generatefile.pdf and b/hw-modules/hw-printer/src/main/resources/files/generatefile.pdf differ diff --git a/hw-modules/hw-printer/src/main/resources/files/generatelocationlabelfile.pdf b/hw-modules/hw-printer/src/main/resources/files/generatelocationlabelfile.pdf new file mode 100644 index 00000000..ab91690d Binary files /dev/null and b/hw-modules/hw-printer/src/main/resources/files/generatelocationlabelfile.pdf differ diff --git a/hw-modules/hw-printer/src/main/resources/files/locationlabeltemplate.pdf b/hw-modules/hw-printer/src/main/resources/files/locationlabeltemplate.pdf new file mode 100644 index 00000000..f70a8613 Binary files /dev/null and b/hw-modules/hw-printer/src/main/resources/files/locationlabeltemplate.pdf differ diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsBaseLocationController.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsBaseLocationController.java index db8185e4..b21375da 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsBaseLocationController.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsBaseLocationController.java @@ -34,8 +34,7 @@ import com.hw.common.core.web.page.TableDataInfo; */ @RestController @RequestMapping("/wmslocation") -public class WmsBaseLocationController extends BaseController -{ +public class WmsBaseLocationController extends BaseController { @Autowired private IWmsBaseLocationService wmsBaseLocationService; @@ -47,8 +46,7 @@ public class WmsBaseLocationController extends BaseController */ @RequiresPermissions("wms:wmslocation:list") @GetMapping("/list") - public TableDataInfo list(WmsBaseLocation wmsBaseLocation) - { + public TableDataInfo list(WmsBaseLocation wmsBaseLocation) { startPage(); List list = wmsBaseLocationService.selectWmsBaseLocationJoinList(wmsBaseLocation); return getDataTable(list); @@ -60,8 +58,7 @@ public class WmsBaseLocationController extends BaseController @RequiresPermissions("wms:wmslocation:export") @Log(title = "库位", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, WmsBaseLocation wmsBaseLocation) - { + public void export(HttpServletResponse response, WmsBaseLocation wmsBaseLocation) { List list = wmsBaseLocationService.selectWmsBaseLocationJoinList(wmsBaseLocation); ExcelUtil util = new ExcelUtil(WmsBaseLocation.class); util.exportExcel(response, list, "库位数据"); @@ -72,8 +69,7 @@ public class WmsBaseLocationController extends BaseController */ @RequiresPermissions("wms:wmslocation:query") @GetMapping(value = "/{locationId}") - public AjaxResult getInfo(@PathVariable("locationId") Long locationId) - { + public AjaxResult getInfo(@PathVariable("locationId") Long locationId) { return success(wmsBaseLocationService.selectWmsBaseLocationByLocationId(locationId)); } @@ -83,8 +79,7 @@ public class WmsBaseLocationController extends BaseController @RequiresPermissions("wms:wmslocation:add") @Log(title = "库位", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody WmsBaseLocation wmsBaseLocation) - { + public AjaxResult add(@RequestBody WmsBaseLocation wmsBaseLocation) { return toAjax(wmsBaseLocationService.insertWmsBaseLocation(wmsBaseLocation)); } @@ -94,8 +89,7 @@ public class WmsBaseLocationController extends BaseController @RequiresPermissions("wms:wmslocation:edit") @Log(title = "库位", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody WmsBaseLocation wmsBaseLocation) - { + public AjaxResult edit(@RequestBody WmsBaseLocation wmsBaseLocation) { return toAjax(wmsBaseLocationService.updateWmsBaseLocation(wmsBaseLocation)); } @@ -104,17 +98,15 @@ public class WmsBaseLocationController extends BaseController */ @RequiresPermissions("wms:wmslocation:remove") @Log(title = "库位", businessType = BusinessType.DELETE) - @DeleteMapping("/{locationIds}") - public AjaxResult remove(@PathVariable Long[] locationIds) - { + @DeleteMapping("/{locationIds}") + public AjaxResult remove(@PathVariable Long[] locationIds) { return toAjax(wmsBaseLocationService.deleteWmsBaseLocationByLocationIds(locationIds)); } @RequiresPermissions("wms:wmslocation:list") @GetMapping("/getWarehouses") - public AjaxResult list(WmsBaseWarehouse wmsBaseWarehouse) - { + public AjaxResult list(WmsBaseWarehouse wmsBaseWarehouse) { wmsBaseWarehouse.setActiveFlag(WmsConstants.WMS_WAREHOUSE_ACTIVE_FLAG_YES); List list = wmsBaseWarehouseService.selectWmsBaseWarehouseList(wmsBaseWarehouse); return success(list); @@ -127,8 +119,7 @@ public class WmsBaseLocationController extends BaseController @RequiresPermissions("wms:wmslocation:lock") @Log(title = "库位", businessType = BusinessType.LOCK) @GetMapping("/lockWmsLocation/{locationId}") - public AjaxResult lockWmsLocation(@PathVariable Long locationId) - { + public AjaxResult lockWmsLocation(@PathVariable Long locationId) { return toAjax(wmsBaseLocationService.lockWmsBaseLocation(locationId)); } @@ -138,9 +129,35 @@ public class WmsBaseLocationController extends BaseController @RequiresPermissions("wms:wmslocation:lock") @Log(title = "库位", businessType = BusinessType.UNLOCK) @GetMapping("/unlockWmsLocation/{locationId}") - public AjaxResult unlockWmsLocation(@PathVariable Long locationId) - { + public AjaxResult unlockWmsLocation(@PathVariable Long locationId) { return toAjax(wmsBaseLocationService.unlockWmsBaseLocation(locationId)); } + + /** + * 打印库位条码 + * + * @param locationIds + * @return + */ + @RequiresPermissions("wms:wmslocation:printLocationLabel") + @Log(title = "库位", businessType = BusinessType.PRINT) + @GetMapping(value = "/printLocationLabels/{locationIds}") + public AjaxResult printLocationLabels(@PathVariable Long[] locationIds) { + return success(wmsBaseLocationService.printLabels(locationIds, 1)); + } + + /** + * 打印料箱条码 + * + * @param locationIds + * @return + */ + @RequiresPermissions("wms:wmslocation:printContainerLabel") + @Log(title = "库位", businessType = BusinessType.PRINT) + @GetMapping(value = "/printContainerLabels/{locationIds}") + public AjaxResult printContainerLabels(@PathVariable Long[] locationIds) { + return success(wmsBaseLocationService.printLabels(locationIds, 2)); + } + } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsBaseLocation.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsBaseLocation.java index 4c9d56ab..50cda47d 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsBaseLocation.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsBaseLocation.java @@ -32,6 +32,10 @@ public class WmsBaseLocation extends BaseEntity @Excel(name = "库位编码") private String locationCode; + /**料箱编码*/ + private String containerCode; + + /** 排 */ @Excel(name = "排") private Long locRow; @@ -191,6 +195,15 @@ public class WmsBaseLocation extends BaseEntity { return locationCode; } + + public String getContainerCode() { + return containerCode; + } + + public void setContainerCode(String containerCode) { + this.containerCode = containerCode; + } + public void setLocRow(Long locRow) { this.locRow = locRow; diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsBaseLocationService.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsBaseLocationService.java index a91b8446..499406af 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsBaseLocationService.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsBaseLocationService.java @@ -84,4 +84,13 @@ public interface IWmsBaseLocationService * @return 结果 */ public int unlockWmsBaseLocation(Long locationId); + + /** + * 打印库位或料箱条码 + * + * @param locationIds + * @param type(1:库位,2:料箱) + * @return + */ + public int printLabels(Long[] locationIds, int type); } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsBaseLocationServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsBaseLocationServiceImpl.java index f7b8d25f..802c7a03 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsBaseLocationServiceImpl.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsBaseLocationServiceImpl.java @@ -1,12 +1,18 @@ package com.hw.wms.service.impl; +import java.util.HashMap; import java.util.List; +import com.hw.common.core.constant.SecurityConstants; import com.hw.common.core.constant.WmsConstants; import com.hw.common.core.enums.WmsLocationStatus; import com.hw.common.core.exception.ServiceException; import com.hw.common.core.utils.DateUtils; +import com.hw.common.core.utils.StringUtils; import com.hw.common.security.utils.SecurityUtils; +import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.printer.api.RemotePrinterService; +import com.hw.printer.api.domain.vo.PrintContentVo; import com.hw.wms.domain.WmsBaseWarehouse; import com.hw.wms.mapper.WmsBaseWarehouseMapper; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +21,8 @@ import com.hw.wms.mapper.WmsBaseLocationMapper; import com.hw.wms.domain.WmsBaseLocation; import com.hw.wms.service.IWmsBaseLocationService; +import javax.annotation.Resource; + /** * 库位Service业务层处理 * @@ -29,6 +37,9 @@ public class WmsBaseLocationServiceImpl implements IWmsBaseLocationService { @Autowired private WmsBaseWarehouseMapper wmsBaseWarehouseMapper; + @Resource + private RemotePrinterService remotePrinterService; + /** * 查询库位 * @@ -125,11 +136,11 @@ public class WmsBaseLocationServiceImpl implements IWmsBaseLocationService { // return wmsBaseLocationMapper.insertWmsBaseLocation(wmsBaseLocation); WmsBaseLocation baseLocation = wmsBaseLocationMapper.selectWmsBaseLocationByLocationId(locationId); String locationStatus = baseLocation.getLocationStatus(); - if(locationStatus.equals(WmsLocationStatus.MANUALLOCK.getCode())){ + if (locationStatus.equals(WmsLocationStatus.MANUALLOCK.getCode())) { return 1; } - if(!locationStatus.equals(WmsLocationStatus.NORMAL.getCode())){ - throw new ServiceException("库位状态为"+WmsLocationStatus.locationStatusMap.get(locationStatus)+",不能锁定"); + if (!locationStatus.equals(WmsLocationStatus.NORMAL.getCode())) { + throw new ServiceException("库位状态为" + WmsLocationStatus.locationStatusMap.get(locationStatus) + ",不能锁定"); } baseLocation.setLocationStatus(WmsLocationStatus.MANUALLOCK.getCode()); @@ -146,11 +157,11 @@ public class WmsBaseLocationServiceImpl implements IWmsBaseLocationService { public int unlockWmsBaseLocation(Long locationId) { WmsBaseLocation baseLocation = wmsBaseLocationMapper.selectWmsBaseLocationByLocationId(locationId); String locationStatus = baseLocation.getLocationStatus(); - if(locationStatus.equals(WmsLocationStatus.NORMAL.getCode())){ + if (locationStatus.equals(WmsLocationStatus.NORMAL.getCode())) { return 1; } - if(!locationStatus.equals(WmsLocationStatus.MANUALLOCK.getCode())){ - throw new ServiceException("库位状态为"+WmsLocationStatus.locationStatusMap.get(locationStatus)+",不能解锁"); + if (!locationStatus.equals(WmsLocationStatus.MANUALLOCK.getCode())) { + throw new ServiceException("库位状态为" + WmsLocationStatus.locationStatusMap.get(locationStatus) + ",不能解锁"); } baseLocation.setLocationStatus(WmsLocationStatus.NORMAL.getCode()); @@ -158,4 +169,45 @@ public class WmsBaseLocationServiceImpl implements IWmsBaseLocationService { } + /** + * 打印料箱条码 + * + * @param locationIds + * @param type(1:库位,2:料箱) + * @return + */ + @Override + public int printLabels(Long[] locationIds, int type) { + StringBuilder buffer = new StringBuilder(); + for (Long locationId : locationIds) { + WmsBaseLocation baseLocation = wmsBaseLocationMapper.selectWmsBaseLocationByLocationId(locationId); + String qrCode = ""; + if (type == 1) { + qrCode = baseLocation.getLocationCode(); + } else if (type == 2) { + qrCode = baseLocation.getContainerCode(); + } + if (StringUtils.isNotEmpty(qrCode)) { + try { + HashMap params = new HashMap<>(); + params.put("text", qrCode); + params.put("qrCode", qrCode); + PrintContentVo printContentVo = new PrintContentVo(); + printContentVo.setParams(params); + //调用的打印接口 + remotePrinterService.printLocationLabel(printContentVo, SecurityConstants.INNER); + } catch (Exception e) { + buffer.append("打印料箱条码报错——[条码内容:").append(qrCode).append("]").append(e.getMessage()); + } + } else { + buffer.append("打印料箱条码为空——[库位条码:").append(baseLocation.getLocationCode()).append("]"); + } + } + if (buffer.length() == 0) { + return 1; + } else { + throw new ServiceException(buffer.toString()); + } + } + } diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsBaseLocationMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsBaseLocationMapper.xml index c5dd3e32..42d13723 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsBaseLocationMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsBaseLocationMapper.xml @@ -11,6 +11,7 @@ + @@ -41,7 +42,7 @@ - select location_id, warehouse_id, location_code,agv_position_code, warehouse_floor,loc_row, layer_num, loc_column, active_flag, manual_flag, qty_limit, instock_flag, outstock_flag, location_status, batch_mix, create_by, create_time, update_by, update_time, remark, del_flag, shelf_order, check_order, pick_order, pick_flag, is_open_kn_flag, location_scrap_type, volume_limit, weight_limit, length, width, height from wms_base_location + select location_id, warehouse_id, location_code,container_code,agv_position_code, warehouse_floor,loc_row, layer_num, loc_column, active_flag, manual_flag, qty_limit, instock_flag, outstock_flag, location_status, batch_mix, create_by, create_time, update_by, update_time, remark, del_flag, shelf_order, check_order, pick_order, pick_flag, is_open_kn_flag, location_scrap_type, volume_limit, weight_limit, length, width, height from wms_base_location - select wbl.location_id, wbl.warehouse_id,wbl.agv_position_code, wbl.location_code, wbl.loc_row, wbl.layer_num, wbl.loc_column, wbl.active_flag, wbl.manual_flag, + select wbl.location_id, wbl.warehouse_id,wbl.agv_position_code, wbl.location_code,wbl.container_code, wbl.loc_row, wbl.layer_num, wbl.loc_column, wbl.active_flag, wbl.manual_flag, wbl.qty_limit, wbl.instock_flag, wbl.outstock_flag, wbl.location_status, wbl.remark,wbw.warehouse_name from wms_base_location wbl left join wms_base_warehouse wbw on wbl.warehouse_id = wbw.warehouse_id diff --git a/hw-ui/src/api/wms/wmslocation.js b/hw-ui/src/api/wms/wmslocation.js index 576a1863..899a052a 100644 --- a/hw-ui/src/api/wms/wmslocation.js +++ b/hw-ui/src/api/wms/wmslocation.js @@ -68,3 +68,22 @@ export function unlockWmslocation(locationId) { method: 'get' }) } + + + +// 打印库位条码 +export function printLocationLabels(locationId) { + return request({ + url: '/wms/wmslocation/printLocationLabels/' + locationId, + method: 'get' + }) +} + + +// 打印料箱条码 +export function printContainerLabels(locationId) { + return request({ + url: '/wms/wmslocation/printContainerLabels/' + locationId, + method: 'get' + }) +} diff --git a/hw-ui/src/views/mes/processInfo/index.vue b/hw-ui/src/views/mes/processInfo/index.vue index 861ca838..5f2a5b0d 100644 --- a/hw-ui/src/views/mes/processInfo/index.vue +++ b/hw-ui/src/views/mes/processInfo/index.vue @@ -532,8 +532,8 @@ export default { this.$refs["form"].validate(valid => { if (valid) { this.form.mesBaseProcessProdlineList = this.mesBaseProcessProdlineList; - if (this.form.productionTime <= 0) { - this.$modal.msgError("标准工时天、小时、分钟需为大于等于0的正整数!"); + if (this.form.productionTime < 0) { + this.$modal.msgError("标准工时天、小时、分钟需为大于等于0的整数!"); return; } this.convertToSeconds(); diff --git a/hw-ui/src/views/wms/base/wmslocation/index.vue b/hw-ui/src/views/wms/base/wmslocation/index.vue index c648d6ce..20e7c6b0 100644 --- a/hw-ui/src/views/wms/base/wmslocation/index.vue +++ b/hw-ui/src/views/wms/base/wmslocation/index.vue @@ -194,6 +194,31 @@ >删除 + + 打印库位标签 + + + + 打印料箱标签 + + + + @@ -408,7 +408,7 @@ - +