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

import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.tool.framework.yunji.model.ExecuteEnhanceModel;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
import com.lideeyunji.core.framework.config.btncommand.param.ButtonParamAdd;
import com.lideeyunji.core.framework.service.IFrameService;

import java.util.Map;

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


    private String pluginKey;

    private ButtonParamAdd param;

    public ButtonReceiverAdd(ButtonParamAdd param) {
        this.param = param;
    }

    /**
     * 执行命令
     * @return
     */
    @Override
    public ExecuteEnhanceModel receiver() {
        IFrameService frameService = SpringUtils.getBean(IFrameService.class);

        Long dbFormId = param.getDbFormId();
        Map<String, Object> paramMap = param.getParams();
        if(Func.isNotEmpty(paramMap)){
            paramMap.remove("id");
        }

        ExecuteEnhanceModel enhanceModel = frameService.saveData(dbFormId, paramMap);

        return enhanceModel;
    }


}
