package com.brilliance.isc.common.bop.cfa.cfabop.register.impl;

import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.bo.model.Cfabop;
import com.brilliance.isc.bo.model.CfaeadBizInfo;
import com.brilliance.isc.bo.model.CfaeafBizInfo;
import com.brilliance.isc.bo.model.CfaecaBizInfo;
import com.brilliance.isc.common.bop.cfa.cfabop.register.CfabopRegister;
import com.brilliance.isc.vo.lc.BrdBizInfoVo;
import org.springframework.stereotype.Service;

@Service("brd.cfabopRegister")
public class BrdCfabopRegisterImpl implements CfabopRegister {
    @Override
    public void registerCfabopBizInfo(Cfabop cfabop, String cfatyp) {
        if(MdaUtils.isEmpty(cfatyp)){
            cspsLogger.warn("报送类型为空，组数结束!");
            return;
        }

        BrdBizInfoVo brdbiz = (BrdBizInfoVo) cfabop.getRec();

        //依据报送类型 进行报送要素提取
        switch (cfatyp)
        {
            case "ECA":
                CfaecaBizInfo cfaecaBizInfo = cfabop.getCfaeca().getCfaecaBizInfo();
                cfaecaBizInfo.setFinownref(brdbiz.getTrtcreVo().getTrdgrp().getRec().getOwnref());
                cfaecaBizInfo.setStttendat(brdbiz.getTrtcreVo().getTrdgrp().getRec().getOpndat());
                cfaecaBizInfo.setMatdat(brdbiz.getTrtcreVo().getTrdgrp().getRec().getMatdat());
                cfaecaBizInfo.setCfarat(brdbiz.getTrtcreVo().getTrdgrp().getRec().getActrat());
                cfaecaBizInfo.setFincod(brdbiz.getTrtcreVo().getFinmod().getFincod());
                cfaecaBizInfo.setFinamt(brdbiz.getTrtcreVo().getFinmod().getCbs().getCbe().getAmt());
                cfaecaBizInfo.setIntamt(brdbiz.getTrtcreVo().getFinmod().getIntamt());
                cfaecaBizInfo.setTotint(brdbiz.getTrtcreVo().getFinmod().getCbs().getTotint());
                cfaecaBizInfo.setMaxcur(brdbiz.getTrtcreVo().getTrdgrp().getCbs().getMax().getCur());
                cfaecaBizInfo.setMaxamt(brdbiz.getTrtcreVo().getTrdgrp().getCbs().getMax().getAmt());
                break;
            case "EAD":
                CfaeadBizInfo cfaeadBizInfo = cfabop.getCfaead().getCfaeadBizInfo();
                cfaeadBizInfo.setDfdownref(brdbiz.getDftcreVo().getDfdgrp().getRec().getOwnref());
                cfaeadBizInfo.setMatdat(brdbiz.getDftcreVo().getDfdgrp().getRec().getMatdat());
                cfaeadBizInfo.setStttendat(brdbiz.getDftcreVo().getDfdgrp().getRec().getStttendat());
                cfaeadBizInfo.setActrat(brdbiz.getDftcreVo().getDfdgrp().getRec().getActrat());
                cfaeadBizInfo.setFlttyp(brdbiz.getDftcreVo().getDfdgrp().getRec().getFlttyp());
                cfaeadBizInfo.setBankcn(brdbiz.getDftcreVo().getDfdgrp().getRec().getBankcn());
                cfaeadBizInfo.setRescur(brdbiz.getDftcreVo().getDfdgrp().getRec().getRescur());
                cfaeadBizInfo.setResamt(brdbiz.getDftcreVo().getDfdgrp().getRec().getResamt());
                cfaeadBizInfo.setMaxcur(brdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getCur());
                cfaeadBizInfo.setMaxamt(brdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getAmt());
                cfaeadBizInfo.setBrdownref(brdbiz.getOwnref());
                cfaeadBizInfo.setDff(brdbiz.getDftcreVo().getDfdgrp().getDff());
                break;
            case "EAF":
                CfaeafBizInfo cfaeafBizInfo = cfabop.getCfaeaf().getCfaeafBizInfo();
                cfaeafBizInfo.setBrdownref(brdbiz.getOwnref());
                cfaeafBizInfo.setDoccur(brdbiz.getDoccur());
                cfaeafBizInfo.setDocamt(brdbiz.getDocamt());
                cfaeafBizInfo.setMaturity(brdbiz.getMatdat());
                cfaeafBizInfo.setAvbby(brdbiz.getAvbby());
                Cbb maxcbb = (Cbb)cfabop.getCbsMap().get("MAX");
                if(!MdaUtils.isEmpty(maxcbb)){
                    cfaeafBizInfo.setMaxcur(maxcbb.getCur());
                    cfaeafBizInfo.setMaxamt(maxcbb.getAmt());
                }
                break;
            default:
                break;
        }
    }
}
