SchemeRecordMapper.xml 3.85 KB
Newer Older
licc's avatar
licc committed
1 2 3 4
<?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.SchemeRecordMapper">
licc's avatar
licc committed
5
    <resultMap id="recordMap" type="cn.wisenergy.model.app.SchemeQueryRecord">
licc's avatar
licc committed
6 7 8 9 10
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="major_name" property="majorName"/>
        <result column="student_type" property="studentType"/>
        <result column="score" property="score"/>
11
        <result column="major_score" property="majorScore"/>
licc's avatar
licc committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
        <result column="is_delete" property="isDelete"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        scheme_query_record
    </sql>

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

    <sql id="cols_exclude_id">
27
        user_id,major_name, student_type,score,major_score,is_delete,create_time,update_time
licc's avatar
licc committed
28 29 30
    </sql>

    <sql id="vals">
31
        #{userId},#{majorName},#{studentType},#{score}, #{majorScore},#{isDelete},now(),now()
licc's avatar
licc committed
32 33 34 35 36 37 38
    </sql>

    <sql id="updateCondition">
        <if test="userId != null">user_id = #{userId},</if>
        <if test="majorName != null">major_name =#{majorName},</if>
        <if test="studentType != null">student_type =#{studentType},</if>
        <if test="score != null">score =#{score},</if>
39
        <if test="majorScore != null">major_score =#{majorScore},</if>
licc's avatar
licc committed
40 41 42 43 44 45 46 47 48 49
        <if test="isDelete != null">is_delete = #{isDelete},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userId != null">and user_id = #{userId}</if>
        <if test="majorName != null">and major_name =#{majorName}</if>
        <if test="studentType != null">and student_type =#{studentType}</if>
        <if test="score != null">and score =#{score}</if>
50
        <if test="majorScore != null">and major_score =#{majorScore}</if>
licc's avatar
licc committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        <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>

    <insert id="add" parameterType="cn.wisenergy.model.app.SchemeQueryRecord" 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.SchemeQueryRecord">
        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>

licc's avatar
licc committed
82 83 84 85 86 87
    <select id="count" resultType="java.lang.Integer">
        select count(1)
        from
        <include refid="table"/>
        <where>
            is_delete=0
licc's avatar
licc committed
88
            <if test="userId != null">
licc's avatar
licc committed
89 90 91 92 93
                and user_id=#{userId}
            </if>
        </where>
    </select>

licc's avatar
licc committed
94
    <select id="getByUserId" resultType="cn.wisenergy.model.app.SchemeQueryRecord">
licc's avatar
licc committed
95 96 97 98 99 100
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            is_delete=0
licc's avatar
licc committed
101
            and user_id=#{userId}
licc's avatar
licc committed
102
            order by create_time desc
licc's avatar
licc committed
103 104 105 106
            limit #{startNum},#{endNum}
        </where>
    </select>

107 108 109 110 111 112 113 114 115
    <select id="getById" resultMap="recordMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            id=#{id}
        </where>
    </select>
licc's avatar
licc committed
116
</mapper>