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

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.lideeyunji.core.framework.config.btncommand.param.ButtonParamImport;
import com.lideeyunji.core.framework.params.model.ExcelImportResultModel;
import com.lideeyunji.core.framework.service.IExcelFileService;
import com.lideeyunji.core.framework.service.IExcelService;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;

/**
 * 新增按钮执行者
 */
public class ButtonReceiverImport implements IButtonCommandReceiver<ExcelImportResultModel> {


    private String pluginKey;

    private ButtonParamImport param;

    public ButtonReceiverImport(ButtonParamImport param) {
        this.param = param;
    }

    /**
     * 执行命令
     * @return
     */

    @Override
    public ExcelImportResultModel receiver() {
        IExcelService excelService = SpringUtils.getBean(IExcelService.class);
        IExcelFileService excelFileService = SpringUtils.getBean(IExcelFileService.class);


        ExcelImportResultModel resultModel=null;
        //保存Excel数据
        String serviceType = param.getServiceType();
        switch (serviceType){
            case "IMPORT_TEMPLATE"://导入excel到临时库
                long batchCode = IdWorker.getId();
                excelFileService.saveExcelSync(batchCode,param);

                resultModel = new ExcelImportResultModel();
                resultModel.setBatchCode(Func.toStr(batchCode));
                resultModel.setDbFormId(param.getDbFormId());
                resultModel.setTotalCou(param.getDataMapList().size());
                resultModel.setFileId(batchCode);
                break;
            case "HANBLE_TEMPLATE"://处理临时库数据
                excelService.handleTempTable(param.getDbFormId(),param.getBatchCode());
                break;

        }

        return resultModel;
    }




}
