激光打印机调用修改
This commit is contained in:
parent
4d888fb8a3
commit
28aa307f8b
3
pom.xml
3
pom.xml
|
@ -94,7 +94,7 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
<version>2.0.57</version>
|
||||
</dependency>
|
||||
|
||||
<!-- thymeleaf-->
|
||||
|
@ -179,7 +179,6 @@
|
|||
<artifactId>itext-asian</artifactId>
|
||||
<version>5.2.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package com.dpkj.common.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -16,10 +14,9 @@ import java.io.Serializable;
|
|||
* @since 2025-02-08 11:03:06
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LexMarkResultDTO <T> implements Serializable {
|
||||
@Accessors(chain = true)
|
||||
public class LexMarkResultDTO<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -35,12 +32,12 @@ public class LexMarkResultDTO <T> implements Serializable {
|
|||
/**
|
||||
* 对应发送请求的callID。
|
||||
*/
|
||||
private int callID;
|
||||
private Integer callID;
|
||||
|
||||
/**
|
||||
* 错误码:0表示成功;其他表示失败,比如-4表示取消,-48表示超时,-14表示硬件故障
|
||||
*/
|
||||
private int result;
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 发送请求中的actionName
|
||||
|
@ -63,53 +60,5 @@ public class LexMarkResultDTO <T> implements Serializable {
|
|||
*/
|
||||
private T data;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class Param {
|
||||
|
||||
/**
|
||||
* 请求ID
|
||||
*/
|
||||
private int RequestID;
|
||||
|
||||
/**
|
||||
* 命令编码
|
||||
*/
|
||||
private int dwCommandCode;
|
||||
|
||||
/**
|
||||
* 事件名,由发送请求中的actionName+Over组成。
|
||||
*/
|
||||
private String eventName;
|
||||
|
||||
/**
|
||||
* 事件类型编码
|
||||
*/
|
||||
private int eventType;
|
||||
|
||||
/**
|
||||
* 服务
|
||||
*/
|
||||
private int hService;
|
||||
|
||||
/**
|
||||
* 对应发送请求中的devName
|
||||
*/
|
||||
private String cmdName;
|
||||
|
||||
/**
|
||||
* 错误码:0表示成功;其他表示失败,比如-4表示取消,-48表示超时,-14表示硬件故障
|
||||
*/
|
||||
private int result;
|
||||
|
||||
/**
|
||||
* 详情描述
|
||||
*/
|
||||
private String desc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.dpkj.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.dto.LexMarkDTO;
|
||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||
|
@ -8,14 +9,7 @@ import com.dpkj.common.exception.RRException;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -37,68 +31,48 @@ public class ThirdService {
|
|||
private String lexMarkServicePort;
|
||||
|
||||
private static final Map<String, String> devNameMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
devNameMap.put("HtmPrinter", "激光打印机");
|
||||
devNameMap.put("ReceiptPrinter", "凭条打印机");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 利盟台式机-立体机 接口请求
|
||||
*
|
||||
* @param lexMarkDTO 请求DTO
|
||||
* @param clazz 返回类型
|
||||
* @param clazz 返回类型
|
||||
* @return result
|
||||
*/
|
||||
public <T> LexMarkResultDTO<T> callDevice(LexMarkDTO lexMarkDTO, Class<T> clazz) {
|
||||
try {
|
||||
URL url = new URL(lexMarkServiceIp + ":" + lexMarkServicePort + "/CallDevice");
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
String urlStr = lexMarkServiceIp + ":" + lexMarkServicePort + "/CallDevice";
|
||||
log.info("[ThirdService][callDevice][激光打印机打印] 利盟打印接口-url:{}", urlStr);
|
||||
|
||||
// 将LexMarkDTO对象转换为JSON字符串
|
||||
String jsonInputString = JSON.toJSONString(lexMarkDTO);
|
||||
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
|
||||
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
|
||||
wr.write(input, 0, input.length);
|
||||
log.info(jsonInputString);
|
||||
}
|
||||
String params = JSONObject.toJSONString(lexMarkDTO);
|
||||
log.info("[ThirdService][callDevice][激光打印机打印] 利盟打印接口-入参:{}", params);
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
log.error("利盟服务请求失败,响应码:{},请求参数:{}", responseCode, lexMarkDTO);
|
||||
throw new RRException("利盟服务请求失败,响应码:" + responseCode);
|
||||
}
|
||||
String bodyStr = HttpRequest.post(urlStr)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(params)
|
||||
.timeout(30000)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("[ThirdService][callDevice][激光打印机打印] 利盟打印接口-响应:{}", bodyStr);
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
JSONObject bodyJson = (JSONObject) JSONObject.parse(bodyStr);
|
||||
if (StrUtil.isEmpty(bodyJson.getString("param"))) {
|
||||
throw new RRException("利盟服务请求失败,结果响应为空");
|
||||
}
|
||||
in.close();
|
||||
|
||||
// 将响应JSON字符串转换为LexMarkResultDTO对象
|
||||
LexMarkResultDTO<T> lexMarkResultDTO = JSON.parseObject(response.toString(), LexMarkResultDTO.class);
|
||||
// if (lexMarkResultDTO.getResult() != 0) {
|
||||
// log.error("利盟服务请求出错:{}", lexMarkResultDTO);
|
||||
// throw new RRException(lexMarkResultDTO.toString());
|
||||
// }
|
||||
LexMarkResultDTO obj = JSONObject.toJavaObject(bodyJson, LexMarkResultDTO.class);
|
||||
|
||||
// 实例化param位data
|
||||
String param = lexMarkResultDTO.getParam();
|
||||
if (!StringUtils.isEmpty(param)) {
|
||||
try {
|
||||
T t = JSON.parseObject(param, clazz);
|
||||
lexMarkResultDTO.setData(t);
|
||||
}catch (Exception e){
|
||||
log.error("类型转换失败");
|
||||
throw new RRException("转换param位data时,类型与实际类型不匹配");
|
||||
}
|
||||
}
|
||||
T paramObj = JSONObject.toJavaObject(bodyJson.getJSONObject("param"), clazz);
|
||||
obj.setData(paramObj);
|
||||
|
||||
return lexMarkResultDTO;
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
log.error("利盟服务请求失败:{}", lexMarkDTO, e);
|
||||
if (e instanceof RRException) {
|
||||
|
@ -121,7 +95,8 @@ public class ThirdService {
|
|||
|
||||
/**
|
||||
* 打开设备连接或者 链接+初始化
|
||||
* @param devName 设备名称
|
||||
*
|
||||
* @param devName 设备名称
|
||||
* @param resterType 初始化类型,如果不设置,那么就不会进行初始化
|
||||
*/
|
||||
public void open(String devName, Integer resterType) {
|
||||
|
@ -131,7 +106,7 @@ public class ThirdService {
|
|||
lexMarkDTO.setCallID(19283);
|
||||
lexMarkDTO.setDevName(devName);
|
||||
lexMarkDTO.setPluginMethod("exec");
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("", String.format("{\"ServiceName\":\"%s\",\"TimeOut\":90000}", devName));
|
||||
lexMarkDTO.setParam(param.toString());
|
||||
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||
|
@ -143,7 +118,7 @@ public class ThirdService {
|
|||
}
|
||||
|
||||
// 打开后直接进行重置
|
||||
if ( resterType != null && data != null) {
|
||||
if (resterType != null && data != null) {
|
||||
lexMarkDTO.setActionName("Reset");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("", String.format("{\"ResetAction\":%d,\"binNumber\":0}", resterType));
|
||||
|
@ -160,6 +135,7 @@ public class ThirdService {
|
|||
|
||||
/**
|
||||
* 关闭设备练级
|
||||
*
|
||||
* @param devName 设备名称
|
||||
*/
|
||||
public void close(String devName) {
|
||||
|
@ -179,17 +155,18 @@ public class ThirdService {
|
|||
|
||||
/**
|
||||
* 切纸,但是目前凭条和ms439打印机都是可以自动切纸的
|
||||
* @param devName 设备名称
|
||||
*
|
||||
* @param devName 设备名称
|
||||
* @param actionName action名称,实际的动作函数名称
|
||||
* @param mediaType 媒介类型
|
||||
* @param mediaType 媒介类型
|
||||
*/
|
||||
public void cutPaper(String devName, String actionName, Integer mediaType){
|
||||
public void cutPaper(String devName, String actionName, Integer mediaType) {
|
||||
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||
lexMarkDTO.setActionName(actionName);
|
||||
lexMarkDTO.setCallID(19283);
|
||||
lexMarkDTO.setDevName(devName);
|
||||
lexMarkDTO.setPluginMethod("exec");
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("", String.format("{\"mediaCtrol\":%d}", mediaType));
|
||||
lexMarkDTO.setParam(param.toString());
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.dpkj.modules.print.service.MS439PrintService;
|
|||
import com.dpkj.modules.print.utils.FolderUtils;
|
||||
import com.dpkj.modules.print.utils.FontLoader;
|
||||
import com.dpkj.modules.print.utils.PDFUtils;
|
||||
import com.dpkj.modules.print.vo.PrinterParam;
|
||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||
import com.itextpdf.text.BaseColor;
|
||||
import com.itextpdf.text.Document;
|
||||
|
@ -110,6 +111,7 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
// 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.getDuplex(), request.getColor(), request.getDirection()));
|
||||
|
||||
// 计算A4/A5归属
|
||||
int printType = 1; // 默认使用第一层
|
||||
if (printerConfig.getLevelOne().equals("A5")) {
|
||||
|
@ -121,7 +123,7 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
printType = 2;
|
||||
}
|
||||
}
|
||||
param.put("prtData", String.format("PaperNum=%d;PrintType=%d;Stamp=%d;File[0]=%s;WaitNum=%d;copies=%d;stamp=%d;duplex=%d;color=%d;direction=%d",
|
||||
/*param.put("prtData", String.format("PaperNum=%d;PrintType=%d;Stamp=%d;File[0]=%s;WaitNum=%d;copies=%d;stamp=%d;duplex=%d;color=%d;direction=%d",
|
||||
request.getCopies(), // 盖章事件分数,和打印份数一致
|
||||
printType, // 打印类型1-A4或者2-A5
|
||||
request.getStamp(), // 是否盖章
|
||||
|
@ -131,10 +133,19 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
request.getStamp(), // 是否盖章 0-不盖章 1-盖章
|
||||
request.getDuplex(), // 单面还是双面打印 1-单面 2-双面
|
||||
request.getColor(), // 打印的颜色0-黑色,1-彩色
|
||||
request.getDirection()));
|
||||
request.getDirection()));*/
|
||||
|
||||
String prtData = StrUtil.format("PaperNum={};PrintType={};Stamp={};File[0]={};WaitNum={}",
|
||||
request.getCopies(), // 盖章事件分数,和打印份数一致
|
||||
printType, // 打印类型1-A4或者2-A5
|
||||
request.getStamp(), // 是否盖章
|
||||
request.getFileDir(), // 要打印的文件的路径
|
||||
request.getCopies() // 盖章事件分数,和打印份数一致
|
||||
);
|
||||
param.put("prtData", prtData);
|
||||
|
||||
lexMarkDTO.setParam(param.toString());
|
||||
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
||||
LexMarkResultDTO<PrinterParam> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, PrinterParam.class);
|
||||
|
||||
if (paramLexMarkResultDTO.getData().getResult() != 0) {
|
||||
throw new RRException(500, paramLexMarkResultDTO.getData().getResult() + "");
|
||||
|
@ -163,9 +174,12 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
lexMarkDTO.setDevName("HtmPrinter");
|
||||
lexMarkDTO.setPluginMethod("exec");
|
||||
|
||||
// 获取状态
|
||||
LexMarkResultDTO<PrinterStatus> status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
|
||||
if (status.getResult() != 0) {
|
||||
// 打开打印机
|
||||
thirdService.open("HtmPrinter", 0);
|
||||
// 打印
|
||||
status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
|
||||
}
|
||||
|
||||
|
@ -363,9 +377,9 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
item.put("loitemRv", range);// 参考区间
|
||||
item.put("loitemUnit", unit);// 单位
|
||||
item.put("inspectionMethod", method);// 测试方法
|
||||
item.put("oaflag", StrUtil.equals(oaflag,"0") || StrUtil.equals(oaflag,"1"));// 结果异常标志|-1-不计算改指标的参考、1-正常、2-偏低、3-偏高、4-阳性(异常)、5-警戒下限、6-警戒上限、7-复查下限、8-复查上限、9-线性异常
|
||||
item.put("oaflagLow", StrUtil.equals(oaflag,"2"));// 2显示下箭头
|
||||
item.put("oaflagHigh", StrUtil.equals(oaflag,"3"));// 3显示上箭头
|
||||
item.put("oaflag", StrUtil.equals(oaflag, "0") || StrUtil.equals(oaflag, "1"));// 结果异常标志|-1-不计算改指标的参考、1-正常、2-偏低、3-偏高、4-阳性(异常)、5-警戒下限、6-警戒上限、7-复查下限、8-复查上限、9-线性异常
|
||||
item.put("oaflagLow", StrUtil.equals(oaflag, "2"));// 2显示下箭头
|
||||
item.put("oaflagHigh", StrUtil.equals(oaflag, "3"));// 3显示上箭头
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,15 @@ import com.dpkj.common.dto.LexMarkResultDTO;
|
|||
import com.dpkj.common.exception.RRException;
|
||||
import com.dpkj.common.utils.TemplateUtils;
|
||||
import com.dpkj.common.utils.ThirdService;
|
||||
import com.dpkj.modules.print.enums.*;
|
||||
import com.dpkj.modules.print.enums.MS439DeviceStatusEnum;
|
||||
import com.dpkj.modules.print.enums.MS439InkStatusEnum;
|
||||
import com.dpkj.modules.print.enums.MS439MediaStatusEnum;
|
||||
import com.dpkj.modules.print.enums.MS439PaperStatusEnum;
|
||||
import com.dpkj.modules.print.enums.MS439TonerStatusEnum;
|
||||
import com.dpkj.modules.print.enums.ReceiptTemplateEnum;
|
||||
import com.dpkj.modules.print.service.PrintService;
|
||||
import com.dpkj.modules.print.utils.FolderUtils;
|
||||
import com.dpkj.modules.print.vo.PrinterParam;
|
||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -47,7 +53,7 @@ public class RegisterServiceImpl implements PrintService {
|
|||
private static final int FIXED_WIDTH = 730;
|
||||
|
||||
@Override
|
||||
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
public LexMarkResultDTO<PrinterParam> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
FolderUtils.checkFolderAndCreate(saveDir);
|
||||
|
||||
if (height <= 0) {
|
||||
|
@ -172,7 +178,7 @@ public class RegisterServiceImpl implements PrintService {
|
|||
param.put("mediaCtrl", 1); // 媒介类型,当前为:打印缓冲区 + 弹出 + 剪纸
|
||||
param.put("fields", StringUtils.join(filePathList, "&"));
|
||||
lexMarkDTO.setParam(param.toJSONString());
|
||||
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
||||
LexMarkResultDTO<PrinterParam> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, PrinterParam.class);
|
||||
|
||||
for (String path : deletePathList) {
|
||||
if (path != null && !path.isEmpty()) {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.dpkj.modules.print.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 利盟接口返回值DTO
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-02-08 11:03:06
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PrinterParam implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 请求ID
|
||||
*/
|
||||
private Integer RequestID;
|
||||
|
||||
/**
|
||||
* 命令编码
|
||||
*/
|
||||
private Integer dwCommandCode;
|
||||
|
||||
/**
|
||||
* 事件名,由发送请求中的actionName+Over组成。
|
||||
*/
|
||||
private String eventName;
|
||||
|
||||
/**
|
||||
* 事件类型编码
|
||||
*/
|
||||
private Integer eventType;
|
||||
|
||||
/**
|
||||
* 服务
|
||||
*/
|
||||
private Integer hService;
|
||||
|
||||
/**
|
||||
* 对应发送请求中的devName
|
||||
*/
|
||||
private String cmdName;
|
||||
|
||||
/**
|
||||
* 错误码:0表示成功;其他表示失败,比如-4表示取消,-48表示超时,-14表示硬件故障
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 详情描述
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,15 @@
|
|||
package com.dpkj.modules.print.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PrinterStatus {
|
||||
@Accessors(chain = true)
|
||||
public class PrinterStatus implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* sp服务版本号
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue