package com.brilliance.isc.doc.handle.impl.bopmod;

import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.isc.bo.bop.bopprint.BopTrnBo;
import com.brilliance.isc.bo.model.Bopgat;
import com.brilliance.isc.bo.model.Boppay;
import com.brilliance.isc.bo.model.Boprem;
import com.brilliance.isc.common.bopset.service.IBopPrintService;
import com.brilliance.isc.common.codetable.service.CodetableService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

@Component
public class BuildBopmodLetter {

    @Resource(name = "dba.print")
    private IBopPrintService dbaprintService;

    @Resource(name = "dbd.print")
    private IBopPrintService dbdprintService;

    @Resource(name = "dbb.print")
    private IBopPrintService dbbprintService;

    @Resource(name = "dbe.print")
    private IBopPrintService dbeprintService;

    @Resource(name = "dbc.print")
    private IBopPrintService dbcprintService;

    @Resource(name = "dbf.print")
    private IBopPrintService dbfprintService;





    //涉外/境内收入申报单
    public Map<String, Object> buildBopgat(Bopgat bopgat) {
        bopgat.reset();
        Map<String, Object> map = new HashMap<>();
        //获取收付汇日期
        Date paydat = Dates.today();
        if(!MdaUtils.isEmpty(bopgat.getCtlmod().getDbl().getReldat())){
            paydat = bopgat.getCtlmod().getDbl().getReldat();
        }
        //打印组数
        if("1".equals(bopgat.getSzflg())){
            map = dbaprintService.getInputMapData(bopgat.getDbagrp(),paydat,bopgat.getAloneflg());
        }else if("2".equals(bopgat.getSzflg())){
            map = dbdprintService.getInputMapData(bopgat.getDbdgrp(),paydat,bopgat.getAloneflg());
        }

        return map;
    }

    //境外/境内汇款申请书
    public Map<String, Object> buildBoprem(Boprem boprem) {
        boprem.reset();
        Map<String, Object> map = new HashMap<>();
        //获取收付汇日期
        Date paydat = Dates.today();
        if(!MdaUtils.isEmpty(boprem.getCtlmod().getDbl().getReldat())){
            paydat = boprem.getCtlmod().getDbl().getReldat();
        }
        //打印组数
        if("1".equals(boprem.getSzflg())){
            map = dbbprintService.getInputMapData(boprem.getDbbgrp(),paydat,boprem.getAloneflg());
        }else if("2".equals(boprem.getSzflg())){
            map = dbeprintService.getInputMapData(boprem.getDbegrp(),paydat,boprem.getAloneflg());
        }

        return map;
    }

    //对外/境内付款承兑通知书
    public Map<String, Object> buildBoppay(Boppay boppay) {
        boppay.reset();
        Map<String, Object> map = new HashMap<>();
        //获取收付汇日期
        Date paydat = Dates.today();
        if(!MdaUtils.isEmpty(boppay.getCtlmod().getDbl().getReldat())){
            paydat = boppay.getCtlmod().getDbl().getReldat();
        }
        //打印组数
        if("1".equals(boppay.getSzflg())){
            map = dbcprintService.getInputMapData(boppay.getDbcgrp(),paydat,boppay.getAloneflg());
        }else if("2".equals(boppay.getSzflg())){
            map = dbfprintService.getInputMapData(boppay.getDbfgrp(),paydat,boppay.getAloneflg());
        }
        return map;
    }

    //补充交易信息打印
    public Map<String, Object> buildBoppayForTrn(Boppay boppay, BopTrnBo bopTrnBo) {
        boppay.reset();
        Map<String, Object> map = new HashMap<>();
        //获取收付汇日期
        Date paydat = Dates.today();
        if(!MdaUtils.isEmpty(boppay.getCtlmod().getDbl().getReldat())){
            paydat = boppay.getCtlmod().getDbl().getReldat();
        }
        //打印组数
        if("1".equals(boppay.getSzflg())){
            map = dbcprintService.getInputMapDataForTrn(boppay.getDbcgrp(),paydat,boppay.getAloneflg(),bopTrnBo);
        }else if("2".equals(boppay.getSzflg())){
            map = dbfprintService.getInputMapDataForTrn(boppay.getDbfgrp(),paydat,boppay.getAloneflg(),bopTrnBo);
        }
        return map;
    }

    //补充交易信息打印
    public Map<String, Object> buildBopremForTrn(Boprem boprem, BopTrnBo bopTrnBo) {
        boprem.reset();
        Map<String, Object> map = new HashMap<>();
        //获取收付汇日期
        Date paydat = Dates.today();
        if(!MdaUtils.isEmpty(boprem.getCtlmod().getDbl().getReldat())){
            paydat = boprem.getCtlmod().getDbl().getReldat();
        }
        //打印组数
        if("1".equals(boprem.getSzflg())){
            map = dbbprintService.getInputMapDataForTrn(boprem.getDbbgrp(),paydat,boprem.getAloneflg(),bopTrnBo);
        }else if("2".equals(boprem.getSzflg())){
            map = dbeprintService.getInputMapDataForTrn(boprem.getDbegrp(),paydat,boprem.getAloneflg(),bopTrnBo);
        }

        return map;
    }
}
