<?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.WorkLeaveMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkLeave">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="type_id" property="typeId"/>
        <result column="start_date" property="startDate"/>
        <result column="end_date" property="endDate"/>
        <result column="des" property="des"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
    </resultMap>

    <sql id="vals">
       #{id},#{userId},#{typeId},#{startDate},#{endDate},#{des},#{createTime},#{modifyTime}
    </sql>

    <sql id="cols_exclude_id">
       user_id, type_id, start_date, end_date, des, create_time, modify_time
    </sql>

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

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

    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
    insert into <include refid="table"/>(<include refid="cols"/> )
    value (<include refid="vals"/> )
    </insert>

    <select id="getListByUserId" resultMap="BaseResultMap">
    select <include refid="cols"/>
    from <include refid="table"/>
    where user_id = #{userId}
    order by start_date DESC
    </select>

</mapper>