fix:修复ms439打印机逻辑
This commit is contained in:
parent
620bf524db
commit
4fbe38b04a
5
pom.xml
5
pom.xml
|
@ -100,6 +100,11 @@
|
||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.zxing</groupId>
|
||||||
|
<artifactId>javase</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- JSoup HTML Parser -->
|
<!-- JSoup HTML Parser -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -5,8 +5,11 @@ import com.dpkj.common.exception.RRException;
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.EncodeHintType;
|
import com.google.zxing.EncodeHintType;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
import com.google.zxing.oned.Code128Writer;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
||||||
|
@ -91,9 +94,9 @@ public class TemplateUtils {
|
||||||
|
|
||||||
// 保存图片
|
// 保存图片
|
||||||
if (saveDir != null && !"".equals(saveDir.toString())) {
|
if (saveDir != null && !"".equals(saveDir.toString())) {
|
||||||
String outputPath = saveDir.toString() + "\\genera_image_" + System.currentTimeMillis() + ".png";
|
String outputPath = saveDir.toString() + "/genera_image_" + System.currentTimeMillis() + ".png";
|
||||||
ImageIO.write(image, "PNG", new File(outputPath));
|
ImageIO.write(image, "PNG", new File(outputPath));
|
||||||
saveDir.reverse();
|
saveDir.delete(0, saveDir.length());
|
||||||
saveDir.append(outputPath);
|
saveDir.append(outputPath);
|
||||||
}
|
}
|
||||||
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
|
||||||
|
@ -141,10 +144,11 @@ public class TemplateUtils {
|
||||||
// 判单是否有图片生成,统一后面采用的是_2base64Type
|
// 判单是否有图片生成,统一后面采用的是_2base64Type
|
||||||
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 type = split.length > 2 ? Integer.parseInt(split[2]) : 1;
|
||||||
int height = split.length > 3 ? Integer.parseInt(split[3]) : 100;
|
int width = split.length > 2 ? Integer.parseInt(split[3]) : 100;
|
||||||
|
int height = split.length > 3 ? Integer.parseInt(split[4]) : 100;
|
||||||
// 如果是图片类型,需要进行base64转换
|
// 如果是图片类型,需要进行base64转换
|
||||||
String base64 = this.generateQRCode(String.valueOf(data.get(key)), width, height);
|
String base64 = this.generateQRCode(type, String.valueOf(data.get(key)), width, height);
|
||||||
context.setVariable(split[0], "data:image/jpeg;base64," + base64);
|
context.setVariable(split[0], "data:image/jpeg;base64," + base64);
|
||||||
} else {
|
} else {
|
||||||
// 普通字段直接设置
|
// 普通字段直接设置
|
||||||
|
@ -161,18 +165,31 @@ public class TemplateUtils {
|
||||||
* 根据内容生成二维码
|
* 根据内容生成二维码
|
||||||
* @param content 转换内容
|
* @param content 转换内容
|
||||||
*/
|
*/
|
||||||
private String generateQRCode(String content, int width, int height) {
|
private String generateQRCode(int type, String content, int width, int height) {
|
||||||
try {
|
try {
|
||||||
|
BufferedImage qrImage = null;
|
||||||
|
BitMatrix bitMatrix = null;
|
||||||
|
if (type == 1) {
|
||||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 设置字符编码为 UTF-8
|
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 设置字符编码为 UTF-8
|
||||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); // 设置纠错级别
|
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); // 设置纠错级别
|
||||||
|
|
||||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||||
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
|
bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
|
||||||
|
|
||||||
|
qrImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
|
}else if (type == 2) {
|
||||||
|
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||||
|
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||||
|
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
|
||||||
|
|
||||||
|
Code128Writer barcodeWriter = new Code128Writer();
|
||||||
|
bitMatrix = barcodeWriter.encode(content, BarcodeFormat.CODE_128, width, height, hints);
|
||||||
|
|
||||||
|
qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
BufferedImage qrImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
|
||||||
qrImage.createGraphics();
|
qrImage.createGraphics();
|
||||||
|
|
||||||
Graphics2D graphics = (Graphics2D) qrImage.getGraphics();
|
Graphics2D graphics = (Graphics2D) qrImage.getGraphics();
|
||||||
graphics.setColor(Color.WHITE);
|
graphics.setColor(Color.WHITE);
|
||||||
graphics.fillRect(0, 0, width, height);
|
graphics.fillRect(0, 0, width, height);
|
||||||
|
@ -190,8 +207,8 @@ public class TemplateUtils {
|
||||||
ImageIO.write(qrImage, "png", baos);
|
ImageIO.write(qrImage, "png", baos);
|
||||||
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("二维码生成失败");
|
log.error("二维码/条形码生成失败", e);
|
||||||
throw new RRException("二维码生成失败");
|
throw new RRException("二维码/条形码生成失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class RegisterController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/print")
|
@PostMapping("/print")
|
||||||
public Result<LexMarkResultDTO> registerByFilePath(@RequestBody @Validated ReceiptPrintRequest request){
|
public Result<LexMarkResultDTO> registerByFilePath(@RequestBody @Validated ReceiptPrintRequest request){
|
||||||
// String testData = "{\"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_1_250_250\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
String testData = "{\"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_1_250_250\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
||||||
// String testData = "{\"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_2_500_160\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
// String testData = "{\"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_2_500_160\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
||||||
return Result.ok((LexMarkResultDTO)printService.printImage(JSONObject.parseObject(request.getTemplateFillData()), request.getTemplateName(), request.getWidth(), request.getHeight(), request.getFileDir()));
|
return Result.ok((LexMarkResultDTO)printService.printImage(JSONObject.parseObject(testData), request.getTemplateName(), request.getWidth(), request.getHeight(), request.getFileDir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,12 +48,12 @@ public class ReceiptPrintRequest implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 小票渲染宽度,默认为:600
|
* 小票渲染宽度,默认为:600
|
||||||
*/
|
*/
|
||||||
private Integer width = 730;
|
private Integer width = 600;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成的模板的高度,默认为:950
|
* 生成的模板的高度,默认为:950
|
||||||
*/
|
*/
|
||||||
private Integer height = 1350;
|
private Integer height = 950;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
|
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
|
|
||||||
|
|
||||||
// printType 选择箱子
|
// printType 选择箱子
|
||||||
// param.put("prtData", String.format("PrintType=%d;pagesource=%s;copies=%d;file[0]=%s;stamp=%d;duplex=%d;color=%d;direction=%d",
|
// param.put("prtData", String.format("PrintType=%d;pagesource=%s;copies=%d;file[0]=%s;stamp=%d;duplex=%d;color=%d;direction=%d",
|
||||||
// request.getPagesource(), request.getCopies(), request.getFileDir(), request.getStamp(),
|
// request.getPagesource(), request.getCopies(), request.getFileDir(), request.getStamp(),
|
||||||
|
|
Loading…
Reference in New Issue