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

import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.register.diasav.IDiasavRegister;
import com.brilliance.isc.common.trndia.service.TrndiaService;
import com.brilliance.isc.common.trndia.vo.TrndiaVo;
import com.brilliance.isc.common.vo.SimpleModuleVo;
import com.brilliance.isc.vo.component.trtcre.TrtcreVo;
import com.brilliance.mda.runtime.mda.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.brilliance.mda.runtime.mda.Constants.DiaToWrite;

@Component
public class TrtcreDiasavRegister implements IDiasavRegister {

    @Autowired
    private TrndiaService trndiaService;

    @Override
    public void diasav(TrndiaVo trndia) {
        TrtcreVo trtcreVo = trndia.getRec().getTrtcreVo();
        if (trtcreVo != null && "X".equals(trtcreVo.getCrefinflg())) {
            String fintyp = trtcreVo.getTrdgrp().getRec().getFintyp();
            String inifrm = Strings.mid(SettleContext.getTransName(),1,2);
            SimpleModuleVo linkModule = SimpleModuleVo.buildModule(trtcreVo.getTrdgrp().getRec().getInr(), "TRD");
            switch(inifrm) {
                case "DI":
                case "DE":
                case "BD":
                case "BF":
                    trndiaService.trnDiaSet(trndia,"TRTDUE", trtcreVo.getTrdgrp().getRec().getMatdat(), "PSD", Strings.getText("国内信用证买方押汇到期提示:$1",trtcreVo.getTrdgrp().getRec().getOwnref()), "TRTSET", DiaToWrite, linkModule, trtcreVo.getTrdgrp().getRec().getOwnref());
                    break;
                default:
                    switch(fintyp) {
                        case "BRF":
                            fintyp = "进口信用证押汇";
                            break;
                        case "LOA":
                            fintyp = "汇出汇款押汇";
                            break;
                        case "PCL":
                            fintyp = "打包贷款";
                            break;
                        case "BEL":
                            fintyp = "Export Loan";
                            break;
                        case "BCF":
                            fintyp = "进口代收押汇";
                            break;
                        case "ICF":
                            fintyp = "Import Remi. Loan";
                            break;
                        case "ECF":
                            fintyp = "汇出汇款押汇";
                            break;
                        case "DRF":
                            fintyp = "买方押汇";
                            break;
                        default:
                            fintyp = "押汇";
                    }
                    trndiaService.trnDiaSet(trndia,"TRTDUE", trtcreVo.getTrdgrp().getRec().getMatdat(), "PSD", Strings.getText("$2到期提示:$1", trtcreVo.getTrdgrp().getRec().getOwnref(), fintyp), "TRTSET", DiaToWrite, linkModule, trtcreVo.getTrdgrp().getRec().getOwnref());
            }
        }
    }
}
