From c68906e59e21a8ee7b7041a2ccd28a1c6226e1a9 Mon Sep 17 00:00:00 2001 From: tangzh Date: Mon, 7 Apr 2025 09:05:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ntController.java => PrintController.java} | 20 ++--- .../controller/StoreOrderController.java | 52 ++++++------- .../com/zbkj/common/constants/Constants.java | 7 ++ .../zbkj/common/constants/YlyConstants.java | 4 +- .../com/zbkj/common/enums/EnumPintNode.java | 32 ++++++++ food-service/pom.xml | 4 + .../zbkj/service/service/PrintService.java | 17 +++++ .../zbkj/service/service/YlyPrintService.java | 14 ---- .../service/impl/OrderPayServiceImpl.java | 6 +- .../impl/printer/JiabPrintServiceImpl.java | 73 +++++++++++++++++++ .../service/impl/printer/PrintHandle.java | 56 ++++++++++++++ .../{ => printer}/YlyPrintServiceImpl.java | 32 ++++---- .../java/com/zbkj/service/util/YlyUtil.java | 7 +- .../com/zbkj/service/util/jiab/JiabUtil.java | 38 ++++++++++ 14 files changed, 290 insertions(+), 72 deletions(-) rename food-admin/src/main/java/com/zbkj/admin/controller/{YlyPrintController.java => PrintController.java} (56%) create mode 100644 food-common/src/main/java/com/zbkj/common/enums/EnumPintNode.java create mode 100644 food-service/src/main/java/com/zbkj/service/service/PrintService.java delete mode 100644 food-service/src/main/java/com/zbkj/service/service/YlyPrintService.java create mode 100644 food-service/src/main/java/com/zbkj/service/service/impl/printer/JiabPrintServiceImpl.java create mode 100644 food-service/src/main/java/com/zbkj/service/service/impl/printer/PrintHandle.java rename food-service/src/main/java/com/zbkj/service/service/impl/{ => printer}/YlyPrintServiceImpl.java (83%) create mode 100644 food-service/src/main/java/com/zbkj/service/util/jiab/JiabUtil.java diff --git a/food-admin/src/main/java/com/zbkj/admin/controller/YlyPrintController.java b/food-admin/src/main/java/com/zbkj/admin/controller/PrintController.java similarity index 56% rename from food-admin/src/main/java/com/zbkj/admin/controller/YlyPrintController.java rename to food-admin/src/main/java/com/zbkj/admin/controller/PrintController.java index f7bf36f..6432f40 100644 --- a/food-admin/src/main/java/com/zbkj/admin/controller/YlyPrintController.java +++ b/food-admin/src/main/java/com/zbkj/admin/controller/PrintController.java @@ -1,33 +1,35 @@ package com.zbkj.admin.controller; +import com.zbkj.common.enums.EnumPintNode; import com.zbkj.common.response.CommonResult; -import com.zbkj.service.service.YlyPrintService; +import com.zbkj.service.service.impl.printer.PrintHandle; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; /** - * 易联云打印订单 - + * 打印订单 */ @Slf4j @RestController @RequestMapping("api/admin/yly") -@Api(tags = "易联云 打印订单小票") //配合swagger使用 -public class YlyPrintController { - +@Api(tags = "打印订单小票") //配合swagger使用 +public class PrintController { @Autowired - private YlyPrintService ylyPrintService; + private PrintHandle printHandle; @PreAuthorize("hasAuthority('admin:yly:print')") @ApiOperation(value = "打印小票") @RequestMapping(value = "/print/{ordid}", method = RequestMethod.GET) public CommonResult updateStatus(@PathVariable String ordid) { - ylyPrintService.YlyPrint(ordid,false); + printHandle.print(ordid, EnumPintNode.PLATFORM); return CommonResult.success(); } } diff --git a/food-admin/src/main/java/com/zbkj/admin/controller/StoreOrderController.java b/food-admin/src/main/java/com/zbkj/admin/controller/StoreOrderController.java index 07b0e68..3a42309 100644 --- a/food-admin/src/main/java/com/zbkj/admin/controller/StoreOrderController.java +++ b/food-admin/src/main/java/com/zbkj/admin/controller/StoreOrderController.java @@ -212,32 +212,32 @@ public class StoreOrderController { } - /** - * 核销码核销订单 - * - * @author stivepeim - * @since 2020-09-01 - */ - @PreAuthorize("hasAuthority('admin:order:write:update')") - @ApiOperation(value = "核销码核销订单") - @RequestMapping(value = "/writeUpdate/{vCode}", method = RequestMethod.GET) - public CommonResult verificationOrder(@PathVariable String vCode) { - return CommonResult.success(storeOrderVerification.verificationOrderByCode(vCode)); - } - - /** - * 核销码查询待核销订单 - * - * @author stivepeim - * @since 2020-09-01 - */ - @PreAuthorize("hasAuthority('admin:order:write:confirm')") - @ApiOperation(value = "核销码查询待核销订单") - @RequestMapping(value = "/writeConfirm/{vCode}", method = RequestMethod.GET) - public CommonResult verificationConfirmOrder( - @PathVariable String vCode) { - return CommonResult.success(storeOrderVerification.getVerificationOrderByCode(vCode)); - } +// /** +// * 核销码核销订单 +// * +// * @author stivepeim +// * @since 2020-09-01 +// */ +// @PreAuthorize("hasAuthority('admin:order:write:update')") +// @ApiOperation(value = "核销码核销订单") +// @RequestMapping(value = "/writeUpdate/{vCode}", method = RequestMethod.GET) +// public CommonResult verificationOrder(@PathVariable String vCode) { +// return CommonResult.success(storeOrderVerification.verificationOrderByCode(vCode)); +// } +// +// /** +// * 核销码查询待核销订单 +// * +// * @author stivepeim +// * @since 2020-09-01 +// */ +// @PreAuthorize("hasAuthority('admin:order:write:confirm')") +// @ApiOperation(value = "核销码查询待核销订单") +// @RequestMapping(value = "/writeConfirm/{vCode}", method = RequestMethod.GET) +// public CommonResult verificationConfirmOrder( +// @PathVariable String vCode) { +// return CommonResult.success(storeOrderVerification.getVerificationOrderByCode(vCode)); +// } /** * 订单统计详情 diff --git a/food-common/src/main/java/com/zbkj/common/constants/Constants.java b/food-common/src/main/java/com/zbkj/common/constants/Constants.java index d41499a..30fe82a 100644 --- a/food-common/src/main/java/com/zbkj/common/constants/Constants.java +++ b/food-common/src/main/java/com/zbkj/common/constants/Constants.java @@ -562,4 +562,11 @@ public class Constants { /** 失效 */ public static final Integer STATUS_INVALID = 0; + // 支付成功自动打印开关 + public static final String PRINT_AUTO_STATUS = "print_auto_status"; + // 打印开关 + public static final String PRINT_STATUS = "print_status"; + // 打印类型,1佳博,2易联云 + public static final String PRINT_TYPE = "pint_type"; + } diff --git a/food-common/src/main/java/com/zbkj/common/constants/YlyConstants.java b/food-common/src/main/java/com/zbkj/common/constants/YlyConstants.java index b66d67d..3b66d3a 100644 --- a/food-common/src/main/java/com/zbkj/common/constants/YlyConstants.java +++ b/food-common/src/main/java/com/zbkj/common/constants/YlyConstants.java @@ -14,10 +14,8 @@ public class YlyConstants { public static final String YLY_PRINT_APP_MACHINE_CODE = "ylyprint_app_machine_code"; // 易联云打印机设备密钥 public static final String YLY_PRINT_APP_MACHINE_MSIGN = "ylyprint_app_machine_msign"; - // 易联云打印开关 - public static final String YLY_PRINT_AUTO_STATUS = "ylyprint_auto_status"; - public static final String YLY_PRINT_STATUS = "ylyprint_status"; // public static final String YLY_REDIS_TOKEN = "yly_token"; + } diff --git a/food-common/src/main/java/com/zbkj/common/enums/EnumPintNode.java b/food-common/src/main/java/com/zbkj/common/enums/EnumPintNode.java new file mode 100644 index 0000000..713d63f --- /dev/null +++ b/food-common/src/main/java/com/zbkj/common/enums/EnumPintNode.java @@ -0,0 +1,32 @@ +package com.zbkj.common.enums; + +public enum EnumPintNode { + + CREATE_ORDER("1","下单自动打印"), + PLATFORM("2","平台手动打印"), + ; + + private String name; + private String code; + + EnumPintNode(String name, String code) { + this.name = name; + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/food-service/pom.xml b/food-service/pom.xml index 7435392..0da500e 100644 --- a/food-service/pom.xml +++ b/food-service/pom.xml @@ -22,6 +22,10 @@ food-common ${food-common} + + net.java.dev.jna + jna + \ No newline at end of file diff --git a/food-service/src/main/java/com/zbkj/service/service/PrintService.java b/food-service/src/main/java/com/zbkj/service/service/PrintService.java new file mode 100644 index 0000000..6592791 --- /dev/null +++ b/food-service/src/main/java/com/zbkj/service/service/PrintService.java @@ -0,0 +1,17 @@ +package com.zbkj.service.service; + +/** + * 打印机打印订单 service + */ +public interface PrintService { + + String code(); + + /** + * 打印商品信息 + * + * @param ordId 订单id + */ + void print(String ordId); + +} diff --git a/food-service/src/main/java/com/zbkj/service/service/YlyPrintService.java b/food-service/src/main/java/com/zbkj/service/service/YlyPrintService.java deleted file mode 100644 index 16d2a7e..0000000 --- a/food-service/src/main/java/com/zbkj/service/service/YlyPrintService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.zbkj.service.service; - -/** - * 易联云打印订单 service - - */ -public interface YlyPrintService { - /** - * 易联云打印商品信息 - * @param ordId 订单id - * @param isAuto 是否自动打印 - */ - void YlyPrint(String ordId,boolean isAuto); -} diff --git a/food-service/src/main/java/com/zbkj/service/service/impl/OrderPayServiceImpl.java b/food-service/src/main/java/com/zbkj/service/service/impl/OrderPayServiceImpl.java index 9d76ac0..6412783 100644 --- a/food-service/src/main/java/com/zbkj/service/service/impl/OrderPayServiceImpl.java +++ b/food-service/src/main/java/com/zbkj/service/service/impl/OrderPayServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.zbkj.common.constants.*; +import com.zbkj.common.enums.EnumPintNode; import com.zbkj.common.exception.CrmebException; import com.zbkj.common.model.combination.StoreCombination; import com.zbkj.common.model.combination.StorePink; @@ -28,6 +29,7 @@ import com.zbkj.common.utils.WxPayUtil; import com.zbkj.common.vo.*; import com.zbkj.service.delete.OrderUtils; import com.zbkj.service.service.*; +import com.zbkj.service.service.impl.printer.PrintHandle; import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -144,7 +146,7 @@ public class OrderPayServiceImpl implements OrderPayService { private UserExperienceRecordService userExperienceRecordService; @Autowired - private YlyPrintService ylyPrintService; + private PrintHandle printHandle; @Autowired private SystemNotificationService systemNotificationService; @@ -300,7 +302,7 @@ public class OrderPayServiceImpl implements OrderPayService { autoSendCoupons(storeOrder); // 根据配置 打印小票 - ylyPrintService.YlyPrint(storeOrder.getOrderId(),true); + printHandle.print(storeOrder.getOrderId(), EnumPintNode.CREATE_ORDER); } catch (Exception e) { e.printStackTrace(); diff --git a/food-service/src/main/java/com/zbkj/service/service/impl/printer/JiabPrintServiceImpl.java b/food-service/src/main/java/com/zbkj/service/service/impl/printer/JiabPrintServiceImpl.java new file mode 100644 index 0000000..caa555d --- /dev/null +++ b/food-service/src/main/java/com/zbkj/service/service/impl/printer/JiabPrintServiceImpl.java @@ -0,0 +1,73 @@ +package com.zbkj.service.service.impl.printer; + +import com.zbkj.service.service.PrintService; +import com.zbkj.service.service.StoreOrderInfoService; +import com.zbkj.service.service.StoreOrderService; +import com.zbkj.service.util.jiab.JiabUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 佳博打印机 + */ +@Service +public class JiabPrintServiceImpl implements PrintService { + + private static final Logger logger = LoggerFactory.getLogger(JiabPrintServiceImpl.class); + + @Autowired + private StoreOrderService storeOrderService; + + @Autowired + private StoreOrderInfoService storeOrderInfoService; + + private static JiabUtil pjb = JiabUtil.INSTANCE; + + @Override + public String code() { + return "1"; + } + + @Override + public void print(String ordId) { + System.out.println("1111"); +// System.setProperty("jna.encoding", "GBK"); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyMMddHHmmss"); +// +// pjb.openport("GP-L80160 Series"); +// pjb.setup("100", "200", "5", "8", "0", "0", "0"); +// pjb.clearbuffer(); +// pjb.windowsfont(120, 0, 48, 0, 0, 0, "宋体", "领料清单"); +// +// int height = 100; +// pjb.windowsfont(5, height, 26, 0, 0, 0, "宋体", "单号:" + sdf.format(new Date())); +// height += 70; +// pjb.windowsfont(5, height, 32, 0, 0, 0, "宋体", "PO号"); +// pjb.windowsfont(160, height, 32, 0, 0, 0, "宋体", "物料描述"); +// pjb.windowsfont(330, height, 32, 0, 0, 0, "宋体", "数量"); +// +// height = height + 45; +// pjb.windowsfont(5, height, 26, 0, 0, 0, "宋体", "111"); +// pjb.windowsfont(380, height, 26, 0, 0, 0, "宋体", 2 + ""); +//// if (line > 1) { +//// for (int j = 0; j < line; j++) { +//// String substring = desc.substring(8 * j, 8 * (j + 1) > desc.length() ? desc.length() : 8 * (j + 1)); +//// pjb.windowsfont(130, height, 26, 0, 0, 0, "宋体", substring); +//// height = height + 45; +//// if(height > 800) { +//// pjb.printlabel("1", "1"); +//// pjb.clearbuffer(); +//// height = 0; +//// } +//// } +//// } +// pjb.windowsfont(200, height + 100, 28, 0, 0, 0, "宋体", "签字:"); +// pjb.printlabel("1", "1"); +// pjb.closeport(); + } +} diff --git a/food-service/src/main/java/com/zbkj/service/service/impl/printer/PrintHandle.java b/food-service/src/main/java/com/zbkj/service/service/impl/printer/PrintHandle.java new file mode 100644 index 0000000..9635d05 --- /dev/null +++ b/food-service/src/main/java/com/zbkj/service/service/impl/printer/PrintHandle.java @@ -0,0 +1,56 @@ +package com.zbkj.service.service.impl.printer; + +import com.zbkj.common.constants.Constants; +import com.zbkj.common.constants.YlyConstants; +import com.zbkj.common.enums.EnumPintNode; +import com.zbkj.common.exception.CrmebException; +import com.zbkj.service.service.PrintService; +import com.zbkj.service.service.SystemConfigService; +import com.zbkj.service.util.YlyUtil; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class PrintHandle { + + private final Logger logger = LoggerFactory.getLogger(PrintHandle.class); + @Autowired private YlyUtil ylyUtil; + @Autowired private List printServices; + @Autowired private SystemConfigService systemConfigService; + private Map printHashMap = new HashMap<>(); + + @PostConstruct + public void init() { + printServices.stream().forEach(i -> { + printHashMap.put(i.code(), i); + }); + } + + public void print(String orderId, EnumPintNode pintNode) { + if (pintNode == pintNode.CREATE_ORDER && ylyUtil.checkYlyPrintAfterPaySuccess()) { + logger.info("未开启支付成功自动打印开关,略过"); + return; + } + if (ylyUtil.checkYlyPrintStatus()) { + logger.info("未开启打印开关,略过"); + } + String printType = systemConfigService.getValueByKey(Constants.PRINT_TYPE); + if (StringUtils.isEmpty(printType)) { + logger.info("未配置打印类型,略过"); + } + PrintService printService = printHashMap.get(printType); + if (null == printService) { + logger.info("未配置打印类型,略过"); + } + printService.print(orderId); + } + +} diff --git a/food-service/src/main/java/com/zbkj/service/service/impl/YlyPrintServiceImpl.java b/food-service/src/main/java/com/zbkj/service/service/impl/printer/YlyPrintServiceImpl.java similarity index 83% rename from food-service/src/main/java/com/zbkj/service/service/impl/YlyPrintServiceImpl.java rename to food-service/src/main/java/com/zbkj/service/service/impl/printer/YlyPrintServiceImpl.java index 29de80f..14c5b45 100644 --- a/food-service/src/main/java/com/zbkj/service/service/impl/YlyPrintServiceImpl.java +++ b/food-service/src/main/java/com/zbkj/service/service/impl/printer/YlyPrintServiceImpl.java @@ -1,4 +1,4 @@ -package com.zbkj.service.service.impl; +package com.zbkj.service.service.impl.printer; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; @@ -9,10 +9,7 @@ import com.zbkj.common.model.order.StoreOrder; import com.zbkj.common.request.YlyPrintRequest; import com.zbkj.common.request.YlyPrintRequestGoods; import com.zbkj.common.vo.StoreOrderInfoOldVo; -import com.zbkj.service.service.StoreOrderInfoService; -import com.zbkj.service.service.StoreOrderService; -import com.zbkj.service.service.SystemConfigService; -import com.zbkj.service.service.YlyPrintService; +import com.zbkj.service.service.*; import com.zbkj.service.util.YlyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +23,7 @@ import java.util.List; * 易联云打印订单 service */ @Service -public class YlyPrintServiceImpl implements YlyPrintService { +public class YlyPrintServiceImpl implements PrintService { private static final Logger logger = LoggerFactory.getLogger(YlyPrintServiceImpl.class); @Autowired private StoreOrderService storeOrderService; @@ -40,21 +37,26 @@ public class YlyPrintServiceImpl implements YlyPrintService { @Autowired private YlyUtil ylyUtil; + + @Override + public String code() { + return "2"; + } + /** * 易联云打印商品信息 * * @param orderId 订单id - * @param isAuto 是否自动打印 */ @Override - public void YlyPrint(String orderId, boolean isAuto) { - if (ylyUtil.checkYlyPrintStatus()) { - throw new CrmebException("易联云 未开启打印"); - } - // 判断是否开启自动打印 - if (isAuto && ylyUtil.checkYlyPrintAfterPaySuccess()) { - return; - } + public void print(String orderId) { +// if (ylyUtil.checkYlyPrintStatus()) { +// throw new CrmebException("易联云 未开启打印"); +// } +// // 判断是否开启自动打印 +// if (isAuto && ylyUtil.checkYlyPrintAfterPaySuccess()) { +// return; +// } StoreOrder exitOrder = storeOrderService.getByOderId(orderId); if (ObjectUtil.isNull(exitOrder)) { throw new CrmebException("易联云 打印时未找到 订单信息"); diff --git a/food-service/src/main/java/com/zbkj/service/util/YlyUtil.java b/food-service/src/main/java/com/zbkj/service/util/YlyUtil.java index 300e8da..f0b0f23 100644 --- a/food-service/src/main/java/com/zbkj/service/util/YlyUtil.java +++ b/food-service/src/main/java/com/zbkj/service/util/YlyUtil.java @@ -3,6 +3,7 @@ package com.zbkj.service.util; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.zbkj.common.constants.Constants; import com.zbkj.common.constants.YlyConstants; import com.zbkj.common.exception.CrmebException; import com.zbkj.common.request.YlyPrintRequest; @@ -63,7 +64,7 @@ public class YlyUtil { client_secret = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_APP_SECRET); machine_code = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_APP_MACHINE_CODE); msign = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_APP_MACHINE_MSIGN); - status = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_STATUS); + status = systemConfigService.getValueByKey(Constants.PRINT_STATUS); if(StringUtils.isBlank(client_id) || StringUtils.isBlank(client_secret) || StringUtils.isBlank(machine_code) || StringUtils.isBlank(msign)){ throw new CrmebException("易联云配置数据不完整"); @@ -180,7 +181,7 @@ public class YlyUtil { * 付款成后打印易联云订单 */ public boolean checkYlyPrintAfterPaySuccess(){ - String printAuto = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_AUTO_STATUS); + String printAuto = systemConfigService.getValueByKey(Constants.PRINT_AUTO_STATUS); return !StringUtils.isBlank(printAuto) && "'0'".equals(printAuto); } @@ -188,7 +189,7 @@ public class YlyUtil { * 检查是否开启打印 */ public boolean checkYlyPrintStatus(){ - String printAuto = systemConfigService.getValueByKey(YlyConstants.YLY_PRINT_STATUS); + String printAuto = systemConfigService.getValueByKey(Constants.PRINT_STATUS); return !StringUtils.isBlank(printAuto) && "'0'".equals(printAuto); } diff --git a/food-service/src/main/java/com/zbkj/service/util/jiab/JiabUtil.java b/food-service/src/main/java/com/zbkj/service/util/jiab/JiabUtil.java new file mode 100644 index 0000000..fd2afdd --- /dev/null +++ b/food-service/src/main/java/com/zbkj/service/util/jiab/JiabUtil.java @@ -0,0 +1,38 @@ +package com.zbkj.service.util.jiab; + +import com.sun.jna.Library; +import com.sun.jna.Native; + +public interface JiabUtil extends Library { + + JiabUtil INSTANCE = (JiabUtil) Native.loadLibrary("TSCLIB", JiabUtil.class); + + int about(); + + int openport(String pirnterName); + + int closeport(); + + int sendcommand(String printerCommand); + + int setup(String width, String height, String speed, String density, String sensor, String vertical, String offset); + + int downloadpcx(String filename, String image_name); + + int barcode(String x, String y, String type, String height, String readable, String rotation, String narrow, + String wide, String code); + + int printerfont(String x, String y, String fonttype, String rotation, String xmul, String ymul, String text); + + int clearbuffer(); + + int printlabel(String set, String copy); + + int formfeed(); + + int nobackfeed(); + + int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, + String content); + +}