UsersMapper.xml 14.6 KB
Newer Older
licc's avatar
licc committed
1 2 3 4 5 6
<?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="cn.wisenergy.mapper.UsersMapper">
    <resultMap id="userMap" type="cn.wisenergy.model.app.User">
        <id column="id" property="id"/>
licc's avatar
licc committed
7
        <result column="user_id" property="userId"/>
licc's avatar
licc committed
8
        <result column="password" property="password"/>
9
        <result column="head_image" property="headImage"/>
licc's avatar
licc committed
10 11 12 13 14 15 16
        <result column="user_level" property="userLevel"/>
        <result column="cross_border_line" property="crossBorderLine"/>
        <result column="id_card_number" property="idCardNumber"/>
        <result column="fans_nickname" property="fansNickname"/>
        <result column="fans_id" property="fansId"/>
        <result column="invite_code" property="inviteCode"/>
        <result column="be_invited_code" property="beInvitedCode"/>
codezwjava's avatar
codezwjava committed
17
        <result column="customer_service_id" property="customerServiceId"/>
18
        <result column="frozen" property="frozen"/>
licc's avatar
licc committed
19 20 21 22 23
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
licc's avatar
licc committed
24
        user_info
licc's avatar
licc committed
25 26 27 28 29 30 31 32
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
33
        user_id,password,head_image,user_level,cross_border_line,id_card_number,fans_nickname,fans_id, invite_code,
codezwjava's avatar
codezwjava committed
34
        be_invited_code,customer_service_id,create_time,update_time
licc's avatar
licc committed
35 36 37
    </sql>

    <sql id="vals">
38
        #{userId},#{password},#{headImage},#{userLevel},#{crossBorderLine},#{idCardNumber},#{fansNickname},#{fansId},#{inviteCode},
codezwjava's avatar
codezwjava committed
39
        #{beInvitedCode},#{customerServiceId},now(),now()
licc's avatar
licc committed
40 41 42
    </sql>

    <sql id="updateCondition">
licc's avatar
licc committed
43
        <if test="userId != null">user_id = #{userId},</if>
licc's avatar
licc committed
44
        <if test="password != null">password =#{password},</if>
45
        <if test="headImage != null">head_image =#{headImage},</if>
licc's avatar
licc committed
46 47 48 49 50 51 52
        <if test="userLevel != null">user_level =#{userLevel},</if>
        <if test="crossBorderLine != null">cross_border_line =#{crossBorderLine},</if>
        <if test="idCardNumber != null">id_card_number = #{idCardNumber},</if>
        <if test="fansNickname != null">fans_nickname =#{fansNickname},</if>
        <if test="fansId != null">fans_id =#{fansId},</if>
        <if test="inviteCode != null">invite_code =#{inviteCode},</if>
        <if test="beInvitedCode != null">be_invited_code = #{beInvitedCode},</if>
codezwjava's avatar
codezwjava committed
53
        <if test="customerServiceId != null">customer_service_id = #{customerServiceId},</if>
licc's avatar
licc committed
54 55 56 57 58
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
licc's avatar
licc committed
59
        <if test="userId != null">and user_id = #{userId}</if>
licc's avatar
licc committed
60
        <if test="password != null">and password =#{password}</if>
61
        <if test="headImage != null">and head_image =#{headImage}</if>
licc's avatar
licc committed
62 63 64 65 66 67 68
        <if test="userLevel != null">and user_level =#{userLevel}</if>
        <if test="crossBorderLine != null">and cross_border_line =#{crossBorderLine}</if>
        <if test="idCardNumber != null">and id_card_number = #{idCardNumber}</if>
        <if test="fansNickname != null">and fans_nickname =#{fansNickname}</if>
        <if test="fansId != null">and fans_id =#{fansId}</if>
        <if test="inviteCode != null">and invite_code =#{inviteCode}</if>
        <if test="beInvitedCode != null">and be_invited_code = #{beInvitedCode}</if>
codezwjava's avatar
codezwjava committed
69
        <if test="customerServiceId != null">and customer_service_id = #{customerServiceId}</if>
licc's avatar
licc committed
70 71 72 73
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

74

licc's avatar
licc committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    <insert id="add" parameterType="cn.wisenergy.model.app.User" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <update id="edit" parameterType="cn.wisenergy.model.app.User">
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
licc's avatar
licc committed
90 91 92
        <where>
            id = #{id}
        </where>
licc's avatar
licc committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106
    </update>

    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

    <select id="getList" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
107
            be_invited_code=1
licc's avatar
licc committed
108
        </where>
licc's avatar
licc committed
109
        order by create_time desc
licc's avatar
licc committed
110
    </select>
licc's avatar
licc committed
111

liqin's avatar
liqin committed
112 113 114 115 116 117 118 119 120 121
    <select id="getUserById" resultType="cn.wisenergy.model.app.User" parameterType="java.lang.Long">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            id=#{id}
        </where>
    </select>

122
    <select id="getByUserId" resultType="cn.wisenergy.model.app.User" parameterType="string">
licc's avatar
licc committed
123
        select
124
        id,user_id,password,head_image,user_level,cross_border_line,id_card_number,fans_nickname,fans_id, invite_code,
codezwjava's avatar
codezwjava committed
125
        be_invited_code,customer_service_id,create_time,update_time
licc's avatar
licc committed
126
        from
127
        user_info
licc's avatar
licc committed
128 129
        <where>
            user_id=#{userId}
licc's avatar
licc committed
130 131
        </where>
    </select>
132 133 134 135 136 137 138 139 140
    <select id="getById" resultType="java.lang.Integer" parameterType="string">
        select
        userId
        from
        user_info
        <where>
            user_id=#{userId}
        </where>
    </select>
141 142 143 144
    <select id="ByUserId" resultType="java.lang.Integer">
        select
        id
        from
145
        user_info
146 147 148 149
        <where>
            user_id=#{userId}
        </where>
    </select>
m1991's avatar
m1991 committed
150

licc's avatar
licc committed
151 152 153 154 155 156 157 158
    <select id="findAllNotZeroUser" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_level !=0
        </where>
licc's avatar
licc committed
159
    </select>
m1991's avatar
m1991 committed
160

licc's avatar
licc committed
161 162
    <!--查询用户-->
    <select id="findByName" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
163
        select * from User where user_id = #{userId}
licc's avatar
licc committed
164
    </select>
m1991's avatar
m1991 committed
165

licc's avatar
licc committed
166 167
    <!--查询密码-->
    <select id="findPswByName" resultType="String">
m1991's avatar
m1991 committed
168
        select password from user where user_id = #{userId}
licc's avatar
licc committed
169 170 171 172 173 174 175 176
    </select>

    <select id="getByBeInvitedCode" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
codezwjava's avatar
codezwjava committed
177
            invite_code = #{beInvitedCode}
licc's avatar
licc committed
178 179
        </where>
    </select>
m1991's avatar
m1991 committed
180

licc's avatar
licc committed
181 182 183 184 185 186 187 188 189 190
    <select id="getAllGoldUser" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_level >3
        </where>
    </select>

m1991's avatar
m1991 committed
191 192
    <!--用户注册-->
    <insert id="insertbyint">
193 194
        insert into user_info(user_id,invite_code,be_invited_code,user_level,head_image,frozen) value
        (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel},#{headImage},#{frozen})
195 196
    </insert>
    <insert id="save">
197
        insert into user_info(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
licc's avatar
licc committed
198
    </insert>
m1991's avatar
m1991 committed
199

m1991's avatar
m1991 committed
200
    <select id="queryUsersByPhone" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
201
        select
licc's avatar
licc committed
202
        <include refid="vals"/>
m1991's avatar
m1991 committed
203 204 205 206 207 208
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
209 210 211 212 213 214 215 216 217 218 219
    <!--根据用户的推荐人邀请码比对推荐人的本人邀请码,查询推荐人的用户ID-->
    <select id="inviteCodeBeInvitedCode" resultType="java.lang.Integer">
        select
        user_id
        from
        <include refid="table"/>
        <where>
            invite_code=#{beInvitedCode}
        </where>
    </select>
    <!--根据用户的推荐人邀请码比对推荐人的本人邀请码,查询推荐人的用户ID-->
220
    <select id="beInvitedCode1" resultType="java.lang.Integer">
221 222 223 224 225 226 227 228 229
        select
        id
        from
        <include refid="table"/>
        <where>
            invite_code=#{beInvitedCode}
        </where>
    </select>

licc's avatar
licc committed
230
    <select id="InvitedCode2" resultType="cn.wisenergy.model.app.User" parameterType="string">
231 232 233
        select
        *
        from
234
        user_info
235
        <where>
236
            invite_code=#{inviteCode}
237 238 239
        </where>
    </select>

m1991's avatar
m1991 committed
240
    <select id="getuserIdById" resultType="java.lang.Integer">
m1991's avatar
m1991 committed
241 242 243
        select
        id
        from
244
        user_info
m1991's avatar
m1991 committed
245 246 247 248
        <where>
            user_id=#{userId}
        </where>
    </select>
249
    <select id="BYQMById" resultType="String">
m1991's avatar
m1991 committed
250 251 252 253 254 255 256 257
        select
        be_invited_code
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
licc's avatar
licc committed
258
    <update id="edit1">
259 260
        update
        user_info
m1991's avatar
m1991 committed
261 262 263
        <set>
            <if test="userLevel != null">user_level =#{userLevel},</if>
            <if test="inviteCode != null">invite_code =#{inviteCode},</if>
m1991's avatar
m1991 committed
264
            create_time =now(),
m1991's avatar
m1991 committed
265 266 267
            update_time =now()
        </set>
        <where>
licc's avatar
licc committed
268
            user_id = #{userId}
m1991's avatar
m1991 committed
269 270
        </where>
    </update>
m1991's avatar
m1991 committed
271

m1991's avatar
m1991 committed
272

m1991's avatar
m1991 committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    <!--分页查询所有用户信息 -->
    <select id="getUsersListByMap" resultType="cn.wisenergy.model.app.User" parameterType="java.util.Map">
        select id as id,
        user_id as userId,
        password as password,
        user_level as userLevel,
        cross_border_line as crossBorderLine,
        id_card_number as idCardNumber,
        fans_nickname as fansNickname,
        invite_code as inviteCode,
        be_invited_code as beInvitedCode,
        create_time as createTime,
        update_time as updateTime
        from user_info
        <trim prefix="where" prefixOverrides="and | or">
            <if test="id != null">
                and id=#{id}
            </if>
            <if test="account != null and account!=''">
                and userId=#{userId}
            </if>
            <if test="password != null and password!=''">
                and password=#{password}
            </if>
            <if test="salt != null and salt!=''">
                and userLevel=#{userLevel}
            </if>
300

m1991's avatar
m1991 committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
            <if test="sex != null">
                and idCardNumber=#{idCardNumber}
            </if>
            <if test="isAuthentication != null">
                and fansNickname=#{fansNickname}
            </if>
            <if test="name != null and name!=''">
                and inviteCode=#{inviteCode}
            </if>
            <if test="cardNo != null and cardNo!=''">
                and beInvitedCode=#{beInvitedCode}
            </if>
            <if test="null!=creatdTime">
                and creatdTime=#{creatdTime}
            </if>
            <if test="null!=updatedTime">
                and updatedTime=#{updatedTime}
            </if>
        </trim>
        <if test="beginPos != null and pageSize != null ">
            limit #{beginPos},#{pageSize}
        </if>
    </select>

licc's avatar
licc committed
325
    <!--    获取当前用户的所有直接推荐人-->
codezwjava's avatar
codezwjava committed
326
    <select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
327 328 329 330 331 332 333 334 335 336 337
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            be_invited_code=#{inviteCode}
            and user_level=#{userLevel}
        </where>
    </select>

    <select id="queryByInviteCode" resultType="cn.wisenergy.model.app.User">
codezwjava's avatar
codezwjava committed
338 339 340 341 342
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
343
            invite_code=#{inviteCode}
codezwjava's avatar
codezwjava committed
344 345 346
        </where>
    </select>

licc's avatar
licc committed
347 348 349 350 351 352 353 354 355 356
    <select id="getByLevel" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_level=#{userLevel}
        </where>
    </select>

codezwjava's avatar
codezwjava committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    <select id="getUserByIntiveCode" parameterType="string" resultType="string">
        select user_id
        from
        <include refid="table"/>
        where
        invite_code = #{beInvitedCode}
    </select>

    <select id="getUserIdByIntiveCode" resultType="string" parameterType="string">
        select user_id
        from
        <include refid="table"/>
        where
        invite_code = #{outerUserId}
    </select>
m1991's avatar
m1991 committed
372

373
    <select id="getAerialDeliveryUserBeforOneMonth" resultType="cn.wisenergy.model.app.User">
374 375 376 377 378
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
379 380
        be_invited_code = '1'
        and DATE_FORMAT(create_time,'%Y-%m-%d')
licc's avatar
licc committed
381
        BETWEEN #{before} AND #{now}
382 383
    </select>

licc's avatar
licc committed
384
    <select id="randOneGetUserByUserId" resultType="cn.wisenergy.model.app.User">
385 386
        SELECT
        <include refid="cols_all"/>
licc's avatar
licc committed
387 388 389 390
        FROM
        <include refid="table"/>
        WHERE id &lt; #{id}
        ORDER BY RAND() LIMIT 1
391 392
    </select>

codezwjava's avatar
codezwjava committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
    <select id="getListByIntvitedCode" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where be_invited_code = #{intiveCode}
    </select>

    <select id="getuserByBeInvitedCode" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        invite_code = #{be_invited_code}
    </select>

410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
    <select id="getListUserByBeInvitedCode" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        be_invited_code = #{be_invited_code}
    </select>

    <select id="getUserByInviteCode" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        invite_code = #{inviteCode}
    </select>

428 429 430 431 432 433 434 435 436
    <select id="getUserByUserId" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        user_id = #{userId}
    </select>

437

438 439 440 441 442 443
    <select id="getUserList" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
444
            1=1
445
            <if test="userId != null and userId != ''">
licc's avatar
licc committed
446
                and user_id = #{userId}
447
            </if>
licc's avatar
licc committed
448
            <if test="queryTime != null and queryTime != ''">
licc's avatar
licc committed
449 450 451
                and (YEAR(create_time) = YEAR(#{queryTime})
                AND MONTH(create_time) =MONTH(#{queryTime})
                AND DAY(create_time)=DAY(#{queryTime}))
licc's avatar
licc committed
452
            </if>
453 454 455 456 457
        </where>
        order by create_time desc
        limit #{startNum},#{endNum}
    </select>

458
    <select id="countUser" resultType="java.lang.Integer">
459 460
        select count(1)
        from
461
        user_info
462 463
    </select>

licc's avatar
licc committed
464
</mapper>