feat:增加com、TCP打印服务

This commit is contained in:
石崇礼 2025-01-20 14:58:42 +08:00
parent 2986fa0c14
commit d9da4ea307
3 changed files with 119 additions and 1 deletions

View File

@ -18,7 +18,7 @@ public abstract class BaseImagePrint {
/** /**
* 必须要实现这个获取句柄 * 必须要实现这个获取句柄
* @param devName 设备名称 * @param devName 设备名称/串口名称
* @return 窗口句柄 * @return 窗口句柄
*/ */
public abstract Pointer getHandle(String devName); public abstract Pointer getHandle(String devName);

View File

@ -0,0 +1,55 @@
package com.dpkj.modules.autoReplyPrint.service.impl;
import com.dpkj.common.exception.RRException;
import com.dpkj.modules.autoReplyPrint.base.BaseImagePrint;
import com.dpkj.modules.autoReplyPrint.service.ImagePrintService;
import com.dpkj.modules.autoReplyPrint.utils.AutoReplyPrint;
import com.sun.jna.Pointer;
import org.springframework.web.multipart.MultipartFile;
/**
* 串口图片打印
*
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
* @version 1.0
* @since 2025-01-20 14:55:37
*/
public class COMImagePrintServiceImpl extends BaseImagePrint implements ImagePrintService {
@Override
public Pointer getHandle(String devName) {
try {
Pointer pointer = AutoReplyPrint.INSTANCE.CP_Port_OpenLpt(devName);
if ( pointer == null ){
throw new RRException();
}
return pointer;
}catch (Exception e){
e.printStackTrace();
throw new RRException("获取COM串口句柄失败");
}
}
@Override
public void imagePrintFromPath(String devName, int dstw, int dsth, String pszFile, int binaryzation_method, int compression_method) {
super.printFromPath(devName, dstw, dsth, pszFile, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromPathData(String devName, int dstw, int dsth, String pszFile, int binaryzation_method, int compression_method) {
super.printFromPathData(devName, dstw, dsth, pszFile, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromData(String devName, int dstw, int dsth, byte[] data, int binaryzation_method, int compression_method) {
super.printFromData(devName, dstw, dsth, data, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromMultipartFile(String devName, int dstw, int dsth, MultipartFile file, int binaryzation_method, int compression_method) {
super.printFromMultipartFile(devName, dstw, dsth, file, binaryzation_method, compression_method);
}
}

View File

@ -0,0 +1,63 @@
package com.dpkj.modules.autoReplyPrint.service.impl;
import com.dpkj.common.exception.RRException;
import com.dpkj.modules.autoReplyPrint.base.BaseImagePrint;
import com.dpkj.modules.autoReplyPrint.service.ImagePrintService;
import com.dpkj.modules.autoReplyPrint.utils.AutoReplyPrint;
import com.sun.jna.Pointer;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* tcp类型句柄的图片打印
*
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
* @version 1.0
* @since 2025-01-20 14:46:06
*/
@Data
@Service("TCPImagePrint")
@Slf4j
public class TCPImagePrintServiceImpl extends BaseImagePrint implements ImagePrintService {
private String destIP; // 目标ip
private Short destPort; // 目标端口
@Override
public Pointer getHandle(String devName) {
try {
Pointer pointer = AutoReplyPrint.INSTANCE.CP_Port_OpenTcp("0", destIP, destPort, 300000, 1);
if ( pointer == null ){
throw new RRException();
}
return pointer;
}catch (Exception e){
e.printStackTrace();
throw new RRException("获取TCP句柄失败");
}
}
@Override
public void imagePrintFromPath(String devName, int dstw, int dsth, String pszFile, int binaryzation_method, int compression_method) {
super.printFromPath(devName, dstw, dsth, pszFile, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromPathData(String devName, int dstw, int dsth, String pszFile, int binaryzation_method, int compression_method) {
super.printFromPathData(devName, dstw, dsth, pszFile, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromData(String devName, int dstw, int dsth, byte[] data, int binaryzation_method, int compression_method) {
super.printFromData(devName, dstw, dsth, data, binaryzation_method, compression_method);
}
@Override
public void imagePrintFromMultipartFile(String devName, int dstw, int dsth, MultipartFile file, int binaryzation_method, int compression_method) {
super.printFromMultipartFile(devName, dstw, dsth, file, binaryzation_method, compression_method);
}
}