表模型(tableModel)信息

说明

数据库表的富声明,包含:

  • tableDefine: 表定义;
  • orderColumns: 排序字段;
  • bizFieldsMap: 业务key识别,如:createTime,updateTime,queryList, searchKey, allColumn 等信息;
  • dicts: 数据字典项等信息;
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <tableModel>
  3. <tableDefine id='AcCommonExtInfo' cnname='扩展信息' dbTableName='ac_common_ext_info'>
  4. <column dataName='id' columnName='id' cnname='id' columnType='INT' canBeNull='false' readonly='false' isPK='true' length='10' jspTag='TEXT' dictName='' comment='id' />
  5. <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.项目' />
  6. <!-- 省略部分信息 -->
  7. </tableDefine>
  8. <orderColumns>
  9. <orderColumn orderType='desc'>id</orderColumn>
  10. </orderColumns>
  11. <bizFieldsMap>
  12. <bizFields key='createTime'>created</bizFields>
  13. <bizFields key='updateTime'>modified</bizFields>
  14. <bizFields key='queryList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,modified</bizFields>
  15. <bizFields key='addList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
  16. <bizFields key='updateList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
  17. <bizFields key='viewList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
  18. <bizFields key='searchKey'>id,owner_type,type,status</bizFields>
  19. <bizFields key='allColumn'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
  20. </bizFieldsMap>
  21. <dicts>
  22. <dict id='acCommonExtInfo_type_DICT' name='type字段的字典项'>
  23. <option value='1' cssClass=''>文本</option>
  24. <option value='2' cssClass=''>json</option>
  25. <option value='3' cssClass=''>xml</option>
  26. <option value='4' cssClass=''>properties</option>
  27. <option value='5' cssClass=''>开关</option>
  28. </dict>
  29. <dict id='acCommonExtInfo_ownerType_DICT' name='owner_type字段的字典项'>
  30. <option value='1' cssClass=''>系统</option>
  31. <option value='2' cssClass=''>项目</option>
  32. </dict>
  33. <dict id='acCommonExtInfo_status_DICT' name='status字段的字典项'>
  34. <option value='1' cssClass=''>有效</option>
  35. <option value='-1' cssClass=''>无效</option>
  36. </dict>
  37. </dicts>
  38. </tableModel>
  39. ...更多未展示...

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

源码

  1. /**
  2. * 表模型结构
  3. * @author david
  4. * @since 2018/12/12
  5. */
  6. class TableModelVo {
  7. /**
  8. * table的表定义信息
  9. */
  10. TableDefineVo tableDefine;
  11. /**
  12. * 排序字段
  13. */
  14. List<OrderColumnVo> orderColumns;
  15. /**
  16. * 业务字段列表,以逗号分隔
  17. */
  18. Map<String, String> bizFieldsMap = new LinkedHashMap<String, String>();
  19. /**
  20. * 字段List, 转换为List,方便获取
  21. */
  22. Map<String, List<String>> fieldListMap = new HashMap<String, List<String>>();
  23. /**
  24. * 字典项map
  25. */
  26. Map<String, DictVo> dictMap;
  27. /**
  28. * 是否不在List中
  29. * @param listName
  30. * @param columnName
  31. * @return
  32. */
  33. boolean isNotInList(String listName, String columnName) {
  34. return !isInList(listName, columnName);
  35. }
  36. /**
  37. * 是否在List中
  38. * @param listName
  39. * @param columnName
  40. * @return
  41. */
  42. boolean isInList(String listName, String columnName) {
  43. List<String> columnNameList = this.getColumnNameList(listName);
  44. //如果为空,默认为TRUE
  45. if (CollectionUtils.isEmpty(columnNameList)) {
  46. return true;
  47. }
  48. return columnNameList.contains(columnName);
  49. }
  50. /**
  51. * 根据listName获取list列表
  52. * @param listName
  53. * @return
  54. */
  55. List<String> getColumnNameList(String listName) {
  56. if (fieldListMap.containsKey(listName)) {
  57. return fieldListMap.get(listName);
  58. } else {
  59. return this.parseListStrAndPutIntoMap(listName);
  60. }
  61. }
  62. /**
  63. * 将字符串转换为List<String>便于之后contains校验,也可以转为Set
  64. * @param listName
  65. */
  66. private List<String> parseListStrAndPutIntoMap(String listName) {
  67. String listStr = bizFieldsMap.get(listName);
  68. if (StringUtils.isEmpty(listStr)) {
  69. listStr = bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_ALLCOLUMN)
  70. }
  71. if (StringUtils.isEmpty(listStr)) {
  72. return null;
  73. }
  74. String[] columnNameArr = listStr.split(",");
  75. List<String> columnNameList = Arrays.asList(columnNameArr);
  76. fieldListMap.put(listName, columnNameList);
  77. return columnNameList;
  78. }
  79. /**
  80. * 将字符串转换为List<String>便于之后contains校验,也可以转为Set
  81. * @param listName
  82. */
  83. int listSize(String listName) {
  84. List<String> columnNameList = this.getColumnNameList(listName)
  85. //如果为空,默认为全部
  86. if (CollectionUtils.isEmpty(columnNameList)) {
  87. return 0;
  88. }
  89. return columnNameList.size();
  90. }
  91. /**
  92. * 所有列表中是否包含tag
  93. * @param tagName
  94. * @return
  95. */
  96. boolean listContainsTag(String tagName) {
  97. for (ColumnVo column : tableDefine.getColumns()) {
  98. if (column.getJspTag().equalsIgnoreCase(tagName)) {
  99. return true;
  100. }
  101. }
  102. return false;
  103. }
  104. /**
  105. * 列表中是否包含tag
  106. * @param listName
  107. * @param tagName
  108. * @return
  109. */
  110. boolean listContainsTag(String listName, String tagName) {
  111. List<String> list = getColumnNameList(listName);
  112. if (CollectionUtils.isEmpty(list)) {
  113. return false;
  114. }
  115. for (ColumnVo column : tableDefine.getColumns()) {
  116. if (list.contains(column.getColumnName()) && column.getJspTag().equalsIgnoreCase(tagName)) {
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. /**
  123. * 取消,直接通过key获取
  124. * @return
  125. */
  126. @Deprecated
  127. List<String> getSearchKeyList() {
  128. return getColumnNameList(MoliCodeConstant.BIZ_FIELDS_KEY_SEARCHKEY);
  129. }
  130. /**
  131. * 设置bizFields
  132. * @param key
  133. * @param bizFields
  134. */
  135. void putBizFields(String key, String bizFields) {
  136. bizFieldsMap.put(key, bizFields);
  137. }
  138. /**
  139. * 通过key 获取 bizFields
  140. * @param key
  141. */
  142. String getBizFields(String key) {
  143. return bizFieldsMap.get(key);
  144. }
  145. /**
  146. * 获取创建时间字段
  147. */
  148. String getCreateTime() {
  149. return bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_CREATETIME)
  150. }
  151. /**
  152. * 获取更新时间字段
  153. */
  154. String getUpdateTime() {
  155. return bizFieldsMap.get(MoliCodeConstant.BIZ_FIELDS_KEY_UPDATETIME)
  156. }
  157. }