表模型(tableModel)信息

说明

tableModel的json数据格式如下(精简版本):

{
  "tableDefine": {
    "dbTableName": "ac_project",
    "id": "AcProject",
    "cnname": "项目",
    "varDomainName": "acProject",
    "columns": [
      {
        "canBeNull": false,
        "cnname": "id",
        "columnName": "id",
        "columnType": "INT",
        "comment": "id",
        "dataName": "id",
        "isPK": true,
        "jspTag": "TEXT",
        "length": 10,
        "readonly": false
      },
      {
        "canBeNull": true,
        "cnname": "名称",
        "columnName": "name",
        "columnType": "VARCHAR",
        "comment": "名称",
        "dataName": "name",
        "isPK": false,
        "jspTag": "TEXT",
        "length": 50,
        "readonly": false
      },
      {
        "canBeNull": true,
        "cnname": "类型",
        "columnName": "type",
        "columnType": "INT",
        "comment": "类型:1.本地,2.仓库",
        "dataName": "type",
        "dictName": "acProject_type_DICT",
        "isPK": false,
        "jspTag": "SELECT",
        "length": 10,
        "readonly": false
      }
    ],
    "pkColumn": {
      "canBeNull": false,
      "cnname": "id",
      "columnName": "id",
      "columnType": "INT",
      "comment": "id",
      "dataName": "id",
      "isPK": true,
      "jspTag": "TEXT",
      "length": 10,
      "readonly": false
    }
  },
  "bizFieldsMap": {
    "allColumn": "id,name,type,created,modified",
    "addList": "id,name,type",
    "updateList": "id,name,type,created,modified",
    "queryList": "id,name,type,created,modified",
    "viewList": "id,name,type,created,modified",
    "searchKey": "id,name,type",
    "createTime": "created",
    "updateTime": "modified"
  },
  "dictMap": {
    "acProject_type_DICT": {
      "id": "acProject_type_DICT",
      "name": "type字段的字典项",
      "optionList": [
        {
          "name": "本地",
          "value": "1"
        },
        {
          "name": "仓库",
          "value": "2"
        }
      ]
    }
  }
}

tableModel主体信息的属性结构

tableModel(表模型)
	|
  |___tableDefine(表信息)
  |     |
  |     |____id(类名), cnname(中文名称), varDomainName(变量名称), dbTableName(表名)
  |			|
  |			|____columns 列列表信息;
  |						|
  |						|__columnName(数据库列名),dataName(字段名称), columnType(数据库字段类型)
  |						|__length(长度),comment(备注), isPK(是否主键), jspTag(展示类型)
  |						|__canBeNull(是否可为空),dictName(字典项名称),readonly(是否只读)
  |
  |___ bizFieldMap(业务字段map)
  |				|
  |				|__allColumn(全部列名称列表,逗号分隔)
  |				|__addList(新增列名称列表,逗号分隔)
  |				|__updateList (修改列名称列表,逗号分隔)
  |				|__queryList (查询列名称列表,逗号分隔)
  |				|__viewList (查看列名称列表,逗号分隔)
  |				|__createTime (创建时间列名称)
  |				|__updateTime (修改时间列名称)
  |
  |__dictMap(字典项map,略)

主要的方法和功能请参看源码。

配置界面

源码

/**
 * 表模型结构
 * @author david
 * @since 2018/12/12
 */
class TableModelVo {

    /**
     * table的表定义信息
     */
    TableDefineVo tableDefine;
    /**
     * 排序字段
     */
    List<OrderColumnVo> orderColumns;
    /**
     * 业务字段列表,以逗号分隔
     */
    Map<String, String> bizFieldsMap = new LinkedHashMap<String, String>();

    /**
     * 字段List, 转换为List,方便获取
     */
    Map<String, List<String>> fieldListMap = new HashMap<String, List<String>>();

    /**
     * 字典项map
     */
    Map<String, DictVo> dictMap;

    /**
     * 是否不在List中
     * @param listName
     * @param columnName
     * @return
     */
    boolean isNotInList(String listName, String columnName) {
        return !isInList(listName, columnName);
    }

    /**
     * 是否在List中
     * @param listName
     * @param columnName
     * @return
     */
    boolean isInList(String listName, String columnName) {
        List<String> columnNameList = this.getColumnNameList(listName);
        //如果为空,默认为TRUE
        if (CollectionUtils.isEmpty(columnNameList)) {
            return true;
        }
        return columnNameList.contains(columnName);
    }

    /**
     * 根据listName获取list列表
     * @param listName
     * @return
     */
    List<String> getColumnNameList(String listName) {
        if (fieldListMap.containsKey(listName)) {
            return fieldListMap.get(listName);
        } else {
            return this.parseListStrAndPutIntoMap(listName);
        }
    }

    /**
     * 将字符串转换为List<String>便于之后contains校验,也可以转为Set
     * @param listName
     */
    private List<String> parseListStrAndPutIntoMap(String listName) {
        String listStr = bizFieldsMap.get(listName);
        if (StringUtils.isEmpty(listStr)) {
            listStr = bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_ALLCOLUMN)
        }
        if (StringUtils.isEmpty(listStr)) {
            return null;
        }
        String[] columnNameArr = listStr.split(",");
        List<String> columnNameList = Arrays.asList(columnNameArr);
        fieldListMap.put(listName, columnNameList);
        return columnNameList;
    }

    /**
     * 将字符串转换为List<String>便于之后contains校验,也可以转为Set
     * @param listName
     */
    int listSize(String listName) {
        List<String> columnNameList = this.getColumnNameList(listName)
        //如果为空,默认为全部
        if (CollectionUtils.isEmpty(columnNameList)) {
            return 0;
        }
        return columnNameList.size();
    }

    /**
     * 所有列表中是否包含tag
     * @param tagName
     * @return
     */
    boolean listContainsTag(String tagName) {
        for (ColumnVo column : tableDefine.getColumns()) {
            if (column.getJspTag().equalsIgnoreCase(tagName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 列表中是否包含tag
     * @param listName
     * @param tagName
     * @return
     */
    boolean listContainsTag(String listName, String tagName) {
        List<String> list = getColumnNameList(listName);
        if (CollectionUtils.isEmpty(list)) {
            return false;
        }

        for (ColumnVo column : tableDefine.getColumns()) {
            if (list.contains(column.getColumnName()) && column.getJspTag().equalsIgnoreCase(tagName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 取消,直接通过key获取
     * @return
     */
    @Deprecated
    List<String> getSearchKeyList() {
        return getColumnNameList(MoliCodeConstant.BIZ_FIELDS_KEY_SEARCHKEY);
    }

    /**
     * 设置bizFields
     * @param key
     * @param bizFields
     */
    void putBizFields(String key, String bizFields) {
        bizFieldsMap.put(key, bizFields);
    }

    /**
     * 通过key 获取 bizFields
     * @param key
     */
    String getBizFields(String key) {
        return bizFieldsMap.get(key);
    }

    /**
     * 获取创建时间字段
     */
    String getCreateTime() {
        return bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_CREATETIME)
    }
    /**
     * 获取更新时间字段
     */
    String getUpdateTime() {
        return bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_UPDATETIME)
    }
}