package com.brilliance.isc.common.dftcre.service.impl;

import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Strings;
import com.brilliance.isc.bo.Pta;
import com.brilliance.isc.bo.model.Dfdgrp;
import com.brilliance.isc.common.cache.pta.PtaCacheService;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.dftcre.service.DftpService;
import com.brilliance.isc.vo.model.DfdgrpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DftpServiceImpl implements DftpService {

    @Autowired
    private PtaCacheService ptaCacheService;

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    /**
     *   source:dftp.0014.script
     */
    public void defaultDfdgrpRecIntprd(Dfdgrp dfdgrp){
        /**
         if GetFramename == "DFTOPN" or GetFramename == "DFTADV" or GetFramename == "BRTSET" or GetFramename == "BCTSET" or GetFramename == "TRTOPN" or GetFramename == "BDTSET" then

         **/
        String transName = SettleContext.getDirectTransName();
        if( MdaUtils.compareTo(SettleContext.getTransName(),"DFTOPN") == 0
                || MdaUtils.compareTo(transName,"DFTADV") == 0
                || MdaUtils.compareTo(transName,"BRTSET") == 0
                || MdaUtils.compareTo(transName,"BCTSET") == 0
                || MdaUtils.compareTo(transName,"TRTOPN") == 0
                || MdaUtils.compareTo(transName,"BDTSET") == 0
                || MdaUtils.compareTo(transName,"CPTOPN") == 0
                || MdaUtils.compareTo(transName,"CPTATO") == 0 ) {
            if(!dfdgrp.getRec().isModified("intprd")) {
                dfdgrp.getRec().setIntprd("1");
            }
        }
    }

    /**
     *   source:dftp.0015.script
     */
    public void defaultDfdgrpRecOwnusr(Dfdgrp dfdgrp){
        if(MdaUtils.isEmpty(dfdgrp.getRec().getOwnusr()) ) {
            dfdgrp.getRec().setOwnusr(SettleContext.getUserSession().getUsr().getExtkey());
        }
    }

    /**
     *   source:dftp.0021.script
     */
    public void defaultDfdgrpRecFlttyp(Dfdgrp dfdgrp){
        if(!dfdgrp.getRec().isModified("flttyp")) {
            dfdgrp.getRec().setFlttyp("3");
        }
    }

    /**
     *   source:dftp.0022.script
     *//*
    @Default(target="msgtyp",order=1000)
    public boolean defaultMsgtypN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.compareTo(ctx.getTransName(),"DFTMSG") == 0 || MdaUtils.compareTo(ctx.getTransName(),"DFTSET") == 0 )
        {
            if( MdaUtils.compareTo(this.getDfdgrp().getCbs().getMax().getCur(),"CNY") == 0 )
            {
                *//**
                 SetValues( MSGTYP, "CMT" + CR + "HVQ" + CR + "OTH" )

                 **//*
                Systems.setValues(this,"msgtyp","OTH");
                if( MdaUtils.compareTo(ctx.getTransName(),"DFTMSG") == 0 && MdaUtils.compareTo(this.getDfdgrp().getRec().getDfuflg(),"2") == 0 )
                {
                    *//**
                     SetValues( MSGTYP, "CMT" + CR + "HVQ" + CR + "OTH" + CR + "CIV" )

                     **//*
                    Systems.setValues(this,"msgtyp","OTH" + CR + "CIV");
                }
            }
            else
            {
                //外币切境内代付的情况下，可出境内外币
                if( MdaUtils.compareTo(this.getDfdgrp().getRec().getDfuflg(),"2") == 0 )
                {
                    Systems.setValues(this,"msgtyp","202" + CR + "OTH");
                }
                else
                {
                    Systems.setValues(this,"msgtyp","111" + CR + "100" + CR + "202" + CR + "OTH");
                }
                Systems.setEnabled(this,"msgtyp");
            }
        }
        else
        {
            this.setMsgtyp(NULLSTR);
            Systems.resetEnabled(this,"msgtyp");
        }
        if( MdaUtils.compareTo(ctx.getTransName(),"DFTSET") == 0 && MdaUtils.compareTo(this.getDfdgrp().getRec().getFintyp(),"A") == 0 )
        {
            this.setMsgtyp(NULLSTR);
            Systems.resetEnabled(this,"msgtyp");
        }
        if( MdaUtils.compareTo(this.getDfdgrp().getRec().getTrntyp(),"CP") == 0 )
        {
            this.setMsgtyp(NULLSTR);
            Systems.resetEnabled(this,"msgtyp");
        }
        if( MdaUtils.compareTo(ctx.getTransName(),"DFTSET") == 0 )
        {
            if( MdaUtils.compareTo(this.getDfdgrp().getCbs().getMax().getCur(),"CNY") == 0 )
            {
                this.setMsgtyp(NULLSTR);
                Systems.resetEnabled(this,"msgtyp");
            }
        }
        String msgcur = NULLSTR;
        int ignore = 0;
        if( MdaUtils.compareTo(ctx.getTransName(),"DFTMSG") == 0 )
        {
            msgcur = Datas.getContent(this,"\\SETMOD\\DOCCUR");
            ignore = ctx.getErrorCode();
            if( MdaUtils.compareTo(msgcur,"CNY") == 0 )
            {
                Systems.setVisible(this,"msgtyp");
                Systems.setVisible(this,"msgflg");
                Systems.resetEnabled(this,"msgtyp");
                if( MdaUtils.compareTo(this.getDfdgrp().getRec().getFintyp(),"A") == 0 )
                {
                    Systems.resetEnabled(this,"baowflg");
                    Systems.resetEnabled(this,"msgtyp");
                }
                if( MdaUtils.compareTo(this.getDfdgrp().getRec().getDfuflg(),"2") == 0 )
                {
                    Systems.setEnabled(this,"baowflg");
                }
                else
                {
                    Systems.resetEnabled(this,"baowflg");
                }
            }
            else
            {
                Systems.setVisible(this,"msgtyp");
                Systems.setVisible(this,"msgflg");
                Systems.setEnabled(this,"msgtyp");
            }
        }


        return true;
    }

    *//**
     *   source:dftp.0024.script
     *//*
    @Default(target="atd.xnggbh",order=1000)
    public boolean defaultAtdXnggbhN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.isEmpty(this.getAtd().getXnggbh()) && ! Systems.isModified(this.getAtd(),"xnggbh") )
        {
            this.getAtd().setXnggbh(  "NORREF");
        }


        return true;
    }

    *//**
     *   source:dftp.0025.script
     *//*
    @Default(target="resbch",order=1000)
    public boolean defaultResbchN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.isEmpty(this.getResbchnam()) )
        {
            this.setResbch(NULLSTR);
        }


        return true;
    }

    *//**
     *   source:dftp.0030.script
     *//*
    @Default(target="commetlab",order=1000)
    public boolean defaultCommetlabN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.compareTo(Platform.getzmqflg(),"X") == 0 )
        {
            Systems.setVisible(this,"commetlab");
            this.setCommetlab(  "自贸区备注");
        }
        else
        {
            Systems.resetVisible(this,"commetlab");
        }


        return true;
    }

    *//**
     *   source:dftp.0031.script
     *//*
    @Default(target="comsystbl",order=1000)
    public boolean defaultComsystblN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.compareTo(Platform.getzmqflg(),"X") == 0 )
        {
            Systems.setVisible(this,"comsystbl");
            Systems.setValues(this,"comsystbl","1" + CR + "2" + CR + "3" + CR + "4");
        }
        else
        {
            Systems.resetVisible(this,"comsystbl");
        }


        return true;
    }

    *//**
     *   source:dftp.0032.script
     *//*
    @Default(target="commet",order=1000)
    public boolean defaultCommetN1000(){
        IContext ctx = MdaEnv.getContext();

        if( MdaUtils.compareTo(Platform.getzmqflg(),"X") == 0 )
        {
            if( ! Systems.isModified(this,"commet") )
            {
                this.setCommet(NULLSTR);
                if( ! MdaUtils.isEmpty(this.getComsystbl()) )
                {
                    this.setCommet(  Codetables.getCodetableLabelOfTd(this.getComsystbl(),"COMTBL",Systems.getLang()));
                }
            }
        }


        return true;
    }

    *//**
     *   source:dftp.0033.script
     *//*
    @Default(target="updsta",order=1000)
    public boolean defaultUpdstaN1000(){
        IContext ctx = MdaEnv.getContext();

        Systems.resetEnabled(this,"updsta");
        Systems.resetVisible(this,"updsta");
        if( MdaUtils.compareTo(ctx.getTransName(),"DFTMSG") == 0 || MdaUtils.compareTo(ctx.getTransName(),"DFTSET") == 0 )
        {
            Systems.setVisible(this,"updsta");
            if( MdaUtils.isEmpty(this.getResbch()) )
            {
                this.setUpdsta(NULLSTR);
            }
        }


        return true;
    }

    *//**
     *   source:dftp.0037.script
     *//*
    @Default(value={"orcnam","orcadr","pyenam","pyeadr"},order=1000)
    public boolean defaultDefaultByUpdstaN1000(){
        IContext ctx = MdaEnv.getContext();

        Systems.resetEnabled(this,"orcnam");
        Systems.resetEnabled(this,"orcadr");
        Systems.resetEnabled(this,"pyenam");
        Systems.resetEnabled(this,"pyeadr");
        Systems.resetVisible(this,"orcnam");
        Systems.resetVisible(this,"orcadr");
        Systems.resetVisible(this,"pyenam");
        Systems.resetVisible(this,"pyeadr");
        if( MdaUtils.compareTo(this.getUpdsta(),"1") == 0 )
        {
            Systems.setVisible(this,"orcnam");
            Systems.setVisible(this,"orcadr");
            Systems.setVisible(this,"pyenam");
            Systems.setVisible(this,"pyeadr");
            Systems.setEnabled(this,"orcnam");
            Systems.setEnabled(this,"orcadr");
            Systems.setEnabled(this,"pyenam");
            Systems.setEnabled(this,"pyeadr");
        }


        return true;
    }*/

}
