|
@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
-import thyyxxk.wxservice_server.constant.QuerySource;
|
|
|
+import thyyxxk.wxservice_server.constant.TradeState;
|
|
|
import thyyxxk.wxservice_server.dao.InpatientDao;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.entity.ResultVo;
|
|
@@ -19,12 +19,10 @@ import thyyxxk.wxservice_server.entity.hrgresponse.SaveMzFeeResponse;
|
|
|
import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
|
|
|
-import thyyxxk.wxservice_server.utils.DateUtil;
|
|
|
-import thyyxxk.wxservice_server.utils.DecimalTool;
|
|
|
-import thyyxxk.wxservice_server.utils.ResultVoUtil;
|
|
|
-import thyyxxk.wxservice_server.utils.StringUtil;
|
|
|
+import thyyxxk.wxservice_server.utils.*;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @description: 保存付费结果
|
|
@@ -36,14 +34,14 @@ import java.util.Date;
|
|
|
public class SavePayResultService {
|
|
|
private final WxApiDao dao;
|
|
|
private final InpatientDao yjjDao;
|
|
|
- private final AutoRefundService refundService;
|
|
|
+ private final WxRefundService refundService;
|
|
|
private final PushWxMessageService pushWxMessageService;
|
|
|
|
|
|
@Value("${hrgApiUrl}")
|
|
|
private String hrgApiUrl;
|
|
|
|
|
|
@Autowired
|
|
|
- public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, AutoRefundService refundService,
|
|
|
+ public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, WxRefundService refundService,
|
|
|
PushWxMessageService pushWxMessageService) {
|
|
|
this.dao = dao;
|
|
|
this.yjjDao = yjjDao;
|
|
@@ -88,12 +86,19 @@ public class SavePayResultService {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存挂号信息失败,自动退款失败,请联系服务中心进行退款。");
|
|
|
}
|
|
|
|
|
|
- public ResultVo<Object> saveMzChargeInfo(WxPayOrder order, QuerySource source, String successTime) {
|
|
|
+ public ResultVo<Object> saveMzChargeInfo(WxPayOrder order, String successTime) throws InterruptedException {
|
|
|
+ while (TradeVectorUtil.tradeNoBeingRefund(order.getTradeNo())) {
|
|
|
+ TimeUnit.SECONDS.sleep(3);
|
|
|
+ }
|
|
|
if (dao.alreadyPayed(order.getTradeNo()) == 1) {
|
|
|
log.info("订单号:{} 的门诊缴费信息已保存,无需再次保存。", order.getTradeNo());
|
|
|
updateHisChargeStatus(order.getHisOrdNum(), order.getTradeNo());
|
|
|
return ResultVoUtil.success("保存门诊缴费信息成功。");
|
|
|
}
|
|
|
+ Integer status = dao.selectPayStatus(order.getTradeNo());
|
|
|
+ if (null == status || status != TradeState.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.success("因系统原因,订单已退款。请稍后重新缴费或前往一楼收费窗口缴费。");
|
|
|
+ }
|
|
|
JSONObject hrgParam = new JSONObject();
|
|
|
hrgParam.put("patCardType", 1);
|
|
|
hrgParam.put("patCardNo", order.getPatientId());
|
|
@@ -110,38 +115,19 @@ public class SavePayResultService {
|
|
|
if (null != saveMzFeeResponse && null != saveMzFeeResponse.getResultCode() &&
|
|
|
saveMzFeeResponse.getResultCode() == 0) {
|
|
|
updateHisChargeStatus(order.getHisOrdNum(), order.getTradeNo());
|
|
|
- if (source == QuerySource.INTERFACE) {
|
|
|
- String hisOrdNum = order.getHisOrdNum();
|
|
|
- String[] hsrdnms = hisOrdNum.split("_");
|
|
|
- Integer isCovidExam = dao.selectSelfCovidExamReceiptCount(hsrdnms[0], hsrdnms[1], hsrdnms[2]);
|
|
|
- if (null != isCovidExam && isCovidExam > 0) {
|
|
|
- order.setBody("新冠肺炎核酸检测");
|
|
|
- order.setPayDatetime(DateUtil.parseDatetime(successTime));
|
|
|
- return ResultVoUtil.success("showBill", order);
|
|
|
- }
|
|
|
- }
|
|
|
return ResultVoUtil.success("保存门诊缴费信息成功。");
|
|
|
}
|
|
|
if (dao.alreadyPayed(order.getTradeNo()) == 1) {
|
|
|
updateHisChargeStatus(order.getHisOrdNum(), order.getTradeNo());
|
|
|
- if (source == QuerySource.INTERFACE) {
|
|
|
- String hisOrdNum = order.getHisOrdNum();
|
|
|
- String[] hsrdnms = hisOrdNum.split("_");
|
|
|
- Integer isCovidExam = dao.selectSelfCovidExamReceiptCount(hsrdnms[0], hsrdnms[1], hsrdnms[2]);
|
|
|
- if (null != isCovidExam && isCovidExam > 0) {
|
|
|
- order.setBody("新冠肺炎核酸检测");
|
|
|
- order.setPayDatetime(DateUtil.parseDatetime(successTime));
|
|
|
- return ResultVoUtil.success("showBill", order);
|
|
|
- }
|
|
|
- }
|
|
|
return ResultVoUtil.success("保存门诊缴费信息成功。");
|
|
|
}
|
|
|
String message = "保存门诊缴费信息失败,自动退款。";
|
|
|
if (null != saveMzFeeResponse && StringUtil.notBlank(saveMzFeeResponse.getResultMessage())) {
|
|
|
message = saveMzFeeResponse.getResultMessage();
|
|
|
}
|
|
|
+ log.info("【订单号:{}】发起自动退款:{}", order.getTradeNo(), message);
|
|
|
ResultVo<String> refund = refundService.autoRefund(order.getTradeNo(), message);
|
|
|
- log.info("【订单号:{}】保存门诊缴费信息失败,自动退款结果:{}", order.getTradeNo(), refund);
|
|
|
+ log.info("【订单号:{}】自动退款结果:{}", order.getTradeNo(), refund);
|
|
|
if (refund.getCode() == ExceptionEnum.SUCCESS.getCode()) {
|
|
|
dao.refundOrder(order.getTradeNo(), message);
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + message + "】已为您自动退款,请留意到账信息。");
|