增加金域外送
parent
532cfec2dd
commit
47e87687f4
@ -0,0 +1,19 @@
|
||||
package com.ann.demo.entity.interfaceEntity;
|
||||
|
||||
|
||||
public class Patient
|
||||
{
|
||||
private String patientid;
|
||||
|
||||
public void setPatientid(String patientid){
|
||||
this.patientid = patientid;
|
||||
}
|
||||
public String getPatientid(){
|
||||
return this.patientid;
|
||||
}
|
||||
|
||||
public Patient(String patientid) {
|
||||
this.patientid = patientid;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
package com.ann.demo.entity.interfaceEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Root
|
||||
{
|
||||
private String collectorid;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String assortid;
|
||||
|
||||
private Patient patient;
|
||||
|
||||
private List<Scanfiles> scanfiles;
|
||||
|
||||
private String scanusercode;
|
||||
|
||||
private String scanusername;
|
||||
|
||||
public Root(Scanfiles scanfiles,String masterId) {
|
||||
List<Scanfiles> list = new ArrayList<>();
|
||||
list.add(scanfiles);
|
||||
this.collectorid = "10";
|
||||
this.ip = "127.0.0.1";
|
||||
this.assortid = "10";
|
||||
this.patient = new Patient(masterId);
|
||||
this.scanfiles = list;
|
||||
this.scanusercode = "zwh";
|
||||
this.scanusername = "zwh";
|
||||
}
|
||||
|
||||
public void setCollectorid(String collectorid){
|
||||
this.collectorid = collectorid;
|
||||
}
|
||||
public String getCollectorid(){
|
||||
return this.collectorid;
|
||||
}
|
||||
public void setIp(String ip){
|
||||
this.ip = ip;
|
||||
}
|
||||
public String getIp(){
|
||||
return this.ip;
|
||||
}
|
||||
public void setAssortid(String assortid){
|
||||
this.assortid = assortid;
|
||||
}
|
||||
public String getAssortid(){
|
||||
return this.assortid;
|
||||
}
|
||||
public void setPatient(Patient patient){
|
||||
this.patient = patient;
|
||||
}
|
||||
public Patient getPatient(){
|
||||
return this.patient;
|
||||
}
|
||||
public void setScanfiles(List<Scanfiles> scanfiles){
|
||||
this.scanfiles = scanfiles;
|
||||
}
|
||||
public List<Scanfiles> getScanfiles(){
|
||||
return this.scanfiles;
|
||||
}
|
||||
public void setScanusercode(String scanusercode){
|
||||
this.scanusercode = scanusercode;
|
||||
}
|
||||
public String getScanusercode(){
|
||||
return this.scanusercode;
|
||||
}
|
||||
public void setScanusername(String scanusername){
|
||||
this.scanusername = scanusername;
|
||||
}
|
||||
public String getScanusername(){
|
||||
return this.scanusername;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.ann.demo.entity.interfaceEntity;
|
||||
|
||||
public class Scanfiles
|
||||
{
|
||||
private int taskid;
|
||||
|
||||
private String filetitle;
|
||||
|
||||
private int filesource;
|
||||
|
||||
private int filestoragetype;
|
||||
|
||||
private int filetype;
|
||||
|
||||
private String downurl;
|
||||
|
||||
private String serialnum;
|
||||
|
||||
public Scanfiles(String filetitle,String downurl, String serialnum) {
|
||||
this.taskid = -1;
|
||||
this.filetitle = filetitle;
|
||||
this.filesource = 1;
|
||||
this.filestoragetype = 1;
|
||||
this.filetype = 2;
|
||||
this.downurl = downurl;
|
||||
this.serialnum = serialnum;
|
||||
}
|
||||
|
||||
public void setTaskid(int taskid){
|
||||
this.taskid = taskid;
|
||||
}
|
||||
public int getTaskid(){
|
||||
return this.taskid;
|
||||
}
|
||||
public void setFiletitle(String filetitle){
|
||||
this.filetitle = filetitle;
|
||||
}
|
||||
public String getFiletitle(){
|
||||
return this.filetitle;
|
||||
}
|
||||
public void setFilesource(int filesource){
|
||||
this.filesource = filesource;
|
||||
}
|
||||
public int getFilesource(){
|
||||
return this.filesource;
|
||||
}
|
||||
public void setFilestoragetype(int filestoragetype){
|
||||
this.filestoragetype = filestoragetype;
|
||||
}
|
||||
public int getFilestoragetype(){
|
||||
return this.filestoragetype;
|
||||
}
|
||||
public void setFiletype(int filetype){
|
||||
this.filetype = filetype;
|
||||
}
|
||||
public int getFiletype(){
|
||||
return this.filetype;
|
||||
}
|
||||
public void setDownurl(String downurl){
|
||||
this.downurl = downurl;
|
||||
}
|
||||
public String getDownurl(){
|
||||
return this.downurl;
|
||||
}
|
||||
public void setSerialnum(String serialnum){
|
||||
this.serialnum = serialnum;
|
||||
}
|
||||
public String getSerialnum(){
|
||||
return this.serialnum;
|
||||
}
|
||||
}
|
@ -0,0 +1,268 @@
|
||||
package com.ann.demo.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ann.demo.utils.HttpClientUtils;
|
||||
import com.ann.demo.utils.JsonUtils;
|
||||
import com.ann.demo.utils.Md5Utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.axis.client.Call;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.rpc.ParameterMode;
|
||||
import javax.xml.rpc.ServiceException;
|
||||
import javax.xml.rpc.encoding.XMLType;
|
||||
|
||||
import org.apache.axis.client.Service;
|
||||
import org.apache.axis.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 曾文和
|
||||
* @description: 外送报告采集类
|
||||
* @createTime 2023/9/5 16:48
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CollectCheckService {
|
||||
private Map<String,String> tokenCacheMap = new HashMap<>();
|
||||
|
||||
private String FILENAME = "fileName";
|
||||
private String FILEBASE64 = "fileBase64";
|
||||
@Value("${siteCode}")
|
||||
private String siteCode;
|
||||
@Value("${customerCode}")
|
||||
private String customerCode;
|
||||
@Value("${collectionLocation}")
|
||||
private String collectionLocation;
|
||||
@Value("${loginUrl}")
|
||||
private String loginUrl;
|
||||
@Value("${namespaceURI}")
|
||||
private String namespaceURI;
|
||||
@Value("${webServiceMethod}")
|
||||
private String webServiceMethod;
|
||||
@Value("${webServiceDownMethod}")
|
||||
private String webServiceDownMethod;
|
||||
@Value("${downfileUrl}")
|
||||
private String downfileUrl;
|
||||
|
||||
public boolean downFileWithCheck(String masterId,String hospBarcode,String reportOdd,String fileUrl) {
|
||||
//登录
|
||||
String token = getTokenByCheckKey(siteCode, customerCode, collectionLocation);
|
||||
//下载
|
||||
return downFileWithCheck(masterId,hospBarcode,reportOdd,fileUrl,token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param masterId
|
||||
* @param hospBarcode
|
||||
* @param reportOdd
|
||||
* @param fileUrl
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private boolean downFileWithCheck(String masterId,String hospBarcode,String reportOdd,String fileUrl,String token){
|
||||
//根据参数请求接口返回json数据
|
||||
String result = reqInterfaceByParam(hospBarcode, reportOdd, fileUrl, token);
|
||||
//解析返回json数据
|
||||
Map<String,String> map = analysisData(result);
|
||||
//唯一文件码
|
||||
String serialnum = hospBarcode + "_" + reportOdd;
|
||||
//根据解析的数据调用下载
|
||||
String reqResult = downFile(masterId,map,serialnum);
|
||||
if(!StringUtils.isEmpty(reqResult)) {
|
||||
String code = JsonUtils.getValueByKey(reqResult, "code");
|
||||
if(!StringUtils.isEmpty(code) && "0".equals(code)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据解析的数据调用下载
|
||||
* @param map
|
||||
*/
|
||||
private String downFile(String masterId,Map<String, String> map,String serialnum) {
|
||||
if(!CollectionUtils.isEmpty(map)){
|
||||
//设置下载参数
|
||||
Map rootMap = setDownReqParams(masterId, map, serialnum);
|
||||
//调用下载接口
|
||||
String result = HttpClientUtils.doPost(downfileUrl,JSON.toJSONString(rootMap));
|
||||
log.info("上传下载服务result:"+result);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载请求参数
|
||||
* @param masterId
|
||||
* @param map
|
||||
* @param serialnum
|
||||
* @return
|
||||
*/
|
||||
private Map setDownReqParams(String masterId, Map<String, String> map, String serialnum) {
|
||||
//设置文件信息参数
|
||||
Map<String,Object> scanfilesMap = new HashMap<>();
|
||||
scanfilesMap.put("taskid",-1);
|
||||
scanfilesMap.put("filetitle", map.get(FILENAME));
|
||||
scanfilesMap.put("filesource",1);
|
||||
scanfilesMap.put("filestoragetype",1);
|
||||
scanfilesMap.put("filetype",2);
|
||||
scanfilesMap.put("downurl", map.get(FILEBASE64));
|
||||
scanfilesMap.put("serialnum", serialnum +"1");
|
||||
List<Map<String,Object>> scanfilesList = new ArrayList<>();
|
||||
scanfilesList.add(scanfilesMap);
|
||||
//设置患者信息参数
|
||||
Map<String,Object> patientMap = new HashMap<>();
|
||||
patientMap.put("patientid", masterId);
|
||||
//设置全部参数
|
||||
Map rootMap = new HashMap<>();
|
||||
rootMap.put("collectorid","10");
|
||||
rootMap.put("ip","127.0.0.1");
|
||||
rootMap.put("assortid","10");
|
||||
rootMap.put("patient",patientMap);
|
||||
rootMap.put("scanfiles",scanfilesList);
|
||||
rootMap.put("scanusercode","zwh");
|
||||
rootMap.put("scanusername","zwh");
|
||||
return rootMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析返回json数据
|
||||
* @param result
|
||||
*/
|
||||
private Map<String,String> analysisData(String result) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
if(!StringUtils.isEmpty(result)) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
//解析
|
||||
try {
|
||||
// 将JSON字符串转换为Map对象
|
||||
JsonNode jsonNode = objectMapper.readTree(result);
|
||||
String fileName = jsonNode.get("result").get("fileName").asText();
|
||||
if (!StringUtils.isEmpty(fileName)) {
|
||||
fileName = fileName.substring(0, fileName.length() - 4);
|
||||
}
|
||||
map.put(FILENAME,fileName);
|
||||
String fileBase64 = jsonNode.get("result").get("file").asText();
|
||||
map.put(FILEBASE64,fileBase64);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数请求接口
|
||||
* @param hospBarcode
|
||||
* @param reportOdd
|
||||
* @param fileUrl
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private String reqInterfaceByParam(String hospBarcode, String reportOdd, String fileUrl, String token) {
|
||||
Map<String,String> paramMap = new HashMap<>();
|
||||
paramMap.put("siteCode",siteCode);
|
||||
paramMap.put("customerCode",customerCode);
|
||||
paramMap.put("collectionLocation",collectionLocation);
|
||||
paramMap.put("hospBarcode", hospBarcode);
|
||||
paramMap.put("reportOdd", reportOdd);
|
||||
paramMap.put("fileUrl", fileUrl);
|
||||
String paramStr = JSON.toJSONString(paramMap);
|
||||
String jsonMd5 = Md5Utils.strToMd5(paramStr);
|
||||
//调用webService
|
||||
Object[] objects = {jsonMd5, token, paramStr};
|
||||
String[] params ={"md5","token","postJson"};
|
||||
String result = null;
|
||||
try {
|
||||
result = getWebService(loginUrl,namespaceURI,webServiceDownMethod,params,objects);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("调用接口失败:"+objects.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param siteCode
|
||||
* @param customerCode
|
||||
* @param collectionLocation
|
||||
* @return
|
||||
*/
|
||||
private String getTokenByCheckKey(String siteCode,String customerCode,String collectionLocation){
|
||||
//组织协定秘钥secretKey
|
||||
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
|
||||
String toDay = fmt.format(new Date());
|
||||
//判断token是否存在
|
||||
String token = tokenCacheMap.get(toDay);
|
||||
if(!StringUtils.isEmpty(token)){
|
||||
//取缓存
|
||||
return token;
|
||||
}
|
||||
String secretKey = collectionLocation + customerCode + siteCode + toDay;
|
||||
//MD5转换
|
||||
String secretKeyMd5 = Md5Utils.strToMd5(secretKey);
|
||||
//调用第三方webService接口登录
|
||||
//实例化org.apache.axis.client.Service对象
|
||||
//创建service调用对象
|
||||
Object[] objects = {siteCode, customerCode, collectionLocation, secretKeyMd5};
|
||||
String[] params ={"siteCode","customerCode","collectionLocation","secretKey"};
|
||||
String result = getWebService(loginUrl,namespaceURI,webServiceMethod,params,objects);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
//解析
|
||||
try {
|
||||
// 将JSON字符串转换为Map对象
|
||||
JsonNode jsonNode = objectMapper.readTree(result);
|
||||
token = jsonNode.get("result").get("token").asText();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!StringUtils.isEmpty(token)) {
|
||||
//存缓存
|
||||
tokenCacheMap.clear();
|
||||
tokenCacheMap.put(toDay, token);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用webService
|
||||
* @return
|
||||
*/
|
||||
private String getWebService(String webServiceUrl,String namespaceURI,String webServiceMethod,String[] params,Object[] objects ){
|
||||
try {
|
||||
Service service = new Service();
|
||||
Call call;
|
||||
call=(Call) service.createCall();
|
||||
QName opAddEntry = new QName(namespaceURI, webServiceMethod); //设置命名空间和需要调用的方法名
|
||||
call.setTargetEndpointAddress(webServiceUrl); //设置请求路径
|
||||
call.setOperationName(webServiceMethod); //调用的方法名
|
||||
call.setTimeout(Integer.valueOf(2000)); //设置请求超时
|
||||
//按顺序设置请求参数、请求类型,多个需多添加参数
|
||||
for(String param : params){
|
||||
call.addParameter(param, XMLType.XSD_STRING, ParameterMode.IN);
|
||||
}
|
||||
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
|
||||
return (String) call.invoke(opAddEntry,objects);
|
||||
} catch (ServiceException e) {
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.ann.demo.service;
|
||||
|
||||
import org.apache.cxf.Bus;
|
||||
import org.apache.cxf.bus.CXFBusFactory;
|
||||
import org.apache.cxf.endpoint.EndpointImplFactory;
|
||||
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
|
||||
import org.apache.cxf.jaxws.support.JaxWsEndpointImplFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class JAXDynamicClientFactory extends DynamicClientFactory {
|
||||
protected JAXDynamicClientFactory(Bus bus) {
|
||||
super(bus);
|
||||
}
|
||||
|
||||
protected EndpointImplFactory getEndpointImplFactory() {
|
||||
return JaxWsEndpointImplFactory.getSingleton();
|
||||
}
|
||||
|
||||
protected boolean allowWrapperOps() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JAXDynamicClientFactory newInstance(Bus b) {
|
||||
return new JAXDynamicClientFactory(b);
|
||||
}
|
||||
|
||||
public static JAXDynamicClientFactory newInstance() {
|
||||
Bus bus = CXFBusFactory.getThreadDefaultBus();
|
||||
return new JAXDynamicClientFactory(bus);
|
||||
}
|
||||
public boolean compileJavaSrc(String classPath, List srcList, String dest) {
|
||||
org.apache.cxf.common.util.Compiler javaCompiler
|
||||
= new org.apache.cxf.common.util.Compiler();
|
||||
javaCompiler.setEncoding("UTF-8");
|
||||
javaCompiler.setClassPath(classPath);
|
||||
javaCompiler.setOutputDir(dest);
|
||||
javaCompiler.setTarget("1.8");
|
||||
return javaCompiler.compileFiles(srcList);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ann.demo.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonUtils {
|
||||
public static String getValueByKey(String jsonString, String key) {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(jsonString);
|
||||
|
||||
JsonNode valueNode = jsonNode.get(key);
|
||||
if (valueNode != null) {
|
||||
return valueNode.asText();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String jsonString = "{\"name\":\"John\",\"age\":30}";
|
||||
|
||||
String name = getValueByKey(jsonString, "name");
|
||||
int age = Integer.parseInt(getValueByKey(jsonString, "age"));
|
||||
|
||||
System.out.println("Name: " + name);
|
||||
System.out.println("Age: " + age);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.ann.demo.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @author 曾文和
|
||||
* @description: XXX类
|
||||
* @createTime 2023/9/5 16:57
|
||||
*/
|
||||
public class Md5Utils {
|
||||
|
||||
public static String strToMd5(String str) {
|
||||
String hexString = null;
|
||||
try {
|
||||
// 创建MD5消息摘要对象
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
||||
// 计算消息的摘要
|
||||
byte[] digest = md.digest(str.getBytes());
|
||||
|
||||
// 将摘要转换为十六进制字符串
|
||||
hexString = bytesToHex(digest);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return hexString;
|
||||
}
|
||||
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue