|
@ -0,0 +1,196 @@
|
|
|
package com.yihu.wlyy.service.app.ehc;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.ylz.EHCConfigura;
|
|
|
import com.yihu.wlyy.entity.ylz.EHCLog;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.ylz.EHCConfiguraDao;
|
|
|
import com.yihu.wlyy.repository.ylz.EHCLogDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.ylzinfo.ehc.EhcHandler;
|
|
|
import com.ylzinfo.ehc.trans.TransRequest;
|
|
|
import com.ylzinfo.ehc.utils.DateUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by Reece on 2017/10/25/025.
|
|
|
* 居民电子健康卡业务处理
|
|
|
*/
|
|
|
@Service
|
|
|
public class PatientEHCService extends BaseService {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(PatientEHCService.class);
|
|
|
|
|
|
@Value("${wechat.accId}")
|
|
|
private String accId;
|
|
|
@Autowired
|
|
|
private EHCConfiguraDao ehcConfiguraDao;
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private EHCLogDao ehcLogDao;
|
|
|
|
|
|
public String EHCRedirecturl(String getUid) throws Exception {
|
|
|
String result = null;
|
|
|
try {
|
|
|
String format = "yyyyMMddHHmmss";
|
|
|
String currentTime = DateUtils.getOutTradeTime();
|
|
|
String uuid = DateUtil.getUidNo(4);
|
|
|
|
|
|
EHCConfigura config = ehcConfiguraDao.findWorkConfigura();
|
|
|
String api = config.getEhcApi();
|
|
|
String appId = config.getAppId();
|
|
|
String termId = config.getTermId();
|
|
|
String appKey = config.getAppKey();
|
|
|
String signType = config.getSignType();
|
|
|
String encType = config.getEncType();
|
|
|
String version = config.getVersion();
|
|
|
String redirecturl = config.getEhcRedirecturl();
|
|
|
|
|
|
Patient patient = patientDao.findByCode(getUid);
|
|
|
String openId = patient.getOpenid();
|
|
|
String idcard = patient.getIdcard();
|
|
|
String name = patient.getName();
|
|
|
Integer sex = patient.getSex();//1男,2女
|
|
|
if (StringUtils.isEmpty(openId)) {
|
|
|
return "-1";
|
|
|
}
|
|
|
if (StringUtils.isEmpty(idcard)) {
|
|
|
return "-1";
|
|
|
}
|
|
|
if (StringUtils.isEmpty(name)) {
|
|
|
return "-1";
|
|
|
}
|
|
|
if (sex == null) {
|
|
|
return "-1";
|
|
|
}
|
|
|
|
|
|
Date birthday = patient.getBirthday();
|
|
|
String mobile = patient.getMobile();
|
|
|
String phone = patient.getPhone();
|
|
|
String provinceName = patient.getProvinceName();
|
|
|
String cityName = patient.getCityName();
|
|
|
String townName = patient.getTownName();
|
|
|
String streetName = patient.getStreetName();
|
|
|
String address = patient.getAddress();
|
|
|
|
|
|
|
|
|
JSONObject bizContent = new JSONObject();
|
|
|
bizContent.put("open_id", openId);
|
|
|
bizContent.put("account_id", accId);
|
|
|
bizContent.put("out_trade_no", uuid);
|
|
|
bizContent.put("out_trade_time", currentTime);
|
|
|
bizContent.put("id_type", "01");
|
|
|
bizContent.put("id_no", idcard);
|
|
|
bizContent.put("user_name", name);
|
|
|
bizContent.put("user_sex", "" + sex);
|
|
|
|
|
|
bizContent.put("birthday", DateUtil.dateToStr(birthday, format));
|
|
|
bizContent.put("mobile_phone", mobile);
|
|
|
bizContent.put("telephone", phone);
|
|
|
bizContent.put("address", address);
|
|
|
bizContent.put("work_unit", provinceName + cityName + townName + streetName);
|
|
|
|
|
|
result = httpUtils(getUid, api, appId, termId, appKey, signType, encType, version, redirecturl, bizContent);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* http发送请求工具类
|
|
|
*
|
|
|
* @param api 网关地址
|
|
|
* @param appId
|
|
|
* @param termId
|
|
|
* @param appKey
|
|
|
* @param signType
|
|
|
* @param encType
|
|
|
* @param version
|
|
|
* @param url 接口路径
|
|
|
*/
|
|
|
public String httpUtils(String patient, String api, String appId, String termId, String appKey, String signType, String encType, String version, String url, JSONObject bizContent) throws Exception {
|
|
|
String params = null;
|
|
|
String encParams = null;
|
|
|
String response = null;
|
|
|
String error = null;
|
|
|
try {
|
|
|
TransRequest request = new TransRequest();
|
|
|
request.setMethod(url);
|
|
|
request.setApp_id(appId);
|
|
|
request.setTerm_id(termId);
|
|
|
request.setVersion(version);
|
|
|
request.setTimestamp(DateUtils.getOutTradeTime());
|
|
|
request.setSign_type(signType);
|
|
|
request.setEnc_type(encType);
|
|
|
request.setBiz_content(JSONObject.toJSONString(bizContent));
|
|
|
params = JSONObject.toJSONString(request);
|
|
|
EhcHandler ehcHandler = new EhcHandler(api, appId, termId, appKey);
|
|
|
String result = ehcHandler.buildGet(request);
|
|
|
System.out.println(result);
|
|
|
encParams = JSONObject.toJSONString(request);
|
|
|
response = result;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
error = e.getMessage();
|
|
|
}
|
|
|
//保存日志
|
|
|
getLog(patient, url, params, response, error);
|
|
|
logger.info("**************** EHC LOG START **********************");
|
|
|
logger.info("EHC API " + url);
|
|
|
logger.info("EHC PARAMS " + encParams);
|
|
|
logger.info("EHC RESPONSE " + response);
|
|
|
logger.info("EHC ERROR " + error);
|
|
|
logger.info("**************** EHC LOG END **********************");
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public void getLog(String patient, String api, String params, String response, String error) throws Exception {
|
|
|
try {
|
|
|
String type = null;
|
|
|
String content = null;
|
|
|
String method = null;
|
|
|
EHCLog ehcLog = ehcLogDao.findByPatient(patient);
|
|
|
if (ehcLog == null) {
|
|
|
ehcLog = new EHCLog();
|
|
|
}
|
|
|
|
|
|
switch (api) {
|
|
|
case "ehc.ehealthcode.redirecturl":
|
|
|
type = "0";
|
|
|
content = "获取电子健康卡链接";
|
|
|
method = "GET";
|
|
|
break;
|
|
|
}
|
|
|
ehcLog.setPatient(patient);
|
|
|
ehcLog.setApi(api);
|
|
|
ehcLog.setType(type);
|
|
|
ehcLog.setContent(content);
|
|
|
ehcLog.setMethod(method);
|
|
|
ehcLog.setParams(params);
|
|
|
ehcLog.setResponse(response);
|
|
|
ehcLog.setStatus("1");
|
|
|
ehcLog.setCreateTime(new Date());
|
|
|
ehcLog.setError(error);
|
|
|
|
|
|
if (StringUtils.isNotEmpty(error)) {
|
|
|
ehcLog.setStatus("0");
|
|
|
}
|
|
|
ehcLogDao.save(ehcLog);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|