<?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="io.renren.dao.ConsumePeopleDayMapper">

    <resultMap type="ConsumePeopleDay" id="ConsumePeopleDayResult">
        <result property="id"    column="id"    />
        <result property="empId"    column="emp_id"    />
        <result property="accountId"    column="account_id"    />
        <result property="accountName"    column="account_name"    />
        <result property="consumeInterval"    column="consume_interval"    />
        <result property="type"    column="type"    />
        <result property="consumeTime"    column="consume_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="isConsume"    column="is_consume"    />
        <result property="canteen"    column="canteen"    />
        <result property="guid"    column="guid"    />
        <result property="leaveTime"    column="leave_time"    />
    </resultMap>

    <sql id="selectConsumePeopleDayVo">
        select cpd.id, cpd.emp_id, cpd.account_id, cpd.consume_interval, cpd.type, cpd.consume_time, cpd.create_by, cpd.create_time, cpd.update_by, cpd.update_time, cpd.remark,p.name account_name,cpd.is_consume,cpd.canteen,p.guid,cpd.leave_time
        from consume_people_day cpd
        left join sys_people p
        on p.id=cpd.account_id

    </sql>

    <select id="selectConsumePeopleDayList" parameterType="ConsumePeopleDay" resultMap="ConsumePeopleDayResult">
        <include refid="selectConsumePeopleDayVo"/>
        <where>
            <if test="empId != null  and empId != ''"> and cpd.emp_id = #{empId}</if>
            <if test="accountId != null  and accountId != ''"> and cpd.account_id = #{accountId}</if>
            <if test="accountName != null  and accountName != ''"> and p.name = #{accountName}</if>
            <if test="consumeInterval != null  and consumeInterval != ''"> and cpd.consume_interval = #{consumeInterval}</if>
            <if test="type != null  and type != ''"> and cpd.type = #{type}</if>
            <if test="consumeTime != null "> and date_format(cpd.consume_time,'%Y-%m-%d')=  date_format(#{consumeTime},'%Y-%m-%d')</if>
        </where>
        order by cpd.consume_time desc
    </select>

    <select id="selectConsumePeopleDayById" parameterType="Long" resultMap="ConsumePeopleDayResult">
        <include refid="selectConsumePeopleDayVo"/>
        where cpd.id = #{id}
    </select>

    <insert id="insertConsumePeopleDay" parameterType="ConsumePeopleDay" useGeneratedKeys="true" keyProperty="id">
        insert into consume_people_day
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="empId != null">emp_id,</if>
            <if test="accountId != null">account_id,</if>
            <if test="consumeInterval != null">consume_interval,</if>
            <if test="type != null">type,</if>
            <if test="consumeTime != null">consume_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="isConsume != null">is_consume,</if>
            <if test="canteen != null">canteen,</if>
            <if test="reportId != null">report_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="empId != null">#{empId},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="consumeInterval != null">#{consumeInterval},</if>
            <if test="type != null">#{type},</if>
            <if test="consumeTime != null">#{consumeTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isConsume != null">#{isConsume},</if>
            <if test="canteen != null">#{canteen},</if>
            <if test="reportId != null">#{reportId},</if>
         </trim>
    </insert>

    <update id="updateConsumePeopleDay" parameterType="ConsumePeopleDay">
        update consume_people_day
        <trim prefix="SET" suffixOverrides=",">
            <if test="empId != null">emp_id = #{empId},</if>
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="consumeInterval != null">consume_interval = #{consumeInterval},</if>
            <if test="type != null">type = #{type},</if>
            <if test="consumeTime != null">consume_time = #{consumeTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isConsume != null">is_consume = #{isConsume},</if>
            <if test="leaveTime != null">leave_time = #{leaveTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteConsumePeopleDayById" parameterType="Long">
        delete from consume_people_day where id = #{id}
    </delete>

    <delete id="deleteConsumePeopleDayByIds" parameterType="String">
        delete from consume_people_day where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
