HIS医保
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.dpkj.modules.chs.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public interface IHispayService {
|
||||
|
||||
/**
|
||||
@@ -10,5 +12,5 @@ public interface IHispayService {
|
||||
* @return void
|
||||
* @author 萧道子 2025/4/28
|
||||
*/
|
||||
void getPatientInfo(String type, String content);
|
||||
JSONObject getPatientInfo(String type, String content);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package com.dpkj.modules.chs.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileReader;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.config.ChsConfig;
|
||||
import com.dpkj.common.config.HisConfig;
|
||||
import com.dpkj.common.utils.IDGenerator;
|
||||
import com.dpkj.modules.chs.dll.HispayDll;
|
||||
import com.dpkj.modules.chs.service.IHispayService;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -20,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -31,26 +36,29 @@ import java.util.Map;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class HispayServiceImpl implements IHispayService {
|
||||
|
||||
@Autowired
|
||||
private HisConfig hisConfig;
|
||||
|
||||
private static ActiveXComponent dll = HispayDll.instance();
|
||||
|
||||
// @PostConstruct
|
||||
public void postConstruct() {
|
||||
log.info("[HispayServiceImpl][postConstruct][医保DLL-HIS] 初始化动态链接库");
|
||||
initPrinter();
|
||||
}
|
||||
|
||||
|
||||
private void initPrinter() {
|
||||
}
|
||||
private final HisConfig hisConfig;
|
||||
private final ChsConfig chsConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public void getPatientInfo(String type, String content) {
|
||||
public JSONObject getPatientInfo(String type, String content) {
|
||||
Dispatch dispatch = instanceActive();
|
||||
|
||||
/**
|
||||
* 1、删除保存HIS读卡内容的文件 避免读取到错误信息
|
||||
*/
|
||||
// 获取HIS-CHS医保库路径
|
||||
String chsPath = System.getProperty("java.library.path");
|
||||
String filePath = chsPath + "/" + chsConfig.getFileName();
|
||||
// 删除文件
|
||||
FileUtil.del(FileUtil.file(filePath));
|
||||
|
||||
/**
|
||||
* 2、组装参数
|
||||
*/
|
||||
String soleid = IDGenerator.getSnowflakeIdToStr();
|
||||
JSONObject req = new JSONObject() {{
|
||||
put("timestamp", DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss")); // 请求发送时间
|
||||
@@ -65,16 +73,74 @@ public class HispayServiceImpl implements IHispayService {
|
||||
put("phone", ""); // 患者电话号码
|
||||
}});
|
||||
}};
|
||||
|
||||
Document document = XmlUtil.mapToXml(req, "request");
|
||||
String reqParams = XmlUtil.toStr(document, "UTF-8", true, true);
|
||||
Console.log("75 - {}\n", reqParams);
|
||||
String params = XmlUtil.toStr(document, "UTF-8", false, true);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 接口入参:{}", params);
|
||||
|
||||
String rest = "";
|
||||
/**
|
||||
* 3、调用COM函数
|
||||
*/
|
||||
Variant rest = new Variant();
|
||||
Variant call = Dispatch.call(dispatch, "fRun", "BMZXX010", params, rest);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] call返回值:{}", call);
|
||||
|
||||
Variant call = Dispatch.call(dll.getObject(), "fRun", "BMZXX010", reqParams, rest);
|
||||
// 释放资源
|
||||
releaseActive();
|
||||
|
||||
Console.log("82 - {}\n", call);
|
||||
/**
|
||||
* 4、处理读卡结果
|
||||
*/
|
||||
// COM函数调用之后会生成新的文件 需要判断
|
||||
File file = FileUtil.file(filePath);
|
||||
if (!file.exists()) {
|
||||
throw new RuntimeException("读卡失败:数据未读取");
|
||||
}
|
||||
|
||||
// 获取读卡结果
|
||||
FileReader fileReader = new FileReader(file, "GBK");
|
||||
String data = fileReader.readString();
|
||||
|
||||
JSONObject result;
|
||||
try {
|
||||
result = JSONObject.parseObject(data);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 读卡值:{}", result);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("读卡失败:" + data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取HIS医保实例
|
||||
*
|
||||
* @return com.jacob.activeX.ActiveXComponent
|
||||
* @author 萧道子 2025/5/21
|
||||
*/
|
||||
private Dispatch instanceActive() {
|
||||
try {
|
||||
// 初始化
|
||||
ComThread.InitSTA();
|
||||
// 获取COM对象
|
||||
ActiveXComponent active = new ActiveXComponent("PayClient.clsPayClient");
|
||||
log.info("[HispayServiceImpl][instanceActive][HIS医保COM库] 加载成功");
|
||||
return active;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
log.info("[HispayServiceImpl][instanceActive][HIS医保COM库] 加载失败:{}", e.getMessage());
|
||||
throw new RuntimeException("HIS医保COM库加载失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*
|
||||
* @return void
|
||||
* @author 萧道子 2025/5/21
|
||||
*/
|
||||
private void releaseActive() {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user