puzhibing
2023-06-30 f58cca364b731eac2d60a440ffaa804be3cd43fd
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
<?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.stylefeng.guns.modular.system.dao.UserMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.User">
        <id column="id" property="id" />
        <result column="avatar" property="avatar" />
        <result column="account" property="account" />
        <result column="password" property="password" />
        <result column="pass_word_update" property="passWordUpdate"/>
        <result column="salt" property="salt" />
        <result column="name" property="name" />
        <result column="birthday" property="birthday" />
        <result column="sex" property="sex" />
        <result column="email" property="email" />
        <result column="phone" property="phone" />
        <result column="roleid" property="roleid" />
        <result column="deptid" property="deptid" />
        <result column="status" property="status" />
        <result column="createtime" property="createtime" />
        <result column="version" property="version" />
        <result column="role_type" property="roleType" />
        <result column="object_id" property="objectId" />
    </resultMap>
 
    <sql id="Base_Column_List">
        id, account, name, birthday, sex, email, avatar,
        phone, roleid,
        deptid, status,
        createtime, version
    </sql>
 
    <sql id="Base_Column_List_With_Pwd">
        id, account, name, birthday,password, sex, email, avatar,
        phone, roleid,salt,
        deptid, status,
        createtime, version
    </sql>
 
    <select id="selectUsers" resultType="map">
        select
        <include refid="Base_Column_List" />
        from sys_user
        where status != 3
        <if test="name != null and name != ''">
            and (phone like CONCAT('%',#{name},'%')
            or account like CONCAT('%',#{name},'%')
            or name like CONCAT('%',#{name},'%'))
        </if>
        <if test="deptid != null and deptid != 0">
            and (deptid = #{deptid} or deptid in ( select id from sys_dept where pids like CONCAT('%[', #{deptid}, ']%') ))
        </if>
        <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
            and (createTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
        </if>
    </select>
 
    <update id="setStatus">
        update sys_user set status = #{status} where id =
        #{userId}
    </update>
 
    <update id="changePwd">
        update sys_user set password = #{pwd} where id =
        #{userId}
    </update>
 
    <update id="setRoles">
        update sys_user set roleid = #{roleIds} where id =
        #{userId}
    </update>
 
    <select id="getByAccount" resultType="user">
        select
        <include refid="Base_Column_List_With_Pwd" />
        from sys_user where account = #{account} and status != 3
    </select>
 
    <!--根据角色判断菜单有"首页"的数量-->
    <select id="getMenuNumByRole" resultType="java.lang.Integer">
        SELECT IFNULL(COUNT(menuid),0) as num from sys_relation where roleid in (#{roleStr}) and menuid = 2
    </select>
 
    <select id="getUserListPage" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (select CASE when d2.simplename is null then d1.simplename else d2.simplename end as parentName,
        case when uu.sex = 1 then '男' when uu.sex = 2 then '女' else '' end as sexName,
        d1.simplename as deptName,case when uu.status = 1 then '启用' when uu.status = 2 then '冻结' when uu.status = 3 then '删除' else '' end as statusName,
        rr.roleName,
        uu.* from sys_user as uu
        LEFT JOIN sys_dept as d1 on d1.id = uu.deptid
        LEFT JOIN sys_dept as d2 on d2.id = d1.pid
        LEFT JOIN (select s.id,s.name,GROUP_CONCAT(r.name) as roleName from sys_user s
        left join sys_role r on find_in_set(r.id,s.roleid) group by s.id) as rr on rr.id = uu.id
        ) as o
        <where>
            o.status != 3
            <if test="name != null and name != ''">
                and (o.phone like CONCAT('%',#{name},'%')
                or o.account like CONCAT('%',#{name},'%')
                or o.name like CONCAT('%',#{name},'%'))
            </if>
            <if test="deptid != null and deptid != 0">
                and (o.deptid = #{deptid} or o.deptid in ( select id from sys_dept where pids like CONCAT('%[', #{deptid}, ']%') ))
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and (o.createTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
        </where>
        order by o.id desc
    </select>
 
    <select id="getUserListPageAgent" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (select CASE when d2.simplename is null then d1.simplename else d2.simplename end as parentName,
        case when uu.sex = 1 then '男' when uu.sex = 2 then '女' else '' end as sexName,
        d1.simplename as deptName,case when uu.status = 1 then '启用' when uu.status = 2 then '冻结' when uu.status = 3 then '删除' else '' end as statusName,
        rr.roleName,
        uu.* from sys_user as uu
        LEFT JOIN sys_dept as d1 on d1.id = uu.deptid
        LEFT JOIN sys_dept as d2 on d2.id = d1.pid
        LEFT JOIN (select s.id,s.name,GROUP_CONCAT(r.name) as roleName from sys_user s
        left join sys_role r on find_in_set(r.id,s.roleid) group by s.id) as rr on rr.id = uu.id
        ) as o
        <where>
            o.status != 3
            <if test="name != null and name != ''">
                and (o.phone like CONCAT('%',#{name},'%')
                or o.account like CONCAT('%',#{name},'%')
                or o.name like CONCAT('%',#{name},'%'))
            </if>
            <if test="deptid != null and deptid != 0">
                and (o.deptid = #{deptid} or o.deptid in ( select id from sys_dept where pids like CONCAT('%[', #{deptid}, ']%') ))
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and (o.createTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="officeIds != null and officeIds.size() > 0">
                and o.object_id in
                 <foreach collection="officeIds" separator="," item="id" open="(" close=")">
                     #{id}
                 </foreach>
            </if>
             and o.role_type = 2
        </where>
        order by o.id desc
    </select>
 
</mapper>