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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?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.SystemMapper">
 
    <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="roleId" column="role_id" />
      <result property="status" column="status" />
      <result property="createUserId" column="create_user_id" />
      <result property="createTime" column="create_time" />
      
      <association property="org" column="org_id" javaType="TSysOrg" select="getOrgByOrgId" />
      <association property="role" column="role_id" javaType="TSysRole" select="getRoleByRoleId" />
    </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="parOrgId2" column="par_org_id2" />
        <result property="orgType" column="org_type" />
        <result property="regionId" column="region_id" />
        <result property="mapPoint" column="map_point" />
        <result property="createTime" column="create_time" />
        <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>
    <resultMap id="TSysRoleFixed" type="TSysRoleFixed">
        <id property="fixedRoleId" column="fixed_role_id" />
        <result property="fixedRoleName" column="fixed_role_name" />
        <result property="orgType" column="org_type" />
        <result property="actionFor" column="action_for" />
        <result property="orderNum" column="order_num" />
    </resultMap>
 
    <select id="getFixedRoleListByActionFor" resultMap="TSysRoleFixed">
        select * from t_sys_role_fixed
        where org_type=#{orgType} 
            and instr(action_for, concat(',', #{actionFor}, ','))>=1
        order by order_num
    </select>
    <select id="getAllRegions" resultMap="TRegion">
        select * from t_region
        where region_id like #{province}
        order by region_id
    </select>
 
    <select id="getAllSchoolByOrgId" resultMap="TSysOrg">
        select * from t_sys_org
        where org_type='2' and par_org_id=#{orgId}
        order by create_time
    </select>
    <select id="getOrgListByParOrgList" resultMap="TSysOrg">
        select * from t_sys_org
        where org_type=#{orgType} and par_org_id in 
            <foreach item="item" index="index" collection="parOrgList"
                open="(" separator="," close=")">
                #{item.orgId}    
            </foreach>
        
    </select>
    
    <select id="getUserListByOrgIdList" resultMap="TSysUser">
        select * from t_sys_user
        where org_id in 
            <foreach item="item" index="index" collection="orgIdList"
                open="(" separator="," close=")">
                #{item}    
            </foreach>
            <if test="all == false">
                and status='1'
            </if>
    </select>
    <select id="getUserListByOrgId" resultMap="TSysUser">
        select * from t_sys_user
        where org_id=#{orgId}
            <if test="all != true">
                and status='1'
            </if>
        order by login_name
    </select>
 
    <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="getUserRoleActionList" resultType="String" parameterType="String">
        select ra.action_id 
        from t_sys_role_action ra, t_sys_role r, t_sys_user u
        where u.user_id=#{0} and u.status='1'
            and ra.role_id=r.role_id and u.role_id=r.role_id and r.status='1'
    </select>
 
    <sql id="selectAllFromTSysUser">
        select * from t_sys_user
    </sql>
    <select id="getUserByLogin" resultMap="TSysUser">
        <include refid="selectAllFromTSysUser" />
        where login_name=#{0} and password=#{1}
    </select>
    <select id="getUserByLoginName" resultMap="TSysUser">
        <include refid="selectAllFromTSysUser" />
        where login_name=#{0}
    </select>
    
    <insert id="createUser" parameterType="TSysUser">
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="userId">  
            select replace(uuid(),'-','') as userId
        </selectKey>  
    
        insert t_sys_user (
            user_id, 
            login_name, real_name, password,
            org_id, role_id, status, 
            create_user_id, 
            create_time
        ) values (
            #{userId}, 
            #{loginName}, #{realName}, #{password}, 
            #{orgId}, #{roleId}, '1',
            #{createUserId}, 
            date_format(now(),'%Y-%m-%d %H:%i:%S')
            )
    </insert>    
    
    <update id="updateUser" parameterType="TSysUser">
        update t_sys_user
        set user_id=user_id
            <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="roleId !=null and roleId !=''">
                , role_id=#{roleId}
            </if>
            <if test="status !=null and status !=''">
                , status=#{status}
            </if>
 
        where user_id=#{userId}
    </update>
 
    <select id="getRoleListByOrgId" resultMap="TSysRole">
        select * from t_sys_role
        where org_id = #{0}
            <if test="param2 != true">
                and status='1'
            </if>
    </select>
 
 
    <select id="getUserByUserId" resultMap="TSysUser">
        <include refid="selectAllFromTSysUser" />
        where user_id=#{0}
    </select>
</mapper>