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

import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamDetail;
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
import com.jeelowcode.core.framework.service.IDbFormRoleService;
import com.jeelowcode.core.framework.service.IFrameService;

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

/**
 * 详情按钮执行者
 */
public class ButtonReceiverDetail extends ButtonReceiverBase 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);
        IDbFormRoleService dbFormRoleService = SpringUtils.getBean(IDbFormRoleService.class);
        IJeeLowCodeAdapter jeeLowCodeAdapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
        Long tenantId = jeeLowCodeAdapter.getTenantId();

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

        List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbformId,false);

        ResultDataModel resultDataModel = frameService.getDataDetail(dbformId, dataId, params);
        super.webViewAppend(dbformId,resultDataModel.getRecords());
        super.removeNotWebView(dbformId,resultDataModel.getRecords(),roleFieldVoList);
        return resultDataModel;
    }
}
