GenTableColumnMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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="id" 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. <result property="regular" column="regular" />
  40. <result property="tableColumnName" column="table_column_name" />
  41. </resultMap>
  42. <sql id="selectGenTableColumnVo">
  43. select 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, regular, table_column_name from gen_table_column
  44. </sql>
  45. <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  46. <include refid="selectGenTableColumnVo"/>
  47. where table_id = #{tableId}
  48. order by sort
  49. </select>
  50. <select id="selectGenTableColumnIsListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  51. <include refid="selectGenTableColumnVo"/>
  52. where table_id = #{tableId} and (is_in = 'Y' or is_out = 'Y')
  53. </select>
  54. <select id="selectGenTableColumnList" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  55. <include refid="selectGenTableColumnVo"/>
  56. <where>
  57. <if test="tableId != null and tableId != ''">
  58. AND table_id = #{tableId}
  59. </if>
  60. <if test="columnName != null and columnName != ''">
  61. AND lower(column_name) like lower(concat('%', #{columnName}, '%'))
  62. </if>
  63. <if test="htmlType != null and htmlType != ''">
  64. AND html_type = #{htmlType}
  65. </if>
  66. </where>
  67. </select>
  68. <select id="selectGenTableColumnByColumnId" parameterType="long" resultMap="GenTableColumnResult">
  69. <include refid="selectGenTableColumnVo"/>
  70. where id = #{columnId}
  71. limit 1
  72. </select>
  73. <select id="listByTableIdList" parameterType="list" resultMap="GenTableColumnResult">
  74. <include refid="selectGenTableColumnVo"/>
  75. where table_id in
  76. <foreach collection="tableIdList" open="(" close=")" separator="," item="tableId">
  77. #{tableId}
  78. </foreach>
  79. order by sort
  80. </select>
  81. <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
  82. 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
  83. from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
  84. order by ordinal_position
  85. </select>
  86. <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="id">
  87. insert into gen_table_column (
  88. <if test="tableId != null and tableId != ''">table_id,</if>
  89. <if test="columnName != null and columnName != ''">column_name,</if>
  90. <if test="columnComment != null and columnComment != ''">column_comment,</if>
  91. <if test="columnType != null and columnType != ''">column_type,</if>
  92. <if test="javaType != null and javaType != ''">java_type,</if>
  93. <if test="javaField != null and javaField != ''">java_field,</if>
  94. <if test="isPk != null and isPk != ''">is_pk,</if>
  95. <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
  96. <if test="isRequired != null and isRequired != ''">is_required,</if>
  97. <if test="isInsert != null and isInsert != ''">is_insert,</if>
  98. <if test="isEdit != null and isEdit != ''">is_edit,</if>
  99. <if test="isList != null and isList != ''">is_list,</if>
  100. <if test="isQuery != null and isQuery != ''">is_query,</if>
  101. <if test="queryType != null and queryType != ''">query_type,</if>
  102. <if test="htmlType != null and htmlType != ''">html_type,</if>
  103. <if test="foreignKey != null ">foreign_key,</if>
  104. <if test="dictType != null and dictType != ''">dict_type,</if>
  105. <if test="sort != null">sort,</if>
  106. <if test="createBy != null and createBy != ''">create_by,</if>
  107. <if test="hrParentId != null and hrParentId != ''">hr_parent_id,</if>
  108. <if test="mask != null and mask != ''">mask,</if>
  109. <if test="defaultValue != null and defaultValue != ''">default_value,</if>
  110. <if test="numRows != null and numRows != ''">num_rows,</if>
  111. <if test="numColumns != null and numColumns != ''">num_columns,</if>
  112. <if test="fieldTranslator != null and fieldTranslator != ''">field_translator,</if>
  113. <if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes,</if>
  114. <if test="isIn != null and isIn != ''">is_in,</if>
  115. <if test="isOut != null and isOut != ''">is_out,</if>
  116. <if test="regular != null and regular != ''">regular,</if>
  117. <if test="tableColumnName != null and tableColumnName != ''">table_column_name,</if>
  118. create_time
  119. )values(
  120. <if test="tableId != null and tableId != ''">#{tableId},</if>
  121. <if test="columnName != null and columnName != ''">#{columnName},</if>
  122. <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
  123. <if test="columnType != null and columnType != ''">#{columnType},</if>
  124. <if test="javaType != null and javaType != ''">#{javaType},</if>
  125. <if test="javaField != null and javaField != ''">#{javaField},</if>
  126. <if test="isPk != null and isPk != ''">#{isPk},</if>
  127. <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
  128. <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
  129. <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
  130. <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
  131. <if test="isList != null and isList != ''">#{isList},</if>
  132. <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
  133. <if test="queryType != null and queryType != ''">#{queryType},</if>
  134. <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
  135. <if test="foreignKey != null">#{foreignKey},</if>
  136. <if test="dictType != null and dictType != ''">#{dictType},</if>
  137. <if test="sort != null">#{sort},</if>
  138. <if test="createBy != null and createBy != ''">#{createBy},</if>
  139. <if test="hrParentId != null and hrParentId != ''">#{hrParentId},</if>
  140. <if test="mask != null and mask != ''">#{mask},</if>
  141. <if test="defaultValue != null and defaultValue != ''">#{defaultValue},</if>
  142. <if test="numRows != null and numRows != ''">#{numRows},</if>
  143. <if test="numColumns != null and numColumns != ''">#{numColumns},</if>
  144. <if test="fieldTranslator != null and fieldTranslator != ''">#{fieldTranslator},</if>
  145. <if test="extendedAttributes != null and extendedAttributes != ''">#{extendedAttributes},</if>
  146. <if test="isIn != null and isIn != ''">#{isIn},</if>
  147. <if test="isOut != null and isOut != ''">#{isOut},</if>
  148. <if test="regular != null and regular != ''">#{regular},</if>
  149. <if test="tableColumnName != null and tableColumnName != ''">#{tableColumnName},</if>
  150. sysdate()
  151. )
  152. </insert>
  153. <update id="updateGenTableColumn" parameterType="GenTableColumn">
  154. update gen_table_column
  155. <set>
  156. <if test="tableId != null and tableId != ''">table_id = #{tableId},</if>
  157. <if test="columnName != null and columnName != ''">column_name = #{columnName},</if>
  158. <if test="columnComment != null and columnComment != ''">column_comment = #{columnComment},</if>
  159. <if test="columnType != null and columnType != ''">column_type = #{columnType},</if>
  160. <if test="javaType != null and javaType != ''">java_type = #{javaType},</if>
  161. <if test="javaField != null and javaField != ''">java_field = #{javaField},</if>
  162. <if test="isPk != null and isPk != ''">is_pk = #{isPk},</if>
  163. <if test="isIncrement != null and isIncrement != ''">is_increment = #{isIncrement},</if>
  164. <if test="isRequired != null and isRequired != ''">is_required = #{isRequired},</if>
  165. <if test="isInsert != null and isInsert != ''">is_insert = #{isInsert},</if>
  166. <if test="isEdit != null and isEdit != ''">is_edit = #{isEdit},</if>
  167. <if test="isList != null and isList != ''">is_list = #{isList},</if>
  168. <if test="isQuery != null and isQuery != ''">is_query = #{isQuery},</if>
  169. <if test="queryType != null and queryType != ''">query_type = #{queryType},</if>
  170. <if test="htmlType != null and htmlType != ''">html_type = #{htmlType},</if>
  171. <if test="foreignKey != null and foreignKey != ''">foreign_key = #{foreignKey},</if>
  172. <if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
  173. <if test="sort != null">sort = #{sort},</if>
  174. <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
  175. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  176. <if test="hrParentId != null and hrParentId != ''">hr_parent_id = #{hrParentId},</if>
  177. <if test="mask != null and mask != ''">mask = #{mask},</if>
  178. <if test="defaultValue != null and defaultValue != ''">default_value = #{defaultValue},</if>
  179. <if test="numRows != null and numRows != ''">num_rows = #{numRows},</if>
  180. <if test="numColumns != null and numColumns != ''">num_columns = #{numColumns},</if>
  181. <if test="fieldTranslator != null and fieldTranslator != ''">field_translator = #{fieldTranslator},</if>
  182. <if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes = #{extendedAttributes},</if>
  183. <if test="isIn != null and isIn != ''">is_in = #{isIn},</if>
  184. <if test="isOut != null and isOut != ''">is_out = #{isOut},</if>
  185. <if test="regular != null and regular != ''">regular = #{regular},</if>
  186. update_time = sysdate()
  187. </set>
  188. where id = #{id}
  189. </update>
  190. <delete id="deleteGenTableColumnByIds" parameterType="Long">
  191. delete from gen_table_column where table_id in
  192. <foreach collection="array" item="tableId" open="(" separator="," close=")">
  193. #{tableId}
  194. </foreach>
  195. </delete>
  196. <select id="checkColumnNameUnique" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  197. <include refid="selectGenTableColumnVo"/>
  198. where column_name = #{columnName} and table_id = #{tableId} limit 1
  199. </select>
  200. <delete id="deleteGenTableColumns">
  201. delete from gen_table_column where id in
  202. <foreach collection="list" item="item" open="(" separator="," close=")">
  203. #{item.id}
  204. </foreach>
  205. </delete>
  206. <delete id="deleteGenTableColumnByColumnIds" parameterType="Long">
  207. delete from gen_table_column where id in
  208. <foreach collection="array" item="columnId" open="(" separator="," close=")">
  209. #{columnId}
  210. </foreach>
  211. </delete>
  212. </mapper>