liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
<?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">
<!-- 
    namespace:必须与对应的接口全类名一致
    id:必须与对应接口的某个对应的方法名一致
    
 -->
<mapper namespace="com.basic.x01.system.mapper.UserMapper">
 
    <resultMap id="TSysUser" type="TSysUser">
      <id property="userId" column="user_id" />
      <result property="loginName" column="login_name"/>
      <result property="realName" column="real_name"/>
      <result property="password" column="password" />
      <result property="orgId" column="org_id" />
      <result property="orgType" column="org_type" />
      <result property="status" column="status" />
      
      <association property="org" column="org_id" javaType="TSysOrg" select="selectAuthor"/>
    </resultMap>
    
    <resultMap id="TSysOrg" type="TSysOrg">
        <id property="orgId" column="org_id" />
        <result property="orgName" column="org_name" />
        <result property="parOrgId" column="par_org_id" />
        <result property="status" column="status" />
    </resultMap>
 
    <resultMap id="TSysRole" type="TSysRole">
        <id property="roleId" column="role_id" />
        <result property="roleName" column="role_name" />
        <result property="orgId" column="org_id" />
        <result property="isAdmin" column="is_admin" />
        <result property="status" column="status" />
    </resultMap>
    
    <resultMap id="TRegion" type="TRegion">
      <id property="regionId" column="region_id" />
      <result property="regionName" column="region_name"/>
      <result property="parRegionId" column="par_region_id"/>
      <result property="fullName" column="full_name" />
      <result property="lastRegion" column="last_region" />
    </resultMap>
 
    <delete id="removeUserAllRoles">
        delete from t_sys_user_role
        where user_id=#{0}
    </delete>
    
    <insert id="addUserRole">
        insert t_sys_user_role (user_id, role_id) values (
            #{0}, #{1}
        )
    </insert>
 
    <select id="getUserByLoginName" resultMap="TSysUser">
        select * from t_sys_user
        where login_name=#{0}
    </select>
    
    <select id="getRolesByOrgId" resultMap="TSysRole">
        select * from t_sys_role
        where org_id = #{0}
    </select>
    
    <select id="getAllRegions" resultMap="TRegion">
        select * from t_region
        where region_id !='0'
        order by region_id
    </select>
    
    <select id="getUserDiectRegions" resultMap="TRegion">
        select * from t_region
        where region_id in (
            select r.region_id
            from t_org_region r, t_sys_user u
            where r.org_id=u.org_id
                and u.user_id=#{0}
        )
        order by region_id
    </select>
    
    <select id="getRegionByParent" resultMap="TRegion">
        select * from t_region
        where par_region_id in
        <foreach item="item" index="index" collection="list"
            open="(" separator="," close=")">
            #{item.regionId}    
        </foreach>
        
        order by region_id
    </select>
 
    <insert id="createUser" parameterType="TSysUser">
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="userId">  
            select uuid() as userId
        </selectKey>  
    
        insert t_sys_user (user_id, login_name, real_name, password,
            org_id, org_type, status) values (#{userId}, #{loginName},
            #{realName}, #{password}, #{orgId}, #{orgType}, '1'
            )
    </insert>    
 
    <update id="updateUser" parameterType="TSysUser">
        update t_sys_user
        <trim prefix="set" suffixOverrides=",">
            <if test="loginName !=null and loginName !=''">
                login_name=#{loginName}
            </if>
            <if test="realName !=null and realName !=''">
                real_name=#{realName}
            </if>
            <if test="password !=null and password !=''">
                password=#{password}
            </if>
            <if test="orgId !=null and orgId !=''">
                org_id=#{orgId}
            </if>
            <if test="orgType !=null and orgType !=''">
                org_type=#{orgType}
            </if>
            <if test="status !=null and status !=''">
                status=#{status}
            </if>
        </trim>
 
        where user_id=#{userId}
    </update>
    
    <select id="getOrgByOrgId" resultMap="TSysOrg">
        select * from t_sys_org where org_id=#{0}
    </select>
    
    <select id="getRoleByRoleId" resultMap="TSysRole">
        select * from t_sys_role where role_id=#{0}
    </select>
    
    <select id="getUserRoles" resultMap="TSysRole">
        select * from t_sys_role
        where role_id in (select role_id from t_sys_user_role
            where user_id=#{0}
        )
    </select>
    
    <select id="getUserByLogin">
        select * from t_sys_user
        where login_name=#{0}
            and password=#{1}
    </select>
    
    <select id="getUserByUserId" resultMap="TSysUser">
        select * from t_sys_user
        where user_id=#{0}
    </select>
    
    <select id="getUserListByOrgId" resultMap="TSysUser">
        select * from t_sys_user
        where org_id=#{0}
        order by login_name
    </select>
    
    <select id="getUserRoleActions" resultType="String" parameterType="String">
        select ra.action_id 
        from t_sys_role_action ra, t_sys_role r, t_sys_user u, t_sys_user_role ur
        where u.user_id=#{0} and u.status='1' and u.user_id=ur.user_id
            and ra.role_id=r.role_id and ur.role_id=r.role_id and r.status='1'
    </select>
 
</mapper>