UsersMapper.xml 12.3 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
    <!--查询全部-->
    <select id="findAll" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
156
        select * from User
licc's avatar
licc committed
157
    </select>
m1991's avatar
m1991 committed
158

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

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

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

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

228 229 230 231
    <select id="InvitedCode2"  resultType="cn.wisenergy.model.app.User" parameterType="string">
        select
        *
        from
232
        user_info
233
        <where>
234
            invite_code=#{inviteCode}
235 236 237
        </where>
    </select>

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

m1991's avatar
m1991 committed
270

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

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

licc's avatar
licc committed
345 346 347 348 349 350 351 352 353 354
    <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
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    <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
370

371 372 373 374 375 376 377 378 379
    <select id="getAerialDeliveryUser" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        be_invited_code = '1';
    </select>

licc's avatar
licc committed
380
</mapper>