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

import cn.hutool.json.JSONObject;
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamAddBatch;
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
import com.jeelowcode.core.framework.service.IFrameService;

import java.util.List;

/**
 * 新增按钮执行者
 */
public class ButtonReceiverAddBatch implements IButtonCommandReceiver<List<String>> {


    private String pluginKey;

    private ButtonParamAddBatch param;

    public ButtonReceiverAddBatch(ButtonParamAddBatch param) {
        this.param = param;
    }

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

        Long dbFormId = param.getDbFormId();
        List<JSONObject> jsonList = param.getDataMapList();
        for(JSONObject jsonObject:jsonList){
            jsonObject.remove("id");
        }

        List<String> idList = frameService.saveBatchData(dbFormId, jsonList);


        return idList;
    }


}
