package com.brilliance.isc.common.register.document.common;

import com.brilliance.isc.common.register.document.IDocumentRegister;
import com.brilliance.isc.common.trndoc.service.TrndocService;
import com.brilliance.isc.common.trndoc.vo.TrndocVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 收支申报注册面函
 */
@Component
public class BopmodDocumentRegister implements IDocumentRegister {

    @Autowired
    private TrndocService trndocService;

    @Override
    public void registerDocument(TrndocVo trndoc) {
        if(MdaUtils.isEmpty(trndoc.getBoptyp())){
            return;
        }
        //确定角色
        String rol = "";
        String name = Strings.mid(trndoc.getRec().getObjtyp(),1,2).toUpperCase();
        //涉外境内收入申报单
        if("DBA".equals(trndoc.getBoptyp()) || "DBD".equals(trndoc.getBoptyp())){
            switch (name){
                case "BO":
                    rol = "DRR";
                    break;
                case "BE":
                    rol = "BEN";
                    break;
                case "GE":
                case "GC":
                case "NE":
                case "NC":
                    rol = "BEN";
                    break;
                case "CC":
                    rol = "PRE";
                    break;
                case "BT":
                    rol = "BE1";
                    break;
                case "BP":
                    rol = "FIA";
                    break;
                case "CP":
                    rol = "PYE";
                    break;
                default:
                    break;
            }
        }
        //境外境内汇款
        if("DBB".equals(trndoc.getBoptyp()) || "DBE".equals(trndoc.getBoptyp())){
            rol = "OCR";
        }
        //对外付款境内付款承兑
        if("DBC".equals(trndoc.getBoptyp()) || "DBF".equals(trndoc.getBoptyp())){
            switch (name){
                case "BC":
                    rol = "DRE";
                    break;
                case "BR":
                case "GI":
                case "NI":
                case "GC":
                case "NC":
                    rol = "APL";
                    break;
                default:
                    break;
            }
        }
        switch (trndoc.getBoptyp()){
            case "DBA":
                trndocService.defDocEot(trndoc,"TRN", rol+"6", "BOPGATL1", "LET", 0, "", "", "涉外收入申报单", rol, "");
                break;
            case "DBD":
                trndocService.defDocEot(trndoc,"TRN", rol+"8", "BOPIMPL1", "LET", 0, "", "", "境内收入申报单", rol, "");
                break;
            case "DBB":
                trndocService.defDocEot(trndoc,"TRN", rol+"2", "BOPCPOL2", "LET", 0, "", "", "境外汇款申请书", rol, "");
                break;
            case "DBE":
                trndocService.defDocEot(trndoc,"TRN", rol+"2", "BOPCPOL1", "LET", 0, "", "", "境内汇款申请书", rol, "");
                break;
            case "DBC":
                trndocService.defDocEot(trndoc,"TRN", rol+"6", "BOPPAYL1", "LET", 0, "", "", "对外付款/承兑通知书(完整版)", rol, "");
                trndocService.defDocEot(trndoc,"TRN", rol+"7", "BOPPAYL2", "LET", 0, "", "", "对外付款/承兑通知书(补充版)", rol, "");
                break;
            case "DBF":
                trndocService.defDocEot(trndoc,"TRN", rol+"8", "BOPJINL1", "LET", 0, "", "", "境内付款/承兑通知书(完整版)", rol, "");
                trndocService.defDocEot(trndoc,"TRN", rol+"9", "BOPJINL2", "LET", 0, "", "", "境内付款/承兑通知书(补充版)", rol, "");
                break;
            default:
                break;
        }
    }
}
