Compare commits
No commits in common. "c9592dfd90c97cec7b29b83fff17c46675aa644e" and "9e3608772f4182af07af20bc08f8bdc426009ab4" have entirely different histories.
c9592dfd90
...
9e3608772f
|
@ -2,6 +2,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -28,15 +29,4 @@ public class PrinterConfig {
|
|||
* 波特率 串口连接下使用
|
||||
*/
|
||||
private Integer baudRate;
|
||||
|
||||
/**
|
||||
* 终端号
|
||||
*/
|
||||
private String terminalNumber;
|
||||
|
||||
/**
|
||||
* 时间格式
|
||||
*/
|
||||
private String timeType;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.dpkj.modules.print.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.config.PrinterConfig;
|
||||
import com.dpkj.common.dto.LexMarkDTO;
|
||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||
import com.dpkj.common.exception.RRException;
|
||||
|
@ -21,9 +19,6 @@ import javax.imageio.ImageIO;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 挂号服务打印
|
||||
|
@ -36,72 +31,20 @@ import java.util.Date;
|
|||
@Service("registerService")
|
||||
public class RegisterServiceImpl implements PrintService {
|
||||
|
||||
@Resource
|
||||
private PrinterConfig printerConfig;
|
||||
|
||||
@Resource
|
||||
private ThirdService thirdService;
|
||||
|
||||
private static final int MAX_HEIGHT = 1000;
|
||||
private static final int FIXED_WIDTH = 730;
|
||||
private static final int FIXED_WIDTH = 690;
|
||||
|
||||
@Override
|
||||
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
if ( height <= 0){
|
||||
width = FIXED_WIDTH;
|
||||
if ( width > 690 || height <= 0){
|
||||
width = 690;
|
||||
}
|
||||
|
||||
// 强行设置终端号
|
||||
data.put("terminalNumber", printerConfig.getTerminalNumber());
|
||||
|
||||
// 强行设置终端号和打印时间
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(printerConfig.getTimeType());
|
||||
String formattedDate = sdf.format( new Date());
|
||||
data.put("printTime", formattedDate);
|
||||
|
||||
// 获取模板
|
||||
String templateName = ReceiptTemplateEnum.getTemplateName(template);
|
||||
|
||||
int dinyHeight = 0;
|
||||
if (templateName.equals("department")) {
|
||||
// 由于是使用的门诊小票-T2,那么默认的高度为1000,强行设置,通过动态修改渲染的图片的高度
|
||||
height = 1000;
|
||||
|
||||
// 单行最大长度为10
|
||||
int singleLineMaxLength = 10;
|
||||
// 这里的长度取自于department.html模板中的项目单个tr高度,并且略高于该高度
|
||||
int singleLineHeight = 40;
|
||||
// 动态计算长度
|
||||
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 += 35;
|
||||
}
|
||||
|
||||
// 计算是否有就诊医生
|
||||
String doctor = data.getString("doctor");
|
||||
if ( !StringUtils.isEmpty(doctor)){
|
||||
dinyHeight += 35;
|
||||
}
|
||||
|
||||
// 计算是否有就诊科室
|
||||
String department = data.getString("department");
|
||||
if ( !StringUtils.isEmpty(department)){
|
||||
dinyHeight += 35;
|
||||
}
|
||||
|
||||
}
|
||||
height += dinyHeight;
|
||||
|
||||
this.getStatus();
|
||||
StringBuilder filePath = new StringBuilder(saveDir);
|
||||
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
||||
|
@ -111,18 +54,18 @@ public class RegisterServiceImpl implements PrintService {
|
|||
throw new RRException("模板渲染错误");
|
||||
}
|
||||
|
||||
// 计算切割的块数
|
||||
int numPieces = (int) Math.ceil((double) height / MAX_HEIGHT);
|
||||
|
||||
String[] deletePathList = new String[numPieces + 1];
|
||||
String[] deletePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT) + 1];
|
||||
deletePathList[0] = filePath.toString();
|
||||
String[] filePathList = new String[numPieces];
|
||||
String[] filePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT)];
|
||||
// 对图片进行分块处理,当前台式打印机最大参数配置 宽度690,高度1200
|
||||
if ( height > MAX_HEIGHT){
|
||||
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;
|
||||
|
@ -140,7 +83,7 @@ public class RegisterServiceImpl implements PrintService {
|
|||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("模板切割失败");
|
||||
log.error("图片分段错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
|
@ -181,6 +124,7 @@ public class RegisterServiceImpl implements PrintService {
|
|||
}
|
||||
}
|
||||
|
||||
// this.thirdService.close("ReceiptPrinter");
|
||||
return paramLexMarkResultDTO;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,13 +10,8 @@ dpkj:
|
|||
printer:
|
||||
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
||||
connection-type: USB
|
||||
# 终端号设置
|
||||
terminal-Number: PORT-000000001
|
||||
# 打印时间格式化
|
||||
time-Type: yyyy-MM-dd HH:mm:ss
|
||||
# 打印端口 串口连接下使用
|
||||
port-name:
|
||||
# 波特率 串口连接下使用
|
||||
baud-rate:
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,8 @@ dpkj:
|
|||
printer:
|
||||
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
||||
connection-type: USB
|
||||
# 终端号设置
|
||||
terminal-Number: PORT-000000001
|
||||
# 打印时间格式化
|
||||
time-Type: yyyy-MM-dd HH:mm:ss
|
||||
# 打印端口 串口连接下使用
|
||||
port-name:
|
||||
# 波特率 串口连接下使用
|
||||
baud-rate:
|
||||
|
||||
|
|
Loading…
Reference in New Issue