package com.bonus.canteen.core.pay.common.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.canteen.core.allocation.alloc.model.AllocPayModel;
import com.bonus.canteen.core.allocation.api.AllocMetadataApi;
import com.bonus.canteen.core.common.constant.NuclearModeEnum;
import com.bonus.canteen.core.common.utils.LeCodeUtil;
import com.bonus.canteen.core.common.utils.LogUtil;
import com.bonus.canteen.core.order.utils.LeOrderUtil;
import com.bonus.canteen.core.pay.common.constants.PayChannelEnum;
import com.bonus.canteen.core.pay.common.constants.PayChannelSelectEnum;
import com.bonus.canteen.core.pay.common.constants.PayTypeEnum;
import com.bonus.canteen.core.pay.common.dto.PayChannelSplitDTO;
import com.bonus.canteen.core.pay.common.vo.PayChannelSelectDTO;
import com.bonus.canteen.core.pay.common.vo.PayChannelSelectOldVO;
import com.bonus.canteen.core.pay.common.vo.PayChannelSelectResultVO;
import com.bonus.canteen.core.pay.common.vo.PayChannelSplitVO;
import com.bonus.common.houqin.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/** @deprecated */
@Service
@Deprecated
public class PayChannelSelectService {
   private static final Logger log = LoggerFactory.getLogger(PayChannelSelectService.class);
   @Resource
   @Lazy
   protected AllocMetadataApi allocMetadataApi;
   @Deprecated
   public PayChannelSelectOldVO payChannelSelect(PayChannelSelectEnum selectType, AllocPayModel allocPayModel, PayChannelSelectDTO payChannelSelectDTO, PayChannelSelectResultVO resultVO) {
      LogUtil.info("[支付渠道判断]单渠道判断（兼容）", payChannelSelectDTO);
      PayChannelSelectOldVO oldVO = PayChannelSelectOldVO.of(payChannelSelectDTO);
      oldVO.setCouponId(resultVO.getCouponId());
      oldVO.setCustPayVO(resultVO.getCustPayVO());
      switch (selectType) {
         case DEVICE_CONSUME:
            this.deviceOnlineConsume(payChannelSelectDTO, allocPayModel, oldVO);
            break;
         case MOBILE_CONSUME:
            this.mobileConsume(payChannelSelectDTO, allocPayModel, oldVO);
            break;
         case DEVICE_RECHARGE:
            this.deviceRecharge(payChannelSelectDTO, allocPayModel, oldVO);
            break;
         case MOBILE_RECHARGE:
            this.mobileRecharge(payChannelSelectDTO, allocPayModel, oldVO);
            break;
         case DEVICE_QR_CODE:
            this.deviceQrCode(payChannelSelectDTO, allocPayModel, oldVO);
      }

      LogUtil.info("[支付渠道判断]单渠道判断结果（兼容）", oldVO);
      return oldVO;
   }

   @Deprecated
   protected void deviceOnlineConsume(PayChannelSelectDTO payChannelSelectDTO, AllocPayModel allocPayModel, PayChannelSelectOldVO resultVO) {
      if (NuclearModeEnum.NUCLEAR_MODE_QRCODE.getKey().equals(payChannelSelectDTO.getNuClearMode())) {
         String authCode = payChannelSelectDTO.getAuthCode();
         if (LeCodeUtil.isAliPayCode(authCode)) {
            resultVO.setPayType(PayTypeEnum.ALI_QRCODE.getKey());
            resultVO.setPayChannel(this.handleAlipayCodeChannel(allocPayModel));
         } else if (LeCodeUtil.isWechatPayCode(authCode)) {
            resultVO.setPayType(PayTypeEnum.WECHAT_QRCODE.getKey());
            resultVO.setPayChannel(this.handleWechatCodeChannel(allocPayModel));
         }

         if (LeCodeUtil.isICBCCode(authCode)) {
            resultVO.setPayType(PayTypeEnum.ICBC_PAY_CODE.getKey());
            resultVO.setPayChannel(PayChannelEnum.ICBC.getKey());
         } else if (LeCodeUtil.isECNYPayCode(authCode)) {
            resultVO.setPayType(PayTypeEnum.ABC_DCEP_CODE_PAY.getKey());
            if (allocPayModel.supportPayChannel(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibECNYPay())) {
               resultVO.setPayChannel(PayChannelEnum.CIB_PAY.getKey());
            } else {
               if (!allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) || !"1".equals(allocPayModel.getIfUseSzrcbECNY())) {
                  throw new ServiceException("暂不支持此二维码支付");
               }

               resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
            }
         } else if (LeCodeUtil.isUnionPayCode(authCode)) {
            resultVO.setPayType(PayTypeEnum.UNION_PAY_QRCODE.getKey());
            if (!allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) || !"1".equals(allocPayModel.getIfUseSzrcbUnionPay())) {
               throw new ServiceException("暂不支持此二维码支付");
            }

            resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
         }
      }

      this.checkRechargeConsumeTime(resultVO.getPayChannel(), allocPayModel);
   }
   @Deprecated
   protected void mobileConsume(PayChannelSelectDTO payChannelSelectDTO, AllocPayModel allocPayModel, PayChannelSelectOldVO resultVO) {
      Integer payType = payChannelSelectDTO.getPayType();
      if (PayTypeEnum.WECHAT_NATIVE.getKey().equals(payType)) {
         List<Integer> supportPayChannels = allocPayModel.supportPayChannels();
         if (supportPayChannels.contains(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.CIB_PAY.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.ICBC.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.CCB.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.FUIOU_PAY.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.NBCB.getKey());
         } else if (supportPayChannels.contains(PayChannelEnum.WX_RCB.getKey()) && "1".equals(allocPayModel.getIfUseWxrcbWechatAppPay())) {
            resultVO.setPayChannel(PayChannelEnum.WX_RCB.getKey());
         }
      } else if (PayTypeEnum.FUIOU_PAY_H5.getKey().equals(payType)) {
         resultVO.setPayChannel(PayChannelEnum.FUIOU_PAY.getKey());
      } else if (PayTypeEnum.TCRCB_PAY_H5.getKey().equals(payType)) {
         resultVO.setPayChannel(PayChannelEnum.TCRCB.getKey());
      } else if (PayTypeEnum.WX_RCB_NATIVE.getKey().equals(payType)) {
         resultVO.setPayChannel(PayChannelEnum.WX_RCB.getKey());
      }

      resultVO.setPayType(payType);
      this.checkRechargeConsumeTime(resultVO.getPayChannel(), allocPayModel);
   }

   @Deprecated
   protected void deviceRecharge(PayChannelSelectDTO payChannelSelectDTO, AllocPayModel allocPayModel, PayChannelSelectOldVO resultVO) {
      Integer payType = payChannelSelectDTO.getPayType();
      String authCode = payChannelSelectDTO.getAuthCode();
      if (PayTypeEnum.CASH_MACHINE.getKey().equals(payType)) {
         resultVO.setPayType(PayTypeEnum.CASH_MACHINE.getKey());
         resultVO.setPayChannel(PayChannelEnum.CASH.getKey());
      } else if (LeCodeUtil.isAliPayCode(authCode)) {
         resultVO.setPayType(PayTypeEnum.ALI_QRCODE.getKey());
         if (allocPayModel.supportPayChannel(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.ICBC.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.CIB_PAY.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.CCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.FUIOU_PAY.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.TCRCB.getKey()) && "1".equals(allocPayModel.getIfUseTcrcbAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.TCRCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.NBCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCmbAliPay())) {
            resultVO.setPayChannel(PayChannelEnum.CMB_PAY.getKey());
         }
      } else if (LeCodeUtil.isWechatPayCode(authCode)) {
         resultVO.setPayType(PayTypeEnum.WECHAT_QRCODE.getKey());
         if (allocPayModel.supportPayChannel(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.ICBC.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.CIB_PAY.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.CCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.FUIOU_PAY.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.TCRCB.getKey()) && "1".equals(allocPayModel.getIfUseTcrcbWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.TCRCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.NBCB.getKey());
         } else if (allocPayModel.supportPayChannel(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCmbWechatPay())) {
            resultVO.setPayChannel(PayChannelEnum.CMB_PAY.getKey());
         }
      } else if (LeCodeUtil.isECNYPayCode(authCode)) {
         resultVO.setPayType(PayTypeEnum.ABC_DCEP_CODE_PAY.getKey());
         if (!allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) || !"1".equals(allocPayModel.getIfUseSzrcbECNY())) {
            throw new ServiceException("暂不支持此二维码支付");
         }

         resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
      } else {
         if (!LeCodeUtil.isUnionPayCode(authCode)) {
            return;
         }

         resultVO.setPayType(PayTypeEnum.UNION_PAY_QRCODE.getKey());
         if (!allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) || !"1".equals(allocPayModel.getIfUseSzrcbUnionPay())) {
            throw new ServiceException("暂不支持此二维码支付");
         }

         resultVO.setPayChannel(PayChannelEnum.SZRCB.getKey());
      }

      if (!ObjectUtil.notEqual(PayChannelEnum.CASH.getKey(), resultVO.getPayChannel()) || allocPayModel.supportPayChannel(resultVO.getPayChannel())) {
         this.checkRechargeConsumeTime(resultVO.getPayChannel(), allocPayModel);
      }
   }

   @Deprecated
   protected void mobileRecharge(PayChannelSelectDTO payChannelSelectDTO, AllocPayModel allocPayModel, PayChannelSelectOldVO resultVO) {
      Integer payChannel = null;
      if (PayTypeEnum.WECHAT_NATIVE.getKey().equals(payChannelSelectDTO.getPayType())) {
         List<Integer> supportPayChannels = allocPayModel.supportPayChannels();
         if (supportPayChannels.contains(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCMBPayWeChatApp())) {
            payChannel = PayChannelEnum.CMB_PAY.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibWechatAppPay())) {
            payChannel = PayChannelEnum.CIB_PAY.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcWechatPay())) {
            payChannel = PayChannelEnum.ICBC.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbWechatAppPay())) {
            payChannel = PayChannelEnum.CCB.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbWechatAppPay())) {
            payChannel = PayChannelEnum.SZRCB.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouWechatAppPay())) {
            payChannel = PayChannelEnum.FUIOU_PAY.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbWechatAppPay())) {
            payChannel = PayChannelEnum.NBCB.getKey();
         } else if (supportPayChannels.contains(PayChannelEnum.WX_RCB.getKey()) && "1".equals(allocPayModel.getIfUseWxrcbWechatAppPay())) {
            payChannel = PayChannelEnum.WX_RCB.getKey();
         }
      } else if (PayTypeEnum.FUIOU_PAY_H5.getKey().equals(payChannelSelectDTO.getPayType())) {
         payChannel = PayChannelEnum.FUIOU_PAY.getKey();
      } else if (PayTypeEnum.TCRCB_PAY_H5.getKey().equals(payChannelSelectDTO.getPayType())) {
         payChannel = PayChannelEnum.TCRCB.getKey();
      } else {
         if (!PayTypeEnum.WX_RCB_NATIVE.getKey().equals(payChannelSelectDTO.getPayType())) {
            throw new ServiceException("暂不支持此支付方式");
         }

         payChannel = PayChannelEnum.WX_RCB.getKey();
      }

      resultVO.setPayType(payChannelSelectDTO.getPayType());
      resultVO.setPayChannel(payChannel);
      this.checkRechargeConsumeTime(resultVO.getPayChannel(), allocPayModel);
   }

   @Deprecated
   protected void deviceQrCode(PayChannelSelectDTO payChannelSelectDTO, AllocPayModel allocPayModel, PayChannelSelectOldVO resultVO) {
      if (allocPayModel.supportPayChannel(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfCMBMacCreatePayCode())) {
         resultVO.setPayType(PayTypeEnum.CMB_PAY_CODE.getKey());
         resultVO.setPayChannel(PayChannelEnum.CMB_PAY.getKey());
         this.checkRechargeConsumeTime(resultVO.getPayChannel(), allocPayModel);
      } else {
         throw new ServiceException("暂不支持此二维码支付");
      }
   }

   protected Integer handleAlipayCodeChannel(AllocPayModel allocPayModel) {
      if (allocPayModel.supportPayChannel(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcAliPay())) {
         return PayChannelEnum.ICBC.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibAliPay())) {
         return PayChannelEnum.CIB_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCmbAliPay())) {
         return PayChannelEnum.CMB_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbAliPay())) {
         return PayChannelEnum.CCB.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbAliPay())) {
         return PayChannelEnum.SZRCB.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouAliPay())) {
         return PayChannelEnum.FUIOU_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.TCRCB.getKey()) && "1".equals(allocPayModel.getIfUseTcrcbAliPay())) {
         return PayChannelEnum.TCRCB.getKey();
      } else {
         return allocPayModel.supportPayChannel(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbAliPay()) ? PayChannelEnum.NBCB.getKey() : null;
      }
   }

   protected Integer handleWechatCodeChannel(AllocPayModel allocPayModel) {
      if (allocPayModel.supportPayChannel(PayChannelEnum.ICBC.getKey()) && "1".equals(allocPayModel.getIfUseIcbcWechatPay())) {
         return PayChannelEnum.ICBC.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CIB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCibWechatPay())) {
         return PayChannelEnum.CIB_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CMB_PAY.getKey()) && "1".equals(allocPayModel.getIfUseCmbWechatPay())) {
         return PayChannelEnum.CMB_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.CCB.getKey()) && "1".equals(allocPayModel.getIfUseCcbWechatPay())) {
         return PayChannelEnum.CCB.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.SZRCB.getKey()) && "1".equals(allocPayModel.getIfUseSzrcbWechatPay())) {
         return PayChannelEnum.SZRCB.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.FUIOU_PAY.getKey()) && "1".equals(allocPayModel.getIfUseFuiouWechatPay())) {
         return PayChannelEnum.FUIOU_PAY.getKey();
      } else if (allocPayModel.supportPayChannel(PayChannelEnum.TCRCB.getKey()) && "1".equals(allocPayModel.getIfUseTcrcbWechatPay())) {
         return PayChannelEnum.TCRCB.getKey();
      } else {
         return allocPayModel.supportPayChannel(PayChannelEnum.NBCB.getKey()) && "1".equals(allocPayModel.getIfUseNbcbWechatPay()) ? PayChannelEnum.NBCB.getKey() : null;
      }
   }
   protected void checkRechargeConsumeTime(Integer payChannel, AllocPayModel allocPayModel) {
      String startTimeStr = null;
      String endTimeStr = null;
      if (PayChannelEnum.ABC.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getAbcRchrgConStartTime();
         endTimeStr = allocPayModel.getAbcRchrgConEndTime();
      } else if (PayChannelEnum.ICBC.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getIcbcRchrgConStartTime();
         endTimeStr = allocPayModel.getIcbcRchrgConEndTime();
      } else if (PayChannelEnum.CMB_PAY.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getCmbRchrgConStartTime();
         endTimeStr = allocPayModel.getCmbRchrgConEndTime();
      } else if (PayChannelEnum.ECITIC_PAY.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getEciticRchrgConStartTime();
         endTimeStr = allocPayModel.getEciticRchrgConEndTime();
      } else if (PayChannelEnum.CCB.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getCcbRchrgConStartTime();
         endTimeStr = allocPayModel.getCcbRchrgConEndTime();
      } else if (PayChannelEnum.CIB_PAY.getKey().equals(payChannel)) {
         startTimeStr = allocPayModel.getCibRchrgConStartTime();
         endTimeStr = allocPayModel.getCibRchrgConEndTime();
      }

      if (!LeOrderUtil.checkNowTimeWithin(startTimeStr, endTimeStr)) {
         throw new ServiceException("当前时间不支持此支付方式");
      }
   }

   @Deprecated
   public List<PayChannelSplitVO> splitChannelDetails(PayChannelSplitDTO param) {
      log.info("[渠道支付拆分]参数：{}", param);
      List<PayChannelSplitVO> results = CollUtil.newArrayList(new PayChannelSplitVO[0]);
      if (CharSequenceUtil.isNotBlank(param.getCouponId()) && !PayTypeEnum.COUPON.getKey().equals(param.getPayType())) {
         results.add(PayChannelSplitVO.of(PayTypeEnum.COUPON.getKey(), PayChannelEnum.COUPON.getKey()));
      }

      if (!PayChannelEnum.MIXTURE.getKey().equals(param.getPayChannel())) {
         results.add(PayChannelSplitVO.of(param.getPayType(), param.getPayChannel()));
      } else {
         results.add(PayChannelSplitVO.of(PayTypeEnum.MEAL_CARD.getKey(), PayChannelEnum.ACC.getKey()));
         Integer payType = param.getPayType();
         Integer payChannel = null;
         AllocPayModel allocPayModel;
         if (PayTypeEnum.isAlipayChannel(param.getPayType())) {
            payChannel = PayChannelEnum.ALI.getKey();
            if (PayTypeEnum.MIXTURE_PAY_ALI_QRCODE.getKey().equals(payType)) {
               payType = PayTypeEnum.ALI_QRCODE.getKey();
               allocPayModel = this.allocMetadataApi.payApi().queryAvailablePayModel(param.getCanteenId());
               payChannel = this.handleAlipayCodeChannel(allocPayModel);
            } else if (PayTypeEnum.MIXTURE_PAY_ALI_NATIVE.getKey().equals(payType)) {
               payType = PayTypeEnum.ALI_NATIVE.getKey();
            }
         } else if (PayTypeEnum.isWechatChannel(param.getPayType())) {
            payChannel = PayChannelEnum.WECHAT.getKey();
            if (PayTypeEnum.MIXTURE_PAY_WECHAT_QRCODE.getKey().equals(payType)) {
               payType = PayTypeEnum.WECHAT_QRCODE.getKey();
               allocPayModel = this.allocMetadataApi.payApi().queryAvailablePayModel(param.getCanteenId());
               payChannel = this.handleWechatCodeChannel(allocPayModel);
            } else if (PayTypeEnum.MIXTURE_PAY_WECHAT_NATIVE.getKey().equals(payType)) {
               payType = PayTypeEnum.WECHAT_NATIVE.getKey();
            }
         } else if (PayTypeEnum.ACC_BNJ_PAY.getKey().equals(param.getPayType())) {
            payChannel = PayChannelEnum.BNJ.getKey();
         } else {
            log.warn("[渠道支付拆分]不支持的支付类型：{}", param.getPayType());
         }

         if (payChannel != null) {
            results.add(PayChannelSplitVO.of(payType, payChannel));
         }
      }

      log.info("[渠道支付拆分]结果：{}", results);
      return results;
   }
}
