feat:统一小票打印机接口
This commit is contained in:
parent
24820af27a
commit
438d52da0c
7
pom.xml
7
pom.xml
|
@ -111,6 +111,13 @@
|
||||||
<version>3.1.28</version> <!-- 可以根据实际情况调整版本 -->
|
<version>3.1.28</version> <!-- 可以根据实际情况调整版本 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 数据校验-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>2.0.1.Final</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.dpkj.modules.autoReplyPrint.controller;
|
||||||
|
|
||||||
|
import com.dpkj.common.vo.Result;
|
||||||
|
import com.dpkj.modules.autoReplyPrint.request.ReceiptPrintRequest;
|
||||||
|
import com.dpkj.modules.autoReplyPrint.service.ImagePrintService;
|
||||||
|
import com.dpkj.modules.autoReplyPrint.service.impl.TemplateService;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小票打印机控制层
|
||||||
|
*
|
||||||
|
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||||
|
* @version 1.0
|
||||||
|
* @since 2025-03-10 9:29:22
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/receipt")
|
||||||
|
public class ReceiptPrintController {
|
||||||
|
|
||||||
|
@Resource(name = "USBImagePrint")
|
||||||
|
private ImagePrintService usbImagePrintService;
|
||||||
|
|
||||||
|
@PostMapping("/print")
|
||||||
|
private Result<Void> print(@Validated @RequestBody ReceiptPrintRequest request){
|
||||||
|
String devName = "VID:0x0FE6,PID:0x811E"; // 采用默认的devName,不进行入参传值了
|
||||||
|
usbImagePrintService.imagePrintFromPath(devName,
|
||||||
|
request.getWidth(),
|
||||||
|
request.getHeight(),
|
||||||
|
request.getFileDir(),
|
||||||
|
1,
|
||||||
|
0);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.dpkj.modules.autoReplyPrint.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小票打印请求,壁挂和打印机接口 进行统一
|
||||||
|
*
|
||||||
|
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||||
|
* @version 1.0
|
||||||
|
* @since 2025-03-10 9:25:34
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class ReceiptPrintRequest implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件路径地址,填写本地路径,默认为 D:/images
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文件路径不能为空")
|
||||||
|
private String fileDir = "D:/images";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板名称,也可以是自己写的html的字符串文件
|
||||||
|
*/
|
||||||
|
private String templateName = "receipt";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充模板的数据,必填,也可以通过自己设置的模板名称进行设计,部分设计规则
|
||||||
|
* <p>1、特殊字段(二维码图片)类型:qrCodeBase64_2base64Type_120_120,字段解析,qrCodeBase64为字段名称,
|
||||||
|
* _2base64Type为将这个数据转换为图片类型的base64编码,第一个_120图片的宽度,第二个_120的为图片高度</p>
|
||||||
|
* <p>2、需要对传入的JSON数据进行URI编码</p>
|
||||||
|
* <p>3、{"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_120_120":"这里应是二维码的Base64编码数据(如果有)","terminalNumber":"12092794","printTime":"2025-01-15 13:10:08"}</p>
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "模板填充数据不能为空")
|
||||||
|
private String templateFillData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小票渲染宽度,默认为:600
|
||||||
|
*/
|
||||||
|
private Integer width = 600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成的模板的高度,默认为:950
|
||||||
|
*/
|
||||||
|
private Integer height = 950;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class TemplateService {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
Set<String> keys = data.keySet();
|
Set<String> keys = data.keySet();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
// 判单是否有图片生成,统一后面采用的是_2base64Type
|
// 判单是否有图片生成,统一后面采用的是_2base64Type 例子: qrCodeBase64_2base64Type_120_120
|
||||||
String[] split = key.split("_");
|
String[] split = key.split("_");
|
||||||
if (split.length > 1 && split[1].equals("2base64Type")) {
|
if (split.length > 1 && split[1].equals("2base64Type")) {
|
||||||
int width = split.length > 2 ? Integer.parseInt(split[2]) : 100;
|
int width = split.length > 2 ? Integer.parseInt(split[2]) : 100;
|
||||||
|
|
Loading…
Reference in New Issue