HIS医保

This commit is contained in:
萧道子 2025-05-22 18:36:38 +08:00
parent ad4fb627f9
commit 1707e0f4ca
8 changed files with 129 additions and 59 deletions

View File

@ -7,14 +7,17 @@ set NAME=yinyitong-dll-stand
:: 端口号 :: 端口号
set PROT=5946 set PROT=5946
echo 关闭%PROT%端口进程 echo 关闭端口进程:%PROT%
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%PROT%"') do taskkill /pid %%m -t -f for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%PROT%"') do taskkill /pid %%m -t -f
echo 启动%NAME% echo 启动%NAME%
start javaw -jar %~dp0\%NAME%.jar --server.port=%PROT% -Dfile.encoding=UTF-8 -Djava.library.path=%CHSPATH% cd %CHSPATH%
start javaw.exe -Dfile.encoding=UTF-8 -Djava.library.path=%CHSPATH% -Dlog.path=%~dp0 -jar %~dp0\%NAME%.jar --server.port=%PROT%
echo 启动完成 echo 启动完成
::exit exit
pause ::pause

View File

@ -19,4 +19,9 @@ public class ChsConfig {
*/ */
private String orgcode; private String orgcode;
/**
* 医保读卡之后保存信息的文件名
*/
private String fileName;
} }

View File

@ -4,11 +4,14 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console; import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dpkj.common.vo.Result; import com.dpkj.common.vo.Result;
import com.dpkj.modules.chs.service.IHispayService; import com.dpkj.modules.chs.service.IHispayService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -28,26 +31,28 @@ public class HispayController {
private final IHispayService iHispayService; private final IHispayService iHispayService;
@RequestMapping("getPatientInfo") /**
public Result<?> getPatientInfo() { * 通过医保卡或医保电子凭证读卡
*
* @param data : type 1.就诊卡2.医保卡5.门诊号6.患者姓名和电话号码8.电子健康码/9.医保电子凭证
* @return com.dpkj.common.vo.Result<?>
* @author 萧道子 2025/5/20
*/
@PostMapping("findReadCard")
public Result<?> findReadCard(@RequestBody JSONObject data) {
try { try {
iHispayService.getPatientInfo("2", null); String type = data.getString("type");
return Result.ok("成功", null); if (StrUtil.isEmpty(type)) {
throw new RuntimeException("参数缺失");
}
log.info("[HispayController][getPatientInfo][医保读卡] 读卡类型:{}", type);
JSONObject res = iHispayService.getPatientInfo(type, null);
return Result.ok("成功", res);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Result.error("失败"); log.error("[HispayController][getPatientInfo][医保读卡] {}", e.getMessage());
return Result.error(e.getMessage());
} }
} }
@RequestMapping("t1")
public Result<?> t1(@RequestBody JSONObject map) throws InterruptedException {
// Console.log("41 - {}\n", map);
// Thread.sleep(100);
String format = DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_MS_FORMAT);
System.out.println(format);
return Result.ok("成功", format);
}
} }

View File

@ -14,18 +14,5 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class HispayDll { public class HispayDll {
/**
* 获取 AlipayDll 实例同时注册 AlipayDll 控件
*/
public static ActiveXComponent instance() {
try {
ActiveXComponent active = new ActiveXComponent("PayClient.clsPayClient");
log.info("[HispayDll][getPrintSDK][HIS医保COM库] 加载成功");
return active;
} catch (UnsatisfiedLinkError e) {
log.error("[HispayDll][getPrintSDK][HIS医保COM库] 加载失败:{}", e.getMessage());
return null;
}
}
} }

View File

@ -1,5 +1,7 @@
package com.dpkj.modules.chs.service; package com.dpkj.modules.chs.service;
import com.alibaba.fastjson.JSONObject;
public interface IHispayService { public interface IHispayService {
/** /**
@ -10,5 +12,5 @@ public interface IHispayService {
* @return void * @return void
* @author 萧道子 2025/4/28 * @author 萧道子 2025/4/28
*/ */
void getPatientInfo(String type, String content); JSONObject getPatientInfo(String type, String content);
} }

View File

@ -1,15 +1,19 @@
package com.dpkj.modules.chs.service.impl; package com.dpkj.modules.chs.service.impl;
import cn.hutool.core.date.DateUtil; 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.lang.Console;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.XmlUtil; import cn.hutool.core.util.XmlUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dpkj.common.config.ChsConfig;
import com.dpkj.common.config.HisConfig; import com.dpkj.common.config.HisConfig;
import com.dpkj.common.utils.IDGenerator; import com.dpkj.common.utils.IDGenerator;
import com.dpkj.modules.chs.dll.HispayDll; import com.dpkj.modules.chs.dll.HispayDll;
import com.dpkj.modules.chs.service.IHispayService; import com.dpkj.modules.chs.service.IHispayService;
import com.jacob.activeX.ActiveXComponent; import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch; import com.jacob.com.Dispatch;
import com.jacob.com.Variant; import com.jacob.com.Variant;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -20,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
@ -31,26 +36,29 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Service @Service
@AllArgsConstructor
public class HispayServiceImpl implements IHispayService { public class HispayServiceImpl implements IHispayService {
@Autowired private final HisConfig hisConfig;
private HisConfig hisConfig; private final ChsConfig chsConfig;
private static ActiveXComponent dll = HispayDll.instance();
// @PostConstruct
public void postConstruct() {
log.info("[HispayServiceImpl][postConstruct][医保DLL-HIS] 初始化动态链接库");
initPrinter();
}
private void initPrinter() {
}
@Override @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(); String soleid = IDGenerator.getSnowflakeIdToStr();
JSONObject req = new JSONObject() {{ JSONObject req = new JSONObject() {{
put("timestamp", DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss")); // 请求发送时间 put("timestamp", DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss")); // 请求发送时间
@ -65,16 +73,74 @@ public class HispayServiceImpl implements IHispayService {
put("phone", ""); // 患者电话号码 put("phone", ""); // 患者电话号码
}}); }});
}}; }};
Document document = XmlUtil.mapToXml(req, "request"); Document document = XmlUtil.mapToXml(req, "request");
String reqParams = XmlUtil.toStr(document, "UTF-8", true, true); String params = XmlUtil.toStr(document, "UTF-8", false, true);
Console.log("75 - {}\n", reqParams); 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();
}
} }

View File

@ -9,6 +9,8 @@ dpkj:
chs: chs:
# 医保机构编码 # 医保机构编码
orgcode: H53082800070 orgcode: H53082800070
# 医保读卡之后保存信息的文件名
file-name: outfile1191.txt
file: file:
# 文件保存地址 # 文件保存地址
path: D:\Project\Express\upload path: D:\Project\Express\upload

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false"> <configuration debug="false">
<!--定义日志文件的存储地址 --> <!--定义日志文件的存储地址 -->
<property name="LOG_HOME" value="./logs/server"/> <property name="LOG_HOME" value="${log.path:-.}/logs"/>
<!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" />--> <!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" />-->
<!-- 控制台输出 --> <!-- 控制台输出 -->
@ -70,8 +70,8 @@
<root level="INFO"> <root level="INFO">
<appender-ref ref="STDOUT"/> <appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/> <appender-ref ref="FILE"/>
<appender-ref ref="HTML"/> <!-- <appender-ref ref="HTML"/>-->
<appender-ref ref="FILE_HTML"/> <!-- <appender-ref ref="FILE_HTML"/>-->
</root> </root>
</configuration> </configuration>