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.CfaecaBizInfo;
import com.brilliance.isc.common.bop.cfa.cfabop.register.CfabopRegister;
import com.brilliance.isc.vo.finance.BpdBizInfoVo;
import org.springframework.stereotype.Service;

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

        BpdBizInfoVo bpdbiz = (BpdBizInfoVo) cfabop.getRec();

        //依据报送类型 进行报送要素提取
        switch (cfatyp)
        {
            case "ECA":
                CfaecaBizInfo cfaecaBizInfo = cfabop.getCfaeca().getCfaecaBizInfo();
                cfaecaBizInfo.setFinownref(bpdbiz.getOwnref());
                cfaecaBizInfo.setStttendat(bpdbiz.getOpndat());
                cfaecaBizInfo.setMatdat(bpdbiz.getMatdat());
                cfaecaBizInfo.setCfarat(bpdbiz.getCfarat());
                cfaecaBizInfo.setFincod(bpdbiz.getFincod());
                cfaecaBizInfo.setFinamt(bpdbiz.getFinbckamt());
                cfaecaBizInfo.setIntamt(bpdbiz.getIntamt());
                cfaecaBizInfo.setTotint(bpdbiz.getTotint());
                Cbb maxcbb = (Cbb)cfabop.getCbsMap().get("MAX");
                if(!MdaUtils.isEmpty(maxcbb)){
                    cfaecaBizInfo.setMaxcur(maxcbb.getCur());
                    cfaecaBizInfo.setMaxamt(maxcbb.getAmt());
                }

                break;
            case "EAD":
                CfaeadBizInfo cfaeadBizInfo = cfabop.getCfaead().getCfaeadBizInfo();
                cfaeadBizInfo.setDfdownref(bpdbiz.getDftcreVo().getDfdgrp().getRec().getOwnref());
                cfaeadBizInfo.setMatdat(bpdbiz.getDftcreVo().getDfdgrp().getRec().getMatdat());
                cfaeadBizInfo.setStttendat(bpdbiz.getDftcreVo().getDfdgrp().getRec().getStttendat());
                cfaeadBizInfo.setActrat(bpdbiz.getDftcreVo().getDfdgrp().getRec().getActrat());
                cfaeadBizInfo.setFlttyp(bpdbiz.getDftcreVo().getDfdgrp().getRec().getFlttyp());
                cfaeadBizInfo.setBankcn(bpdbiz.getDftcreVo().getDfdgrp().getRec().getBankcn());
                cfaeadBizInfo.setRescur(bpdbiz.getDftcreVo().getDfdgrp().getRec().getRescur());
                cfaeadBizInfo.setResamt(bpdbiz.getDftcreVo().getDfdgrp().getRec().getResamt());
                cfaeadBizInfo.setMaxcur(bpdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getCur());
                cfaeadBizInfo.setMaxamt(bpdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getAmt());
                cfaeadBizInfo.setDff(bpdbiz.getDftcreVo().getDfdgrp().getDff());
                break;
            default:
                break;
        }
    }
}
