fix:优化打印机逻辑
This commit is contained in:
@@ -16,6 +16,8 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,10 +36,17 @@ public class ThirdService {
|
||||
@Value("${app.custom.lexMarkServicePort}")
|
||||
private String lexMarkServicePort;
|
||||
|
||||
private static final Map<String, String> devNameMap = new HashMap<>();
|
||||
static {
|
||||
devNameMap.put("HtmPrinter", "激光打印机");
|
||||
devNameMap.put("ReceiptPrinter", "凭条打印机");
|
||||
}
|
||||
|
||||
/**
|
||||
* 利盟台式机-立体机 接口请求
|
||||
*
|
||||
* @param lexMarkDTO 请求DTO
|
||||
* @param clazz 返回类型
|
||||
* @return result
|
||||
*/
|
||||
public <T> LexMarkResultDTO<T> callDevice(LexMarkDTO lexMarkDTO, Class<T> clazz) {
|
||||
@@ -110,5 +119,87 @@ public class ThirdService {
|
||||
return callDevice(lexMarkDTO, JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开设备连接或者 链接+初始化
|
||||
* @param devName 设备名称
|
||||
* @param resterType 初始化类型,如果不设置,那么就不会进行初始化
|
||||
*/
|
||||
public void open(String devName, Integer resterType) {
|
||||
// 优先自动连接对应的设备
|
||||
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||
lexMarkDTO.setActionName("OpenConnection");
|
||||
lexMarkDTO.setCallID(19283);
|
||||
lexMarkDTO.setDevName(devName);
|
||||
lexMarkDTO.setPluginMethod("exec");
|
||||
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);
|
||||
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||
if (data != null) {
|
||||
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||
throw new RRException("设备: " + devNameMap.get(devName) + " 打开失败!");
|
||||
}
|
||||
}
|
||||
|
||||
// 打开后直接进行重置
|
||||
if ( resterType != null && data != null) {
|
||||
lexMarkDTO.setActionName("Reset");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("", String.format("{\"ResetAction\":%d,\"binNumber\":0}", resterType));
|
||||
lexMarkDTO.setParam(jsonObject.toString());
|
||||
LexMarkResultDTO<JSONObject> resultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||
JSONObject data1 = resultDTO.getData();
|
||||
if (data1 != null) {
|
||||
if (!String.valueOf(data1.get("result")).equals("0")) {
|
||||
throw new RRException("设备: " + devNameMap.get(devName) + " _ " + resterType + " 初始化失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭设备练级
|
||||
* @param devName 设备名称
|
||||
*/
|
||||
public void close(String devName) {
|
||||
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||
lexMarkDTO.setActionName("CloseConnection");
|
||||
lexMarkDTO.setCallID(19283);
|
||||
lexMarkDTO.setDevName(devName);
|
||||
lexMarkDTO.setPluginMethod("exec");
|
||||
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||
if (data != null) {
|
||||
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||
throw new RRException("设备: " + devNameMap.get(devName) + " 关闭失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切纸,但是目前凭条和ms439打印机都是可以自动切纸的
|
||||
* @param devName 设备名称
|
||||
* @param actionName action名称,实际的动作函数名称
|
||||
* @param 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();
|
||||
param.put("", String.format("{\"mediaCtrol\":%d}", mediaType));
|
||||
lexMarkDTO.setParam(param.toString());
|
||||
|
||||
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||
if (data != null) {
|
||||
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||
throw new RRException("设备: " + devNameMap.get(devName) + " 切纸失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user