<?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.patientpropaganda.PatientPropagandaMapper">

    <resultMap type="PatientPropaganda" id="PatientPropagandaResult">
            <result property="id" column="id"/>
            <result property="patientId" column="patient_id"/>
            <result property="propagandaId" column="propaganda_id"/>
            <result property="departmentName" column="department_name"/>
            <result property="propagandaTitle" column="propaganda_title"/>
            <result property="propagandaType" column="propaganda_type"/>
            <result property="propagandaCode" column="propaganda_code"/>
            <result property="propagandaContent" column="propaganda_content"/>
            <result property="propagandaCoverPath" column="propaganda_cover_path"/>
            <result property="articleSummary" column="article_summary"/>
            <result property="voicebroadcast" column="voicebroadcast"/>
            <result property="diseaseTypeName" column="disease_type_name"/>
            <result property="propagandaLink" column="propaganda_link"/>
            <result property="propagandaBarcodePath" column="propaganda_barcode_path"/>
            <result property="remark" column="remark"/>
            <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="selectPatientPropagandaVo">
        select id, patient_id, propaganda_id, department_name, propaganda_title, propaganda_type, propaganda_code, propaganda_content, propaganda_cover_path, article_summary, voicebroadcast, disease_type_name, propaganda_link, propaganda_barcode_path, remark, create_by, create_time, update_by, update_time from patient_propaganda
    </sql>

    <select id="selectPatientPropagandaList" parameterType="PatientPropaganda" resultMap="PatientPropagandaResult">
        <include refid="selectPatientPropagandaVo"/>
        <where>
                        <if test="patientId != null ">
                            and patient_id = #{patientId}
                        </if>
                        <if test="propagandaId != null ">
                            and propaganda_id = #{propagandaId}
                        </if>
                        <if test="departmentName != null  and departmentName != ''">
                            and department_name like concat('%', #{departmentName}, '%')
                        </if>
                        <if test="propagandaTitle != null  and propagandaTitle != ''">
                            and propaganda_title = #{propagandaTitle}
                        </if>
                        <if test="propagandaType != null  and propagandaType != ''">
                            and propaganda_type = #{propagandaType}
                        </if>
                        <if test="propagandaCode != null  and propagandaCode != ''">
                            and propaganda_code = #{propagandaCode}
                        </if>
        </where>
    </select>

    <select id="selectPatientPropagandaById" parameterType="Long"
            resultMap="PatientPropagandaResult">
            <include refid="selectPatientPropagandaVo"/>
            where id = #{id}
    </select>

    <insert id="insertPatientPropaganda" parameterType="PatientPropaganda" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_propaganda
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientId != null">patient_id,
                    </if>
                    <if test="propagandaId != null">propaganda_id,
                    </if>
                    <if test="departmentName != null">department_name,
                    </if>
                    <if test="propagandaTitle != null">propaganda_title,
                    </if>
                    <if test="propagandaType != null">propaganda_type,
                    </if>
                    <if test="propagandaCode != null">propaganda_code,
                    </if>
                    <if test="propagandaContent != null">propaganda_content,
                    </if>
                    <if test="propagandaCoverPath != null">propaganda_cover_path,
                    </if>
                    <if test="articleSummary != null">article_summary,
                    </if>
                    <if test="voicebroadcast != null">voicebroadcast,
                    </if>
                    <if test="diseaseTypeName != null">disease_type_name,
                    </if>
                    <if test="propagandaLink != null">propaganda_link,
                    </if>
                    <if test="propagandaBarcodePath != null">propaganda_barcode_path,
                    </if>
                    <if test="remark != null">remark,
                    </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="patientId != null">#{patientId},
                    </if>
                    <if test="propagandaId != null">#{propagandaId},
                    </if>
                    <if test="departmentName != null">#{departmentName},
                    </if>
                    <if test="propagandaTitle != null">#{propagandaTitle},
                    </if>
                    <if test="propagandaType != null">#{propagandaType},
                    </if>
                    <if test="propagandaCode != null">#{propagandaCode},
                    </if>
                    <if test="propagandaContent != null">#{propagandaContent},
                    </if>
                    <if test="propagandaCoverPath != null">#{propagandaCoverPath},
                    </if>
                    <if test="articleSummary != null">#{articleSummary},
                    </if>
                    <if test="voicebroadcast != null">#{voicebroadcast},
                    </if>
                    <if test="diseaseTypeName != null">#{diseaseTypeName},
                    </if>
                    <if test="propagandaLink != null">#{propagandaLink},
                    </if>
                    <if test="propagandaBarcodePath != null">#{propagandaBarcodePath},
                    </if>
                    <if test="remark != null">#{remark},
                    </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="updatePatientPropaganda" parameterType="PatientPropaganda">
        update patient_propaganda
        <trim prefix="SET" suffixOverrides=",">
                    <if test="patientId != null">patient_id =
                        #{patientId},
                    </if>
                    <if test="propagandaId != null">propaganda_id =
                        #{propagandaId},
                    </if>
                    <if test="departmentName != null">department_name =
                        #{departmentName},
                    </if>
                    <if test="propagandaTitle != null">propaganda_title =
                        #{propagandaTitle},
                    </if>
                    <if test="propagandaType != null">propaganda_type =
                        #{propagandaType},
                    </if>
                    <if test="propagandaCode != null">propaganda_code =
                        #{propagandaCode},
                    </if>
                    <if test="propagandaContent != null">propaganda_content =
                        #{propagandaContent},
                    </if>
                    <if test="propagandaCoverPath != null">propaganda_cover_path =
                        #{propagandaCoverPath},
                    </if>
                    <if test="articleSummary != null">article_summary =
                        #{articleSummary},
                    </if>
                    <if test="voicebroadcast != null">voicebroadcast =
                        #{voicebroadcast},
                    </if>
                    <if test="diseaseTypeName != null">disease_type_name =
                        #{diseaseTypeName},
                    </if>
                    <if test="propagandaLink != null">propaganda_link =
                        #{propagandaLink},
                    </if>
                    <if test="propagandaBarcodePath != null">propaganda_barcode_path =
                        #{propagandaBarcodePath},
                    </if>
                    <if test="remark != null">remark =
                        #{remark},
                    </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="deletePatientPropagandaById" parameterType="Long">
        delete from patient_propaganda where id = #{id}
    </delete>

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