<?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="com.supervision.grassrootsregistration.mapper.BdglFoodMapper">

    <resultMap type="BdglFood" id="BdglFoodResult">
        <result property="id"    column="id"    />
        <result property="recordDate"    column="record_date"    />
        <result property="unitId"    column="unit_id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="chairmanId"    column="chairman_id"    />
        <result property="peopleId1"    column="people_id1"    />
        <result property="contents"    column="contents"    />
        <result property="peopleIds"    column="people_ids"    />
        <result property="repastContent"    column="repast_content"    />
        <result property="createtime"    column="createtime"    />
        <result property="updatetime"    column="updatetime"    />
        <result property="peopleName"    column="people_name"    />
        <result property="chairmanName"    column="chairman_name"    />
        <result property="people1Name"    column="people1_name"    />
        <result property="unitName"    column="unit_name"    />
        <result property="peopleNames"    column="people_names"    />
    </resultMap>

    <sql id="selectBdglFoodVo">
        select id, record_date, unit_id, people_id, chairman_id, people_id1, contents, people_ids, repast_content, createtime, updatetime, people_name, chairman_name, people1_name, unit_name,people_names from bdgl_food
    </sql>

    <select id="selectBdglFoodList" parameterType="BdglFood" resultMap="BdglFoodResult">
        select id, record_date, unit_id, people_id, chairman_id, people_id1, contents, people_ids, repast_content, createtime, updatetime, people_name, chairman_name, people1_name, unit_name,people_names
        from bdgl_food f left join sys_dept t
        on f.unit_id=t.dept_id
        <where>
            <if test="unitId != null ">
                and (f.unit_id=#{unitId} or find_in_set(#{unitId}, t.ancestors))
            </if>
            <if test="recordDate != null "> and f.record_date = #{recordDate}</if>
            <if test="peopleId != null "> and f.people_id = #{peopleId}</if>
            <if test="chairmanId != null "> and f.chairman_id = #{chairmanId}</if>
            <if test="peopleId1 != null "> and f.people_id1 = #{peopleId1}</if>
            <if test="contents != null  and contents != ''"> and f.contents = #{contents}</if>
            <if test="peopleIds != null  and peopleIds != ''"> and f.people_ids = #{peopleIds}</if>
            <if test="repastContent != null  and repastContent != ''"> and f.repast_content = #{repastContent}</if>
            <if test="createtime != null  and createtime != ''"> and f.createtime = #{createtime}</if>
            <if test="updatetime != null  and updatetime != ''"> and f.updatetime = #{updatetime}</if>
            <if test="peopleName != null  and peopleName != ''"> and f.people_name like concat('%', #{peopleName}, '%')</if>
            <if test="chairmanName != null  and chairmanName != ''"> and f.chairman_name like concat('%', #{chairmanName}, '%')</if>
            <if test="people1Name != null  and people1Name != ''"> and f.people1_name like concat('%', #{people1Name}, '%')</if>
            <if test="unitName != null  and unitName != ''"> and f.unit_name like concat('%', #{unitName}, '%')</if>
            <if test="peopleNames != null  and peopleNames != ''"> and f.people_names like concat('%', #{peopleNames}, '%')</if>
        </where>
        order by f.id desc
    </select>

    <select id="selectBdglFoodById" parameterType="Integer" resultMap="BdglFoodResult">
        <include refid="selectBdglFoodVo"/>
        where id = #{id}
    </select>

    <insert id="insertBdglFood" parameterType="BdglFood" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_food
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordDate != null">record_date,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="peopleId != null">people_id,</if>
            <if test="chairmanId != null">chairman_id,</if>
            <if test="peopleId1 != null">people_id1,</if>
            <if test="contents != null">contents,</if>
            <if test="peopleIds != null">people_ids,</if>
            <if test="repastContent != null">repast_content,</if>
            <if test="createtime != null">createtime,</if>
            <if test="updatetime != null">updatetime,</if>
            <if test="peopleName != null">people_name,</if>
            <if test="chairmanName != null">chairman_name,</if>
            <if test="people1Name != null">people1_name,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="peopleNames != null">people_names,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordDate != null">#{recordDate},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="peopleId != null">#{peopleId},</if>
            <if test="chairmanId != null">#{chairmanId},</if>
            <if test="peopleId1 != null">#{peopleId1},</if>
            <if test="contents != null">#{contents},</if>
            <if test="peopleIds != null">#{peopleIds},</if>
            <if test="repastContent != null">#{repastContent},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="updatetime != null">#{updatetime},</if>
            <if test="peopleName != null">#{peopleName},</if>
            <if test="chairmanName != null">#{chairmanName},</if>
            <if test="people1Name != null">#{people1Name},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="peopleNames != null">#{peopleNames},</if>
        </trim>
    </insert>

    <update id="updateBdglFood" parameterType="BdglFood">
        update bdgl_food
        <trim prefix="SET" suffixOverrides=",">
            <if test="recordDate != null">record_date = #{recordDate},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="chairmanId != null">chairman_id = #{chairmanId},</if>
            <if test="peopleId1 != null">people_id1 = #{peopleId1},</if>
            <if test="contents != null">contents = #{contents},</if>
            <if test="peopleIds != null">people_ids = #{peopleIds},</if>
            <if test="repastContent != null">repast_content = #{repastContent},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="updatetime != null">updatetime = #{updatetime},</if>
            <if test="peopleName != null">people_name = #{peopleName},</if>
            <if test="chairmanName != null">chairman_name = #{chairmanName},</if>
            <if test="people1Name != null">people1_name = #{people1Name},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="peopleNames != null">people_names = #{peopleNames},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglFoodById" parameterType="Integer">
        delete from bdgl_food where id = #{id}
    </delete>

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