UsersMapper.xml 12.8 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"/>
licc's avatar
licc committed
18 19 20 21 22
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

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

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

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

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

    <sql id="updateCondition">
licc's avatar
licc committed
42
        <if test="userId != null">user_id = #{userId},</if>
licc's avatar
licc committed
43
        <if test="password != null">password =#{password},</if>
44
        <if test="headImage != null">head_image =#{headImage},</if>
licc's avatar
licc committed
45 46 47 48 49 50 51
        <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
52
        <if test="customerServiceId != null">customer_service_id = #{customerServiceId},</if>
licc's avatar
licc committed
53 54 55 56 57
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
licc's avatar
licc committed
58
        <if test="userId != null">and user_id = #{userId}</if>
licc's avatar
licc committed
59
        <if test="password != null">and password =#{password}</if>
60
        <if test="headImage != null">and head_image =#{headImage}</if>
licc's avatar
licc committed
61 62 63 64 65 66 67
        <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
68
        <if test="customerServiceId != null">and customer_service_id = #{customerServiceId}</if>
licc's avatar
licc committed
69 70 71 72
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

73

licc's avatar
licc committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    <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
89 90 91
        <where>
            id = #{id}
        </where>
licc's avatar
licc committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105
    </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
106
            be_invited_code=1
licc's avatar
licc committed
107 108 109 110
            <if test="createTime != null">
                and(YEAR(create_time) = YEAR(#{createTime})
                AND MONTH(create_time) = MONTH(#{createTime}))
            </if>
licc's avatar
licc committed
111
        </where>
licc's avatar
licc committed
112
        order by create_time desc
licc's avatar
licc committed
113
    </select>
licc's avatar
licc committed
114

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

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

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

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

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

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

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

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

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

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

m1991's avatar
m1991 committed
275

m1991's avatar
m1991 committed
276 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
    <!--分页查询所有用户信息 -->
    <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>
303

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

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

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

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

licc's avatar
licc committed
396
</mapper>