|
|
|
|
package com.ynxbd.common.action.pay;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.ynxbd.ali.helper.AliMedHelper;
|
|
|
|
|
import com.ynxbd.common.action.base.BaseAction;
|
|
|
|
|
import com.ynxbd.common.bean.enums.MerchantEnum;
|
|
|
|
|
import com.ynxbd.common.bean.pay.Order;
|
|
|
|
|
import com.ynxbd.common.bean.pay.PayInHosp;
|
|
|
|
|
import com.ynxbd.common.bean.pay.Recipe;
|
|
|
|
|
import com.ynxbd.common.bean.pay.Register;
|
|
|
|
|
import com.ynxbd.common.config.interceptor.AesDecode;
|
|
|
|
|
import com.ynxbd.common.dao.RxDao;
|
|
|
|
|
import com.ynxbd.common.dao.his.HisMedDao;
|
|
|
|
|
import com.ynxbd.common.helper.common.*;
|
|
|
|
|
import com.ynxbd.common.result.JsonResult;
|
|
|
|
|
import com.ynxbd.common.result.Result;
|
|
|
|
|
import com.ynxbd.common.result.ResultEnum;
|
|
|
|
|
import com.ynxbd.common.result.ServiceException;
|
|
|
|
|
import com.ynxbd.common.service.MedicalService;
|
|
|
|
|
import com.ynxbd.common.service.PayService;
|
|
|
|
|
import com.ynxbd.common.service.params.RequestParams;
|
|
|
|
|
import com.ynxbd.wx.wxfactory.*;
|
|
|
|
|
import com.ynxbd.wx.wxfactory.medical.WxMedConfig;
|
|
|
|
|
import com.ynxbd.wx.wxfactory.medical.models.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.apache.struts2.convention.annotation.Action;
|
|
|
|
|
import org.apache.struts2.convention.annotation.Namespace;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author wsq
|
|
|
|
|
* @Date 2020/9/14 15:43
|
|
|
|
|
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Namespace("/medical")
|
|
|
|
|
public class MedicalAction extends BaseAction {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息获取 | 医保上传 | 医保支付下单
|
|
|
|
|
*/
|
|
|
|
|
@Action("logFeeDetails")
|
|
|
|
|
public Result logFeeDetails(String callNo, String payCode, String qrCode, @AesDecode String openid, @AesDecode String patientId, @AesDecode String hisPatientId, @AesDecode String cardNo, String realName, String treatNum, BigDecimal totalFee) {
|
|
|
|
|
log.warn("[医保]上传明细数据调试 callNo={}, payCode={}, openid={}, qrCode={}, treatNum={}, patientId={}, hisPatientId={}, cardNo={}, realName={}, totalFee={}",
|
|
|
|
|
callNo, payCode, openid, qrCode, treatNum, patientId, hisPatientId, ParamHelper.hideIdCardNo(cardNo), realName, totalFee);
|
|
|
|
|
if (callNo == null || payCode == null || openid == null || qrCode == null || patientId == null || cardNo == null || totalFee == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) { // 支付方式异常
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息获取 | 医保上传 | 医保支付下单
|
|
|
|
|
*/
|
|
|
|
|
@Action("getFeeDetails")
|
|
|
|
|
public Result getFeeDetails(String callNo, String payCode, String qrCode, @AesDecode String openid, @AesDecode String patientId, @AesDecode String hisPatientId, @AesDecode String cardNo, String realName, String treatNum, BigDecimal totalFee) {
|
|
|
|
|
try {
|
|
|
|
|
log.info("[医保]上传明细下单 callNo={}, payCode={}, openid={}, qrCode={}, treatNum={}, patientId={}, hisPatientId={}, cardNo={}, realName={}, totalFee={}",
|
|
|
|
|
callNo, payCode, openid, qrCode, treatNum, patientId, hisPatientId, ParamHelper.hideIdCardNo(cardNo), realName, totalFee);
|
|
|
|
|
if (callNo == null || payCode == null || openid == null || qrCode == null || patientId == null || cardNo == null || totalFee == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) { // 支付方式异常
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MedInsInfo medInsInfo;
|
|
|
|
|
switch (PEnum.findEnum(callNo)) {
|
|
|
|
|
case REG:
|
|
|
|
|
Boolean isSplitTime = getReqParamByKey("isSplitTime", Boolean.class);
|
|
|
|
|
|
|
|
|
|
Register reg = new Register().getRegParams(new RequestParams(request), true);
|
|
|
|
|
if ("*".equals(reg.getRegCode())) {
|
|
|
|
|
return Result.error("任意医师的号源不能进行医保支付");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DateHelper.isToday(reg.getRegDate())) {
|
|
|
|
|
return Result.error("医保支付仅支持今日挂号");
|
|
|
|
|
}
|
|
|
|
|
medInsInfo = new MedicalService().hisRegMedUploadDetails(merchantEnum, qrCode, openid, treatNum, patientId, hisPatientId, cardNo, realName, reg, isSplitTime);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECIPE:
|
|
|
|
|
String ybAttrib = getReqParamByKey("ybAttrib");
|
|
|
|
|
String ybBZCode = getReqParamByKey("ybBZCode");
|
|
|
|
|
String ybBZName = getReqParamByKey("ybBZName");
|
|
|
|
|
String recipeJson = getReqParamByKey("recipeJson"); // 处方JSON集 [{ recipeId: item.id, recipeFee: item.amount }]
|
|
|
|
|
log.info("[医保-处方]上传明细下单 treatNum={}, ybAttrib={}, ybBZCode={}, ybBZName={}, recipeJson={}", treatNum, ybAttrib, ybBZCode, ybBZName, recipeJson);
|
|
|
|
|
if (treatNum == null || recipeJson == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
medInsInfo = new MedicalService().hisRxUploadDetails(merchantEnum, qrCode, openid, treatNum, patientId, hisPatientId, cardNo, realName, totalFee, ybAttrib, ybBZCode, ybBZName, recipeJson);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OUT_HOSP:
|
|
|
|
|
log.info("[医保-住院结算]上传明细下单 treatNum={}", treatNum);
|
|
|
|
|
if (treatNum == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
medInsInfo = new MedicalService().hisOutHospUploadDetails(merchantEnum, qrCode, openid, treatNum, patientId, hisPatientId, cardNo, realName);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return Result.error("调用方式不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result.success(medInsInfo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return Result.error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取授权链接
|
|
|
|
|
*/
|
|
|
|
|
@Action("getRefundAuthUrl")
|
|
|
|
|
public Result getRefundAuthUrl() {
|
|
|
|
|
JSONObject respJson = WxMedHelper.getMdAuthUrl("wx-medical-refund.html", null, isHttpsWithProxy());
|
|
|
|
|
return Result.success(respJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [处方流转]获取授权链接
|
|
|
|
|
*/
|
|
|
|
|
@Action("getAuthUrl")
|
|
|
|
|
public Result getAuthUrl(@AesDecode String url) {
|
|
|
|
|
if (ObjectUtils.isEmpty(url)) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_INVALID);
|
|
|
|
|
}
|
|
|
|
|
JSONObject respJson = WxMedHelper.getMdAuthRedirectUrl(url);
|
|
|
|
|
return Result.success(respJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Action("medicalAuth")
|
|
|
|
|
public Result medicalAuth(String openid, String qrCode) {
|
|
|
|
|
log.info("[医保建档] openid-{}, qrCode={}", openid, qrCode);
|
|
|
|
|
MedicalUserInfo info = WxFactory.Medical.Common().getUserInfo(WxMedConfig.PARTNER_URL, openid, qrCode);
|
|
|
|
|
log.info("[医保建档获取用户信息] resp:{}", info);
|
|
|
|
|
return Result.success(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Action("getMedicalAuthUrl")
|
|
|
|
|
public Result getMedicalAuthUrl(String url) {
|
|
|
|
|
JSONObject respJson = WxMedHelper.getMdAuthUrl(url, null, isHttpsWithProxy());
|
|
|
|
|
return Result.success(respJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取对账链接
|
|
|
|
|
*
|
|
|
|
|
* @param billDate 账单日期
|
|
|
|
|
* @param billType 账单类型 ALL,返回当日所有订单信息,默认 SUCCESS,返回当日成功支付的订单 REFUND,返回当日退款订单
|
|
|
|
|
* @param key 加密密钥
|
|
|
|
|
* @return 下载链接
|
|
|
|
|
*/
|
|
|
|
|
@Action("downBill")
|
|
|
|
|
public Result downBill(String billDate, String billType, String key) {
|
|
|
|
|
log.info("[医保]下载对账订单,billDate-{}, billType-{}, key-{}", billDate, billType, key);
|
|
|
|
|
if (billDate == null || billType == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
if (!DateHelper.getCurDate().equals(AesMicroHelper.decode(key))) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_INVALID);
|
|
|
|
|
}
|
|
|
|
|
return Result.success(WxMedHelper.downBill(billDate, billType));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 医保支付下单
|
|
|
|
|
*
|
|
|
|
|
* @param callNo 业务类型[挂号:register; 处方缴费:recipe]
|
|
|
|
|
* @param payCode 调用码[如:wx_medical]
|
|
|
|
|
* @param openid openid
|
|
|
|
|
* @param patientId 患者id
|
|
|
|
|
* @param cardNo 患者证件号
|
|
|
|
|
* @param realName 患者真实姓名
|
|
|
|
|
* @param treatNum 门诊号(挂号不传,处方必传)
|
|
|
|
|
* @param payOrdId -医保订单号id(接口返回)
|
|
|
|
|
* @param payAuthNo -医保授权码(接口返回)
|
|
|
|
|
* @param mdTrtId -医保-就诊ID(接口返回)
|
|
|
|
|
* @param chrgBchno -医保-收费单据号(接口返回)
|
|
|
|
|
* @param mdUserId -医保-用户ID(接口返回)
|
|
|
|
|
* @param totalFee -订单金额(接口返回)
|
|
|
|
|
* @param acctFee -医保-个人账户支付金额(接口返回)
|
|
|
|
|
* @param hifpFee -医保-统筹支付金额(接口返回)
|
|
|
|
|
* @param insuranceFee -个账 + 统筹支付金额(接口返回)
|
|
|
|
|
* @param cashFee -现金金额(接口返回)
|
|
|
|
|
* @param familyType 家庭关系(非必传)
|
|
|
|
|
* @param familyName 家人姓名(非必传)
|
|
|
|
|
* @param familyCardNo 家人证件号码(非必传)
|
|
|
|
|
*/
|
|
|
|
|
@Action("order")
|
|
|
|
|
public Result order(String callNo, String payCode, String payOpenId, @AesDecode String openid, @AesDecode String patientId, @AesDecode String cardNo, @AesDecode String hisPatientId, String realName, String treatNum, String payOrdId, String payAuthNo, String mdTrtId, String chrgBchno, String mdUserId,
|
|
|
|
|
BigDecimal totalFee, BigDecimal acctFee, BigDecimal hifpFee, BigDecimal insuranceFee, BigDecimal cashFee, String familyType, String familyName, String familyCardNo, String medicalCardInstId, String medicalCardId) {
|
|
|
|
|
try {
|
|
|
|
|
log.info("[医保]下单入参 callNo={}, payCode={}, openid={}, patientId={}, totalFee={}, hisPatientId={}, cardNo={}, treatNum={}, payOrdId={}",
|
|
|
|
|
callNo, payCode, openid, patientId, totalFee, hisPatientId, ParamHelper.hideIdCardNo(cardNo), treatNum, payOrdId);
|
|
|
|
|
if (StrUtil.hasBlank(callNo, payCode, openid, patientId, cardNo) || totalFee == null) {
|
|
|
|
|
System.out.println("[医保]下单参数缺失");
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result result = PayService.isPaymentPermittedByTime();
|
|
|
|
|
if (result != null) {
|
|
|
|
|
System.out.println("[医保]凌晨禁止支付");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) { // 支付方式异常
|
|
|
|
|
log.error("[医保]支付方式异常 payCode={}", payCode);
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
Order order = new Order();
|
|
|
|
|
String bizTradeNo = merchantEnum.createBizTradeNo();
|
|
|
|
|
order.setOutTradeNo(bizTradeNo);
|
|
|
|
|
order.setBizTradeNo(bizTradeNo);
|
|
|
|
|
order.setIp(HttpHelper.getIpAddress(request));
|
|
|
|
|
|
|
|
|
|
order.setTradeNo(payOrdId);
|
|
|
|
|
order.setPayOrdId(payOrdId);
|
|
|
|
|
order.setPayAuthNo(payAuthNo);
|
|
|
|
|
order.setPayMoney(cashFee);
|
|
|
|
|
order.setAcctFee(acctFee);
|
|
|
|
|
order.setHifpFee(hifpFee);
|
|
|
|
|
order.setTotalFee(totalFee);
|
|
|
|
|
order.setInsuranceFee(insuranceFee);
|
|
|
|
|
|
|
|
|
|
order.setChrgBchno(chrgBchno);
|
|
|
|
|
order.setMdTrtId(mdTrtId);
|
|
|
|
|
order.setMdUserId(mdUserId);
|
|
|
|
|
order.setPayDeviceId("mobile");
|
|
|
|
|
order.setTreatNum(treatNum);
|
|
|
|
|
order.setPayMchCode(merchantEnum.CODE);
|
|
|
|
|
order.setOpenid(openid);
|
|
|
|
|
order.setPayOpenId(payOpenId);
|
|
|
|
|
order.setPatientId(patientId);
|
|
|
|
|
order.setHisPatientId(hisPatientId);
|
|
|
|
|
order.setIdCardNo(cardNo);
|
|
|
|
|
order.setPatientName(realName);
|
|
|
|
|
|
|
|
|
|
order.setFamilyType(familyType);
|
|
|
|
|
order.setFamilyName(familyName);
|
|
|
|
|
order.setFamilyCardNo(familyCardNo);
|
|
|
|
|
order.setMedicalCardInstId(medicalCardInstId);
|
|
|
|
|
order.setMedicalCardId(medicalCardId);
|
|
|
|
|
|
|
|
|
|
PEnum serverEnum = PEnum.findEnum(callNo);
|
|
|
|
|
switch (serverEnum) {
|
|
|
|
|
case REG:
|
|
|
|
|
Register regOrder = JsonHelper.copy(order, Register.class);
|
|
|
|
|
regOrder = regOrder.getRegParams(new RequestParams(request), true);
|
|
|
|
|
return new MedicalService().createRegOrder(merchantEnum, regOrder, serverEnum);
|
|
|
|
|
|
|
|
|
|
case RECIPE:
|
|
|
|
|
String recipeJson = getReqParamByKey("recipeJson");
|
|
|
|
|
if (recipeJson == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_BLANK);
|
|
|
|
|
}
|
|
|
|
|
String payWay = getReqParamByKey("payWay");
|
|
|
|
|
Integer rxType = getReqParamByKey("rxType", Integer.class);
|
|
|
|
|
Recipe rxOrder = JsonHelper.copy(order, Recipe.class);
|
|
|
|
|
return new MedicalService().createRxOrder(merchantEnum, rxOrder, serverEnum, recipeJson, payWay, rxType);
|
|
|
|
|
|
|
|
|
|
case OUT_HOSP:
|
|
|
|
|
PayInHosp outHospOrder = JsonHelper.copy(order, PayInHosp.class);
|
|
|
|
|
return new MedicalService().createOutHospOrder(merchantEnum, outHospOrder, serverEnum);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return Result.error("调用方式不存在");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return Result.error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 医保退费(线上)
|
|
|
|
|
*/
|
|
|
|
|
@Action("refundMed")
|
|
|
|
|
public Result refundMed(String payCode, String callNo, String openid, String qrCode, String outTradeNo, @AesDecode String tradeNo) {
|
|
|
|
|
// tradeNo = Base64Helper.decodeEn(tradeNo);
|
|
|
|
|
log.info("[医保退费] callNo={}, openid={}, qrCode={}, outTradeNo={}, tradeNo={}", callNo, openid, qrCode, outTradeNo, tradeNo);
|
|
|
|
|
if (openid == null || qrCode == null || outTradeNo == null || tradeNo == null) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
if (!WxMedConfig.IS_DEV) {
|
|
|
|
|
return Result.error("环境异常调用失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) { // 支付方式异常
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RxDao rxDao = new RxDao();
|
|
|
|
|
Recipe recipe = rxDao.selectByTradeNo(tradeNo);
|
|
|
|
|
if (recipe == null) {
|
|
|
|
|
return Result.error(ResultEnum.DATA_NOT_FOUND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Boolean isDevUser = MedicalService.isDevUser(recipe.getOpenid());
|
|
|
|
|
if (isDevUser == null || !isDevUser) {
|
|
|
|
|
return Result.error("不是测试用户");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer payStatus = recipe.getPayStatus();
|
|
|
|
|
Integer hisStatus = recipe.getHisStatus();
|
|
|
|
|
String chrgBchno = recipe.getChrgBchno();
|
|
|
|
|
String bankTransNo = recipe.getBankTransNo();
|
|
|
|
|
String mdUserId = recipe.getMdUserId();
|
|
|
|
|
|
|
|
|
|
BigDecimal cashFee = recipe.getPayMoney();
|
|
|
|
|
BigDecimal acctFee = recipe.getAcctFee();
|
|
|
|
|
BigDecimal hifpFee = recipe.getHifpFee();
|
|
|
|
|
|
|
|
|
|
if (payStatus == null || hisStatus == null || chrgBchno == null || bankTransNo == null || mdUserId == null || cashFee == null || acctFee == null || hifpFee == null) {
|
|
|
|
|
log.info("[医保]退费参数缺失 outTradeNo={}, bankTransNo={}, payStatus={}, hisStatus={}, chrgBchno={}, cashFee={}, acctFee={}, hifpFee={}", outTradeNo, bankTransNo, payStatus, hisStatus, chrgBchno, cashFee, acctFee, hifpFee);
|
|
|
|
|
return Result.error(ResultEnum.PAY_ORDER_PARAMS_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal insuranceFee = acctFee.add(hifpFee);
|
|
|
|
|
if (payStatus != 0) { // 都已成功禁止退费
|
|
|
|
|
return Result.error(ResultEnum.PAY_ORDER_NO_PAY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (hisStatus == 0) { // 都已成功禁止退费
|
|
|
|
|
// return Result.error(ResultEnum.PAY_ORDER_NO_PAY);
|
|
|
|
|
// }
|
|
|
|
|
Result result = new MedicalService().refund(merchantEnum, openid, qrCode, chrgBchno.substring(1), outTradeNo, bankTransNo, tradeNo, mdUserId, cashFee, insuranceFee);
|
|
|
|
|
String message = result.isOK() ? WxPayHelper.OK : result.getMessage();
|
|
|
|
|
if (!rxDao.updateRefundByTradeNo(tradeNo, message)) {
|
|
|
|
|
log.info("[医保]修改退费信息失败 [{}] outTradeNo={}, tradeNo={}", message, outTradeNo, tradeNo);
|
|
|
|
|
}
|
|
|
|
|
if (result.isOK()) {
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取需要退费的订单
|
|
|
|
|
*/
|
|
|
|
|
@Action("getRefundMedOrders")
|
|
|
|
|
public Result getRefundMedOrders(String openid, String begDate, String endDate) {
|
|
|
|
|
log.info("[医保]查询需退费订单 openid={}, begDate={}, endDate={}", openid, begDate, endDate);
|
|
|
|
|
RxDao rxDao = new RxDao();
|
|
|
|
|
List<Order> orders = rxDao.selectRefundList(openid, begDate, endDate);
|
|
|
|
|
for (Order order : orders) {
|
|
|
|
|
if (order.getTradeNo() != null) {
|
|
|
|
|
order.setTradeNo(AesWxHelper.encode(order.getTradeNo()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result.success(orders);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询HIS医保对账记录
|
|
|
|
|
*/
|
|
|
|
|
@Action("getHisAccountsInfo")
|
|
|
|
|
public Result getHisAccountsInfo(String payCode, String mdUserId) {
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) {
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
JsonResult jsonResult = HisMedDao.getMedAccounts(merchantEnum, mdUserId);
|
|
|
|
|
return Result.success(jsonResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [医保]微信支付订单查询
|
|
|
|
|
*
|
|
|
|
|
* @param outTradeNo 订单号
|
|
|
|
|
* @param medTransId 医保交易流水号
|
|
|
|
|
*/
|
|
|
|
|
@Action("queryOrder")
|
|
|
|
|
public Result queryOrder(String payCode, String outTradeNo, String medTransId, String callNo) {
|
|
|
|
|
log.info("[医保]查询订单 payCode={}, outTradeNo={}, medTransId={}, callNo={}", payCode, outTradeNo, medTransId, callNo);
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode, MerchantEnum.WX_MEDICAL);
|
|
|
|
|
if (merchantEnum == null) {
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> orderObj = new HashMap<>();
|
|
|
|
|
if (!ObjectUtils.isEmpty(callNo)) { // 传递业务类型,返回费用信息
|
|
|
|
|
orderObj = new MedicalService().queryOrderFee(callNo, outTradeNo, medTransId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (merchantEnum.equals(MerchantEnum.WX_MEDICAL)) {
|
|
|
|
|
WxMedOrder order = WxMedHelper.queryOrder(WxCacheHelper.getAccessToken(), outTradeNo, medTransId);
|
|
|
|
|
order.setOrderObj(orderObj);
|
|
|
|
|
if (order.isOk()) {
|
|
|
|
|
return Result.success(order);
|
|
|
|
|
}
|
|
|
|
|
return Result.error(order.getMessage());
|
|
|
|
|
|
|
|
|
|
} else if (merchantEnum.equals(MerchantEnum.ALI_MEDICAL)) {
|
|
|
|
|
Order order = AliMedHelper.queryTrade(outTradeNo, medTransId);
|
|
|
|
|
order.setOrderObj(orderObj);
|
|
|
|
|
if (order.hasErrorMsg()) {
|
|
|
|
|
return Result.error(order.getErrorMsg());
|
|
|
|
|
}
|
|
|
|
|
return Result.success(order);
|
|
|
|
|
} else {
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Action("queryRefund")
|
|
|
|
|
public Result queryRefund(String payCode, String outRefundNo, String outTradeNo, String mdTransId) {
|
|
|
|
|
log.info("[医保]查询退费订单 payCode={}, outRefundNo={}, outTradeNo={}, mdTransId={}", payCode, outRefundNo, outTradeNo, mdTransId);
|
|
|
|
|
|
|
|
|
|
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
|
|
|
|
|
if (merchantEnum == null) { // 支付方式异常
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isEmpty(outRefundNo) && ObjectUtils.isEmpty(outTradeNo) && ObjectUtils.isEmpty(mdTransId)) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_BLANK);
|
|
|
|
|
}
|
|
|
|
|
if (merchantEnum.equals(MerchantEnum.WX_MEDICAL)) {
|
|
|
|
|
MedicalRefundInfo info = WxMedHelper.queryRefund(outRefundNo, outTradeNo, mdTransId);
|
|
|
|
|
info.setAppid(null);
|
|
|
|
|
info.setMchId(null);
|
|
|
|
|
return Result.success(info);
|
|
|
|
|
}
|
|
|
|
|
return Result.error(ResultEnum.PAY_TYPE_NOT_SUPPORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * HIS医保退费
|
|
|
|
|
// */
|
|
|
|
|
// @Action("queryRefund")
|
|
|
|
|
// public Result queryRefund(String accessToken, String outTradeNo, String mdTransId) {
|
|
|
|
|
// MedicalRefundInfo info = WxMedicalHelper.queryRefund(accessToken, outTradeNo, mdTransId);
|
|
|
|
|
// return Result.success(info);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [医保支付]微信回调通知
|
|
|
|
|
*/
|
|
|
|
|
@Action("payNotify")
|
|
|
|
|
public Result payNotify() {
|
|
|
|
|
try {
|
|
|
|
|
log.info("【微信-医保】回调通知...");
|
|
|
|
|
MedicalNotify notifyInfo = WxMedHelper.paidMedNotify(request);
|
|
|
|
|
// 成功返回
|
|
|
|
|
Result.respXml(MedRespHelper.respOk(WxMedConfig.PAY_KEY));
|
|
|
|
|
|
|
|
|
|
String outTradeNo = notifyInfo.getHospOutTradeNo();
|
|
|
|
|
String openid = notifyInfo.getOpenid();
|
|
|
|
|
String bankTransNo = notifyInfo.getMedTransId();
|
|
|
|
|
|
|
|
|
|
String payInfo = notifyInfo.getInfo();
|
|
|
|
|
BigDecimal totalFee = notifyInfo.getTotalFee();
|
|
|
|
|
String payDate = notifyInfo.getPayDate();
|
|
|
|
|
String payTime = notifyInfo.getPayTime();
|
|
|
|
|
|
|
|
|
|
String notifyType = notifyInfo.getAttach();
|
|
|
|
|
|
|
|
|
|
log.info("【微信-医保】[{}] 收到通知 outTradeNo={}, bankTransNo={}, notifyType={}",
|
|
|
|
|
notifyType, outTradeNo, bankTransNo, notifyType);
|
|
|
|
|
|
|
|
|
|
new MedicalService().commonNotify(MerchantEnum.WX_MEDICAL, notifyType, outTradeNo, totalFee, bankTransNo, payDate, payTime, openid, payInfo);
|
|
|
|
|
return null;
|
|
|
|
|
} catch (ServiceException e) {
|
|
|
|
|
return Result.respXml(MedRespHelper.resp(e, WxMedConfig.PAY_KEY));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Action("outHospTest")
|
|
|
|
|
// public Result outHospTest() {
|
|
|
|
|
// System.out.println("住院测试...");
|
|
|
|
|
// new MedicalService().outHospPaidNoticeHis(MerchantEnum.WX_MEDICAL, "WX0c8f4caa38bc4a558ab4ea4a69b5", "M26081237393763727", "2026-08-12", "12:00:52", "om5HqvlWTys3Bqls6YV-o4iA3Zqg", null);
|
|
|
|
|
// return Result.success();
|
|
|
|
|
// }
|
|
|
|
|
}
|