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

import com.lideeyunji.core.framework.config.btncommand.filter.CriteriaList;
import com.lideeyunji.core.framework.config.btncommand.filter.RemoveFieldCriteriaList;
import com.lideeyunji.core.framework.config.btncommand.filter.ViewFieldCriteriaList;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.tool.framework.yunji.enums.ParamEnum;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
import com.lideeyunji.core.framework.config.btncommand.param.ButtonParamList;
import com.lideeyunji.core.framework.service.IFrameService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

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

/**
 * 编辑按钮执行者
 */
public class ButtonReceiverList implements IButtonCommandReceiver<ResultDataModel> {


    private String pluginKey;

    private ButtonParamList param;

    public ButtonReceiverList(ButtonParamList param) {
        this.param = param;
    }

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

        Long dbformId = param.getDbFormId();
        Map<String, Object> params = param.getParams();
        if(Func.isNotEmpty(params)){
            params.remove(ParamEnum.ALL_QUERY_FIELD.getCode());//特殊字段不允许用户带过来
        }
        Page page = param.getPage();
        ResultDataModel resultDataModel = frameService.getDataList(dbformId, page, params);
        List<Map<String, Object>> records = resultDataModel.getRecords();

        CriteriaList viewFieldCriteriaList = new ViewFieldCriteriaList();//处理虚拟化字段
        viewFieldCriteriaList.meetCriteria(dbformId,records);

        CriteriaList removeFieldCriteriaList = new RemoveFieldCriteriaList();//移除不是列表显示的字段
        removeFieldCriteriaList.meetCriteria(dbformId,records);

        return resultDataModel;
    }
}
