2025-03-12 17:12:48 +08:00
|
|
|
|
package com.dpkj.modules.autoReplyPrint.controller;
|
|
|
|
|
|
2025-03-14 16:31:53 +08:00
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dpkj.common.exception.RRException;
|
2025-03-12 17:12:48 +08:00
|
|
|
|
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.*;
|
2025-03-14 16:31:53 +08:00
|
|
|
|
import org.thymeleaf.util.StringUtils;
|
2025-03-12 17:12:48 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2025-03-14 16:31:53 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private TemplateService templateService;
|
|
|
|
|
|
2025-03-12 17:12:48 +08:00
|
|
|
|
@PostMapping("/print")
|
|
|
|
|
private Result<Void> print(@Validated @RequestBody ReceiptPrintRequest request){
|
|
|
|
|
String devName = "VID:0x0FE6,PID:0x811E"; // 采用默认的devName,不进行入参传值了
|
2025-03-14 16:31:53 +08:00
|
|
|
|
StringBuilder filePath = new StringBuilder(request.getFileDir());
|
|
|
|
|
//
|
|
|
|
|
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
|
|
|
|
if ( !StringUtils.isEmpty(request.getTemplateName()) && !StringUtils.isEmpty(request.getFileDir())){
|
|
|
|
|
String templateFillData = request.getTemplateFillData();
|
|
|
|
|
if ( !StringUtils.isEmpty(templateFillData)){
|
|
|
|
|
byte[] image = templateService.generateReceiptImage(
|
|
|
|
|
JSONObject.parseObject(request.getTemplateFillData()),
|
|
|
|
|
request.getTemplateName(),
|
|
|
|
|
request.getWidth(),
|
|
|
|
|
request.getHeight(),
|
|
|
|
|
filePath);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
throw new RRException("模板渲染错误");
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 17:12:48 +08:00
|
|
|
|
usbImagePrintService.imagePrintFromPath(devName,
|
|
|
|
|
request.getWidth(),
|
|
|
|
|
request.getHeight(),
|
2025-03-14 16:31:53 +08:00
|
|
|
|
filePath.toString(),
|
2025-03-12 17:12:48 +08:00
|
|
|
|
1,
|
|
|
|
|
0);
|
|
|
|
|
return Result.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|