表模型(tableModel)信息
说明
数据库表的富声明,包含:
- tableDefine: 表定义;
- orderColumns: 排序字段;
- bizFieldsMap: 业务key识别,如:createTime,updateTime,queryList, searchKey, allColumn 等信息;
- dicts: 数据字典项等信息;
<?xml version="1.0" encoding="UTF-8" ?>
<tableModel>
<tableDefine id='AcCommonExtInfo' cnname='扩展信息' dbTableName='ac_common_ext_info'>
<column dataName='id' columnName='id' cnname='id' columnType='INT' canBeNull='false' readonly='false' isPK='true' length='10' jspTag='TEXT' dictName='' comment='id' />
<column dataName='ownerType' columnName='owner_type' cnname='归属类型' columnType='INT' canBeNull='false' readonly='false' isPK='false' length='10' jspTag='SELECT' dictName='acCommonExtInfo_ownerType_DICT' comment='归属类型:1.系统,2.项目' />
<!-- 省略部分信息 -->
</tableDefine>
<orderColumns>
<orderColumn orderType='desc'>id</orderColumn>
</orderColumns>
<bizFieldsMap>
<bizFields key='createTime'>created</bizFields>
<bizFields key='updateTime'>modified</bizFields>
<bizFields key='queryList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,modified</bizFields>
<bizFields key='addList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
<bizFields key='updateList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
<bizFields key='viewList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
<bizFields key='searchKey'>id,owner_type,type,status</bizFields>
<bizFields key='allColumn'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
</bizFieldsMap>
<dicts>
<dict id='acCommonExtInfo_type_DICT' name='type字段的字典项'>
<option value='1' cssClass=''>文本</option>
<option value='2' cssClass=''>json</option>
<option value='3' cssClass=''>xml</option>
<option value='4' cssClass=''>properties</option>
<option value='5' cssClass=''>开关</option>
</dict>
<dict id='acCommonExtInfo_ownerType_DICT' name='owner_type字段的字典项'>
<option value='1' cssClass=''>系统</option>
<option value='2' cssClass=''>项目</option>
</dict>
<dict id='acCommonExtInfo_status_DICT' name='status字段的字典项'>
<option value='1' cssClass=''>有效</option>
<option value='-1' cssClass=''>无效</option>
</dict>
</dicts>
</tableModel>
...更多未展示...
主要的方法和功能请参看源码。
源码
/**
* 表模型结构
* @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)
}
}