
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.config.btncommand.param.ButtonParamDetail;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
import com.lideeyunji.core.framework.service.IFrameService;

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

/**
 * 详情按钮执行者
 */
public class ButtonReceiverDetail implements IButtonCommandReceiver<ResultDataModel> {


    private String pluginKey;

    private ButtonParamDetail param;

    public ButtonReceiverDetail(ButtonParamDetail param) {
        this.param = param;
    }

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

        Long dbformId = param.getDbFormId();
        Long dataId = param.getDataId();
        Map<String, Object> params = param.getParams();


        ResultDataModel resultDataModel = frameService.getDataDetail(dbformId, dataId, 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;
    }
}
