d2513a54e0306ef153ed3b7c9282a3d4ca27a2fa.svn-base
5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.thinkgem.jeesite.modules.sys.dao.RoleDao">
<resultMap id="roleResult" type="Role">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="enname" column="enname" />
<result property="roleType" column="roleType" />
<result property="dataScope" column="dataScope" />
<result property="remarks" column="remarks" />
<result property="useable" column="useable" />
<result property="sysData" column="sysData" /><!--
<collection property="userList" ofType="User">
<id property="id" column="userList.id" />
<id property="loginName" column="userList.loginName" />
<id property="name" column="userList.name" />
<id property="email" column="userList.email" />
<id property="phone" column="userList.phone" />
<id property="mobile" column="userList.mobile" />
<id property="office.name" column="userList.office.name" />
<id property="company.name" column="userList.company.name" />
</collection> -->
<collection property="menuList" ofType="Menu">
<id property="id" column="menuList.id" />
</collection>
<collection property="officeList" ofType="Office">
<id property="id" column="officeList.id" />
</collection>
</resultMap>
<sql id="roleColumns">
a.id,
a.office_id AS "office.id",
a.name,
a.enname,
a.role_type AS roleType,
a.data_scope AS dataScope,
a.remarks,
a.create_by AS "createBy.id",
a.create_date,
a.update_by AS "updateBy.id",
a.update_date,
a.del_flag,
o.name AS "office.name",
o.code,
a.useable AS useable,
a.is_sys AS sysData
</sql>
<select id="get" resultMap="roleResult">
SELECT
<include refid="roleColumns"/>,<!--
ur.user_id AS "userList.id",
u.login_name AS "userList.loginName",
u.name AS "userList.name",
u.email AS "userList.email",
u.phone AS "userList.phone",
u.mobile AS "userList.mobile",
uc.name AS "userList.company.name",
uo.name AS "userList.office.name", -->
rm.menu_id AS "menuList.id",
ro.office_id AS "officeList.id"
FROM sys_role a
JOIN sys_office o ON o.id = a.office_id<!--
LEFT JOIN sys_user_role ur ON ur.role_id = a.id
LEFT JOIN sys_user u ON u.id = ur.user_id
LEFT JOIN sys_office uc ON uc.id = u.company_id
LEFT JOIN sys_office uo ON uo.id = u.office_id -->
LEFT JOIN sys_role_menu rm ON rm.role_id = a.id
LEFT JOIN sys_role_office ro ON ro.role_id = a.id
WHERE a.id = #{id}
</select>
<select id="getByName" resultType="Role">
SELECT
<include refid="roleColumns"/>
FROM sys_role a
JOIN sys_office o ON o.id = a.office_id
WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL}
</select>
<select id="getByEnname" resultType="Role">
SELECT
<include refid="roleColumns"/>
FROM sys_role a
JOIN sys_office o ON o.id = a.office_id
WHERE a.enname = #{enname} AND a.del_flag = #{DEL_FLAG_NORMAL}
</select>
<select id="findList" resultMap="roleResult">
SELECT <!-- DISTINCT -->
<include refid="roleColumns"/>,
ro.office_id AS "officeList.id"
FROM sys_role a
LEFT JOIN sys_office o ON o.id = a.office_id
LEFT JOIN sys_user_role ur ON ur.role_id = a.id
LEFT JOIN sys_user u ON u.id = ur.user_id
LEFT JOIN sys_role_office ro ON ro.role_id = a.id
WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable}
<if test="user != null and user.id != null and user.id != ''">
AND u.id = #{user.id}
</if>
<if test="user != null and user.loginName != null and user.loginName != ''">
AND u.login_name = #{user.loginName}
</if>
<!-- 数据范围过滤 -->
${sqlMap.dsf}
ORDER BY o.code, a.name
</select>
<select id="findAllList" resultType="Role">
SELECT
<include refid="roleColumns"/>
FROM sys_role a
LEFT JOIN sys_office o ON o.id = a.office_id
WHERE a.del_flag = #{DEL_FLAG_NORMAL}
ORDER BY o.code, a.name
</select>
<insert id="insert">
INSERT INTO sys_role(
id,
office_id,
name,
enname,
role_type,
data_scope,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag,
is_sys,
useable
) VALUES (
#{id},
#{office.id},
#{name},
#{enname},
#{roleType},
#{dataScope},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag},
#{sysData},
#{useable}
)
</insert>
<update id="update">
UPDATE sys_role SET
office_id = #{office.id},
name = #{name},
enname = #{enname},
role_type = #{roleType},
data_scope = #{dataScope},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
is_sys = #{sysData},
useable = #{useable}
WHERE id = #{id}
</update>
<delete id="deleteRoleMenu">
DELETE FROM sys_role_menu WHERE role_id = #{id}
</delete>
<insert id="insertRoleMenu">
INSERT INTO sys_role_menu(role_id, menu_id)
<foreach collection="menuList" item="menu" separator=" union all ">
SELECT #{id}, #{menu.id} FROM dual
</foreach>
</insert>
<delete id="deleteRoleOffice">
DELETE FROM sys_role_office WHERE role_id = #{id}
</delete>
<insert id="insertRoleOffice">
INSERT INTO sys_role_office(role_id, office_id)
<foreach collection="officeList" item="office" separator=" union all ">
SELECT #{id}, #{office.id} FROM dual
</foreach>
</insert>
<update id="delete">
UPDATE sys_role SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
</mapper>