You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
6.3 KiB
137 lines
6.3 KiB
package com.ynxbd.common.service;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ynxbd.common.action.pay.PQREnum;
|
|
import com.ynxbd.common.bean.enums.MerchantEnum;
|
|
import com.ynxbd.common.bean.pay.PayCasebook;
|
|
import com.ynxbd.common.dao.CasebookDao;
|
|
import com.ynxbd.common.helper.common.CodeHelper;
|
|
import com.ynxbd.common.helper.common.DateHelper;
|
|
import com.ynxbd.common.helper.common.JsonHelper;
|
|
import com.ynxbd.common.helper.xbd.XBDEnum;
|
|
import com.ynxbd.common.helper.xbd.XBDHttpHelper;
|
|
import com.ynxbd.common.result.Result;
|
|
import com.ynxbd.common.result.ResultEnum;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
@Slf4j
|
|
public class CasebookService {
|
|
|
|
public Result placeOrder(MerchantEnum merchantEnum, String ip, String openid, String patientId, String treatNum, String totalFee, String applyId, String getWay, String useToName) {
|
|
if (openid == null || patientId == null || totalFee == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
if (new BigDecimal(totalFee).compareTo(BigDecimal.ZERO) == 0) {
|
|
return Result.error(ResultEnum.PAY_MONEY_IS_ZERO);
|
|
}
|
|
|
|
if (isPay(patientId, treatNum, applyId, getWay, useToName)) {
|
|
log.info("{} [病历]订单已支付 applyId-{}, patientId={},treatNum-{},getWay-{},useToName-{}", merchantEnum.NAME, applyId, patientId, treatNum, getWay, useToName);
|
|
return Result.error(ResultEnum.APPLY_REPEAT);
|
|
}
|
|
|
|
String outTradeNo = CodeHelper.getOutTradeNo(merchantEnum);
|
|
|
|
if (!isSaveCasebookInfo(patientId, treatNum, applyId, new BigDecimal(totalFee), outTradeNo, getWay, useToName)) {
|
|
log.info("{} [病历]下单信息存储失败 applyId-{}, patientId={},treatNum-{}", merchantEnum.NAME, applyId, patientId, treatNum);
|
|
return Result.error(ResultEnum.SPECIFIED_QUESTIONED_USER_NOT_EXIST);
|
|
}
|
|
|
|
|
|
String body = "病历复印缴费 住院号=" + treatNum;
|
|
|
|
JSONObject respJson = PayService.createOrder(merchantEnum, openid, patientId, totalFee, outTradeNo, PQREnum.CASEBOOK.CODE, ip, body);
|
|
if (respJson == null) {
|
|
return Result.error(ResultEnum.PAY_ERROR); // 支付异常
|
|
}
|
|
return Result.success(respJson);
|
|
}
|
|
|
|
public boolean isExit(String patientId, String treatNum, String getWay, String useToName) {
|
|
if (patientId == null || treatNum == null) {
|
|
log.info("[病历复印]唤起支付 存入 applyId失败,patientId-{},treatNum-{},", patientId, treatNum);
|
|
return false;
|
|
}
|
|
return new CasebookDao().selectIsExit(patientId, treatNum, getWay, useToName);
|
|
}
|
|
|
|
/**
|
|
* @param patientId 患者id
|
|
* @param treatNum 住院号
|
|
* @return 是否成功
|
|
*/
|
|
public boolean isSaveCasebookInfo(String patientId, String treatNum, String applyId, BigDecimal totalFee, String outTradeNo, String getWay, String useToName) {
|
|
if (patientId == null || treatNum == null) {
|
|
log.info("[病历复印]唤起支付 存入 applyId失败,patientId-{},treatNum-{},totalFee-{}", patientId, treatNum, totalFee);
|
|
return false;
|
|
}
|
|
return new CasebookDao().updatePayStatePre(patientId, treatNum, applyId, totalFee, outTradeNo, getWay, useToName);
|
|
}
|
|
|
|
public boolean isPay(String patientId, String treatNum, String applyId, String getWay, String useToName) {
|
|
if (patientId == null || treatNum == null) {
|
|
log.info("[病历复印]查重失败,patientId-{},treatNum-{},applyId-{}", patientId, treatNum, applyId);
|
|
return false;
|
|
}
|
|
return new CasebookDao().selectIsPay(patientId, treatNum, applyId, getWay, useToName);
|
|
}
|
|
|
|
/**
|
|
* 新增预约记录首次存入
|
|
*
|
|
* @param casebook 病历订单信息
|
|
* @return 是否成功
|
|
*/
|
|
public boolean addApply(PayCasebook casebook, String openId, String patientId) {
|
|
if (casebook == null) {
|
|
log.info("casebook is null");
|
|
return false;
|
|
}
|
|
return new CasebookDao().insert(casebook, openId, patientId);
|
|
}
|
|
|
|
public void payNotify(MerchantEnum merchantEnum, String openid, BigDecimal totalFee, String outTradeNo, String bankTransNo, String payInfo) {
|
|
CasebookDao casebookDao = new CasebookDao();
|
|
PayCasebook order = casebookDao.selectByOutTradeNo(outTradeNo);
|
|
|
|
String casebookId = order.getApplyId();
|
|
if (ObjectUtils.isEmpty(casebookId)) {
|
|
log.error("[病历]病历申请ID缺失 outTradeNo={}, bankTransNo={}, casebookId={}", outTradeNo, bankTransNo, casebookId);
|
|
return;
|
|
}
|
|
|
|
Integer payStates = order.getPayStatus();
|
|
if (payStates == 0) {
|
|
log.error("[病历]订单已支付 outTradeNo={}, bankTransNo={}, casebookId={}", outTradeNo, bankTransNo, casebookId);
|
|
return;
|
|
}
|
|
if (!casebookDao.updatePayStateOk(outTradeNo, bankTransNo)) {
|
|
log.info("[病历]修改支付状态失败 outTradeNo={}, bankTransNo={}, casebookId={}", outTradeNo, bankTransNo, casebookId);
|
|
}
|
|
|
|
log.info("[病历] 开始回调支付状态 borrowNo-{}", casebookId);
|
|
String jsonString = XBDHttpHelper.ExecMethodGet(XBDEnum.BLSM_Appointment_SetISPay.Name, params -> {
|
|
params.put("borrowNo", casebookId);
|
|
params.put("payDateTime", DateHelper.getCurDateTime());
|
|
});
|
|
|
|
log.info("[病历]回调返回 resp={}", jsonString);
|
|
String code = JsonHelper.parseObject(jsonString).getString("Code");
|
|
if (code == null) {
|
|
if (!casebookDao.updateNotifyOk(outTradeNo)) {
|
|
log.info("[病历]更新订单信息失败 outTradeNo={}, bankTransNo={}, casebookId={}", outTradeNo, bankTransNo, casebookId);
|
|
}
|
|
return;
|
|
}
|
|
|
|
String message = JsonHelper.parseObject(jsonString).getString("Msg");
|
|
log.info("[病历]回调失败 code={}, message={}", code, message);
|
|
if (!casebookDao.updateNotifyErr(outTradeNo, message)) {
|
|
log.info("[病历]更新订单错误信息失败 outTradeNo={}, code={}, message={}", outTradeNo, code, message);
|
|
}
|
|
}
|
|
}
|
|
|