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

import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamSummary;
import com.jeelowcode.core.framework.service.IFrameService;
import com.jeelowcode.core.framework.utils.Func;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 统计按钮执行者
 */
public class ButtonReceiverSummary implements IButtonCommandReceiver<Map<String, Object>> {


    private String pluginKey;

    private ButtonParamSummary param;

    public ButtonReceiverSummary(ButtonParamSummary param) {
        this.param = param;
    }

    /**
     * 执行命令
     *
     * @return
     */
    @Override
    public Map<String, Object> receiver() {
        IFrameService frameService = SpringUtils.getBean(IFrameService.class);
        Long dbformId = param.getDbFormId();
        Map<String, Object> params = param.getParams();
        ResultDataModel resultDataModel = frameService.getDataSummaryList(dbformId, params);

        Map<String, Object> resultMap = new HashMap<>();
        if(Func.isEmpty(resultDataModel)){
            return resultMap;
        }
        List<Map<String, Object>> dataMapList = resultDataModel.getRecords();
        if (Func.isEmpty(dataMapList)) {//数据为空
            return resultMap;
        }
        return dataMapList.get(0);
    }



}
