Compare commits
3 Commits
9e3608772f
...
c9592dfd90
Author | SHA1 | Date |
---|---|---|
|
c9592dfd90 | |
|
85b2b1bd87 | |
|
6c126a6757 |
|
@ -2,7 +2,6 @@ package com.dpkj.common.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,4 +28,15 @@ public class PrinterConfig {
|
||||||
* 波特率 串口连接下使用
|
* 波特率 串口连接下使用
|
||||||
*/
|
*/
|
||||||
private Integer baudRate;
|
private Integer baudRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 终端号
|
||||||
|
*/
|
||||||
|
private String terminalNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间格式
|
||||||
|
*/
|
||||||
|
private String timeType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.dpkj.modules.print.service.impl;
|
package com.dpkj.modules.print.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.dpkj.common.config.PrinterConfig;
|
||||||
import com.dpkj.common.dto.LexMarkDTO;
|
import com.dpkj.common.dto.LexMarkDTO;
|
||||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||||
import com.dpkj.common.exception.RRException;
|
import com.dpkj.common.exception.RRException;
|
||||||
|
@ -19,6 +21,9 @@ import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 挂号服务打印
|
* 挂号服务打印
|
||||||
|
@ -31,20 +36,72 @@ import java.io.IOException;
|
||||||
@Service("registerService")
|
@Service("registerService")
|
||||||
public class RegisterServiceImpl implements PrintService {
|
public class RegisterServiceImpl implements PrintService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PrinterConfig printerConfig;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ThirdService thirdService;
|
private ThirdService thirdService;
|
||||||
|
|
||||||
private static final int MAX_HEIGHT = 1000;
|
private static final int MAX_HEIGHT = 1000;
|
||||||
private static final int FIXED_WIDTH = 690;
|
private static final int FIXED_WIDTH = 730;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||||
if ( width > 690 || height <= 0){
|
if ( height <= 0){
|
||||||
width = 690;
|
width = FIXED_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 强行设置终端号
|
||||||
|
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);
|
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();
|
this.getStatus();
|
||||||
StringBuilder filePath = new StringBuilder(saveDir);
|
StringBuilder filePath = new StringBuilder(saveDir);
|
||||||
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
||||||
|
@ -54,18 +111,18 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
throw new RRException("模板渲染错误");
|
throw new RRException("模板渲染错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] deletePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT) + 1];
|
// 计算切割的块数
|
||||||
|
int numPieces = (int) Math.ceil((double) height / MAX_HEIGHT);
|
||||||
|
|
||||||
|
String[] deletePathList = new String[numPieces + 1];
|
||||||
deletePathList[0] = filePath.toString();
|
deletePathList[0] = filePath.toString();
|
||||||
String[] filePathList = new String[(int) Math.ceil((double) height / MAX_HEIGHT)];
|
String[] filePathList = new String[numPieces];
|
||||||
// 对图片进行分块处理,当前台式打印机最大参数配置 宽度690,高度1200
|
// 对图片进行分块处理,当前台式打印机最大参数配置 宽度690,高度1200
|
||||||
if ( height > MAX_HEIGHT){
|
if ( height > MAX_HEIGHT){
|
||||||
try {
|
try {
|
||||||
// 读取输入图片
|
// 读取输入图片
|
||||||
BufferedImage originalImage = ImageIO.read(new File(filePath.toString()));
|
BufferedImage originalImage = ImageIO.read(new File(filePath.toString()));
|
||||||
|
|
||||||
// 计算切割的块数
|
|
||||||
int numPieces = (int) Math.ceil((double) height / MAX_HEIGHT);
|
|
||||||
|
|
||||||
// 循环切割图片并保存每一块
|
// 循环切割图片并保存每一块
|
||||||
for (int i = 0; i < numPieces; i++) {
|
for (int i = 0; i < numPieces; i++) {
|
||||||
int startY = i * MAX_HEIGHT;
|
int startY = i * MAX_HEIGHT;
|
||||||
|
@ -83,7 +140,7 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("图片分段错误");
|
log.error("模板切割失败");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
|
@ -124,7 +181,6 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.thirdService.close("ReceiptPrinter");
|
|
||||||
return paramLexMarkResultDTO;
|
return paramLexMarkResultDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,13 @@ dpkj:
|
||||||
printer:
|
printer:
|
||||||
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
||||||
connection-type: USB
|
connection-type: USB
|
||||||
|
# 终端号设置
|
||||||
|
terminal-Number: PORT-000000001
|
||||||
|
# 打印时间格式化
|
||||||
|
time-Type: yyyy-MM-dd HH:mm:ss
|
||||||
# 打印端口 串口连接下使用
|
# 打印端口 串口连接下使用
|
||||||
port-name:
|
port-name:
|
||||||
# 波特率 串口连接下使用
|
# 波特率 串口连接下使用
|
||||||
baud-rate:
|
baud-rate:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,11 @@ dpkj:
|
||||||
printer:
|
printer:
|
||||||
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
# 打印机连接方式 USB: usb连接 | BTMS:串口连接
|
||||||
connection-type: USB
|
connection-type: USB
|
||||||
|
# 终端号设置
|
||||||
|
terminal-Number: PORT-000000001
|
||||||
|
# 打印时间格式化
|
||||||
|
time-Type: yyyy-MM-dd HH:mm:ss
|
||||||
# 打印端口 串口连接下使用
|
# 打印端口 串口连接下使用
|
||||||
port-name:
|
port-name:
|
||||||
# 波特率 串口连接下使用
|
# 波特率 串口连接下使用
|
||||||
baud-rate:
|
baud-rate:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue