UsersMapper.xml 8.24 KB
Newer Older
licc's avatar
licc committed
1 2 3
<?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">

licc's avatar
licc committed
4
<mapper namespace="cn.wisenergy.mapper.UsersMapper">
licc's avatar
licc committed
5
    <resultMap id="userMap" type="cn.wisenergy.model.app.User">
licc's avatar
licc committed
6 7 8 9
        <id column="id" property="id"/>
        <result column="user_name" property="userName"/>
        <result column="password" property="password"/>
        <result column="phone" property="phone"/>
10
        <result column="uuid" property="uuid"/>
licc's avatar
licc committed
11
        <result column="head_image" property="headImage"/>
licc's avatar
licc committed
12 13
        <result column="sex" property="sex"/>
        <result column="school" property="school"/>
14
        <result column="exam_type" property="examType"/>
licc's avatar
licc committed
15
        <result column="source" property="source"/>
licc's avatar
licc committed
16 17 18
        <result column="is_delete" property="isDelete"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
19
        <result column="is_vip" property="isVip"/>
cy's avatar
cy committed
20
        <result column="openid" property="openid"/>
21
        <result column="vip_mobile" property="vipMobile"/>
licc's avatar
licc committed
22
    </resultMap>
licc's avatar
licc committed
23

licc's avatar
licc committed
24 25 26
    <sql id="table">
        user
    </sql>
licc's avatar
licc committed
27

licc's avatar
licc committed
28 29 30 31
    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>
licc's avatar
licc committed
32

licc's avatar
licc committed
33
    <sql id="cols_exclude_id">
34
        user_name,password, phone,uuid,head_image,sex,school, exam_type,source,is_delete,create_time,update_time,is_vip,openid,vip_mobile
licc's avatar
licc committed
35
    </sql>
licc's avatar
licc committed
36

licc's avatar
licc committed
37
    <sql id="vals">
38
        #{userName},#{password},#{phone},#{uuid},#{headImage},#{sex},#{school},#{examType}, #{source},
39
        #{isDelete},now(),now(),#{isVip},#{openid},#{vipMobile}
licc's avatar
licc committed
40
    </sql>
licc's avatar
licc committed
41

licc's avatar
licc committed
42 43 44 45
    <sql id="updateCondition">
        <if test="userName != null">user_name = #{userName},</if>
        <if test="password != null">password =#{password},</if>
        <if test="phone != null">phone =#{phone},</if>
46
        <if test="uuid != null">uuid =#{uuid},</if>
licc's avatar
licc committed
47
        <if test="headImage != null">head_image =#{headImage},</if>
licc's avatar
licc committed
48 49
        <if test="sex != null">sex =#{sex},</if>
        <if test="school != null">school =#{school},</if>
licc's avatar
licc committed
50
        <if test="examType != null">exam_type = #{examType},</if>
licc's avatar
licc committed
51
        <if test="source != null">source = #{source},</if>
licc's avatar
licc committed
52
        <if test="isDelete != null">is_delete = #{isDelete},</if>
53
        update_time =now(),
cy's avatar
cy committed
54
        <if test="isVip != null">is_vip = #{isVip},</if>
55 56
        <if test="openid != null">openid =#{openid},</if>
        <if test="vipMobile != null">vip_mobile =#{vipMobile}</if>
licc's avatar
licc committed
57
    </sql>
licc's avatar
licc committed
58

licc's avatar
licc committed
59 60 61 62 63
    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userName != null">and user_name = #{userName}</if>
        <if test="password != null">and password =#{password}</if>
        <if test="phone != null">and phone =#{phone}</if>
64
        <if test="uuid != null">and uuid =#{uuid}</if>
licc's avatar
licc committed
65
        <if test="headImage != null">and head_image =#{headImage}</if>
licc's avatar
licc committed
66 67
        <if test="sex != null">and sex =#{sex}</if>
        <if test="school != null">and school =#{school}</if>
licc's avatar
licc committed
68
        <if test="examType != null">and exam_type = #{examType}</if>
licc's avatar
licc committed
69
        <if test="source != null">and source = #{source}</if>
licc's avatar
licc committed
70 71 72
        <if test="isDelete != null">and is_delete = #{isDelete}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
cy's avatar
cy committed
73
        <if test="isVip != null">and is_vip = #{isVip}</if>
74 75
        <if test="openid != null">and openid =#{openid},</if>
        <if test="vipMobile != null">vip_mobile =#{vipMobile}</if>
licc's avatar
licc committed
76
    </sql>
licc's avatar
licc committed
77

licc's avatar
licc committed
78
    <insert id="add" parameterType="cn.wisenergy.model.app.User" keyProperty="id" useGeneratedKeys="true">
licc's avatar
licc committed
79 80 81 82 83 84 85
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>
licc's avatar
licc committed
86

licc's avatar
licc committed
87
    <update id="edit" parameterType="cn.wisenergy.model.app.User">
licc's avatar
licc committed
88 89 90 91 92
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
licc's avatar
licc committed
93
        <where>
licc's avatar
licc committed
94
            id = #{id}
licc's avatar
licc committed
95
        </where>
licc's avatar
licc committed
96
    </update>
licc's avatar
licc committed
97

licc's avatar
licc committed
98 99 100 101 102 103
    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

104 105 106 107 108 109 110 111
    <select id="getById" resultMap="userMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>id = #{id}</where>
    </select>

licc's avatar
licc committed
112 113 114 115 116 117 118
    <select id="countByPhoneAnsUserId" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM
        <include refid="table"/>
        WHERE phone=#{phone} and id !=#{userId} and is_delete=0
    </select>

liaoanyuan's avatar
liaoanyuan committed
119 120 121 122 123 124
    <select id="getList" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
125
            is_delete=0 and is_vip = 2
liaoanyuan's avatar
liaoanyuan committed
126

127
            <if test="startTime != null and startTime !=''">
liaoanyuan's avatar
liaoanyuan committed
128
                and create_time
licc's avatar
licc committed
129 130
                between #{startTime}
            </if>
liaoanyuan's avatar
liaoanyuan committed
131

132
            <if test="endTime != null and endTime !=''">and #{endTime}</if>
133

134
            <if test="userName != null and userName !=''">and user_name like ('%' #{userName} '%')</if>
135

136
            <if test="phone != null and phone !=''">and phone like ('%' #{phone} '%')</if>
liaoanyuan's avatar
liaoanyuan committed
137
            order by create_time desc
138 139 140
            <if test="pageNo != null">
                limit #{pageNo},#{pageSize}
            </if>
liaoanyuan's avatar
liaoanyuan committed
141 142 143
        </where>
    </select>

liaoanyuan's avatar
liaoanyuan committed
144 145 146 147
    <select id="getUserNumbers" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM
        <include refid="table"/>
148
        <where>
149
            is_delete=0 and is_vip = 2
150 151 152 153 154

            <if test="startTime != null">
                and create_time
                between #{startTime}
            </if>
155
            <if test="endTime != null">and #{endTime}</if>
156 157 158 159

            <if test="userName != null">and user_name like ('%' #{userName} '%')</if>

            <if test="phone != null">and phone like ('%' #{phone} '%')</if>
160 161
        </where>

liaoanyuan's avatar
liaoanyuan committed
162
    </select>
licc's avatar
licc committed
163 164 165 166 167 168 169 170

    <select id="getByPhone" resultType="cn.wisenergy.model.app.User">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="table"/>
        where is_delete=0 and phone=#{phone}
    </select>
licc's avatar
licc committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185


    <select id="test" resultType="cn.wisenergy.model.app.User">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="list != null">
                <foreach collection="list" index="index" item="id" separator="or" open="(" close=")">
                    user_name LIKE CONCAT('%',#{id},'%')
                </foreach>
            </if>
        </where>
    </select>
186 187 188 189 190 191 192 193

    <select id="getUserByStaffId" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            is_delete=0
cy's avatar
cy committed
194
            <if test="list != null and (list.size)>0">
195 196 197 198 199
              and  id in
                <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
                    #{id.userVipId}
                </foreach>
            </if>
cy's avatar
cy committed
200 201
            <if test="userName != null and userName!=''"> and user_name like ('%' #{userName} '%')</if>
            <if test="phone != null and phone!=''"> and phone like ('%' #{phone} '%')</if>
202 203 204 205 206 207
            order by create_time desc
            <if test="pageNo != null">
                limit #{pageNo},#{pageSize}
            </if>
        </where>
    </select>
cy's avatar
cy committed
208

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    <select id="getVipUserNumbers" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM
        <include refid="table"/>
        <where>
            is_delete=0 and is_vip = 1
            <if test="list != null and (list.size)>0">
                and  id in
                <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
                    #{id.userVipId}
                </foreach>
            </if>

            <if test="startTime != null">
                and create_time
                between #{startTime}
            </if>
            <if test="endTime != null">and #{endTime}</if>

            <if test="userName != null">and user_name like ('%' #{userName} '%')</if>

            <if test="phone != null">and phone like ('%' #{phone} '%')</if>
        </where>

    </select>

cy's avatar
cy committed
235

licc's avatar
licc committed
236
</mapper>