UsersMapper.xml 10.5 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>
103 104 105 106
           <if test="createTime != null">
               YEAR(create_time) = YEAR(#{createTime})
               AND MONTH(create_time) = MONTH(#{createTime})
           </if>
licc's avatar
licc committed
107 108
        </where>
    </select>
licc's avatar
licc committed
109

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

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

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

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

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

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

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

m1991's avatar
m1991 committed
234

m1991's avatar
m1991 committed
235 236 237 238 239 240 241 242 243 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
    <!--分页查询所有用户信息 -->
    <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>
            <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>

codezwjava's avatar
codezwjava committed
289 290
<!--    获取当前用户的所有直接推荐人-->
    <select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
291 292 293 294 295 296 297 298 299 300 301
        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
302 303 304 305 306
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
307
            invite_code=#{inviteCode}
codezwjava's avatar
codezwjava committed
308 309 310
        </where>
    </select>

m1991's avatar
m1991 committed
311 312 313 314 315 316 317 318 319 320 321 322
    <update id="updateByUserid">
        update
        <include refid="table"/>
        set
        (user_level,invite_code,)
        value
        (#{userLevel},#{inviteCode})
        <where>
            user_id=#{userId}
        </where>
    </update>

m1991's avatar
m1991 committed
323

licc's avatar
licc committed
324
</mapper>