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
<?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.wisenergy.mapper.WorkUserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkUser">
<id column="id" property="id" />
<result column="oa_user_id" property="oaUserId" />
<result column="dept_id" property="deptId" />
<result column="name" property="name" />
<result column="login_name" property="loginName" />
<result column="password" property="password" />
<result column="phone" property="phone" />
<result column="email" property="email" />
<result column="role" property="role" />
<result column="type" property="type" />
<result column="status" property="status" />
<result column="wx_id" property="wxId" />
<result column="submit_order" property="submitOrder"/>
<result column="create_time" property="createTime" />
<result column="modify_time" property="modifyTime" />
</resultMap>
<sql id="table">
work_user
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
name, oa_user_id, login_name, phone, dept_id, email, role ,type,status,wx_id,submit_order,create_time,modify_time
</sql>
<sql id="values">
#{name},#{oaUserId},#{loginName},#{phone},#{deptId},#{email},#{role},#{type},#{status},#{wxId},#{submitOrder},now(),now()
</sql>
<sql id="updateCondition">
<if test="name != null">name = #{name},</if>
<if test="oaUserId != null">oa_user_id = #{oaUserId},</if>
<if test="loginName != null">login_name = #{loginName},</if>
<if test="password != null">password = #{password},</if>
<if test="phone != null">phone =#{phone},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="email != null">email = #{email},</if>
<if test="role != null">role = #{role},</if>
<if test="type != null">type =#{type},</if>
<if test="status != null">status = #{status},</if>
<if test="wxId != null">wx_id =#{wxId},</if>
<if test="submitOrder != null">submit_order = #{submitOrder},</if>
modify_time =now()
</sql>
<sql id="criteria">
<if test="id != null">and id = #{id}</if>
<if test="oaUserId != null">and oa_user_id = #{oaUserId}</if>
<if test="name != null">and name = #{name}</if>
<if test="loginName != null">and login_name = #{loginName}</if>
<if test="password != null">and password = #{password}</if>
<if test="phone != null">and phone =#{phone}</if>
<if test="deptId != null">and dept_id = #{deptId}</if>
<if test="email != null">and email = #{email}</if>
<if test="role != null">and role = #{role}</if>
<if test="type != null">and type =#{type}</if>
<if test="status != null">and status = #{status}</if>
<if test="wxId != null">and wx_id =#{wxId}</if>
<if test="submitOrder != null">and submit_order = #{submitOrder}</if>
<if test="createTime != null">and create_time >= #{createTime}</if>
<if test="modifyTime != null">and #{modifyTime} >= modify_time</if>
</sql>
<select id="getUserInfo" resultMap="BaseResultMap" parameterType="map" >
select <include refid="cols_all"/>
from <include refid="table"/>
<where>
<include refid="criteria"/>
</where>
</select>
<select id="getUserById" resultMap="BaseResultMap" parameterType="integer" >
select <include refid="cols_all"/>
from <include refid="table"/>
where id = #{userId}
</select>
<select id="getStatisticsTableDtos" resultType="cn.wisenergy.model.dto.StatisticsTableDto">
select u.id AS user_id, u.name AS user_name, d.dept_name
from work_user u join work_dept d on u.dept_id=d.id
where u.id in
<foreach collection="list" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</select>
<update id="updateUserInfo" parameterType="cn.wisenergy.model.app.WorkUser">
update <include refid="table"/>
set <include refid="updateCondition"/>
where id = #{id}
</update>
<update id="updateStatusAndSubmitOrderById">
update <include refid="table"/>
<set>
<if test="status !=null">
status = #{status},
</if>
<if test="submitOrder !=null">
submit_order = #{submitOrder}
</if>
</set>
where id = #{userId}
</update>
<resultMap id="UserRoleMap" type="cn.wisenergy.model.dto.UserRoleDto">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="status" property="status"/>
<result column="dept_id" property="deptId"/>
<result column="dept_name" property="deptName"/>
<result column="submit_order" property="submitOrder"/>
<collection property="workRoles" column="id" javaType="List" select="getUserRole" ofType="cn.wisenergy.model.app.WorkRole"/>
</resultMap>
<select id="getUserRoleDto" resultMap="UserRoleMap">
select u.id as 'id',u.name as 'name',u.status as 'status',if(r.id is null,0,r.id) as 'role_id',r.name as 'role_name',d.id as 'dept_id',d.dept_name,u.submit_order
from work_user u LEFT JOIN (select role_id,user_id FROM work_user_role) ur ON u.id = ur.user_id
LEFT JOIN work_dept d ON u.dept_id = d.id
LEFT JOIN work_role r on ur.role_id = r.id
<where>
<if test="null !=status">
AND u.status = #{status}
</if>
<if test="null !=key and ''!=key">
AND u.name like concat('%',#{key},'%')
</if>
<if test="null != deptId">
AND u.dept_id = #{deptId}
</if>
<if test="null !=roleId and roleId != 0">
AND r.id = #{roleId}
</if>
<if test="null !=roleId and roleId == 0">
AND r.id is null
</if>
</where>
GROUP BY u.id
</select>
<select id="getUserRole" resultType="cn.wisenergy.model.app.WorkRole">
SELECT r.id ,r.name
FROM work_user_role ur LEFT JOIN work_role r
ON ur.role_id = r.id
WHERE ur.user_id = #{id}
</select>
<select id="getUserSortByStatus" resultType="cn.wisenergy.model.app.WorkUser">
select <include refid="cols_all"/>
from <include refid="table"/>
<where>
<if test="null != status">
AND status = #{status}
</if>
</where>
ORDER BY CONVERT( `name` USING gbk )
</select>
</mapper>