package cc.smtweb.system.bpm.web.engine.model.listcard.lcms;

import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.util.StringUtil;
import cc.smtweb.system.bpm.web.design.form.ModelForm;

/**
 * @Author:lip
 * @Date : 2022/9/2 17:06
 * 主子表配置信息类
 */
public class LCMsConfig {
    //列表主表数据集
    public static final String dsList = "list";
    //卡片主表数据集
    public static final String dsCard = "card";
    //卡片子表列表数据集
    public static final String dsSList = "listSub";
    //卡片子表卡片数据集
    public static final String dsSCard = "cardSub";
    // 模型的配置信息类
    public static class Config{
        private final ModelForm modelForm;

        public Config(ModelForm modelForm) {
            this.modelForm = modelForm;
        }

       // 获取子表的主表外键字段
        public String getSubFKField(){
            String subFKField = modelForm.getOpts().readMap("config").readMap("props").readString("subForeignKey", "");;
            if(StringUtil.isEmpty(subFKField)){
                throw new BizException("未获取到子表外键配置");
            }
            return subFKField;
        }
        // 获取子表ID
        public long getSubTableId(){
            long subTableId = modelForm.getOpts().readMap("config").readMap("props").readLong("subTable");;
            if(subTableId<=0L){
                throw new BizException("未获取到子表配置");
            }
            return subTableId;
        }
    }

}
