UserMapper.xml
6.47 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
<?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="cn.com.glsx.neshield.modules.mapper.UserMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.neshield.modules.entity.User">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="username" jdbcType="VARCHAR" property="username"/>
<result column="account" jdbcType="VARCHAR" property="account"/>
<result column="password" jdbcType="VARCHAR" property="password"/>
<result column="phone_number" jdbcType="VARCHAR" property="phoneNumber"/>
<result column="portrait" jdbcType="VARCHAR" property="portrait"/>
<result column="email" jdbcType="VARCHAR" property="email"/>
<result column="gender" jdbcType="INTEGER" property="gender"/>
<result column="position_" jdbcType="VARCHAR" property="position"/>
<result column="tenant_id" jdbcType="INTEGER" property="tenantId"/>
<result column="department_id" jdbcType="INTEGER" property="departmentId"/>
<result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
<result column="salt" jdbcType="VARCHAR" property="salt"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="is_admin" jdbcType="TINYINT" property="admin"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
id, username, account, `password`, phone_number,
portrait, email, gender, position, salt, tenant_id, department_id,
superior_id, is_admin, del_flag, enable_status,
created_date, created_by, updated_date, updated_by
</sql>
<select id="selectById" resultMap="BaseResultMap">
select * from t_user
where id = #{id}
and del_flag = 0
</select>
<select id="selectByDepartmentId" resultMap="BaseResultMap">
select * from t_user
where department_id = #{departmentId}
and del_flag = 0
</select>
<select id="selectExcludeUserIdByDepartmentId" resultMap="BaseResultMap">
select * from t_user
where del_flag = 0
and department_id = #{departmentId}
and id <![CDATA[ <> ]]> #{userId}
</select>
<select id="selectCntByAccount" parameterType="java.lang.String" resultType="java.lang.Integer">
select count(account) from t_user
where account = #{account}
and del_flag = 0
</select>
<select id="selectByAccount" parameterType="java.lang.String" resultMap="BaseResultMap">
select * from t_user
where account = #{account}
and del_flag = 0
limit 1
</select>
<select id="selectList" resultMap="BaseResultMap"
parameterType="cn.com.glsx.neshield.modules.model.param.UserSearch">
select
<include refid="Base_Column_List"/>
from t_user where del_flag = 0
<if test="searchField != null and searchField !=''">
and (
account like CONCAT('%',#{searchField},'%')
or
phone_number like CONCAT('%',#{searchField},'%')
or
username like CONCAT('%',#{searchField},'%')
or
id = #{searchField}
)
</if>
<if test="userId != null">
and user_id = #{userId}
</if>
<if test="userStatus != null">
and enable_status = #{userStatus}
</if>
<if test="departmentIdList != null and departmentIdList.size() > 0">
and department_id in
<foreach collection="departmentIdList" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</if>
order by id desc
</select>
<update id="logicDeleteById">
update t_user set del_flag = -1 where id = #{id}
</update>
<select id="countByCriterial" parameterType="cn.com.glsx.neshield.modules.model.param.UserBO"
resultType="java.lang.Integer">
select count(*) from t_user
where del_flag = 0
<if test="departmentId != null">
and department_id = #{departmentId}
</if>
<if test="departmentIds != null and departmentIds.size() > 0">
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</if>
</select>
<select id="countDepartmentsUser" resultType="cn.com.glsx.neshield.modules.model.view.DepartmentCount">
select department_id as departmentId, count(*) as userNumber from t_user
where del_flag = 0
<if test="departmentIds != null and departmentIds.size() > 0">
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</if>
group by department_id
</select>
<select id="selectDepartmentsSubordinate" resultType="cn.com.glsx.neshield.modules.entity.User">
select tu.id id, tu.account account, tu.username username, tu.department_id departmentId,
tu.phone_number phoneNumber, tu.enable_status enableStatus, tu.created_date createdDate
from t_user tu, t_user_path tup
where tu.del_flag = 0 and tup.del_flag = 0
and tu.id = tup.sub_id
and tup.superior_id = #{userId}
<if test="userStatus != null">
and tu.enable_status = #{userStatus}
</if>
<if test="searchField != null">
and (
tu.account like CONCAT('%',#{searchField},'%')
or
tu.phone_number like CONCAT('%',#{searchField},'%')
or
tu.username like CONCAT('%',#{searchField},'%')
)
</if>
<if test="departmentIdList != null and departmentIdList.size() > 0">
and tu.department_id in
<foreach collection="departmentIdList" separator="," close=")" open="(" item="departmentId">
#{departmentId}
</foreach>
</if>
</select>
</mapper>