|
@ -0,0 +1,527 @@
|
|
|
package com.yihu.wlyy.service.service;
|
|
|
|
|
|
import cn.com.zoe.crypto.jna.CryptoKey;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.service.common.SystemConfig;
|
|
|
import com.yihu.wlyy.service.common.http.HttpApiException;
|
|
|
import com.yihu.wlyy.service.common.util.DateUtil;
|
|
|
import com.yihu.wlyy.service.common.util.SOAPUtil;
|
|
|
import com.yihu.wlyy.service.dao.*;
|
|
|
import com.yihu.wlyy.service.entity.Patient;
|
|
|
import com.yihu.wlyy.service.entity.PatientReservation;
|
|
|
import com.yihu.wlyy.service.entity.SignFamily;
|
|
|
import com.yihu.wlyy.service.service.guahao.GuahaoDoctor;
|
|
|
import com.zoe.phip.ssp.sdk.ApiException;
|
|
|
import net.sf.json.JSON;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
import java.io.StringWriter;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by hzp on 2016/8/13.
|
|
|
* 厦门市民健康网挂号服务
|
|
|
*/
|
|
|
@Service
|
|
|
public class JMService {
|
|
|
|
|
|
private String GET_TOKEN="getToken";
|
|
|
private String FIND_MY_VACCIN="findMyVaccin";
|
|
|
private String FIND_CHILDREN = "findChildren";
|
|
|
private String FIND_DEPT="findDept";//获取接种门诊
|
|
|
|
|
|
private String redis_key ="imm:imm_token_key";
|
|
|
|
|
|
private String accId = SystemConfig.getInstance().getAccId();
|
|
|
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
|
|
|
@Autowired
|
|
|
public DoctorDao doctorDao;
|
|
|
|
|
|
@Autowired
|
|
|
private HospitalMappingDao hospitalMappingDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PatientReservationDao patientReservationDao;
|
|
|
|
|
|
@Autowired
|
|
|
SignFamilyDao signFamilyDao;
|
|
|
|
|
|
@Autowired
|
|
|
private LogService logService;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
@Value("${zyapi.openCrypto}")
|
|
|
private Boolean openCrypto;
|
|
|
|
|
|
@Value("${imm.url}")
|
|
|
private String immUrl;
|
|
|
|
|
|
@Value("${imm.credential}")
|
|
|
private String immcredential;
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************************/
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计免预约Post接口
|
|
|
*/
|
|
|
private String immPostSecond(String apistr,String content, Map<String,String> params) throws Exception
|
|
|
{
|
|
|
String re = "";
|
|
|
|
|
|
ZysoftApi api = ZysoftApi.getSingleton();
|
|
|
CryptoKey key = api.buildCryptoKey();
|
|
|
if(!params.containsKey("Credential")&&!params.containsKey("Key")) {
|
|
|
//strCredential和strKey设置
|
|
|
params.put("Credential", api.encodeParam(key,immcredential));
|
|
|
params.put("Key", key.getKey());
|
|
|
}
|
|
|
|
|
|
String msgBody = net.sf.json.JSONObject.fromObject(params).toString();
|
|
|
//System.out.print("params:"+msgBody+"\r\n");
|
|
|
//新增日志
|
|
|
String method = "POST";
|
|
|
Boolean isSuccess = true;
|
|
|
String error = "";
|
|
|
|
|
|
int times = 0;
|
|
|
try {
|
|
|
// re = api.post("jhmy/"+apistr, params, null,false);
|
|
|
re = api.post(immUrl+"/"+apistr, params, null,false);
|
|
|
|
|
|
//---结果验证,并保存日志 ---START
|
|
|
if (StringUtils.isEmpty(re)) {
|
|
|
// 请求失败
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,"接口返回的结果为空");
|
|
|
throw new Exception("接口返回的结果为空");
|
|
|
} else if (StringUtils.startsWith(re, "System-Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = re.substring(re.indexOf(":") + 1, re.length());
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
throw new Exception(error);
|
|
|
} else if (StringUtils.startsWith(re, "Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = re.substring(re.indexOf(":") + 1, re.length());
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
throw new Exception(error);
|
|
|
}
|
|
|
//---结果验证,并保存日志 ---END
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr, net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
ex.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
isSuccess = false;
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
|
|
|
if(ex instanceof ApiException)
|
|
|
{
|
|
|
ApiException apiEx = (ApiException) ex;
|
|
|
throw new HttpApiException(apiEx.errorCode(),ex.getMessage());
|
|
|
}
|
|
|
else{
|
|
|
throw new HttpApiException(-1,ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计免请求结果验证,并保存日志
|
|
|
* @param url
|
|
|
* @param content
|
|
|
* @param method
|
|
|
* @param msgBody
|
|
|
* @param res
|
|
|
*/
|
|
|
private void verificationImmResult(String result,String title,String url,String content,String method,String msgBody,String res) throws Exception{
|
|
|
String error = "";
|
|
|
Boolean isSuccess = false;
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
// 请求失败
|
|
|
//保存http日志
|
|
|
error = title;
|
|
|
logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
|
|
|
throw new Exception(error);
|
|
|
} else if (StringUtils.startsWith(result, "System-Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = result.substring(result.indexOf(":") + 1, result.length());
|
|
|
logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
|
|
|
throw new Exception(error);
|
|
|
} else if (StringUtils.startsWith(result, "Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = result.substring(result.indexOf(":") + 1, result.length());
|
|
|
logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
|
|
|
throw new Exception(error);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取免疫接种儿童信息
|
|
|
* @param credential 条形编码
|
|
|
* @return
|
|
|
*/
|
|
|
public String GetChildrenInfo(String credential)throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("etmykh", credential);
|
|
|
result = immPostSecond(FIND_CHILDREN,"计免预约-获取儿童信息成功",params);
|
|
|
|
|
|
if (StringUtils.startsWith(result, "OK")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
result = result.substring(result.indexOf(":") + 1, result.length());
|
|
|
}
|
|
|
|
|
|
com.alibaba.fastjson.JSONObject data = com.alibaba.fastjson.JSONObject.parseObject(result);
|
|
|
|
|
|
if(data.containsKey("OK")){
|
|
|
result = data.getString("OK");
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取免疫接种机构列表
|
|
|
* @return
|
|
|
*/
|
|
|
public String GetOrgImmuneList()throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
|
|
|
String condition = "<root><zone>350203</zone><zone>350206</zone><zone>350205</zone><zone>350211</zone><zone>350212</zone><zone>350213</zone></root>";
|
|
|
String[] values = SOAPUtil.getCredential(condition, true);
|
|
|
// System.out.println(condition);
|
|
|
|
|
|
ZysoftApi api = ZysoftApi.getSingleton();
|
|
|
CryptoKey key = api.buildCryptoKey();
|
|
|
params.put("Condition", api.encodeParam(key,condition));
|
|
|
params.put("Credential", api.encodeParam(key,immcredential));
|
|
|
params.put("Key", key.getKey());
|
|
|
return immPostSecond("GetOrgImmuneList","计免预约-获取免疫接种机构列表",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取免疫接种号源
|
|
|
* @param orgId 机构编码
|
|
|
* @param scheduleId 排班ID
|
|
|
* @return
|
|
|
*/
|
|
|
public String GetOrgNumberList(String orgId, String scheduleId) throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("OrgId", orgId);
|
|
|
params.put("ScheduleId", scheduleId);
|
|
|
return immPostSecond("GetOrgNumberList","计免预约-获取免疫接种号源",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取免疫接种排班信息
|
|
|
* @param orgCode 机构编码
|
|
|
* @param strStart 开始时间
|
|
|
* @param strEnd 结束时间
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String GetOrgScheduleList(String orgCode, String strStart, String strEnd) throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("OrgCode", orgCode);
|
|
|
params.put("StartTime", strStart);
|
|
|
params.put("EndTime", strEnd);
|
|
|
return immPostSecond("GetOrgScheduleList","计免预约-获取免疫接种排班信息",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据条形编码获取预约记录
|
|
|
* @param barCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String GetResImmuneListWithBarCode(String barCode) throws Exception{
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("BarCode", barCode);
|
|
|
return immPostSecond("GetResImmuneListWithBarCode","计免预约-根据条形编码获取预约记录",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取免疫接种排班信息和号源信息
|
|
|
* @param orgCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String GetOrgScheduleAndNumberList(String orgCode)throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("OrgCode", orgCode);
|
|
|
return immPostSecond("GetOrgScheduleAndNumberList","计免预约-获取免疫接种排班信息和号源信息",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*免疫接种确认预约
|
|
|
* @param barCode
|
|
|
* @param orgCode
|
|
|
* @param sectionType
|
|
|
* @param strStart
|
|
|
* @param ssid
|
|
|
* @param patientName
|
|
|
* @param patientID
|
|
|
* @param patientPhone
|
|
|
* @return
|
|
|
*/
|
|
|
public String RegisterImmune(String barCode,
|
|
|
String orgCode,
|
|
|
String sectionType,
|
|
|
String strStart,
|
|
|
String ssid,
|
|
|
String patientName,
|
|
|
String patientID,
|
|
|
String patientPhone)throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("BarCode", barCode);
|
|
|
params.put("OrgCode", orgCode);
|
|
|
params.put("SectionType", sectionType);
|
|
|
params.put("StartTime", strStart);
|
|
|
params.put("SSID", ssid);
|
|
|
params.put("PatientName", patientName);
|
|
|
params.put("PatientID", patientID);
|
|
|
params.put("PatientPhone", patientPhone);
|
|
|
result = immPostSecond("RegisterImmune","计免预约-免疫接种确认预约",params);
|
|
|
|
|
|
if (StringUtils.startsWith(result, "OK")){
|
|
|
result = "OK";
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 免疫接种取消预约
|
|
|
* @param barCode
|
|
|
* @param orgCode
|
|
|
* @param sectionType
|
|
|
* @param strStart
|
|
|
* @param ssid
|
|
|
* @param patientName
|
|
|
* @param patientID
|
|
|
* @param patientPhone
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String UnResRegisterImmune(String barCode,
|
|
|
String orgCode,
|
|
|
String sectionType,
|
|
|
String strStart,
|
|
|
String ssid,
|
|
|
String patientName,
|
|
|
String patientID,
|
|
|
String patientPhone) throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("BarCode", barCode);
|
|
|
params.put("OrgCode", orgCode);
|
|
|
params.put("SectionType", sectionType);
|
|
|
params.put("StartTime", strStart);
|
|
|
params.put("SSID", ssid);
|
|
|
params.put("PatientName", patientName);
|
|
|
params.put("PatientID", patientID);
|
|
|
params.put("PatientPhone", patientPhone);
|
|
|
result = immPostSecond("UnResRegisterImmune","计免预约-免疫接种确认预约",params);
|
|
|
|
|
|
if (StringUtils.startsWith(result, "OK")){
|
|
|
result = "OK";
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
/***************************************易联众计免接口**********************************************************/
|
|
|
/**
|
|
|
* 计免预约Post接口
|
|
|
*/
|
|
|
private String ylzImmGetSecond(String apistr,String content, Map<String,String> params) throws Exception
|
|
|
{
|
|
|
String re = "";
|
|
|
|
|
|
ZysoftApi api = ZysoftApi.getSingleton();
|
|
|
|
|
|
//新增日志
|
|
|
String method = "GET";
|
|
|
Boolean isSuccess = true;
|
|
|
String error = "";
|
|
|
|
|
|
int times = 0;
|
|
|
try {
|
|
|
re = api.get(immUrl+"/"+apistr, params, null,false);
|
|
|
|
|
|
//---结果验证,并保存日志 ---START
|
|
|
if (StringUtils.isEmpty(re)) {
|
|
|
// 请求失败
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,"接口返回的结果为空");
|
|
|
throw new Exception("接口返回的结果为空");
|
|
|
} else if (StringUtils.startsWith(re, "System-Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = re.substring(re.indexOf(":") + 1, re.length());
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
throw new Exception(error);
|
|
|
} else if (StringUtils.startsWith(re, "Error")) {
|
|
|
// 调用失败
|
|
|
//保存http日志
|
|
|
error = re.substring(re.indexOf(":") + 1, re.length());
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
throw new Exception(error);
|
|
|
}
|
|
|
//---结果验证,并保存日志 ---END
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr, net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
//保存token到reids
|
|
|
if (isSuccess && apistr.equals(GET_TOKEN)){
|
|
|
//System.out.println();
|
|
|
redisTemplate.opsForValue().set(redis_key, com.alibaba.fastjson.JSON.parseObject(re).getString("body"),4,TimeUnit.HOURS);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
ex.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
isSuccess = false;
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,apistr,content,method,apistr,net.sf.json.JSONObject.fromObject(params).toString(),re,error);
|
|
|
|
|
|
if(ex instanceof ApiException)
|
|
|
{
|
|
|
ApiException apiEx = (ApiException) ex;
|
|
|
throw new HttpApiException(apiEx.errorCode(),ex.getMessage());
|
|
|
}
|
|
|
else{
|
|
|
throw new HttpApiException(-1,ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
private String apiString = "Action";
|
|
|
|
|
|
/**
|
|
|
* 获取口令,4小时有效,465439011
|
|
|
* @return
|
|
|
*/
|
|
|
public String getToken() throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("act", GET_TOKEN);
|
|
|
params.put("accId", accId);
|
|
|
return ylzImmGetSecond("getToken","计免预约-获取口令",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取社区疫苗字典
|
|
|
* @return
|
|
|
*/
|
|
|
public String ymjsAll() throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("act", "ymjsAll");
|
|
|
params.put("accId", "q9Bt3TE00KaigEW5EJVIMA==");
|
|
|
params.put("_token", "525870222");
|
|
|
return ylzImmGetSecond(apiString,"计免预约-获取社区疫苗字典",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取计划免疫接种记录
|
|
|
* @return
|
|
|
*/
|
|
|
public String findWzymBymykh() throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("act", "findWzymBymykh");
|
|
|
params.put("accId", "q9Bt3TE00KaigEW5EJVIMA==");
|
|
|
params.put("_token", "118328844");
|
|
|
params.put("etmykh", "0052182708");
|
|
|
return ylzImmGetSecond(apiString,"计免预约-获取计划免疫接种记录",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取计划免疫接种记录
|
|
|
* @return
|
|
|
*/
|
|
|
public String findMyVaccin(String deptNum ,String etmykh) throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("act", FIND_MY_VACCIN);
|
|
|
params.put("accId", accId);
|
|
|
|
|
|
params.put("token", getTokenCheck());
|
|
|
params.put("deptNum",deptNum);
|
|
|
params.put("etmykh", etmykh);
|
|
|
//params.put("etmykh", "0052182708");
|
|
|
return ylzImmGetSecond(FIND_MY_VACCIN,"计免预约-获取计划免疫接种记录",params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取接种门诊
|
|
|
* @param etmykh
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String findDept(String etmykh) throws Exception {
|
|
|
String result = "";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("act", FIND_DEPT);
|
|
|
params.put("accId", accId);
|
|
|
params.put("token", getTokenCheck());
|
|
|
params.put("etmykh", etmykh);
|
|
|
//params.put("etmykh", "0052182708");
|
|
|
return ylzImmGetSecond(FIND_DEPT,"计免预约-获取接种门诊",params);
|
|
|
}
|
|
|
|
|
|
public String getTokenCheck() throws Exception{
|
|
|
String token = "";
|
|
|
if (!redisTemplate.hasKey(redis_key)){
|
|
|
getToken();
|
|
|
}
|
|
|
token = redisTemplate.opsForValue().get(redis_key).toString();
|
|
|
return token;
|
|
|
}
|
|
|
}
|