UsersMapper.xml 4.98 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"/>
licc's avatar
licc committed
10
        <result column="head_image" property="headImage"/>
licc's avatar
licc committed
11 12
        <result column="sex" property="sex"/>
        <result column="school" property="school"/>
13
        <result column="exam_type" property="examType"/>
licc's avatar
licc committed
14
        <result column="source" property="source"/>
licc's avatar
licc committed
15 16 17 18
        <result column="is_delete" property="isDelete"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
licc's avatar
licc committed
19

licc's avatar
licc committed
20 21 22
    <sql id="table">
        user
    </sql>
licc's avatar
licc committed
23

licc's avatar
licc committed
24 25 26 27
    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>
licc's avatar
licc committed
28

licc's avatar
licc committed
29
    <sql id="cols_exclude_id">
licc's avatar
licc committed
30
        user_name,password, phone,head_image,sex,school, exam_type,source,is_delete,create_time,update_time
licc's avatar
licc committed
31
    </sql>
licc's avatar
licc committed
32

licc's avatar
licc committed
33
    <sql id="vals">
34
        #{userName},#{password},#{phone},#{headImage},#{sex},#{school},#{examType}, #{source},
licc's avatar
licc committed
35
        #{isDelete},now(),now()
licc's avatar
licc committed
36
    </sql>
licc's avatar
licc committed
37

licc's avatar
licc committed
38 39 40 41
    <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>
licc's avatar
licc committed
42
        <if test="headImage != null">head_image =#{headImage},</if>
licc's avatar
licc committed
43 44
        <if test="sex != null">sex =#{sex},</if>
        <if test="school != null">school =#{school},</if>
licc's avatar
licc committed
45
        <if test="examType != null">exam_type = #{examType},</if>
licc's avatar
licc committed
46
        <if test="source != null">source = #{source},</if>
licc's avatar
licc committed
47 48 49
        <if test="isDelete != null">is_delete = #{isDelete},</if>
        update_time =now()
    </sql>
licc's avatar
licc committed
50

licc's avatar
licc committed
51 52 53 54 55
    <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>
licc's avatar
licc committed
56
        <if test="headImage != null">and head_image =#{headImage}</if>
licc's avatar
licc committed
57 58
        <if test="sex != null">and sex =#{sex}</if>
        <if test="school != null">and school =#{school}</if>
licc's avatar
licc committed
59
        <if test="examType != null">and exam_type = #{examType}</if>
licc's avatar
licc committed
60
        <if test="source != null">and source = #{source}</if>
licc's avatar
licc committed
61 62 63 64
        <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>
    </sql>
licc's avatar
licc committed
65

licc's avatar
licc committed
66
    <insert id="add" parameterType="cn.wisenergy.model.app.User" keyProperty="id" useGeneratedKeys="true">
licc's avatar
licc committed
67 68 69 70 71 72 73
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>
licc's avatar
licc committed
74

licc's avatar
licc committed
75
    <update id="edit" parameterType="cn.wisenergy.model.app.User">
licc's avatar
licc committed
76 77 78 79 80
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
licc's avatar
licc committed
81
        <where>
licc's avatar
licc committed
82
            id = #{id}
licc's avatar
licc committed
83
        </where>
licc's avatar
licc committed
84
    </update>
licc's avatar
licc committed
85

licc's avatar
licc committed
86 87 88 89 90 91
    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

licc's avatar
licc committed
92 93 94 95 96 97 98
    <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
99 100 101 102 103 104 105 106
    <select id="getList" resultMap="userMap" parameterType="map">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            is_delete=0

liaoanyuan's avatar
liaoanyuan committed
107
            <if test="startTime != null">
liaoanyuan's avatar
liaoanyuan committed
108
                and create_time
licc's avatar
licc committed
109 110
                between #{startTime}
            </if>
liaoanyuan's avatar
liaoanyuan committed
111

liaoanyuan's avatar
liaoanyuan committed
112 113
            <if test="endTime != null">and #{endTime}</if>
            order by create_time desc
114
            limit #{pageNo},#{pageSize}
liaoanyuan's avatar
liaoanyuan committed
115 116 117
        </where>
    </select>

liaoanyuan's avatar
liaoanyuan committed
118 119 120 121 122 123
    <select id="getUserNumbers" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM
        <include refid="table"/>
        where is_delete=0
    </select>
licc's avatar
licc committed
124 125 126 127 128 129 130 131

    <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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146


    <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>
licc's avatar
licc committed
147
</mapper>