diff --git a/src/main/java/com/dpkj/common/config/PrinterConfig.java b/src/main/java/com/dpkj/common/config/PrinterConfig.java index 78a034d..85577ad 100644 --- a/src/main/java/com/dpkj/common/config/PrinterConfig.java +++ b/src/main/java/com/dpkj/common/config/PrinterConfig.java @@ -2,7 +2,6 @@ package com.dpkj.common.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; /** @@ -29,4 +28,15 @@ public class PrinterConfig { * 波特率 串口连接下使用 */ private Integer baudRate; + + /** + * 终端号 + */ + private String terminalNumber; + + /** + * 时间格式 + */ + private String timeType; + } diff --git a/src/main/java/com/dpkj/modules/autoReplyPrint/controller/ReceiptPrintController.java b/src/main/java/com/dpkj/modules/autoReplyPrint/controller/ReceiptPrintController.java index 095ccf0..340ad46 100644 --- a/src/main/java/com/dpkj/modules/autoReplyPrint/controller/ReceiptPrintController.java +++ b/src/main/java/com/dpkj/modules/autoReplyPrint/controller/ReceiptPrintController.java @@ -1,6 +1,8 @@ package com.dpkj.modules.autoReplyPrint.controller; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.dpkj.common.config.PrinterConfig; import com.dpkj.common.exception.RRException; import com.dpkj.common.vo.Result; import com.dpkj.modules.autoReplyPrint.enums.ReceiptTemplateEnum; @@ -15,6 +17,8 @@ import org.thymeleaf.util.StringUtils; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.annotation.Resource; @@ -30,6 +34,12 @@ import javax.annotation.Resource; @RequestMapping("/receipt") public class ReceiptPrintController { + @Resource + private PrinterConfig printerConfig; + + private static final int MAX_HEIGHT = 1000; + private static final int FIXED_WIDTH = 730; + @Resource(name = "USBImagePrint") private ImagePrintService usbImagePrintService; @@ -40,16 +50,72 @@ public class ReceiptPrintController { private Result print(@Validated @RequestBody ReceiptPrintRequest request) throws UnsupportedEncodingException { String devName = "VID:0x0FE6,PID:0x811E"; // 采用默认的devName,不进行入参传值了 String templateName = ReceiptTemplateEnum.getTemplateName(request.getTemplateName()); + + // 宽度固定 + request.setWidth(request.getWidth() > 610 ? 600 : request.getWidth()); + + JSONObject data = JSONObject.parseObject(URLDecoder.decode(request.getTemplateFillData(), "UTF-8")); + + // 强行设置终端号 + data.put("terminalNumber", printerConfig.getTerminalNumber()); + + // 强行设置终端号和打印时间 + SimpleDateFormat sdf = new SimpleDateFormat(printerConfig.getTimeType()); + String formattedDate = sdf.format( new Date()); + data.put("printTime", formattedDate); + + Integer height = request.getHeight(); + + int dinyHeight = 0; + if (templateName.equals("department")) { + // 由于是使用的门诊小票-T2,那么默认的高度为1000,强行设置,通过动态修改渲染的图片的高度 + height = 1100; + + // 单行最大长度为10 + int singleLineMaxLength = 10; + // 这里的长度取自于department.html模板中的项目单个tr高度,并且略高于该高度 + int singleLineHeight = 30; + // 动态计算长度 + JSONArray items = data.getJSONArray("items"); + for (Object item : items) { + JSONObject itemEntity = (JSONObject) item; + String projectName = String.valueOf(itemEntity.get("name")); + int length = projectName.length(); + int count = (int)Math.ceil((double) length / singleLineMaxLength); + dinyHeight += count * singleLineHeight; + } + + // 计算是否有门诊号 + String outpatientNumber = data.getString("outpatientNumber"); + if ( !StringUtils.isEmpty(outpatientNumber)){ + dinyHeight += 28; + } + + // 计算是否有就诊医生 + String doctor = data.getString("doctor"); + if ( !StringUtils.isEmpty(doctor)){ + dinyHeight += 28; + } + + // 计算是否有就诊科室 + String department = data.getString("department"); + if ( !StringUtils.isEmpty(department)){ + dinyHeight += 28; + } + + } + height += dinyHeight; + // 进行模板填充 // String testData = "{\"hospitalName\":\"澜沧县中医医院\",\"registeTerminalName\":\"中国农业银行自助终端\",\"registeType\":\"自助挂号\",\"name\":\"刘博雅\",\"gender\":\"男\",\"age\":28,\"birthDate\":\"1996-06-31\",\"cardNumber\":\"6221**********0731\",\"outpatientNumber\":\"2501150038\",\"department\":\"普外科门诊\",\"visitLevel\":\"普通号\",\"doctor\":\"普通门诊\",\"sequence\":\"1\",\"registerDate\":\"2025-01-15\",\"totalFee\":4.00,\"paymentMethod\":\"微信扫码支付\",\"orderNumber\":\"\",\"transactionNumber\":\"2025011513090412092794szztzzj\",\"qrCodeBase64_2base64Type_1_250_250\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}"; StringBuilder filePath = new StringBuilder(request.getFileDir()); // 校验是否选中了模板,如果没选中模板的话则不需要另外生成了 if ( !StringUtils.isEmpty(request.getTemplateName()) && !StringUtils.isEmpty(request.getFileDir())){ byte[] image = templateService.generateReceiptImage( - JSONObject.parseObject(URLDecoder.decode(request.getTemplateFillData(), "UTF-8")), + data, templateName, request.getWidth(), - request.getHeight(), + height, filePath); }else { throw new RRException("模板渲染错误"); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index eb3f984..3aa74e7 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,6 +6,10 @@ dpkj: printer: # 打印机连接方式 USB: usb连接 | BTMS:串口连接 connection-type: USB + # 终端号设置 + terminal-Number: PORT-000000001 + # 打印时间格式化 + time-Type: yyyy-MM-dd HH:mm:ss # 打印端口 串口连接下使用 port-name: # 波特率 串口连接下使用 diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index ee209b1..e24f50f 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -6,11 +6,16 @@ dpkj: printer: # 打印机连接方式 USB: usb连接 | BTMS:串口连接 connection-type: USB + # 终端号设置 + terminal-Number: PORT-000000001 + # 打印时间格式化 + time-Type: yyyy-MM-dd HH:mm:ss # 打印端口 串口连接下使用 port-name: # 波特率 串口连接下使用 baud-rate: + # 身份证读取等待时间 IDCardReader: waitingTime: 30000 diff --git a/src/main/resources/templates/department.html b/src/main/resources/templates/department.html index cd9209f..2daeb88 100644 --- a/src/main/resources/templates/department.html +++ b/src/main/resources/templates/department.html @@ -7,50 +7,50 @@
-
************
-
-
+
************
+
+
-----------------------------------------------------------------------------
-
+
- 姓名: - 性别: - 年龄: + 姓名:
+ 性别: + 年龄:
门诊号:
就诊医生:
就诊科室:
-
-----------------------------------------------------------------------------
-
+
-----------------------------------------------------------------------------
+
费用总额: 个人支付:
实收金额:
实收金额:
-
-----------------------------------------------------------------------------
+
-----------------------------------------------------------------------------
- - +
+ - - + +
项目名称 数量 单价 小计
-----------------------------------------------------------------------------
-
+
终端编号:
打印时间:
-
+
温馨提示
1.请取走全部凭条、并妥善保管
2.如果对缴费结算存在疑问,请到人工窗口咨询 diff --git a/src/main/resources/templates/hospitalPayment.html b/src/main/resources/templates/hospitalPayment.html index b326a50..b6c6eee 100644 --- a/src/main/resources/templates/hospitalPayment.html +++ b/src/main/resources/templates/hospitalPayment.html @@ -12,7 +12,7 @@
-----------------------------------------------------------------------------
-
+
姓  名:
性  别:
年  龄:
diff --git a/src/main/resources/templates/outpatientPayment.html b/src/main/resources/templates/outpatientPayment.html index 8015894..07028fe 100644 --- a/src/main/resources/templates/outpatientPayment.html +++ b/src/main/resources/templates/outpatientPayment.html @@ -12,7 +12,7 @@
-----------------------------------------------------------------------------
-
+
姓  名:
性  别:
年  龄:
diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html index 2c6932b..bcfda5d 100644 --- a/src/main/resources/templates/register.html +++ b/src/main/resources/templates/register.html @@ -29,7 +29,7 @@
-----------------------------------------------------------------------------
-
+
姓  名:
性  别:
年  龄: