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
echo 关闭%PROT%端口进程
echo 关闭端口进程:%PROT%
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 启动完成
::exit
pause
exit
::pause

View File

@ -19,4 +19,9 @@ public class ChsConfig {
*/
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.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.dpkj.common.vo.Result;
import com.dpkj.modules.chs.service.IHispayService;
import lombok.AllArgsConstructor;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -28,26 +31,28 @@ public class HispayController {
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 {
iHispayService.getPatientInfo("2", null);
return Result.ok("成功", null);
String type = data.getString("type");
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) {
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
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;
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);
}

View File

@ -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();
}
}

View File

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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<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)" />-->
<!-- 控制台输出 -->
@ -70,8 +70,8 @@
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
<appender-ref ref="HTML"/>
<appender-ref ref="FILE_HTML"/>
<!-- <appender-ref ref="HTML"/>-->
<!-- <appender-ref ref="FILE_HTML"/>-->
</root>
</configuration>