<?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.medicalhealth.mapper.BdglDiagnoseMapper">

    <resultMap type="BdglDiagnose" id="BdglDiagnoseResult">
        <result property="id"    column="id"    />
        <result property="unitId"    column="unit_id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="address"    column="address"    />
        <result property="startTime"    column="start_time"    />
        <result property="duration"    column="duration"    />
        <result property="endTime"    column="end_time"    />
        <result property="adminId"    column="admin_id"    />
        <result property="createtime"    column="createtime"    />
        <result property="updatetime"    column="updatetime"    />
        <result property="illness"    column="illness"    />
        <result property="unitName"    column="unit_name"    />
        <result property="peopleName"    column="people_name"    />
        <result property="adminname"    column="adminname"    />
        <result property="accompanyingPerson"    column="accompanying_person"    />
        <result property="state"    column="state"    />
    </resultMap>

    <sql id="selectBdglDiagnoseVo">
        select id, unit_id, people_id, address, start_time, duration, end_time, admin_id, createtime, updatetime, illness, unit_name, people_name, adminname, accompanying_person, state from bdgl_diagnose
    </sql>

    <select id="selectBdglDiagnoseList" parameterType="BdglDiagnose" resultMap="BdglDiagnoseResult">
        <include refid="selectBdglDiagnoseVo"/>
        <where>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="peopleId != null "> and people_id = #{peopleId}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="duration != null  and duration != ''"> and duration = #{duration}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="adminId != null "> and admin_id = #{adminId}</if>
            <if test="createtime != null  and createtime != ''"> and createtime = #{createtime}</if>
            <if test="updatetime != null  and updatetime != ''"> and updatetime = #{updatetime}</if>
            <if test="illness != null  and illness != ''"> and illness = #{illness}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="peopleName != null  and peopleName != ''"> and people_name like concat('%', #{peopleName}, '%')</if>
            <if test="adminname != null  and adminname != ''"> and adminname like concat('%', #{adminname}, '%')</if>
            <if test="accompanyingPerson != null  and accompanyingPerson != ''"> and accompanying_person = #{accompanyingPerson}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
        </where>
    </select>

    <select id="selectBdglDiagnoseById" parameterType="Integer" resultMap="BdglDiagnoseResult">
        <include refid="selectBdglDiagnoseVo"/>
        where id = #{id}
    </select>

    <insert id="insertBdglDiagnose" parameterType="BdglDiagnose" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_diagnose
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitId != null">unit_id,</if>
            <if test="peopleId != null">people_id,</if>
            <if test="address != null">address,</if>
            <if test="startTime != null">start_time,</if>
            <if test="duration != null">duration,</if>
            <if test="endTime != null">end_time,</if>
            <if test="adminId != null">admin_id,</if>
            <if test="createtime != null">createtime,</if>
            <if test="updatetime != null">updatetime,</if>
            <if test="illness != null">illness,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="peopleName != null">people_name,</if>
            <if test="adminname != null">adminname,</if>
            <if test="accompanyingPerson != null">accompanying_person,</if>
            <if test="state != null">state,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="unitId != null">#{unitId},</if>
            <if test="peopleId != null">#{peopleId},</if>
            <if test="address != null">#{address},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="duration != null">#{duration},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="adminId != null">#{adminId},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="updatetime != null">#{updatetime},</if>
            <if test="illness != null">#{illness},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="peopleName != null">#{peopleName},</if>
            <if test="adminname != null">#{adminname},</if>
            <if test="accompanyingPerson != null">#{accompanyingPerson},</if>
            <if test="state != null">#{state},</if>
        </trim>
    </insert>

    <update id="updateBdglDiagnose" parameterType="BdglDiagnose">
        update bdgl_diagnose
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="address != null">address = #{address},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="adminId != null">admin_id = #{adminId},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="updatetime != null">updatetime = #{updatetime},</if>
            <if test="illness != null">illness = #{illness},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="peopleName != null">people_name = #{peopleName},</if>
            <if test="adminname != null">adminname = #{adminname},</if>
            <if test="accompanyingPerson != null">accompanying_person = #{accompanyingPerson},</if>
            <if test="state != null">state = #{state},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglDiagnoseById" parameterType="Integer">
        delete from bdgl_diagnose where id = #{id}
    </delete>

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