身份证读取、社保卡读取
This commit is contained in:
19
src/main/java/com/dpkj/common/constant/LexMarkConst.java
Normal file
19
src/main/java/com/dpkj/common/constant/LexMarkConst.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.dpkj.common.constant;
|
||||
|
||||
/**
|
||||
* 利盟台式机 设备调用逻辑名
|
||||
*/
|
||||
public interface LexMarkConst {
|
||||
/**
|
||||
* 身份证读取
|
||||
*/
|
||||
String ID_CARD_READ = "RFIDCardReader";
|
||||
/**
|
||||
* 社保卡读取
|
||||
*/
|
||||
String CARD_READER = "CardReader";
|
||||
/**
|
||||
* 打印机
|
||||
*/
|
||||
String RECEIPT_PRINTER = "ReceiptPrinter";
|
||||
}
|
||||
58
src/main/java/com/dpkj/common/dto/LexMarkResultVO.java
Normal file
58
src/main/java/com/dpkj/common/dto/LexMarkResultVO.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.dpkj.common.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
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
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LexMarkResultVO<T> implements Serializable {
|
||||
/**
|
||||
* 对应发送请求中的devName
|
||||
*/
|
||||
private String devName;
|
||||
|
||||
/**
|
||||
* 事件名,由发送请求中的actionName+Over组成。
|
||||
*/
|
||||
private String msgName;
|
||||
|
||||
/**
|
||||
* 对应发送请求的callID。
|
||||
*/
|
||||
private int callID;
|
||||
|
||||
/**
|
||||
* 错误码:0表示成功;其他表示失败,比如-4表示取消,-48表示超时,-14表示硬件故障
|
||||
*/
|
||||
private int result;
|
||||
|
||||
/**
|
||||
* 发送请求中的actionName
|
||||
*/
|
||||
private String cmdName;
|
||||
|
||||
/**
|
||||
* 返回参数
|
||||
*/
|
||||
private T param;
|
||||
|
||||
/**
|
||||
* 详情描述
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
}
|
||||
|
||||
80
src/main/java/com/dpkj/common/utils/ThirdServiceUtil.java
Normal file
80
src/main/java/com/dpkj/common/utils/ThirdServiceUtil.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.dpkj.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.dpkj.common.dto.LexMarkDTO;
|
||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||
import com.dpkj.common.dto.LexMarkResultVO;
|
||||
import com.dpkj.common.exception.RRException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 第三方服务,主要是调用打印机等
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-02-08 10:45:01
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ThirdServiceUtil {
|
||||
|
||||
@Value("${app.custom.lexMarkServiceIp}")
|
||||
private String lexMarkServiceIp;
|
||||
@Value("${app.custom.lexMarkServicePort}")
|
||||
private String lexMarkServicePort;
|
||||
|
||||
/**
|
||||
* 利盟台式机-立体机 接口请求
|
||||
* @param lexMarkDTO 请求DTO
|
||||
* @return result
|
||||
*/
|
||||
public <T> T callDevice(LexMarkDTO lexMarkDTO, Class<T> responseType) {
|
||||
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");
|
||||
// 将 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);
|
||||
}
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
throw new RRException("利盟服务请求失败,响应码:" + responseCode);
|
||||
}
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
// 将响应 JSON 字符串转换为泛型对象
|
||||
T result = JSON.parseObject(response.toString(), responseType);
|
||||
if (result instanceof LexMarkResultVO && ((LexMarkResultVO) result).getResult() != 0) {
|
||||
throw new RRException(result.toString());
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
if (e instanceof RRException) {
|
||||
throw new RRException(((RRException) e).getCode(), e.getMessage());
|
||||
}
|
||||
throw new RRException("利盟服务请求失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user