Compare commits
No commits in common. "85909ab1f8f9c230321da2e26d766b7b12d93ca8" and "e945c2cb1fcc3c84b6f24f0afea8bee9a1525505" have entirely different histories.
85909ab1f8
...
e945c2cb1f
|
@ -15,10 +15,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 挂号服务打印
|
||||
|
@ -34,14 +31,8 @@ public class RegisterServiceImpl implements PrintService {
|
|||
@Resource
|
||||
private ThirdService thirdService;
|
||||
|
||||
private static final int MAX_HEIGHT = 1000;
|
||||
private static final int FIXED_WIDTH = 690;
|
||||
|
||||
@Override
|
||||
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
if ( width > 690 || height <= 0){
|
||||
width = 690;
|
||||
}
|
||||
// 获取模板
|
||||
String templateName = ReceiptTemplateEnum.getTemplateName(template);
|
||||
|
||||
|
@ -54,72 +45,34 @@ public class RegisterServiceImpl implements PrintService {
|
|||
throw new RRException("模板渲染错误");
|
||||
}
|
||||
|
||||
String[] deletePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT) + 1];
|
||||
deletePathList[0] = filePath.toString();
|
||||
String[] filePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT)];
|
||||
// 对图片进行分块处理,当前台式打印机最大参数配置 宽度690,高度1200
|
||||
if ( height > 1200){
|
||||
try {
|
||||
// 读取输入图片
|
||||
BufferedImage originalImage = ImageIO.read(new File(filePath.toString()));
|
||||
|
||||
// 计算切割的块数
|
||||
int numPieces = (int) Math.ceil((double) height / MAX_HEIGHT);
|
||||
|
||||
// 循环切割图片并保存每一块
|
||||
for (int i = 0; i < numPieces; i++) {
|
||||
int startY = i * MAX_HEIGHT;
|
||||
int pieceHeight = Math.min(MAX_HEIGHT, height - startY);
|
||||
|
||||
// 创建一个新的 BufferedImage 对象,用于存储切割的部分
|
||||
BufferedImage piece = new BufferedImage(FIXED_WIDTH, pieceHeight, BufferedImage.TYPE_INT_RGB);
|
||||
piece.getGraphics().drawImage(originalImage, 0, 0, FIXED_WIDTH, pieceHeight, 0, startY, FIXED_WIDTH, startY + pieceHeight, null);
|
||||
|
||||
// 保存切割的图片块
|
||||
File outputFile = new File(saveDir + "/output_" + (i + 1) + ".jpg");
|
||||
filePathList[i] = "LOGO" + (i + 1) + "=" + saveDir + "/output_" + (i + 1) + ".jpg";
|
||||
deletePathList[i + 1] = saveDir + "/output_" + (i + 1) + ".jpg";
|
||||
ImageIO.write(piece, "jpg", outputFile);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
filePathList[0] = "LOGO" + filePath.toString();
|
||||
}
|
||||
|
||||
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||
lexMarkDTO.setActionName("PrintForm");
|
||||
lexMarkDTO.setCallID(19256);
|
||||
lexMarkDTO.setDevName("ReceiptPrinter");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("TimeOut", 30000);
|
||||
param.put("formName", "GWIReceiptForm_example"); // 表单名从
|
||||
param.put("mediaName", "GWIReceiptMedia_example"); // 媒介类型
|
||||
param.put("formName", "ReceiptForm"); // 表单名从
|
||||
param.put("mediaName", "Blank"); // 媒介类型
|
||||
param.put("alignment", 0); // 对齐方式
|
||||
param.put("offsetX", 0); // x
|
||||
param.put("offsetY", 0); // y
|
||||
param.put("resolution", 1); // 媒介类型,当前为:打印缓冲区 + 弹出 + 剪纸
|
||||
param.put("mediaCtrl", 8); // 1\2\4\6\8打印的清晰度
|
||||
param.put("fields", StringUtils.join(filePathList, "&"));
|
||||
param.put("resolution", 8); //
|
||||
param.put("mediaCtrl", 1);
|
||||
param.put("fields", "LOGO=" + filePath);
|
||||
lexMarkDTO.setParam(param.toJSONString());
|
||||
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
||||
|
||||
for (String path : deletePathList) {
|
||||
File file = new File(path);
|
||||
File file = new File(filePath.toString());
|
||||
// 检查文件是否存在
|
||||
if (file.exists() ) {
|
||||
// 尝试删除文件
|
||||
if (file.delete()) {
|
||||
log.info("文件删除成功: " + path);
|
||||
log.info("文件删除成功: " + filePath);
|
||||
} else {
|
||||
log.info("文件删除失败: " + path);
|
||||
log.info("文件删除失败: " + filePath);
|
||||
}
|
||||
} else {
|
||||
log.info("文件不存在: " + path);
|
||||
}
|
||||
log.info("文件不存在: " + filePath);
|
||||
}
|
||||
|
||||
// this.thirdService.close("ReceiptPrinter");
|
||||
|
|
Loading…
Reference in New Issue