UsersMapper.xml 14.1 KB
Newer Older
licc's avatar
licc committed
1 2 3
<?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">

licc's avatar
licc committed
4
<mapper namespace="cn.wisenergy.mapper.UsersMapper">
licc's avatar
licc committed
5
    <resultMap id="userMap" type="cn.wisenergy.model.app.User">
licc's avatar
licc committed
6 7 8 9
        <id column="id" property="id"/>
        <result column="user_name" property="userName"/>
        <result column="password" property="password"/>
        <result column="phone" property="phone"/>
10
        <result column="uuid" property="uuid"/>
licc's avatar
licc committed
11
        <result column="head_image" property="headImage"/>
licc's avatar
licc committed
12 13
        <result column="sex" property="sex"/>
        <result column="school" property="school"/>
14
        <result column="exam_type" property="examType"/>
licc's avatar
licc committed
15
        <result column="source" property="source"/>
licc's avatar
licc committed
16 17 18
        <result column="is_delete" property="isDelete"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
19
        <result column="is_vip" property="isVip"/>
cy's avatar
cy committed
20
        <result column="openid" property="openid"/>
21
        <result column="vip_mobile" property="vipMobile"/>
xc's avatar
xc committed
22 23 24 25 26 27 28 29
        <result column="last_login_time" property="lastLoginTime"/>
    </resultMap>
    <resultMap extends="userMap" id="ExBaseResultMap" type="cn.wisenergy.model.app.User">
        <result column="culture_grade" jdbcType="VARCHAR" property="cultureGrade" />
        <result column="major_grade" jdbcType="VARCHAR" property="majorGrade" />
        <result column="usable_limit" jdbcType="VARCHAR" property="usableLimit" />
        <result column="type" jdbcType="VARCHAR" property="type" />
        <result column="money" jdbcType="VARCHAR" property="money" />
licc's avatar
licc committed
30
    </resultMap>
licc's avatar
licc committed
31

licc's avatar
licc committed
32 33 34
    <sql id="table">
        user
    </sql>
licc's avatar
licc committed
35

licc's avatar
licc committed
36 37 38 39
    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>
licc's avatar
licc committed
40

licc's avatar
licc committed
41
    <sql id="cols_exclude_id">
42
        user_name,password, phone,uuid,head_image,sex,school, exam_type,source,is_delete,create_time,update_time,is_vip,openid,vip_mobile
licc's avatar
licc committed
43
    </sql>
licc's avatar
licc committed
44

licc's avatar
licc committed
45
    <sql id="vals">
46
        #{userName},#{password},#{phone},#{uuid},#{headImage},#{sex},#{school},#{examType}, #{source},
47
        #{isDelete},now(),now(),#{isVip},#{openid},#{vipMobile}
licc's avatar
licc committed
48
    </sql>
licc's avatar
licc committed
49

licc's avatar
licc committed
50 51 52 53
    <sql id="updateCondition">
        <if test="userName != null">user_name = #{userName},</if>
        <if test="password != null">password =#{password},</if>
        <if test="phone != null">phone =#{phone},</if>
54
        <if test="uuid != null">uuid =#{uuid},</if>
licc's avatar
licc committed
55
        <if test="headImage != null">head_image =#{headImage},</if>
licc's avatar
licc committed
56 57
        <if test="sex != null">sex =#{sex},</if>
        <if test="school != null">school =#{school},</if>
licc's avatar
licc committed
58
        <if test="examType != null">exam_type = #{examType},</if>
licc's avatar
licc committed
59
        <if test="source != null">source = #{source},</if>
licc's avatar
licc committed
60
        <if test="isDelete != null">is_delete = #{isDelete},</if>
61
        update_time =now(),
cy's avatar
cy committed
62
        <if test="isVip != null">is_vip = #{isVip},</if>
63 64
        <if test="openid != null">openid =#{openid},</if>
        <if test="vipMobile != null">vip_mobile =#{vipMobile}</if>
licc's avatar
licc committed
65
    </sql>
licc's avatar
licc committed
66

licc's avatar
licc committed
67 68 69 70 71
    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userName != null">and user_name = #{userName}</if>
        <if test="password != null">and password =#{password}</if>
        <if test="phone != null">and phone =#{phone}</if>
72
        <if test="uuid != null">and uuid =#{uuid}</if>
licc's avatar
licc committed
73
        <if test="headImage != null">and head_image =#{headImage}</if>
licc's avatar
licc committed
74 75
        <if test="sex != null">and sex =#{sex}</if>
        <if test="school != null">and school =#{school}</if>
licc's avatar
licc committed
76
        <if test="examType != null">and exam_type = #{examType}</if>
licc's avatar
licc committed
77
        <if test="source != null">and source = #{source}</if>
licc's avatar
licc committed
78 79 80
        <if test="isDelete != null">and is_delete = #{isDelete}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
cy's avatar
cy committed
81
        <if test="isVip != null">and is_vip = #{isVip}</if>
82 83
        <if test="openid != null">and openid =#{openid},</if>
        <if test="vipMobile != null">vip_mobile =#{vipMobile}</if>
licc's avatar
licc committed
84
    </sql>
licc's avatar
licc committed
85

86 87 88 89 90 91 92 93
    <select id="selectOne" resultMap="userMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="phone != null and phone !=''">and phone =  #{phone}</if>
            <if test="is_delete != null and is_delete !=''">and is_delete =  #{is_delete}</if>
94
            <if test="vip_mobile != null and vip_mobile !=''">and vip_mobile =  #{vip_mobile}</if>
95
            <if test="openid != null and openid !=''">and openid =  #{openid}</if>
96 97 98
        </where>
    </select>

licc's avatar
licc committed
99
    <insert id="add" parameterType="cn.wisenergy.model.app.User" keyProperty="id" useGeneratedKeys="true">
licc's avatar
licc committed
100 101 102 103 104 105 106
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>
licc's avatar
licc committed
107

licc's avatar
licc committed
108
    <update id="edit" parameterType="cn.wisenergy.model.app.User">
licc's avatar
licc committed
109 110 111 112 113
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
licc's avatar
licc committed
114
        <where>
licc's avatar
licc committed
115
            id = #{id}
licc's avatar
licc committed
116
        </where>
licc's avatar
licc committed
117
    </update>
licc's avatar
licc committed
118

licc's avatar
licc committed
119 120 121 122 123 124
    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

125 126 127 128 129 130 131 132
    <select id="getById" resultMap="userMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>id = #{id}</where>
    </select>

licc's avatar
licc committed
133 134 135 136 137 138 139
    <select id="countByPhoneAnsUserId" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM
        <include refid="table"/>
        WHERE phone=#{phone} and id !=#{userId} and is_delete=0
    </select>

liaoanyuan's avatar
liaoanyuan committed
140 141 142 143 144 145
    <select id="getList" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
146
            is_delete=0 and is_vip = 2
liaoanyuan's avatar
liaoanyuan committed
147

cy's avatar
cy committed
148
            <if test="startTime != null">
liaoanyuan's avatar
liaoanyuan committed
149
                and create_time
licc's avatar
licc committed
150 151
                between #{startTime}
            </if>
liaoanyuan's avatar
liaoanyuan committed
152

cy's avatar
cy committed
153
            <if test="endTime != null ">and #{endTime}</if>
154

155
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
156

157
            <if test="phone != null and phone !=''">and phone like ('%' #{phone} '%')</if>
liaoanyuan's avatar
liaoanyuan committed
158
            order by create_time desc
159
            <if test="pageNo != null">
xc's avatar
xc committed
160 161 162 163 164 165 166 167 168 169 170 171 172
                limit #{pageNo},#{pageSize}
            </if>
        </where>
    </select>

    <select id="getListQuery" parameterType="map" resultMap="ExBaseResultMap">
        SELECT u.id, u.user_name, u.PASSWORD, u.phone, u.uuid, u.head_image, u.sex, u.school, u.exam_type, u.source, u.is_delete, u.create_time,
         u.update_time, u.is_vip, u.openid, u.vip_mobile,u.last_login_time,
         s.culture_grade, s.major_grade, ul.usable_limit
        FROM `user` u LEFT JOIN score s ON s.user_id = u.id
        LEFT JOIN user_limit ul ON ul.user_id = u.id
        <where>
            is_delete=0 and is_vip = 2
cy's avatar
cy committed
173 174
            <if test="startTime != null">
                and u.create_time
xc's avatar
xc committed
175 176
                between #{startTime}
            </if>
cy's avatar
cy committed
177
            <if test="endTime != null">and #{endTime}</if>
xc's avatar
xc committed
178 179 180 181
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
            <if test="phone != null and phone !=''">and phone like ('%' #{phone} '%')</if>
            order by create_time desc
            <if test="pageNo != null">
182 183
                limit #{pageNo},#{pageSize}
            </if>
liaoanyuan's avatar
liaoanyuan committed
184 185 186
        </where>
    </select>

187 188
    <select id="getListQueryVip" parameterType="map" resultMap="ExBaseResultMap">
        SELECT u.id, u.user_name, u.phone, u.sex, u.school, u.exam_type, u.source, u.is_delete, u.create_time,
189
        u.update_time, u.is_vip, u.vip_mobile,s.culture_grade, s.major_grade,st.staff_name
190
        FROM `user` u LEFT JOIN score s ON s.user_id = u.id
191 192
        left join staff_user_vip suv on u.id=suv.user_vip_id
        LEFT JOIN staff st on suv.staff_id=st.id
193
        <where>
194
             u.is_delete=0 and is_vip = 1
cy's avatar
cy committed
195
            <if test="startTime != null">
196 197 198
                and create_time
                between #{startTime}
            </if>
cy's avatar
cy committed
199
            <if test="endTime != null ">and #{endTime}</if>
200 201
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
            <if test="vipMobile != null and vipMobile !=''">and vip_mobile like ('%' #{vipMobile} '%')</if>
202
            <if test="staffName != null and staffName !=''">and staff_name like ('%' #{staffName} '%')</if>
203 204 205 206 207 208 209 210 211 212
            order by create_time desc
            <if test="pageNo != null">
                limit #{pageNo},#{pageSize}
            </if>
        </where>
    </select>

    <select id="getListVipCount" parameterType="map" resultType="java.lang.Integer">
        SELECT count(1)
        FROM `user` u LEFT JOIN score s ON s.user_id = u.id
213 214
        left join staff_user_vip suv on u.id=suv.user_vip_id
        LEFT JOIN staff st on suv.staff_id=st.id
215
        <where>
216
            u.is_delete=0 and is_vip = 1
cy's avatar
cy committed
217
            <if test="startTime != null ">
218 219 220
                and create_time
                between #{startTime}
            </if>
cy's avatar
cy committed
221
            <if test="endTime != null">and #{endTime}</if>
222 223
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
            <if test="vipMobile != null and vipMobile !=''">and vip_mobile like ('%' #{vipMobile} '%')</if>
224
            <if test="staffName != null and staffName !=''">and staff_name like ('%' #{staffName} '%')</if>
225 226 227 228 229 230 231 232 233 234 235 236
        </where>
    </select>


    <select id="getStaffVipUser" parameterType="map" resultMap="ExBaseResultMap">
        SELECT u.id, u.user_name, u.phone, u.sex, u.school, u.exam_type, u.source, u.is_delete, u.create_time,
        u.update_time, u.is_vip, u.vip_mobile,u.last_login_time,
        s.culture_grade, s.major_grade
        FROM `user` u LEFT JOIN score s ON s.user_id = u.id
        LEFT JOIN staff_user_vip su on u.id= su.user_vip_id
        <where>
            u.is_delete=0 and u.is_vip = 1 and su.staff_id=#{staffId}
cy's avatar
cy committed
237
            <if test="startTime != null ">
238 239 240
                and create_time
                between #{startTime}
            </if>
cy's avatar
cy committed
241
            <if test="endTime != null ">and #{endTime}</if>
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
            <if test="vipMobile != null and vipMobile !=''">and vip_mobile like ('%' #{vipMobile} '%')</if>
            order by create_time desc
            <if test="pageNo != null">
                limit #{pageNo},#{pageSize}
            </if>
        </where>
    </select>

    <select id="staffVipUserCount" parameterType="map" resultType="java.lang.Integer">
        SELECT count(1)
        FROM `user` u LEFT JOIN score s ON s.user_id = u.id
        LEFT JOIN staff_user_vip su on u.id= su.user_vip_id
        <where>
            u.is_delete=0 and u.is_vip = 1 and su.staff_id=#{staffId}
cy's avatar
cy committed
257
            <if test="startTime != null ">
258 259 260
                and create_time
                between #{startTime}
            </if>
cy's avatar
cy committed
261
            <if test="endTime != null ">and #{endTime}</if>
262 263 264 265 266
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
            <if test="vipMobile != null and vipMobile !=''">and vip_mobile like ('%' #{vipMobile} '%')</if>
        </where>
    </select>

liaoanyuan's avatar
liaoanyuan committed
267 268 269 270
    <select id="getUserNumbers" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM
        <include refid="table"/>
271
        <where>
272
            is_delete=0 and is_vip = 2
273 274 275 276 277

            <if test="startTime != null">
                and create_time
                between #{startTime}
            </if>
278
            <if test="endTime != null">and #{endTime}</if>
279 280 281 282

            <if test="userName != null">and user_name like ('%' #{userName} '%')</if>

            <if test="phone != null">and phone like ('%' #{phone} '%')</if>
283 284
        </where>

liaoanyuan's avatar
liaoanyuan committed
285
    </select>
licc's avatar
licc committed
286 287 288 289 290 291 292 293

    <select id="getByPhone" resultType="cn.wisenergy.model.app.User">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="table"/>
        where is_delete=0 and phone=#{phone}
    </select>
licc's avatar
licc committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308


    <select id="test" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="list != null">
                <foreach collection="list" index="index" item="id" separator="or" open="(" close=")">
                    user_name LIKE CONCAT('%',#{id},'%')
                </foreach>
            </if>
        </where>
    </select>
309 310 311 312 313 314 315

    <select id="getUserByStaffId" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
316
            is_vip=1
cy's avatar
cy committed
317
            <if test="list != null and (list.size)>0">
318 319 320 321 322
              and  id in
                <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
                    #{id.userVipId}
                </foreach>
            </if>
cy's avatar
cy committed
323 324
            <if test="userName != null and userName!=''"> and user_name like ('%' #{userName} '%')</if>
            <if test="phone != null and phone!=''"> and phone like ('%' #{phone} '%')</if>
325 326 327 328 329 330
            order by create_time desc
            <if test="pageNo != null">
                limit #{pageNo},#{pageSize}
            </if>
        </where>
    </select>
cy's avatar
cy committed
331

332 333 334 335 336
    <select id="getVipUserNumbers" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM
        <include refid="table"/>
        <where>
337
             is_vip = 1
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
            <if test="list != null and (list.size)>0">
                and  id in
                <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
                    #{id.userVipId}
                </foreach>
            </if>

            <if test="startTime != null">
                and create_time
                between #{startTime}
            </if>
            <if test="endTime != null">and #{endTime}</if>

            <if test="userName != null">and user_name like ('%' #{userName} '%')</if>

            <if test="phone != null">and phone like ('%' #{phone} '%')</if>
        </where>

    </select>

cy's avatar
cy committed
358

licc's avatar
licc committed
359
</mapper>