提交 | 用户 | 时间
|
e57a89
|
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.jcdm.system.mapper.SysUserMapper"> |
|
6 |
|
|
7 |
<resultMap type="SysUser" id="SysUserResult"> |
|
8 |
<id property="userId" column="user_id" /> |
|
9 |
<result property="deptId" column="dept_id" /> |
|
10 |
<result property="userName" column="user_name" /> |
|
11 |
<result property="nickName" column="nick_name" /> |
|
12 |
<result property="email" column="email" /> |
|
13 |
<result property="phonenumber" column="phonenumber" /> |
|
14 |
<result property="sex" column="sex" /> |
|
15 |
<result property="avatar" column="avatar" /> |
|
16 |
<result property="password" column="password" /> |
|
17 |
<result property="status" column="status" /> |
|
18 |
<result property="delFlag" column="del_flag" /> |
|
19 |
<result property="loginIp" column="login_ip" /> |
|
20 |
<result property="loginDate" column="login_date" /> |
|
21 |
<result property="createBy" column="create_by" /> |
|
22 |
<result property="createTime" column="create_time" /> |
|
23 |
<result property="updateBy" column="update_by" /> |
|
24 |
<result property="updateTime" column="update_time" /> |
|
25 |
<result property="remark" column="remark" /> |
|
26 |
<association property="dept" javaType="SysDept" resultMap="deptResult" /> |
|
27 |
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" /> |
|
28 |
</resultMap> |
|
29 |
|
|
30 |
<resultMap id="deptResult" type="SysDept"> |
|
31 |
<id property="deptId" column="dept_id" /> |
|
32 |
<result property="parentId" column="parent_id" /> |
|
33 |
<result property="deptName" column="dept_name" /> |
|
34 |
<result property="ancestors" column="ancestors" /> |
|
35 |
<result property="orderNum" column="order_num" /> |
|
36 |
<result property="leader" column="leader" /> |
|
37 |
<result property="status" column="dept_status" /> |
|
38 |
</resultMap> |
|
39 |
|
|
40 |
<resultMap id="RoleResult" type="SysRole"> |
|
41 |
<id property="roleId" column="role_id" /> |
|
42 |
<result property="roleName" column="role_name" /> |
|
43 |
<result property="roleKey" column="role_key" /> |
|
44 |
<result property="roleSort" column="role_sort" /> |
|
45 |
<result property="dataScope" column="data_scope" /> |
|
46 |
<result property="status" column="role_status" /> |
|
47 |
</resultMap> |
|
48 |
|
|
49 |
<sql id="selectUserVo"> |
|
50 |
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, |
|
51 |
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, |
|
52 |
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status |
|
53 |
from sys_user u |
|
54 |
left join sys_dept d on u.dept_id = d.dept_id |
|
55 |
left join sys_user_role ur on u.user_id = ur.user_id |
|
56 |
left join sys_role r on r.role_id = ur.role_id |
|
57 |
</sql> |
|
58 |
|
|
59 |
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> |
|
60 |
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u |
|
61 |
left join sys_dept d on u.dept_id = d.dept_id |
|
62 |
where u.del_flag = '0' |
|
63 |
<if test="userId != null and userId != 0"> |
|
64 |
AND u.user_id = #{userId} |
|
65 |
</if> |
|
66 |
<if test="userName != null and userName != ''"> |
|
67 |
AND u.user_name like concat('%', #{userName}, '%') |
|
68 |
</if> |
|
69 |
<if test="status != null and status != ''"> |
|
70 |
AND u.status = #{status} |
|
71 |
</if> |
|
72 |
<if test="phonenumber != null and phonenumber != ''"> |
|
73 |
AND u.phonenumber like concat('%', #{phonenumber}, '%') |
|
74 |
</if> |
|
75 |
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> |
|
76 |
<!-- and <![CDATA[ u.create_time >= convert(datetime, #{params.beginTime}, 20)]]>--> |
|
77 |
and datediff(d, u.create_time, #{params.beginTime}) <![CDATA[<=]]> 0 |
|
78 |
</if> |
|
79 |
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> |
|
80 |
<!-- and <![CDATA[ u.create_time <= convert(datetime, #{params.endTime}, 20)]]>--> |
|
81 |
and datediff(d, u.create_time, #{params.endTime}) <![CDATA[>=]]> 0 |
|
82 |
</if> |
|
83 |
<if test="deptId != null and deptId != 0"> |
|
84 |
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE charindex(',' + CONVERT (nvarchar, #{deptId}), ',' + ancestors) > 0 )) |
|
85 |
</if> |
|
86 |
<!-- 数据范围过滤 --> |
|
87 |
${params.dataScope} |
|
88 |
</select> |
|
89 |
|
|
90 |
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> |
|
91 |
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time |
|
92 |
from sys_user u |
|
93 |
left join sys_dept d on u.dept_id = d.dept_id |
|
94 |
left join sys_user_role ur on u.user_id = ur.user_id |
|
95 |
left join sys_role r on r.role_id = ur.role_id |
|
96 |
where u.del_flag = '0' and r.role_id = #{roleId} |
|
97 |
<if test="userName != null and userName != ''"> |
|
98 |
AND u.user_name like concat('%', #{userName}, '%') |
|
99 |
</if> |
|
100 |
<if test="phonenumber != null and phonenumber != ''"> |
|
101 |
AND u.phonenumber like concat('%', #{phonenumber}, '%') |
|
102 |
</if> |
|
103 |
<!-- 数据范围过滤 --> |
|
104 |
${params.dataScope} |
|
105 |
</select> |
|
106 |
|
|
107 |
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> |
|
108 |
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time |
|
109 |
from sys_user u |
|
110 |
left join sys_dept d on u.dept_id = d.dept_id |
|
111 |
left join sys_user_role ur on u.user_id = ur.user_id |
|
112 |
left join sys_role r on r.role_id = ur.role_id |
|
113 |
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL) |
|
114 |
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId}) |
|
115 |
<if test="userName != null and userName != ''"> |
|
116 |
AND u.user_name like concat('%', #{userName}, '%') |
|
117 |
</if> |
|
118 |
<if test="phonenumber != null and phonenumber != ''"> |
|
119 |
AND u.phonenumber like concat('%', #{phonenumber}, '%') |
|
120 |
</if> |
|
121 |
<!-- 数据范围过滤 --> |
|
122 |
${params.dataScope} |
|
123 |
</select> |
|
124 |
|
|
125 |
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult"> |
|
126 |
<include refid="selectUserVo"/> |
|
127 |
where u.user_name = #{userName} and u.del_flag = '0' |
|
128 |
</select> |
|
129 |
|
|
130 |
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult"> |
|
131 |
<include refid="selectUserVo"/> |
|
132 |
where u.user_id = #{userId} |
|
133 |
</select> |
|
134 |
|
|
135 |
<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult"> |
|
136 |
select top(1) user_id, user_name from sys_user where user_name = #{userName} and del_flag = '0' |
|
137 |
</select> |
|
138 |
|
|
139 |
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult"> |
|
140 |
select top(1) user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' |
|
141 |
</select> |
|
142 |
|
|
143 |
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult"> |
|
144 |
select top(1) user_id, email from sys_user where email = #{email} and del_flag = '0' |
|
145 |
</select> |
|
146 |
|
|
147 |
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> |
|
148 |
insert into sys_user( |
|
149 |
<if test="userId != null and userId != 0">user_id,</if> |
|
150 |
<if test="deptId != null and deptId != 0">dept_id,</if> |
|
151 |
<if test="userName != null and userName != ''">user_name,</if> |
|
152 |
<if test="nickName != null and nickName != ''">nick_name,</if> |
|
153 |
<if test="email != null and email != ''">email,</if> |
|
154 |
<if test="avatar != null and avatar != ''">avatar,</if> |
|
155 |
<if test="phonenumber != null and phonenumber != ''">phonenumber,</if> |
|
156 |
<if test="sex != null and sex != ''">sex,</if> |
|
157 |
<if test="password != null and password != ''">password,</if> |
|
158 |
<if test="status != null and status != ''">status,</if> |
|
159 |
<if test="createBy != null and createBy != ''">create_by,</if> |
|
160 |
<if test="remark != null and remark != ''">remark,</if> |
|
161 |
create_time |
|
162 |
)values( |
|
163 |
<if test="userId != null and userId != ''">#{userId},</if> |
|
164 |
<if test="deptId != null and deptId != ''">#{deptId},</if> |
|
165 |
<if test="userName != null and userName != ''">#{userName},</if> |
|
166 |
<if test="nickName != null and nickName != ''">#{nickName},</if> |
|
167 |
<if test="email != null and email != ''">#{email},</if> |
|
168 |
<if test="avatar != null and avatar != ''">#{avatar},</if> |
|
169 |
<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if> |
|
170 |
<if test="sex != null and sex != ''">#{sex},</if> |
|
171 |
<if test="password != null and password != ''">#{password},</if> |
|
172 |
<if test="status != null and status != ''">#{status},</if> |
|
173 |
<if test="createBy != null and createBy != ''">#{createBy},</if> |
|
174 |
<if test="remark != null and remark != ''">#{remark},</if> |
|
175 |
getdate() |
|
176 |
) |
|
177 |
</insert> |
|
178 |
|
|
179 |
<update id="updateUser" parameterType="SysUser"> |
|
180 |
update sys_user |
|
181 |
<set> |
|
182 |
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if> |
|
183 |
<if test="userName != null and userName != ''">user_name = #{userName},</if> |
|
184 |
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if> |
|
185 |
<if test="email != null ">email = #{email},</if> |
|
186 |
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if> |
|
187 |
<if test="sex != null and sex != ''">sex = #{sex},</if> |
|
188 |
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if> |
|
189 |
<if test="password != null and password != ''">password = #{password},</if> |
|
190 |
<if test="status != null and status != ''">status = #{status},</if> |
|
191 |
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if> |
|
192 |
<if test="loginDate != null">login_date = #{loginDate},</if> |
|
193 |
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
|
194 |
<if test="remark != null">remark = #{remark},</if> |
|
195 |
update_time = getdate() |
|
196 |
</set> |
|
197 |
where user_id = #{userId} |
|
198 |
</update> |
|
199 |
|
|
200 |
<update id="updateUserStatus" parameterType="SysUser"> |
|
201 |
update sys_user set status = #{status} where user_id = #{userId} |
|
202 |
</update> |
|
203 |
|
|
204 |
<update id="updateUserAvatar" parameterType="SysUser"> |
|
205 |
update sys_user set avatar = #{avatar} where user_name = #{userName} |
|
206 |
</update> |
|
207 |
|
|
208 |
<update id="resetUserPwd" parameterType="SysUser"> |
|
209 |
update sys_user set password = #{password} where user_name = #{userName} |
|
210 |
</update> |
|
211 |
|
|
212 |
<delete id="deleteUserById" parameterType="Long"> |
|
213 |
update sys_user set del_flag = '2' where user_id = #{userId} |
|
214 |
</delete> |
|
215 |
|
|
216 |
<delete id="deleteUserByIds" parameterType="Long"> |
|
217 |
update sys_user set del_flag = '2' where user_id in |
|
218 |
<foreach collection="array" item="userId" open="(" separator="," close=")"> |
|
219 |
#{userId} |
|
220 |
</foreach> |
|
221 |
</delete> |
|
222 |
|
|
223 |
</mapper> |