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

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

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

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

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

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

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

70

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

112
    <select id="getByUserId" resultType="cn.wisenergy.model.app.User" parameterType="string">
licc's avatar
licc committed
113 114 115 116 117 118
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
licc's avatar
licc committed
119 120
        </where>
    </select>
121 122 123 124
    <select id="ByUserId" resultType="java.lang.Integer">
        select
        id
        from
125
        user_info
126 127 128 129
        <where>
            user_id=#{userId}
        </where>
    </select>
m1991's avatar
m1991 committed
130

licc's avatar
licc committed
131 132
    <!--查询全部-->
    <select id="findAll" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
133
        select * from User
licc's avatar
licc committed
134
    </select>
m1991's avatar
m1991 committed
135

licc's avatar
licc committed
136 137
    <!--查询用户-->
    <select id="findByName" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
138
        select * from User where user_id = #{userId}
licc's avatar
licc committed
139
    </select>
m1991's avatar
m1991 committed
140

licc's avatar
licc committed
141 142
    <!--查询密码-->
    <select id="findPswByName" resultType="String">
m1991's avatar
m1991 committed
143
        select password from user where user_id = #{userId}
licc's avatar
licc committed
144 145 146 147 148 149 150 151 152 153 154
    </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
155

licc's avatar
licc committed
156 157 158 159 160 161 162 163 164 165
    <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
166
    <!--用户注册-->
licc's avatar
licc committed
167
    <insert id="save">
licc's avatar
licc committed
168 169
        insert into user(user_id,invite_code,be_invited_code,user_level) value
        (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
m1991's avatar
m1991 committed
170 171
    </insert>
    <insert id="insertbyint">
172
        insert into user_info(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
licc's avatar
licc committed
173
    </insert>
m1991's avatar
m1991 committed
174

m1991's avatar
m1991 committed
175
    <select id="queryUsersByPhone" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
176
        select
licc's avatar
licc committed
177
        <include refid="vals"/>
m1991's avatar
m1991 committed
178 179 180 181 182 183
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
184 185 186 187 188 189 190 191 192 193 194
    <!--根据用户的推荐人邀请码比对推荐人的本人邀请码,查询推荐人的用户ID-->
    <select id="inviteCodeBeInvitedCode" resultType="java.lang.Integer">
        select
        user_id
        from
        <include refid="table"/>
        <where>
            invite_code=#{beInvitedCode}
        </where>
    </select>
    <!--根据用户的推荐人邀请码比对推荐人的本人邀请码,查询推荐人的用户ID-->
195
    <select id="beInvitedCode1" resultType="java.lang.Integer">
196 197 198 199 200 201 202 203 204
        select
        id
        from
        <include refid="table"/>
        <where>
            invite_code=#{beInvitedCode}
        </where>
    </select>

m1991's avatar
m1991 committed
205
    <select id="getuserIdById" resultType="java.lang.Integer">
m1991's avatar
m1991 committed
206 207 208 209 210 211 212 213
        select
        id
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
m1991's avatar
m1991 committed
214 215 216 217 218 219 220 221 222
    <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
223
    <update id="edit1">
224 225
        update
        user_info
m1991's avatar
m1991 committed
226 227 228
        <set>
            <if test="userLevel != null">user_level =#{userLevel},</if>
            <if test="inviteCode != null">invite_code =#{inviteCode},</if>
m1991's avatar
m1991 committed
229
            create_time =now(),
m1991's avatar
m1991 committed
230 231 232
            update_time =now()
        </set>
        <where>
licc's avatar
licc committed
233
            user_id = #{userId}
m1991's avatar
m1991 committed
234 235
        </where>
    </update>
m1991's avatar
m1991 committed
236

m1991's avatar
m1991 committed
237

m1991's avatar
m1991 committed
238 239 240 241 242
    <!--分页查询所有用户信息 -->
    <select id="getUsersListByMap" resultType="cn.wisenergy.model.app.User" parameterType="java.util.Map">
        select id as id,
        user_id as userId,
        password as password,
243
        userName as userName,
m1991's avatar
m1991 committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
        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>
            <if test="userName != null and userName!=''">
                and crossBorderLine=#{crossBorderLine}
            </if>
            <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
293
    <!--    获取当前用户的所有直接推荐人-->
codezwjava's avatar
codezwjava committed
294
    <select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
295 296 297 298 299 300 301 302 303 304 305
        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
306 307 308 309 310
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
311
            invite_code=#{inviteCode}
codezwjava's avatar
codezwjava committed
312 313 314
        </where>
    </select>

licc's avatar
licc committed
315 316 317 318 319 320 321 322 323 324
    <select id="getByLevel" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_level=#{userLevel}
        </where>
    </select>

m1991's avatar
m1991 committed
325

licc's avatar
licc committed
326
</mapper>