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.TrdBizInfoVo;
import org.springframework.stereotype.Service;

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

        TrdBizInfoVo trdbiz = (TrdBizInfoVo) cfabop.getRec();

        //依据报送类型 进行报送要素提取
        switch (cfatyp)
        {
            case "ECA":
                CfaecaBizInfo cfaecaBizInfo = cfabop.getCfaeca().getCfaecaBizInfo();
                cfaecaBizInfo.setFinownref(trdbiz.getOwnref());
                cfaecaBizInfo.setStttendat(trdbiz.getStttendat());
                cfaecaBizInfo.setMatdat(trdbiz.getMatdat());
                cfaecaBizInfo.setCfarat(trdbiz.getCfarat());
                cfaecaBizInfo.setFincod(trdbiz.getFincod());
                cfaecaBizInfo.setFinamt(trdbiz.getFinbckamt());
                cfaecaBizInfo.setIntamt(trdbiz.getIntamt());
                cfaecaBizInfo.setTotint(trdbiz.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(trdbiz.getDftcreVo().getDfdgrp().getRec().getOwnref());
                cfaeadBizInfo.setMatdat(trdbiz.getDftcreVo().getDfdgrp().getRec().getMatdat());
                cfaeadBizInfo.setStttendat(trdbiz.getDftcreVo().getDfdgrp().getRec().getStttendat());
                cfaeadBizInfo.setActrat(trdbiz.getDftcreVo().getDfdgrp().getRec().getActrat());
                cfaeadBizInfo.setFlttyp(trdbiz.getDftcreVo().getDfdgrp().getRec().getFlttyp());
                cfaeadBizInfo.setBankcn(trdbiz.getDftcreVo().getDfdgrp().getRec().getBankcn());
                cfaeadBizInfo.setRescur(trdbiz.getDftcreVo().getDfdgrp().getRec().getRescur());
                cfaeadBizInfo.setResamt(trdbiz.getDftcreVo().getDfdgrp().getRec().getResamt());
                cfaeadBizInfo.setMaxcur(trdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getCur());
                cfaeadBizInfo.setMaxamt(trdbiz.getDftcreVo().getDfdgrp().getCbs().getMax().getAmt());
                cfaeadBizInfo.setDff(trdbiz.getDftcreVo().getDfdgrp().getDff());
                break;
            default:
                break;
        }
    }
}
