<?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.xinelu.manage.mapper.nursestationpersoncertificate.NurseStationPersonCertificateMapper">

    <resultMap type="NurseStationPersonCertificate" id="NurseStationPersonCertificateResult">
        <result property="id" column="id"/>
        <result property="nurseStationPersonId" column="nurse_station_person_id"/>
        <result property="certificateName" column="certificate_name"/>
        <result property="certificateCode" column="certificate_code"/>
        <result property="certificateUrl" column="certificate_url"/>
        <result property="sort" column="sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectNurseStationPersonCertificateVo">
        select id,
               nurse_station_person_id,
               certificate_name,
               certificate_code,
               certificate_url,
               sort,
               create_by,
               create_time,
               update_by,
               update_time
        from nurse_station_person_certificate
    </sql>

    <select id="selectNurseStationPersonCertificateList" parameterType="NurseStationPersonCertificate"
            resultMap="NurseStationPersonCertificateResult">
        <include refid="selectNurseStationPersonCertificateVo"/>
        <where>
            <if test="nurseStationPersonId != null ">
                and nurse_station_person_id = #{nurseStationPersonId}
            </if>
            <if test="certificateName != null  and certificateName != ''">
                and certificate_name like concat('%', #{certificateName}, '%')
            </if>
            <if test="certificateCode != null  and certificateCode != ''">
                and certificate_code = #{certificateCode}
            </if>
            <if test="certificateUrl != null  and certificateUrl != ''">
                and certificate_url = #{certificateUrl}
            </if>
        </where>
    </select>

    <select id="selectNurseStationPersonCertificateById" parameterType="Long"
            resultMap="NurseStationPersonCertificateResult">
        <include refid="selectNurseStationPersonCertificateVo"/>
        where id = #{id}
    </select>

    <insert id="insertNurseStationPersonCertificate" parameterType="NurseStationPersonCertificate"
            useGeneratedKeys="true"
            keyProperty="id">
        insert into nurse_station_person_certificate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nurseStationPersonId != null">nurse_station_person_id,
            </if>
            <if test="certificateName != null">certificate_name,
            </if>
            <if test="certificateCode != null">certificate_code,
            </if>
            <if test="certificateUrl != null">certificate_url,
            </if>
            <if test="sort != null">sort,
            </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nurseStationPersonId != null">#{nurseStationPersonId},
            </if>
            <if test="certificateName != null">#{certificateName},
            </if>
            <if test="certificateCode != null">#{certificateCode},
            </if>
            <if test="certificateUrl != null">#{certificateUrl},
            </if>
            <if test="sort != null">#{sort},
            </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>
        </trim>
    </insert>

    <update id="updateNurseStationPersonCertificate" parameterType="NurseStationPersonCertificate">
        update nurse_station_person_certificate
        <trim prefix="SET" suffixOverrides=",">
            <if test="nurseStationPersonId != null">nurse_station_person_id =
                #{nurseStationPersonId},
            </if>
            <if test="certificateName != null">certificate_name =
                #{certificateName},
            </if>
            <if test="certificateCode != null">certificate_code =
                #{certificateCode},
            </if>
            <if test="certificateUrl != null">certificate_url =
                #{certificateUrl},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNurseStationPersonCertificateById" parameterType="Long">
        delete
        from nurse_station_person_certificate
        where id = #{id}
    </delete>

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

    <insert id="insertNurseStationPersonCertificateList" parameterType="java.util.List">
        insert into nurse_station_person_certificate(
        nurse_station_person_id,
        certificate_name,
        certificate_code,
        certificate_url,
        sort,
        create_by,
        create_time,
        update_by,
        update_time
        ) values
        <foreach item="NurseStationPersonCertificate" index="index" collection="list" separator=",">
            (
            #{NurseStationPersonCertificate.nurseStationPersonId},
            #{NurseStationPersonCertificate.certificateName},
            #{NurseStationPersonCertificate.certificateCode},
            #{NurseStationPersonCertificate.certificateUrl},
            #{NurseStationPersonCertificate.sort},
            #{NurseStationPersonCertificate.createBy},
            #{NurseStationPersonCertificate.createTime},
            #{NurseStationPersonCertificate.updateBy},
            #{NurseStationPersonCertificate.updateTime}
            )
        </foreach>
    </insert>

    <select id="selectNurseStationPersonCertificateByIds" parameterType="Long"
            resultType="NurseStationPersonCertificate">
        select id,
        nurse_station_person_id,
        certificate_name,
        certificate_code,
        certificate_url,
        sort,
        create_by,
        create_time,
        update_by,
        update_time
        from nurse_station_person_certificate
        <where>
            <if test="nurseStationPersonIdsList != null  and nurseStationPersonIdsList.size() > 0 ">
                and nurse_station_person_id in
                <foreach item="nurseStationPersonIds" collection="nurseStationPersonIdsList" open="(" separator=","
                         close=")">
                    #{nurseStationPersonIds}
                </foreach>
            </if>
        </where>
    </select>

    <delete id="deleteNurseStationPersonCertificateByPersonIds">
        delete from nurse_station_person_certificate where nurse_station_person_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>