GenTableColumnMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. <id 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. </resultMap>
  32. <sql id="selectGenTableColumnVo">
  33. 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 from gen_table_column
  34. </sql>
  35. <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  36. <include refid="selectGenTableColumnVo"/>
  37. where table_id = #{tableId}
  38. order by sort
  39. </select>
  40. <select id="selectGenTableColumnListByColumnId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  41. <include refid="selectGenTableColumnVo"/>
  42. where column_id = #{columnId}
  43. limit 1
  44. </select>
  45. <select id="listByTableIdList" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  46. <include refid="selectGenTableColumnVo"/>
  47. where table_id in
  48. <foreach collection="tableIdList" open="(" close=")" separator="," item="tableId">
  49. #{tableId}
  50. </foreach>
  51. order by sort
  52. </select>
  53. <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
  54. 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
  55. from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
  56. order by ordinal_position
  57. </select>
  58. <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
  59. insert into gen_table_column (
  60. <if test="tableId != null and tableId != ''">table_id,</if>
  61. <if test="columnName != null and columnName != ''">column_name,</if>
  62. <if test="columnComment != null and columnComment != ''">column_comment,</if>
  63. <if test="columnType != null and columnType != ''">column_type,</if>
  64. <if test="javaType != null and javaType != ''">java_type,</if>
  65. <if test="javaField != null and javaField != ''">java_field,</if>
  66. <if test="isPk != null and isPk != ''">is_pk,</if>
  67. <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
  68. <if test="isRequired != null and isRequired != ''">is_required,</if>
  69. <if test="isInsert != null and isInsert != ''">is_insert,</if>
  70. <if test="isEdit != null and isEdit != ''">is_edit,</if>
  71. <if test="isList != null and isList != ''">is_list,</if>
  72. <if test="isQuery != null and isQuery != ''">is_query,</if>
  73. <if test="queryType != null and queryType != ''">query_type,</if>
  74. <if test="htmlType != null and htmlType != ''">html_type,</if>
  75. <if test="foreignKey != null ">foreign_key,</if>
  76. <if test="dictType != null and dictType != ''">dict_type,</if>
  77. <if test="sort != null">sort,</if>
  78. <if test="createBy != null and createBy != ''">create_by,</if>
  79. create_time
  80. )values(
  81. <if test="tableId != null and tableId != ''">#{tableId},</if>
  82. <if test="columnName != null and columnName != ''">#{columnName},</if>
  83. <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
  84. <if test="columnType != null and columnType != ''">#{columnType},</if>
  85. <if test="javaType != null and javaType != ''">#{javaType},</if>
  86. <if test="javaField != null and javaField != ''">#{javaField},</if>
  87. <if test="isPk != null and isPk != ''">#{isPk},</if>
  88. <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
  89. <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
  90. <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
  91. <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
  92. <if test="isList != null and isList != ''">#{isList},</if>
  93. <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
  94. <if test="queryType != null and queryType != ''">#{queryType},</if>
  95. <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
  96. <if test="foreignKey != null">#{foreignKey},</if>
  97. <if test="dictType != null and dictType != ''">#{dictType},</if>
  98. <if test="sort != null">#{sort},</if>
  99. <if test="createBy != null and createBy != ''">#{createBy},</if>
  100. sysdate()
  101. )
  102. </insert>
  103. <update id="updateGenTableColumn" parameterType="GenTableColumn">
  104. update gen_table_column
  105. <set>
  106. column_comment = #{columnComment},
  107. java_type = #{javaType},
  108. java_field = #{javaField},
  109. is_insert = #{isInsert},
  110. is_edit = #{isEdit},
  111. is_list = #{isList},
  112. is_query = #{isQuery},
  113. is_required = #{isRequired},
  114. query_type = #{queryType},
  115. html_type = #{htmlType},
  116. dict_type = #{dictType},
  117. foreign_key = #{foreignKey},
  118. sort = #{sort},
  119. update_by = #{updateBy},
  120. update_time = sysdate()
  121. </set>
  122. where column_id = #{columnId}
  123. </update>
  124. <delete id="deleteGenTableColumnByIds" parameterType="Long">
  125. delete from gen_table_column where table_id in
  126. <foreach collection="array" item="tableId" open="(" separator="," close=")">
  127. #{tableId}
  128. </foreach>
  129. </delete>
  130. <select id="checkColumnNameUnique" parameterType="Long" resultType="com.boman.gen.domain.GenTableColumn">
  131. <include refid="selectGenTableColumnVo"/>
  132. where column_name = #{columnName} limit 1
  133. </select>
  134. <delete id="deleteGenTableColumns">
  135. delete from gen_table_column where column_id in
  136. <foreach collection="list" item="item" open="(" separator="," close=")">
  137. #{item.columnId}
  138. </foreach>
  139. </delete>
  140. </mapper>