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

import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamAdd;
import com.jeelowcode.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;
    }


}
