xiangpei
2024-06-06 c2dc62c3d40be033cdb65fa54473f7f355e67e88
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?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.ycl.jxkg.mapper.UserMapper">
    <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.entity.User">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="user_uuid" jdbcType="VARCHAR" property="userUuid"/>
        <result column="user_name" jdbcType="VARCHAR" property="userName"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="real_name" jdbcType="VARCHAR" property="realName"/>
        <result column="age" jdbcType="INTEGER" property="age"/>
        <result column="sex" jdbcType="INTEGER" property="sex"/>
        <result column="birth_day" jdbcType="TIMESTAMP" property="birthDay"/>
        <result column="user_level" jdbcType="INTEGER" property="userLevel"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="role" jdbcType="INTEGER" property="role"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="image_path" jdbcType="VARCHAR" property="imagePath"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
        <result column="last_active_time" jdbcType="TIMESTAMP" property="lastActiveTime"/>
        <result column="deleted" jdbcType="BIT" property="deleted"/>
        <result column="wx_open_id" jdbcType="VARCHAR" property="wxOpenId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        , user_uuid, user_name, password, real_name, age, sex, birth_day, user_level, phone,
    role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id
    </sql>
 
 
    <select id="getAllUser" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user where deleted=0
    </select>
 
    <select id="getUserById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where id=#{value}
    </select>
 
    <select id="getUserByUserName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{value} limit 1
    </select>
 
    <select id="getUserByUserNamePwd" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{username} and password=#{pwd} limit 1
    </select>
 
    <select id="getUserByUuid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_uuid=#{value,jdbcType=VARCHAR}
    </select>
 
 
    <select id="userPageList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%',#{name},'%')
            </if>
        </where>
        ORDER BY id
        <if test="offset != null and limit != null ">
            <bind name="patternAdd" value="limit*offset"/>
            limit #{limit} OFFSET #{offset}
        </if>
    </select>
 
 
    <select id="userPageCount" resultType="java.lang.Integer">
        select count(*) from t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%', #{name}, '%')
            </if>
        </where>
    </select>
 
 
    <select id="userPage" resultMap="BaseResultMap" parameterType="com.ycl.jxkg.domain.vo.admin.user.UserPageRequestVO">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_user
        <where>
            and deleted=0
            <if test="userName != null and userName != ''">
                and user_name like concat('%',#{userName},'%')
            </if>
            <if test="role != null ">
                and role= #{role}
            </if>
        </where>
    </select>
 
 
    <insert id="insertUser" parameterType="com.ycl.jxkg.domain.entity.User"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
            (user_uuid, user_name, password, real_name, age, last_active_time)
        values (#{userUuid,jdbcType=VARCHAR}, #{userName}, #{password}, #{realName}, #{age}, #{lastActiveTime})
    </insert>
 
    <insert id="insertUsers" parameterType="java.util.List"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
        (user_uuid,user_name,password,real_name,age,last_active_time)
        values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (#{item.userUuid},#{item.userName},#{item.password},#{item.realName},#{item.age},
            #{item.lastActiveTime})
        </foreach>
    </insert>
 
 
    <update id="updateUser" parameterType="com.ycl.jxkg.domain.entity.User">
        update t_user
        <set>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="age != null">age = #{age},</if>
            <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
        </set>
        where id = #{id}
    </update>
 
 
    <update id="updateUsersAge">
        update t_user set age = #{age} where id in
        <foreach item="id" collection="idslist" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </update>
 
 
    <delete id="deleteUsersByIds">
        delete from t_user where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="selectAllCount" resultType="java.lang.Integer">
        SELECT count(*)
        from t_user
        where deleted = 0
    </select>
 
 
    <select id="selectByUserName" resultType="com.ycl.jxkg.domain.other.KeyValue">
        SELECT id as value,user_name as name
        from t_user
        where deleted=0
          and user_name like concat('%'
            , #{value}
            , '%')
            limit 5
    </select>
 
 
    <select id="selectByIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </select>
 
 
    <select id="selectByWxOpenId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and wx_open_id = #{wxOpenId}
        limit 1
    </select>
 
    <select id="classesStudent" resultType="com.ycl.jxkg.domain.vo.StudentVO">
        SELECT tu.id,
               tu.real_name,
               tu.phone
        FROM t_user tu
                 INNER JOIN t_classes_user tcu ON tu.id = tcu.user_id
        WHERE tcu.classes_id = #{classesId}
        ORDER BY tcu.create_time
    </select>
 
</mapper>