UsersMapper.xml 9.43 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"/>
licc's avatar
licc committed
9 10 11 12 13 14 15
        <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
16 17 18 19 20
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

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

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

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

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

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

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

67

licc's avatar
licc committed
68 69 70 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
    <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
100 101
        </where>
    </select>
licc's avatar
licc committed
102

licc's avatar
licc committed
103 104 105 106 107 108 109
    <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
110 111
        </where>
    </select>
112 113 114 115
    <select id="ByUserId" resultType="java.lang.Integer">
        select
        id
        from
116
        user_info
117 118 119 120
        <where>
            user_id=#{userId}
        </where>
    </select>
m1991's avatar
m1991 committed
121

licc's avatar
licc committed
122 123
    <!--查询全部-->
    <select id="findAll" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
124
        select * from User
licc's avatar
licc committed
125
    </select>
m1991's avatar
m1991 committed
126

licc's avatar
licc committed
127 128
    <!--查询用户-->
    <select id="findByName" resultType="cn.wisenergy.model.app.User">
m1991's avatar
m1991 committed
129
        select * from User where user_id = #{userId}
licc's avatar
licc committed
130
    </select>
m1991's avatar
m1991 committed
131

licc's avatar
licc committed
132 133
    <!--查询密码-->
    <select id="findPswByName" resultType="String">
m1991's avatar
m1991 committed
134
        select password from user where user_id = #{userId}
licc's avatar
licc committed
135 136 137 138 139 140 141 142 143 144 145
    </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
146

licc's avatar
licc committed
147 148 149 150 151 152 153 154 155 156
    <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
157
    <!--用户注册-->
licc's avatar
licc committed
158
    <insert id="save">
m1991's avatar
m1991 committed
159 160 161
        insert into user(user_id,invite_code,be_invited_code,user_level) value (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
    </insert>
    <insert id="insertbyint">
162
        insert into user_info(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
licc's avatar
licc committed
163
    </insert>
m1991's avatar
m1991 committed
164

m1991's avatar
m1991 committed
165 166 167 168 169 170 171 172 173
    <select id="queryUsersByPhone" resultType="java.lang.Integer">
        select
          user_id
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
174 175 176 177 178 179 180 181 182 183 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-->
    <select id="BeInvitedCode1" resultType="java.lang.Integer">
        select
        id
        from
        <include refid="table"/>
        <where>
            invite_code=#{beInvitedCode}
        </where>
    </select>

m1991's avatar
m1991 committed
195 196 197 198 199 200 201 202 203 204
    <select id="getuserIdById" resultType="cn.wisenergy.model.app.User">
        select
        id
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
    <update id="edit1" parameterType="cn.wisenergy.model.app.User">
205 206
        update
        user_info
m1991's avatar
m1991 committed
207 208 209 210 211 212 213 214 215
        <set>
            <if test="userLevel != null">user_level =#{userLevel},</if>
            <if test="inviteCode != null">invite_code =#{inviteCode},</if>
            update_time =now()
        </set>
        <where>
            user_id = #{userId}
        </where>
    </update>
m1991's avatar
m1991 committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 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

    <!--分页查询所有用户信息 -->
    <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
271 272 273 274 275 276 277 278 279 280 281 282
<!--    获取当前用户的所有直接推荐人-->
    <select id="getByInviteCode" resultType="cn.wisenergy.model.app.User" parameterType="string">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            be_invited_code=#{inviteCode}
        </where>
        and user_level=#{userlevel}
    </select>

m1991's avatar
m1991 committed
283

licc's avatar
licc committed
284
</mapper>