GenTableColumnMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.boman.gen.mapper.GenTableColumnMapper">
  6. <resultMap type="GenTableColumn" id="GenTableColumnResult">
  7. <result property="columnId" column="column_id" />
  8. <result property="tableId" column="table_id" />
  9. <result property="columnName" column="column_name" />
  10. <result property="columnComment" column="column_comment" />
  11. <result property="columnType" column="column_type" />
  12. <result property="javaType" column="java_type" />
  13. <result property="javaField" column="java_field" />
  14. <result property="isPk" column="is_pk" />
  15. <result property="isIncrement" column="is_increment" />
  16. <result property="isRequired" column="is_required" />
  17. <result property="isInsert" column="is_insert" />
  18. <result property="isEdit" column="is_edit" />
  19. <result property="isList" column="is_list" />
  20. <result property="isQuery" column="is_query" />
  21. <result property="queryType" column="query_type" />
  22. <result property="htmlType" column="html_type" />
  23. <result property="foreignKey" column="foreign_key" />
  24. <result property="dictType" column="dict_type" />
  25. <result property="sort" column="sort" />
  26. <result property="createBy" column="create_by" />
  27. <result property="createTime" column="create_time" />
  28. <result property="updateBy" column="update_by" />
  29. <result property="updateTime" column="update_time" />
  30. <result property="hrParentId" column="hr_parent_id" />
  31. <result property="mask" column="mask" />
  32. <result property="defaultValue" column="default_value" />
  33. <result property="numRows" column="num_rows" />
  34. <result property="numColumns" column="num_columns" />
  35. <result property="fieldTranslator" column="field_translator" />
  36. <result property="extendedAttributes" column="extended_attributes" />
  37. <result property="isIn" column="is_in" />
  38. <result property="isOut" column="is_out" />
  39. </resultMap>
  40. <sql id="selectGenTableColumnVo">
  41. select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, foreign_key, dict_type, sort, create_by, create_time, update_by, update_time, hr_parent_id, mask, default_value, num_rows, num_columns, field_translator, extended_attributes, is_in, is_out from gen_table_column
  42. </sql>
  43. <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  44. <include refid="selectGenTableColumnVo"/>
  45. where table_id = #{tableId}
  46. order by sort
  47. </select>
  48. <select id="selectGenTableColumnByColumnId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  49. <include refid="selectGenTableColumnVo"/>
  50. where column_id = #{columnId}
  51. limit 1
  52. </select>
  53. <select id="listByTableIdList" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  54. <include refid="selectGenTableColumnVo"/>
  55. where table_id in
  56. <foreach collection="tableIdList" open="(" close=")" separator="," item="tableId">
  57. #{tableId}
  58. </foreach>
  59. order by sort
  60. </select>
  61. <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
  62. select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
  63. from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
  64. order by ordinal_position
  65. </select>
  66. <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
  67. insert into gen_table_column (
  68. <if test="tableId != null and tableId != ''">table_id,</if>
  69. <if test="columnName != null and columnName != ''">column_name,</if>
  70. <if test="columnComment != null and columnComment != ''">column_comment,</if>
  71. <if test="columnType != null and columnType != ''">column_type,</if>
  72. <if test="javaType != null and javaType != ''">java_type,</if>
  73. <if test="javaField != null and javaField != ''">java_field,</if>
  74. <if test="isPk != null and isPk != ''">is_pk,</if>
  75. <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
  76. <if test="isRequired != null and isRequired != ''">is_required,</if>
  77. <if test="isInsert != null and isInsert != ''">is_insert,</if>
  78. <if test="isEdit != null and isEdit != ''">is_edit,</if>
  79. <if test="isList != null and isList != ''">is_list,</if>
  80. <if test="isQuery != null and isQuery != ''">is_query,</if>
  81. <if test="queryType != null and queryType != ''">query_type,</if>
  82. <if test="htmlType != null and htmlType != ''">html_type,</if>
  83. <if test="foreignKey != null ">foreign_key,</if>
  84. <if test="dictType != null and dictType != ''">dict_type,</if>
  85. <if test="sort != null">sort,</if>
  86. <if test="createBy != null and createBy != ''">create_by,</if>
  87. <if test="hrParentId != null and hrParentId != ''">hr_parent_id,</if>
  88. <if test="mask != null and mask != ''">mask,</if>
  89. <if test="defaultValue != null and defaultValue != ''">default_value,</if>
  90. <if test="numRows != null and numRows != ''">num_rows,</if>
  91. <if test="numColumns != null and numColumns != ''">num_columns,</if>
  92. <if test="fieldTranslator != null and fieldTranslator != ''">field_translator,</if>
  93. <if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes,</if>
  94. <if test="isIn != null and isIn != ''">is_in,</if>
  95. <if test="isOut != null and isOut != ''">is_out,</if>
  96. create_time
  97. )values(
  98. <if test="tableId != null and tableId != ''">#{tableId},</if>
  99. <if test="columnName != null and columnName != ''">#{columnName},</if>
  100. <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
  101. <if test="columnType != null and columnType != ''">#{columnType},</if>
  102. <if test="javaType != null and javaType != ''">#{javaType},</if>
  103. <if test="javaField != null and javaField != ''">#{javaField},</if>
  104. <if test="isPk != null and isPk != ''">#{isPk},</if>
  105. <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
  106. <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
  107. <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
  108. <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
  109. <if test="isList != null and isList != ''">#{isList},</if>
  110. <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
  111. <if test="queryType != null and queryType != ''">#{queryType},</if>
  112. <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
  113. <if test="foreignKey != null">#{foreignKey},</if>
  114. <if test="dictType != null and dictType != ''">#{dictType},</if>
  115. <if test="sort != null">#{sort},</if>
  116. <if test="createBy != null and createBy != ''">#{createBy},</if>
  117. <if test="hrParentId != null and hrParentId != ''">#{hrParentId},</if>
  118. <if test="mask != null and mask != ''">#{mask},</if>
  119. <if test="defaultValue != null and defaultValue != ''">#{defaultValue},</if>
  120. <if test="numRows != null and numRows != ''">#{numRows},</if>
  121. <if test="numColumns != null and numColumns != ''">#{numColumns},</if>
  122. <if test="fieldTranslator != null and fieldTranslator != ''">#{fieldTranslator},</if>
  123. <if test="extendedAttributes != null and extendedAttributes != ''">#{extendedAttributes},</if>
  124. <if test="isIn != null and isIn != ''">#{isIn},</if>
  125. <if test="isOut != null and isOut != ''">#{isOut},</if>
  126. sysdate()
  127. )
  128. </insert>
  129. <update id="updateGenTableColumn" parameterType="GenTableColumn">
  130. update gen_table_column
  131. <set>
  132. <if test="tableId != null and tableId != ''">table_id = #{tableId},</if>
  133. <if test="columnName != null and columnName != ''">column_name = #{columnName},</if>
  134. <if test="columnComment != null and columnComment != ''">column_comment = #{columnComment},</if>
  135. <if test="columnType != null and columnType != ''">column_type = #{columnType},</if>
  136. <if test="javaType != null and javaType != ''">java_type = #{javaType},</if>
  137. <if test="javaField != null and javaField != ''">java_field = #{javaField},</if>
  138. <if test="isPk != null and isPk != ''">is_pk = #{isPk},</if>
  139. <if test="isIncrement != null and isIncrement != ''">is_increment = #{isIncrement},</if>
  140. <if test="isRequired != null and isRequired != ''">is_required = #{isRequired},</if>
  141. <if test="isInsert != null and isInsert != ''">is_insert = #{isInsert},</if>
  142. <if test="isEdit != null and isEdit != ''">is_edit = #{isEdit},</if>
  143. <if test="isList != null and isList != ''">is_list = #{isList},</if>
  144. <if test="isQuery != null and isQuery != ''">is_query = #{isQuery},</if>
  145. <if test="queryType != null and queryType != ''">query_type = #{queryType},</if>
  146. <if test="htmlType != null and htmlType != ''">html_type = #{htmlType},</if>
  147. <if test="foreignKey != null and foreignKey != ''">foreign_key = #{foreignKey},</if>
  148. <if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
  149. <if test="sort != null">sort = #{sort},</if>
  150. <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
  151. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  152. <if test="hrParentId != null and hrParentId != ''">hr_parent_id = #{hrParentId},</if>
  153. <if test="mask != null and mask != ''">mask = #{mask},</if>
  154. <if test="defaultValue != null and defaultValue != ''">default_value = #{defaultValue},</if>
  155. <if test="numRows != null and numRows != ''">num_rows = #{numRows},</if>
  156. <if test="numColumns != null and numColumns != ''">num_columns = #{numColumns},</if>
  157. <if test="fieldTranslator != null and fieldTranslator != ''">field_translator = #{fieldTranslator},</if>
  158. <if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes = #{extendedAttributes},</if>
  159. <if test="isIn != null and isIn != ''">is_in = #{isIn},</if>
  160. <if test="isOut != null and isOut != ''">is_out = #{isOut},</if>
  161. update_time = sysdate()
  162. </set>
  163. where column_id = #{columnId}
  164. </update>
  165. <delete id="deleteGenTableColumnByIds" parameterType="Long">
  166. delete from gen_table_column where table_id in
  167. <foreach collection="array" item="tableId" open="(" separator="," close=")">
  168. #{tableId}
  169. </foreach>
  170. </delete>
  171. <select id="checkColumnNameUnique" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  172. <include refid="selectGenTableColumnVo"/>
  173. where column_name = #{columnName} and table_id = #{tableId} limit 1
  174. </select>
  175. <delete id="deleteGenTableColumns">
  176. delete from gen_table_column where column_id in
  177. <foreach collection="list" item="item" open="(" separator="," close=")">
  178. #{item.columnId}
  179. </foreach>
  180. </delete>
  181. <delete id="deleteGenTableColumnByColumnIds" parameterType="Long">
  182. delete from gen_table_column where column_id in
  183. <foreach collection="array" item="columnId" open="(" separator="," close=")">
  184. #{columnId}
  185. </foreach>
  186. </delete>
  187. </mapper>