
package com.lideeyunji.core.framework.config.btncommand.receiver;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lideeyunji.core.framework.config.btncommand.param.ButtonParamReportExport;
import com.lideeyunji.core.framework.service.IExcelService;
import com.lideeyunji.core.framework.service.IFrameService;
import com.lideeyunji.tool.framework.excel.model.MoreSheetConfig;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 新增报表导出执行者
 */
public class ButtonReceiverReportExport implements IButtonCommandReceiver<List<MoreSheetConfig>> {


    private String pluginKey;

    private ButtonParamReportExport param;

    public ButtonReceiverReportExport(ButtonParamReportExport param) {
        this.param = param;
    }

    /**
     * 执行命令
     * @return
     */
    @Override
    public List<MoreSheetConfig> receiver() {
        IExcelService excelService = SpringUtils.getBean(IExcelService.class);
        IFrameService frameService = SpringUtils.getBean(IFrameService.class);

        String reportCode = param.getReportCode();
        Map<String, Object> params = param.getParams();

        //数据列表
        Page page=new Page(1,-1);
        ResultDataModel model = frameService.getReportDataList(reportCode, page,params);

        //获取基本信息
        MoreSheetConfig sheet = excelService.getExcelReportModel(reportCode);
        sheet.setDataList(model.getRecords());

        List<MoreSheetConfig> sheetList = new ArrayList<>();
        sheetList.add(sheet);
        return sheetList;
    }


}
