GenTableColumnMapper.xml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.ruoyi.generator.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="dictType" column="dict_type" />
  24. <result property="sort" column="sort" />
  25. <result property="createBy" column="create_by" />
  26. <result property="createTime" column="create_time" />
  27. <result property="updateBy" column="update_by" />
  28. <result property="updateTime" column="update_time" />
  29. </resultMap>
  30. <sql id="selectGenTableColumnVo">
  31. 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, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
  32. </sql>
  33. <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
  34. <include refid="selectGenTableColumnVo"/>
  35. where table_id = #{tableId}
  36. order by sort
  37. </select>
  38. <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
  39. select lower(temp.column_name) as column_name,
  40. (case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required,
  41. (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
  42. temp.column_id as sort,
  43. temp.comments as column_comment,
  44. (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
  45. lower(temp.data_type) as column_type
  46. from (
  47. select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type
  48. , row_number() over (partition by col.column_name order by uc.constraint_type desc) as row_flg
  49. from user_tab_columns col
  50. left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
  51. left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
  52. left join user_constraints uc on uc.constraint_name = ucc.constraint_name
  53. where col.table_name = upper(#{tableName})
  54. ) temp
  55. WHERE temp.row_flg = 1
  56. ORDER BY temp.column_id
  57. </select>
  58. <insert id="insertGenTableColumn" parameterType="GenTableColumn">
  59. <selectKey keyProperty="columnId" resultType="long" order="BEFORE">
  60. SELECT seq_gen_table_column.NEXTVAL as columnId FROM DUAL
  61. </selectKey>
  62. insert into gen_table_column (
  63. <if test="columnId != null and columnId != ''">column_id,</if>
  64. <if test="tableId != null and tableId != ''">table_id,</if>
  65. <if test="columnName != null and columnName != ''">column_name,</if>
  66. <if test="columnComment != null and columnComment != ''">column_comment,</if>
  67. <if test="columnType != null and columnType != ''">column_type,</if>
  68. <if test="javaType != null and javaType != ''">java_type,</if>
  69. <if test="javaField != null and javaField != ''">java_field,</if>
  70. <if test="isPk != null and isPk != ''">is_pk,</if>
  71. <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
  72. <if test="isRequired != null and isRequired != ''">is_required,</if>
  73. <if test="isInsert != null and isInsert != ''">is_insert,</if>
  74. <if test="isEdit != null and isEdit != ''">is_edit,</if>
  75. <if test="isList != null and isList != ''">is_list,</if>
  76. <if test="isQuery != null and isQuery != ''">is_query,</if>
  77. <if test="queryType != null and queryType != ''">query_type,</if>
  78. <if test="htmlType != null and htmlType != ''">html_type,</if>
  79. <if test="dictType != null and dictType != ''">dict_type,</if>
  80. <if test="sort != null">sort,</if>
  81. <if test="createBy != null and createBy != ''">create_by,</if>
  82. create_time
  83. )values(
  84. <if test="columnId != null and columnId != ''">#{columnId},</if>
  85. <if test="tableId != null and tableId != ''">#{tableId},</if>
  86. <if test="columnName != null and columnName != ''">#{columnName},</if>
  87. <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
  88. <if test="columnType != null and columnType != ''">#{columnType},</if>
  89. <if test="javaType != null and javaType != ''">#{javaType},</if>
  90. <if test="javaField != null and javaField != ''">#{javaField},</if>
  91. <if test="isPk != null and isPk != ''">#{isPk},</if>
  92. <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
  93. <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
  94. <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
  95. <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
  96. <if test="isList != null and isList != ''">#{isList},</if>
  97. <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
  98. <if test="queryType != null and queryType != ''">#{queryType},</if>
  99. <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
  100. <if test="dictType != null and dictType != ''">#{dictType},</if>
  101. <if test="sort != null">#{sort},</if>
  102. <if test="createBy != null and createBy != ''">#{createBy},</if>
  103. sysdate
  104. )
  105. </insert>
  106. <update id="updateGenTableColumn" parameterType="GenTableColumn">
  107. update gen_table_column
  108. <set>
  109. column_comment = #{columnComment},
  110. java_type = #{javaType},
  111. java_field = #{javaField},
  112. is_insert = #{isInsert,jdbcType=CHAR},
  113. is_edit = #{isEdit,jdbcType=CHAR},
  114. is_list = #{isList,jdbcType=CHAR},
  115. is_query = #{isQuery,jdbcType=CHAR},
  116. is_required = #{isRequired,jdbcType=CHAR},
  117. query_type = #{queryType},
  118. html_type = #{htmlType},
  119. dict_type = #{dictType},
  120. sort = #{sort},
  121. update_by = #{updateBy,jdbcType=VARCHAR},
  122. update_time = sysdate
  123. </set>
  124. where column_id = #{columnId}
  125. </update>
  126. <delete id="deleteGenTableColumnByIds" parameterType="Long">
  127. delete from gen_table_column where table_id in
  128. <foreach collection="array" item="tableId" open="(" separator="," close=")">
  129. #{tableId}
  130. </foreach>
  131. </delete>
  132. <delete id="deleteGenTableColumns">
  133. delete from gen_table_column where column_id in
  134. <foreach collection="list" item="item" open="(" separator="," close=")">
  135. #{item.columnId}
  136. </foreach>
  137. </delete>
  138. </mapper>