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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamReportExport;
import com.jeelowcode.core.framework.params.model.ExcelModel;
import com.jeelowcode.core.framework.service.IExcelService;
import com.jeelowcode.core.framework.service.IFrameService;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;

import java.util.Map;

/**
 * 新增报表导出执行者
 */
public class ButtonReceiverReportExport extends ButtonReceiverBase implements IButtonCommandReceiver<ExcelModel> {


    private String pluginKey;

    private ButtonParamReportExport param;

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

    /**
     * 执行命令
     * @return
     */
    @Override
    public ExcelModel 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);

        //获取基本信息
        ExcelModel excelModel = excelService.getExcelReportModel(reportCode);
        excelModel.setDataMapList(model.getRecords());

        return excelModel;
    }


}
