UsersMapper.xml 14 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 109 110 111
            <if test="createTime != null">
                and(YEAR(create_time) = YEAR(#{createTime})
                AND MONTH(create_time) = MONTH(#{createTime}))
            </if>
licc's avatar
licc committed
112
        </where>
licc's avatar
licc committed
113
        order by create_time desc
licc's avatar
licc committed
114
    </select>
licc's avatar
licc committed
115

liqin's avatar
liqin committed
116 117 118 119 120 121 122 123 124 125
    <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>

126
    <select id="getByUserId" resultType="cn.wisenergy.model.app.User" parameterType="string">
licc's avatar
licc committed
127
        select
128
        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
129
        be_invited_code,customer_service_id,create_time,update_time
licc's avatar
licc committed
130
        from
131
        user_info
licc's avatar
licc committed
132 133
        <where>
            user_id=#{userId}
licc's avatar
licc committed
134 135
        </where>
    </select>
136 137 138 139 140 141 142 143 144
    <select id="getById" resultType="java.lang.Integer" parameterType="string">
        select
        userId
        from
        user_info
        <where>
            user_id=#{userId}
        </where>
    </select>
145 146 147 148
    <select id="ByUserId" resultType="java.lang.Integer">
        select
        id
        from
149
        user_info
150 151 152 153
        <where>
            user_id=#{userId}
        </where>
    </select>
m1991's avatar
m1991 committed
154

licc's avatar
licc committed
155 156 157 158 159 160 161 162
    <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
163
    </select>
m1991's avatar
m1991 committed
164

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

licc's avatar
licc committed
170 171
    <!--查询密码-->
    <select id="findPswByName" resultType="String">
m1991's avatar
m1991 committed
172
        select password from user where user_id = #{userId}
licc's avatar
licc committed
173 174 175 176 177 178 179 180
    </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
181
            invite_code = #{beInvitedCode}
licc's avatar
licc committed
182 183
        </where>
    </select>
m1991's avatar
m1991 committed
184

licc's avatar
licc committed
185 186 187 188 189 190 191 192 193 194
    <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
195 196
    <!--用户注册-->
    <insert id="insertbyint">
197 198
        insert into user_info(user_id,invite_code,be_invited_code,user_level,head_image,frozen) value
        (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel},#{headImage},#{frozen})
199 200
    </insert>
    <insert id="save">
201
        insert into user_info(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
licc's avatar
licc committed
202
    </insert>
m1991's avatar
m1991 committed
203

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

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

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

m1991's avatar
m1991 committed
276

m1991's avatar
m1991 committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
    <!--分页查询所有用户信息 -->
    <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>
304

m1991's avatar
m1991 committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
            <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
329
    <!--    获取当前用户的所有直接推荐人-->
codezwjava's avatar
codezwjava committed
330
    <select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
331 332 333 334 335 336 337 338 339 340 341
        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
342 343 344 345 346
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
347
            invite_code=#{inviteCode}
codezwjava's avatar
codezwjava committed
348 349 350
        </where>
    </select>

licc's avatar
licc committed
351 352 353 354 355 356 357 358 359 360
    <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
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
    <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
376

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

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

codezwjava's avatar
codezwjava committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
    <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>

414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    <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>

432 433 434 435 436 437 438 439 440
    <select id="getUserByUserId" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        user_id = #{userId}
    </select>

licc's avatar
licc committed
441
</mapper>