提交 | 用户 | 时间
|
0ca254
|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
A |
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.jcdm.generator.mapper.GenTableColumnMapper"> |
|
6 |
|
|
7 |
<resultMap type="GenTableColumn" id="GenTableColumnResult"> |
|
8 |
<id property="columnId" column="column_id" /> |
|
9 |
<result property="tableId" column="table_id" /> |
|
10 |
<result property="columnName" column="column_name" /> |
|
11 |
<result property="columnComment" column="column_comment" /> |
|
12 |
<result property="columnType" column="column_type" /> |
|
13 |
<result property="javaType" column="java_type" /> |
|
14 |
<result property="javaField" column="java_field" /> |
|
15 |
<result property="isPk" column="is_pk" /> |
|
16 |
<result property="isIncrement" column="is_increment" /> |
|
17 |
<result property="isRequired" column="is_required" /> |
|
18 |
<result property="isInsert" column="is_insert" /> |
|
19 |
<result property="isEdit" column="is_edit" /> |
|
20 |
<result property="isList" column="is_list" /> |
|
21 |
<result property="isQuery" column="is_query" /> |
|
22 |
<result property="queryType" column="query_type" /> |
|
23 |
<result property="htmlType" column="html_type" /> |
|
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 |
</resultMap> |
|
31 |
|
|
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, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column |
|
34 |
</sql> |
|
35 |
|
|
36 |
<select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult"> |
|
37 |
<include refid="selectGenTableColumnVo"/> |
|
38 |
where table_id = #{tableId} |
|
39 |
order by sort |
|
40 |
</select> |
|
41 |
|
|
42 |
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> |
|
43 |
SELECT a.name AS column_name, |
|
44 |
(CASE WHEN a.isnullable = 1 THEN 0 ELSE 1 END) AS is_required, |
|
45 |
(CASE WHEN ( |
|
46 |
SELECT COUNT(*) FROM sysobjects |
|
47 |
WHERE (name IN ( |
|
48 |
SELECT name FROM sysindexes |
|
49 |
WHERE (id = a.id) |
|
50 |
AND (indid IN ( |
|
51 |
SELECT indid FROM sysindexkeys |
|
52 |
WHERE (id = a.id) |
|
53 |
AND (colid IN (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name))) |
|
54 |
)))) |
|
55 |
AND (xtype = 'PK') |
|
56 |
) > 0 THEN 1 |
|
57 |
ELSE 0 END) AS is_pk, |
|
58 |
a.colorder AS sort, |
|
59 |
isnull(g.[value], ' ') AS column_comment, |
|
60 |
(CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN 1 ELSE 0 END) AS is_increment, |
|
61 |
b.name AS column_type |
|
62 |
FROM syscolumns as a |
|
63 |
LEFT JOIN systypes b ON a.xtype = b.xusertype |
|
64 |
INNER JOIN sysobjects d ON a.id = d.id AND d.xtype = 'U' AND d.name <![CDATA[<>]]> 'dtproperties' |
|
65 |
LEFT JOIN syscomments e ON a.cdefault = e.id |
|
66 |
LEFT JOIN sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id |
|
67 |
LEFT JOIN sys.extended_properties f ON d.id = f.class AND f.minor_id = 0 |
|
68 |
LEFT JOIN sys.objects h ON a.id = h.object_id |
|
69 |
LEFT JOIN sys.schemas i ON h.schema_id = i.schema_id |
|
70 |
WHERE d.name = #{tableName} |
|
71 |
ORDER BY a.colorder |
|
72 |
</select> |
|
73 |
|
|
74 |
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> |
|
75 |
insert into gen_table_column ( |
|
76 |
<if test="tableId != null and tableId != ''">table_id,</if> |
|
77 |
<if test="columnName != null and columnName != ''">column_name,</if> |
|
78 |
<if test="columnComment != null and columnComment != ''">column_comment,</if> |
|
79 |
<if test="columnType != null and columnType != ''">column_type,</if> |
|
80 |
<if test="javaType != null and javaType != ''">java_type,</if> |
|
81 |
<if test="javaField != null and javaField != ''">java_field,</if> |
|
82 |
<if test="isPk != null and isPk != ''">is_pk,</if> |
|
83 |
<if test="isIncrement != null and isIncrement != ''">is_increment,</if> |
|
84 |
<if test="isRequired != null and isRequired != ''">is_required,</if> |
|
85 |
<if test="isInsert != null and isInsert != ''">is_insert,</if> |
|
86 |
<if test="isEdit != null and isEdit != ''">is_edit,</if> |
|
87 |
<if test="isList != null and isList != ''">is_list,</if> |
|
88 |
<if test="isQuery != null and isQuery != ''">is_query,</if> |
|
89 |
<if test="queryType != null and queryType != ''">query_type,</if> |
|
90 |
<if test="htmlType != null and htmlType != ''">html_type,</if> |
|
91 |
<if test="dictType != null and dictType != ''">dict_type,</if> |
|
92 |
<if test="sort != null">sort,</if> |
|
93 |
<if test="createBy != null and createBy != ''">create_by,</if> |
|
94 |
create_time |
|
95 |
)values( |
|
96 |
<if test="tableId != null and tableId != ''">#{tableId},</if> |
|
97 |
<if test="columnName != null and columnName != ''">#{columnName},</if> |
|
98 |
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> |
|
99 |
<if test="columnType != null and columnType != ''">#{columnType},</if> |
|
100 |
<if test="javaType != null and javaType != ''">#{javaType},</if> |
|
101 |
<if test="javaField != null and javaField != ''">#{javaField},</if> |
|
102 |
<if test="isPk != null and isPk != ''">#{isPk},</if> |
|
103 |
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> |
|
104 |
<if test="isRequired != null and isRequired != ''">#{isRequired},</if> |
|
105 |
<if test="isInsert != null and isInsert != ''">#{isInsert},</if> |
|
106 |
<if test="isEdit != null and isEdit != ''">#{isEdit},</if> |
|
107 |
<if test="isList != null and isList != ''">#{isList},</if> |
|
108 |
<if test="isQuery != null and isQuery != ''">#{isQuery},</if> |
|
109 |
<if test="queryType != null and queryType != ''">#{queryType},</if> |
|
110 |
<if test="htmlType != null and htmlType != ''">#{htmlType},</if> |
|
111 |
<if test="dictType != null and dictType != ''">#{dictType},</if> |
|
112 |
<if test="sort != null">#{sort},</if> |
|
113 |
<if test="createBy != null and createBy != ''">#{createBy},</if> |
|
114 |
getdate() |
|
115 |
) |
|
116 |
</insert> |
|
117 |
|
|
118 |
<update id="updateGenTableColumn" parameterType="GenTableColumn"> |
|
119 |
update gen_table_column |
|
120 |
<set> |
|
121 |
is_insert = #{isInsert}, |
|
122 |
is_edit = #{isEdit}, |
|
123 |
is_list = #{isList}, |
|
124 |
is_query = #{isQuery}, |
|
125 |
is_required = #{isRequired}, |
|
126 |
<if test="columnComment != null">column_comment = #{columnComment},</if> |
|
127 |
<if test="javaType != null">java_type = #{javaType},</if> |
|
128 |
<if test="javaField != null">java_field = #{javaField},</if> |
|
129 |
<if test="queryType != null">query_type = #{queryType},</if> |
|
130 |
<if test="htmlType != null">html_type = #{htmlType},</if> |
|
131 |
<if test="dictType != null">dict_type = #{dictType},</if> |
|
132 |
<if test="sort != null">sort = #{sort},</if> |
|
133 |
<if test="updateBy != null">update_by = #{updateBy},</if> |
|
134 |
update_time = getdate() |
|
135 |
</set> |
|
136 |
where column_id = #{columnId} |
|
137 |
</update> |
|
138 |
|
|
139 |
<delete id="deleteGenTableColumnByIds" parameterType="Long"> |
|
140 |
delete from gen_table_column where table_id in |
|
141 |
<foreach collection="array" item="tableId" open="(" separator="," close=")"> |
|
142 |
#{tableId} |
|
143 |
</foreach> |
|
144 |
</delete> |
|
145 |
|
|
146 |
<delete id="deleteGenTableColumns"> |
|
147 |
delete from gen_table_column where column_id in |
|
148 |
<foreach collection="list" item="item" open="(" separator="," close=")"> |
|
149 |
#{item.columnId} |
|
150 |
</foreach> |
|
151 |
</delete> |
|
152 |
|
|
153 |
</mapper> |