|
@ -5,10 +5,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.JavaType;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.entity.charge.WlyyCharge;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.organization.HospitalMapping;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.repository.charge.ChargeDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
@ -61,6 +63,8 @@ public class OnePayService {
|
|
|
PatientDao patientDao;
|
|
|
@Autowired
|
|
|
SignFamilyDao signFamilyDao;
|
|
|
@Autowired
|
|
|
DoctorDao doctorDao;
|
|
|
|
|
|
/**
|
|
|
* 查询绑卡信息(本人)
|
|
@ -122,11 +126,16 @@ public class OnePayService {
|
|
|
|
|
|
try {
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
// requestParams.setTransType();
|
|
|
// requestParams.setVersion();
|
|
|
// requestParams.setSign();
|
|
|
// requestParams.setEncryptData();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setSignType(signType);
|
|
|
requestParams.setEncryptType(encryptType);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
|
|
|
|
|
|
|
|
|
// 请求报文体参数,详见接口文档各接口——请求参数定义
|
|
|
// 如医保绑卡信息请求参数
|
|
@ -143,6 +152,7 @@ public class OnePayService {
|
|
|
// 如医保卡绑卡信息返回参数
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
|
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, BindCard.class);
|
|
|
// 只返回了业务出参的附属绑卡情况 res.getRespCode()级别获取所有返回参数
|
|
|
result = objectMapper.readValue(objectMapper.writeValueAsString(res.getParam().get("attachList")), javaType);
|
|
|
} else {
|
|
|
isSuccess = false;
|
|
@ -156,7 +166,7 @@ public class OnePayService {
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
|
|
|
//保存http日志
|
|
|
//type=3易联众接口 保存http日志
|
|
|
logService.saveHttpLog(isSuccess, config.getBindCardType(), "查询绑卡信息", "POST", null, msgBody, response, error, logService.onepayType);
|
|
|
|
|
|
if (!isSuccess) {
|
|
@ -169,20 +179,20 @@ public class OnePayService {
|
|
|
/**
|
|
|
* 家庭医生签约支付
|
|
|
*/
|
|
|
public String charge(String orgCode, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid) throws Exception {
|
|
|
public String charge(String orgCode, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid,String accessToken) throws Exception {
|
|
|
//获取机构映射
|
|
|
HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
|
|
|
if (hos == null) {
|
|
|
throw new Exception("no hospital mapping!");
|
|
|
}
|
|
|
|
|
|
return charge(orgCode, hos.getName(), hos.getAppId(), hos.getAppSecret(), chargeType, chargeRelation, totalAmount, feeDetail, patient, openid);
|
|
|
return charge(orgCode, hos.getName(), hos.getAppId(), hos.getAppSecret(), chargeType, chargeRelation, totalAmount, feeDetail, patient, openid,accessToken);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 家庭医生签约支付,成功则返回支付路径
|
|
|
*/
|
|
|
private String charge(String orgCode, String orgName, String appId, String appSecret, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid) throws Exception {
|
|
|
private String charge(String orgCode, String orgName, String appId, String appSecret, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid,String accessToken) throws Exception {
|
|
|
Boolean isSuccess = true;
|
|
|
String msgBody = "";
|
|
|
String response = "";
|
|
@ -192,12 +202,12 @@ public class OnePayService {
|
|
|
String subject = "家庭医生签约支付"; // 订单名称
|
|
|
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
|
|
|
|
|
|
// 未真正完成支付以前预存储支付信息到wlyy_charge表
|
|
|
WlyyCharge charge = new WlyyCharge();
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
|
charge.setChargeType(chargeType); //交易类型
|
|
|
charge.setChargeRelation(chargeRelation); //交易关联代码
|
|
|
charge.setChargeRelation(chargeRelation); //交易关联代码 wlyy_sign_family字段code
|
|
|
charge.setCode(uuid); // 接入应用支付业务流水号
|
|
|
Date now = new Date();
|
|
|
charge.setCreateTime(now);
|
|
@ -228,6 +238,9 @@ public class OnePayService {
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
String currentDateTime = formatter.format(now);
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
// requestParams.setVersion();
|
|
|
// requestParams.setSign();
|
|
|
// requestParams.setEncryptData();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(currentDateTime);
|
|
|
requestParams.setSignType(signType);
|
|
@ -251,36 +264,49 @@ public class OnePayService {
|
|
|
// params.put("insuranceAmount",insuranceAmount); //医保支付金额
|
|
|
// params.put("financialAmount",financialAmount); //财政补贴金额
|
|
|
// params.put("returnUrl","https://mp.weixin.qq.com/insurance/pay/detail"); //页面跳转地址
|
|
|
params.put("returnUrl", "/html/qygl/html/pay-result.html"); //页面跳转地址
|
|
|
Properties systemConf = SystemConf.getInstance().getSystemProperties();
|
|
|
String returnUrl = systemConf.getProperty("return_url");
|
|
|
params.put("returnUrl",returnUrl); //页面跳转地址
|
|
|
params.put("feeDetail", feeDetail); //费用明细
|
|
|
params.put("channel", channel); //微信医保支付
|
|
|
params.put("merchName", orgName); //收款单位名称
|
|
|
params.put("subject", subject); //订单名称
|
|
|
//params.put("wxToken","");
|
|
|
params.put("wxToken",accessToken);
|
|
|
|
|
|
|
|
|
//extendParams 扩展入参
|
|
|
//家庭医生签约信息
|
|
|
Map<String, String> familyContent = new HashMap<>();
|
|
|
familyContent.put("moRegNo", "04");//医院签约号
|
|
|
familyContent.put("moRegName", "02"); //签约人姓名
|
|
|
familyContent.put("moRegAddr", "02"); //签约人地址
|
|
|
familyContent.put("moRegTelephone", "04");//签约人联系电话
|
|
|
familyContent.put("moRegOrgNo", "02"); //签约机构
|
|
|
familyContent.put("moRegDocNo", "04");//签约医生编号
|
|
|
familyContent.put("moRegDocName", "02"); //签约医生姓名
|
|
|
familyContent.put("moRegTime", "02"); //签约时间
|
|
|
familyContent.put("moRegEndTime", "02"); //签约截止时间
|
|
|
// 根据签约code查询签约信息
|
|
|
SignFamily signFamily = signFamilyDao.findByCode(chargeRelation);
|
|
|
if (signFamily!=null){
|
|
|
// //签约人Code
|
|
|
String signDoctorCode = signFamily.getSignDoctorCode();
|
|
|
String people = signFamily.getPatient();
|
|
|
// Doctor doctor = doctorDao.findByCode(signDoctorCode);
|
|
|
Patient user = patientDao.findByCode(people);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
Map<String, String> familyContent = new HashMap<>();
|
|
|
familyContent.put("moRegNo", chargeRelation);//医院签约号
|
|
|
familyContent.put("moRegName",signFamily.getName()); //签约人姓名
|
|
|
familyContent.put("moRegAddr",user.getAddress() ); //签约人地址
|
|
|
familyContent.put("moRegTelephone", signFamily.getMobile());//签约人联系电话
|
|
|
familyContent.put("moRegOrgNo", signFamily.getHospital()); //签约机构
|
|
|
familyContent.put("moRegDocNo", signFamily.getSignDoctorCode());//签约医生编号
|
|
|
familyContent.put("moRegDocName", signFamily.getSignDoctorName()); //签约医生姓名
|
|
|
familyContent.put("moRegTime", sdf.format(signFamily.getBegin())); //签约时间
|
|
|
familyContent.put("moRegEndTime", sdf.format(signFamily.getEnd())); //签约截止时间
|
|
|
// familyContent.put("moRegYear", "04");//签约年度
|
|
|
familyContent.put("moRegTear", "04");//签约年度
|
|
|
familyContent.put("moRegSource", "02"); //签约来源
|
|
|
familyContent.put("moCollectOrgNo", "02"); //扣费机构
|
|
|
familyContent.put("moCollectorNo", "04");//扣费人
|
|
|
familyContent.put("benefitType", "02"); //补贴类型
|
|
|
familyContent.put("moBookOrgNo", "04");//登记机构
|
|
|
familyContent.put("moBookerNo", "02"); //登记人
|
|
|
familyContent.put("moBookTime", "02"); //登记时间
|
|
|
params.put("familyContent", objectMapper.writeValueAsString(familyContent));// 请求结构体
|
|
|
familyContent.put("moRegTear", signFamily.getSignYear());//签约年度
|
|
|
familyContent.put("moRegSource", signFamily.getSignSource()); //签约来源
|
|
|
familyContent.put("moCollectOrgNo", "03"); //扣费机构
|
|
|
familyContent.put("moCollectorNo", "04");//扣费人
|
|
|
familyContent.put("benefitType", signFamily.getExpensesType()); //补贴类型
|
|
|
familyContent.put("moBookOrgNo", "05");//登记机构
|
|
|
familyContent.put("moBookerNo", "06"); //登记人
|
|
|
familyContent.put("moBookTime", "07"); //登记时间
|
|
|
params.put("familyContent", objectMapper.writeValueAsString(familyContent));// 家庭医生签约信息
|
|
|
}
|
|
|
//请求结构体
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("feeType", "04");//家庭医生签约
|
|
@ -288,7 +314,7 @@ public class OnePayService {
|
|
|
params.put("requestContent", objectMapper.writeValueAsString(map));// 请求结构体
|
|
|
requestParams.setParam(params);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
//执行支付
|
|
|
//执行支付 获取预支付原生返回值
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
@ -300,7 +326,7 @@ public class OnePayService {
|
|
|
charge.setChargeNo(chargeNo);
|
|
|
|
|
|
} else {
|
|
|
charge.setTradeStatus("1");
|
|
|
// charge.setTradeStatus("1");
|
|
|
isSuccess = false;
|
|
|
error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
|
|
|
}
|
|
@ -328,7 +354,7 @@ public class OnePayService {
|
|
|
/**
|
|
|
* 家庭医生签约支付查询
|
|
|
*/
|
|
|
public Charge chargeQuery(String code) throws Exception {
|
|
|
public Charge chargeQuery(String code,String accessToken) throws Exception {
|
|
|
Boolean isSuccess = true;
|
|
|
String msgBody = "";
|
|
|
String response = "";
|
|
@ -340,24 +366,29 @@ public class OnePayService {
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
|
|
|
try {
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
// requestParams.setVersion();
|
|
|
// requestParams.setSign();
|
|
|
// requestParams.setEncryptData();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setSignType(signType);
|
|
|
requestParams.setEncryptType(encryptType);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setTransType(config.getChargeQueryType());
|
|
|
|
|
|
//业务参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("outChargeNo", code); //接入应用结算业务流水号
|
|
|
params.put("wxToken", accessToken);
|
|
|
|
|
|
requestParams.setParam(params);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
//执行支付
|
|
|
//执行支付 返回原生返回值
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
|
// 只返回业务出参 res.getResponseContent()返回医保机构体
|
|
|
|
|
|
result = JSON.toJavaObject(res.getParam(), Charge.class);
|
|
|
|
|
|
//业务处理*******************
|
|
@ -374,7 +405,7 @@ public class OnePayService {
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
|
|
|
//保存http日志
|
|
|
//type = 3易联众接口保存http日志
|
|
|
logService.saveHttpLog(isSuccess, config.getChargeType(), "家庭医生签约支付查询", "POST", null, msgBody, response, error, logService.onepayType);
|
|
|
|
|
|
if (!isSuccess) {
|
|
@ -450,12 +481,12 @@ public class OnePayService {
|
|
|
/**
|
|
|
* 更新所有记录的交易状态
|
|
|
*/
|
|
|
private List<WlyyCharge> updateTradeStatus(List<WlyyCharge> list) {
|
|
|
private List<WlyyCharge> updateTradeStatus(List<WlyyCharge> list,String accessToken) {
|
|
|
//更新交易状态
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (WlyyCharge item : list) {
|
|
|
try {
|
|
|
Charge charge = chargeQuery(item.getCode());
|
|
|
Charge charge = chargeQuery(item.getCode(),accessToken);
|
|
|
if (charge != null) {
|
|
|
item.setTradeStatus(charge.getTradeStatus()); // 交易状态0 成功 1 失败 2 已退款
|
|
|
item.setChargeNo(charge.getChargeNo()); // 流水号
|
|
@ -479,29 +510,35 @@ public class OnePayService {
|
|
|
/**
|
|
|
* 通过交易关联代码获取交易列表
|
|
|
*/
|
|
|
public List<WlyyCharge> chargeList(String chargeType, String chargeRelation) throws Exception {
|
|
|
public List<WlyyCharge> chargeList(String chargeType, String chargeRelation,String accessToken) throws Exception {
|
|
|
List<WlyyCharge> list = chargeDao.findByChargeTypeAndChargeRelation(chargeType, chargeRelation);
|
|
|
|
|
|
return updateTradeStatus(list);
|
|
|
return updateTradeStatus(list,accessToken);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过患者代码获取交易列表
|
|
|
*/
|
|
|
public List<WlyyCharge> chargeListByPatient(String patient, Integer page, Integer size) throws Exception {
|
|
|
public List<WlyyCharge> chargeListByPatient(String patient, String accessToken,Integer page, Integer size) throws Exception {
|
|
|
|
|
|
PageRequest pageRequest = new PageRequest(page - 1, size);
|
|
|
List<WlyyCharge> list = chargeDao.findByPatient(patient, pageRequest);
|
|
|
|
|
|
return updateTradeStatus(list);
|
|
|
return updateTradeStatus(list,accessToken);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更改数据 wlyy_sign_family wlyy_charge
|
|
|
*/
|
|
|
public void updateData(String patient, String chargeNo) throws Exception {
|
|
|
chargeDao.updateByChargeNo(chargeNo);
|
|
|
signFamilyDao.updatePatientBegin(patient, new Date(), chargeNo, "1");
|
|
|
public void updateData(String chargeCode,String chargeNo,String chargeTime,String totalAmount,String insuranceAmount,String selfPayAmount,String billNo,String miRegisterNo) throws Exception {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat();
|
|
|
Date chargeSuccess = sdf.parse(chargeTime);
|
|
|
Date updateTime = new Date();
|
|
|
chargeDao.updateByChargeCode(chargeCode,chargeTime,updateTime,Integer.parseInt(totalAmount),Integer.parseInt(insuranceAmount),Integer.parseInt(selfPayAmount),
|
|
|
billNo,miRegisterNo,"0");
|
|
|
// 根据wlyy_charge的code 去查找关联代码signCode在更新签约表
|
|
|
WlyyCharge charge = chargeDao.findByCode(chargeCode);
|
|
|
signFamilyDao.updatePatientBegin(charge.getChargeRelation(), chargeSuccess, chargeNo, "1");
|
|
|
}
|
|
|
|
|
|
}
|