|
@ -10,6 +10,7 @@ import com.yihu.ehr.util.encrypt.MD5;
|
|
|
import com.yihu.ehr.util.log.LogUtil;
|
|
|
import com.yihu.ehr.util.operator.ConfigureUtil;
|
|
|
import com.yihu.ehr.util.operator.StringUtil;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.json.JSONObject;
|
|
@ -75,23 +76,39 @@ public class EsbHttp {
|
|
|
/**
|
|
|
* 应用登录验证
|
|
|
*/
|
|
|
public static String getToken() throws Exception{
|
|
|
String loginAction = HttpHelper.defaultHttpUrl + "/authorizations/clients/" + HttpHelper.clientId;
|
|
|
Map<String, Object> header = new HashMap<>();
|
|
|
header.put("Authorization", "Basic " + HttpHelper.clientKey);
|
|
|
//本地指纹
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("info", "{\"fingerprint\": \""+GetFingerprint()+"\"}");
|
|
|
public static String getToken(){
|
|
|
try {
|
|
|
String loginAction = HttpHelper.defaultHttpUrl + "/authorizations/clients/" + HttpHelper.clientId;
|
|
|
Map<String, Object> header = new HashMap<>();
|
|
|
header.put("Authorization", "Basic " + HttpHelper.clientKey);
|
|
|
//本地指纹
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("info", "{\"fingerprint\": \"" + GetFingerprint() + "\"}");
|
|
|
|
|
|
Response response = HttpHelper.put(loginAction, params, header);
|
|
|
JSONObject obj = new JSONObject(response.body);
|
|
|
//判断是否成功
|
|
|
if(obj.has("token"))
|
|
|
{
|
|
|
return obj.getString("token");
|
|
|
Response response = HttpHelper.put(loginAction, params, header);
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
JSONObject obj = new JSONObject(response.getBody());
|
|
|
//判断是否成功
|
|
|
if (obj.has("token")) {
|
|
|
return obj.getString("token");
|
|
|
} else {
|
|
|
LogUtil.info("返回未包含token。");
|
|
|
return null;
|
|
|
}
|
|
|
} else {
|
|
|
String msg = "获取Token失败。";
|
|
|
|
|
|
if (response != null) {
|
|
|
msg += "(错误代码:" + response.getStatusCode() + ",错误信息:" + response.getBody() + ")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
throw new Exception("获取token失败!");
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogUtil.info("获取Token失败," + ex.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -108,48 +125,65 @@ public class EsbHttp {
|
|
|
paramMap.put("token", token);
|
|
|
String fillMiningMethod = HttpHelper.defaultHttpUrl + "/simplified-esb/changeFillMiningStatus";
|
|
|
Response response = HttpHelper.post(fillMiningMethod, paramMap);
|
|
|
if (response == null || response.statusCode != 200) {
|
|
|
LogUtil.fatal("修改远程补传状态失败,网络错误或者服务器不可用.");
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
LogUtil.info("修改远程补传状态成功。");
|
|
|
}
|
|
|
else{
|
|
|
String msg = "修改远程补传状态失败。";
|
|
|
|
|
|
if (response != null)
|
|
|
{
|
|
|
msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogUtil.fatal("修改远程补传状态失败."+ex.getMessage());
|
|
|
LogUtil.info("修改远程补传状态失败." + ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取公钥
|
|
|
*/
|
|
|
public static String getPublicKey() throws Exception{
|
|
|
String token = getToken();
|
|
|
if (SysConfig.getInstance().getPublicKey() != null) {
|
|
|
return SysConfig.getInstance().getPublicKey();
|
|
|
}
|
|
|
String orgCode = SysConfig.getInstance().getOrgCode();
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
|
paramMap.put("org_code", orgCode);
|
|
|
paramMap.put("token", token);
|
|
|
String publicKeyMethod = HttpHelper.defaultHttpUrl + "/organizations/"+orgCode+"/key";
|
|
|
Response response = HttpHelper.get(publicKeyMethod, paramMap);
|
|
|
if (response == null || response.statusCode != 200) {
|
|
|
LogUtil.fatal("获取公钥失败.网络错误或者服务器不可用.");
|
|
|
return null;
|
|
|
}
|
|
|
public static String getPublicKey(){
|
|
|
try {
|
|
|
JSONObject json = new JSONObject(response.body);
|
|
|
if(json.has("publicKey"))
|
|
|
{
|
|
|
String key = json.getString("publicKey");
|
|
|
SysConfig.getInstance().setPublicKey(key);
|
|
|
return key;
|
|
|
String token = getToken();
|
|
|
if (SysConfig.getInstance().getPublicKey() != null) {
|
|
|
return SysConfig.getInstance().getPublicKey();
|
|
|
}
|
|
|
String orgCode = SysConfig.getInstance().getOrgCode();
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
|
paramMap.put("org_code", orgCode);
|
|
|
paramMap.put("token", token);
|
|
|
String publicKeyMethod = HttpHelper.defaultHttpUrl + "/organizations/"+orgCode+"/key";
|
|
|
Response response = HttpHelper.get(publicKeyMethod, paramMap);
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
JSONObject json = new JSONObject(response.getBody());
|
|
|
if(json.has("publicKey"))
|
|
|
{
|
|
|
String key = json.getString("publicKey");
|
|
|
SysConfig.getInstance().setPublicKey(key);
|
|
|
return key;
|
|
|
}
|
|
|
else{
|
|
|
LogUtil.info("获取公钥失败,返回未包含publicKey。");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
LogUtil.fatal("获取公钥失败");
|
|
|
String msg = "获取公钥失败。";
|
|
|
|
|
|
if (response != null)
|
|
|
{
|
|
|
msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
LogUtil.fatal(e.getMessage());
|
|
|
LogUtil.info(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@ -165,12 +199,20 @@ public class EsbHttp {
|
|
|
params.put("org_code", orgCode);
|
|
|
params.put("token", token);
|
|
|
Response response = HttpHelper.get(versionMethod, params);
|
|
|
if (response == null || response.statusCode != 200) {
|
|
|
LogUtil.fatal("获取健康云平台标准版本号失败,网络错误或者服务器不可用.");
|
|
|
return null;
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
return response.getBody();
|
|
|
}
|
|
|
else{
|
|
|
String msg = "获取健康云平台标准版本号失败";
|
|
|
|
|
|
if (response != null)
|
|
|
{
|
|
|
msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
|
|
|
return response.body;
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
LogUtil.fatal("获取远程版本号异常");
|
|
|
LogUtil.error(e);
|
|
@ -190,7 +232,7 @@ public class EsbHttp {
|
|
|
LogUtil.info("注册病人信息请求失败:病人无身份证,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
|
|
|
return false;
|
|
|
}
|
|
|
String registerMethod = HttpHelper.defaultHttpUrl + "/patient/"+idCord;
|
|
|
String registerMethod = HttpHelper.defaultHttpUrl + "/patients/"+idCord;
|
|
|
if (StringUtil.isEmpty(data)) {
|
|
|
LogUtil.info("注册病人信息请求失败:无具体病人信息,patient_id=" + patient.getPatientId() + ", event_no=" + patient.getEventNo());
|
|
|
return false;
|
|
@ -200,27 +242,19 @@ public class EsbHttp {
|
|
|
paramMap.put("json", data);
|
|
|
paramMap.put("token", token);
|
|
|
Response response = HttpHelper.post(registerMethod, paramMap);
|
|
|
if (response == null) {
|
|
|
LogUtil.info("注册病人信息请求失败:响应response为null,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
|
|
|
}
|
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
LogUtil.info("注册病人信息请求失败.错误代码:" + response.statusCode + "patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
LogUtil.info("注册病人信息成功。patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
JsonNode rootNode = mapper.readValue(response.body, JsonNode.class);
|
|
|
|
|
|
JsonNode codeNode = rootNode.get("code");
|
|
|
JsonNode messageNode = rootNode.get("message");
|
|
|
String result = codeNode.asText();
|
|
|
String message = messageNode.asText();
|
|
|
if (!result.equals("0") || "true".equals(message)) {
|
|
|
LogUtil.info("注册病人信息请求失败.失败信息:" + message + rootNode.get("message").asText() + "patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
|
|
|
else{
|
|
|
String msg = "注册病人信息请求失败。patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo();
|
|
|
if(response != null)
|
|
|
{
|
|
|
msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
return false;
|
|
|
} else {
|
|
|
LogUtil.info("注册病人信息成功,patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@ -244,25 +278,23 @@ public class EsbHttp {
|
|
|
formParams.add(new BasicNameValuePair("org_code", SysConfig.getInstance().getOrgCode()));
|
|
|
formParams.add(new BasicNameValuePair("token", token));
|
|
|
Response response = HttpHelper.postFile(uploadMethod, formParams, file.getAbsolutePath());
|
|
|
if (response == null) {
|
|
|
LogUtil.fatal("上传病人档案请求失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return false;
|
|
|
}
|
|
|
if (response.statusCode != 200) {
|
|
|
LogUtil.fatal("上传病人档案请求失败,错误代码:" + response.statusCode + ",patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
String result = response.body;
|
|
|
if (!result.equals("true")) {
|
|
|
LogUtil.fatal("上传病人档案失败,错误代码:" + result + ",patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return false;
|
|
|
} else {
|
|
|
if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
|
|
|
LogUtil.info("上传病人档案成功,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return true;
|
|
|
}
|
|
|
else {
|
|
|
String msg = "上传病人档案请求失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
if (response != null)
|
|
|
{
|
|
|
msg +="(错误代码:"+ response.getStatusCode() + ",错误信息:"+response.getBody()+")";
|
|
|
}
|
|
|
LogUtil.info(msg);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e) {
|
|
|
LogUtil.fatal("上传病人档案异常,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
LogUtil.error(e);
|
|
|
return false;
|
|
@ -276,7 +308,7 @@ public class EsbHttp {
|
|
|
public static Response download(String remoteVersion, String orgCode) {
|
|
|
try {
|
|
|
String token = getToken();
|
|
|
String downLoadMethod = HttpHelper.defaultHttpUrl + "/"+orgCode+"/source";
|
|
|
String downLoadMethod = HttpHelper.defaultHttpUrl + "/adaptions/"+orgCode+"/source";
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("version_code", remoteVersion);
|
|
|
params.put("org_code", orgCode);
|