Digital Office Automation System Backend
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

GenTableColumnMapper.xml 7.0KB

před 1 dnem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
  31. <if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">
  32. select column_name,
  33. (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required,
  34. (case when column_key = 'PRI' then '1' else '0' end) as is_pk,
  35. ordinal_position as sort,
  36. column_comment,
  37. (case when extra = 'auto_increment' then '1' else '0' end) as is_increment,
  38. column_type
  39. from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
  40. order by ordinal_position
  41. </if>
  42. <if test="@com.ruoyi.common.helper.DataBaseHelper@isOracle()">
  43. select lower(temp.column_name) as column_name,
  44. (case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required,
  45. (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
  46. temp.column_id as sort,
  47. temp.comments as column_comment,
  48. (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
  49. lower(temp.data_type) as column_type
  50. from (
  51. select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type, row_number()
  52. over (partition by col.column_name order by uc.constraint_type desc) as row_flg
  53. from user_tab_columns col
  54. left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
  55. left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
  56. left join user_constraints uc on uc.constraint_name = ucc.constraint_name
  57. where col.table_name = upper(#{tableName})
  58. ) temp
  59. WHERE temp.row_flg = 1
  60. ORDER BY temp.column_id
  61. </if>
  62. <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
  63. SELECT column_name, is_required, is_pk, sort, column_comment, is_increment, column_type
  64. FROM (
  65. SELECT c.relname AS table_name,
  66. a.attname AS column_name,
  67. d.description AS column_comment,
  68. CASE WHEN a.attnotnull AND con.conname IS NULL THEN 1 ELSE 0
  69. END AS is_required,
  70. CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0
  71. END AS is_pk,
  72. a.attnum AS sort,
  73. CASE WHEN "position"(pg_get_expr(ad.adbin, ad.adrelid),
  74. ((c.relname::text || '_'::text) || a.attname::text) || '_seq'::text) > 0 THEN 1 ELSE 0
  75. END AS is_increment,
  76. btrim(
  77. CASE WHEN t.typelem <![CDATA[ <> ]]> 0::oid AND t.typlen = '-1'::integer THEN 'ARRAY'::text ELSE
  78. CASE WHEN t.typtype = 'd'::"char" THEN format_type(t.typbasetype, NULL::integer)
  79. ELSE format_type(a.atttypid, NULL::integer) END
  80. END, '"'::text
  81. ) AS column_type
  82. FROM pg_attribute a
  83. JOIN (pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid) ON a.attrelid = c.oid
  84. LEFT JOIN pg_description d ON d.objoid = c.oid AND a.attnum = d.objsubid
  85. LEFT JOIN pg_constraint con ON con.conrelid = c.oid AND (a.attnum = ANY (con.conkey))
  86. LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
  87. LEFT JOIN pg_type t ON a.atttypid = t.oid
  88. WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
  89. AND a.attnum > 0
  90. AND n.nspname = 'public'::name
  91. ORDER BY c.relname, a.attnum
  92. ) temp
  93. WHERE table_name = (#{tableName})
  94. AND column_type <![CDATA[ <> ]]> '-'
  95. </if>
  96. <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
  97. SELECT
  98. cast(A.NAME as nvarchar) as column_name,
  99. cast(B.NAME as nvarchar) + (case when B.NAME = 'numeric' then '(' + cast(A.prec as nvarchar) + ',' + cast(A.scale as nvarchar) + ')' else '' end) as column_type,
  100. cast(G.[VALUE] as nvarchar) as column_comment,
  101. (SELECT 1 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE Z WHERE TABLE_NAME = D.NAME and A.NAME = Z.column_name ) as is_pk,
  102. colorder as sort
  103. FROM SYSCOLUMNS A
  104. LEFT JOIN SYSTYPES B ON A.XTYPE = B.XUSERTYPE
  105. INNER JOIN SYSOBJECTS D ON A.ID = D.ID AND D.XTYPE='U' AND D.NAME != 'DTPROPERTIES'
  106. LEFT JOIN SYS.EXTENDED_PROPERTIES G ON A.ID = G.MAJOR_ID AND A.COLID = G.MINOR_ID
  107. LEFT JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID AND F.MINOR_ID = 0
  108. WHERE D.NAME = #{tableName}
  109. ORDER BY A.COLORDER
  110. </if>
  111. </select>
  112. </mapper>