<?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.patientblacklistabnormalcause.PatientBlacklistAbnormalCauseMapper">

    <resultMap type="PatientBlacklistAbnormalCause" id="PatientBlacklistAbnormalCauseResult">
            <result property="id" column="id"/>
            <result property="parentId" column="parent_id"/>
            <result property="abnormalCauseCode" column="abnormal_cause_code"/>
            <result property="abnormalCauseValue" column="abnormal_cause_value"/>
            <result property="abnormalCauseLevel" column="abnormal_cause_level"/>
            <result property="status" column="status"/>
            <result property="delFlag" column="del_flag"/>
            <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="selectPatientBlacklistAbnormalCauseVo">
        select id, parent_id, abnormal_cause_code, abnormal_cause_value, abnormal_cause_level, status, del_flag, remark, create_by, create_time, update_by, update_time from patient_blacklist_abnormal_cause
    </sql>

    <select id="selectPatientBlacklistAbnormalCauseList" parameterType="PatientBlacklistAbnormalCause" resultMap="PatientBlacklistAbnormalCauseResult">
        <include refid="selectPatientBlacklistAbnormalCauseVo"/>
        <where>
			del_flag = 0
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <if test="abnormalCauseCode != null  and abnormalCauseCode != ''">
                and abnormal_cause_code = #{abnormalCauseCode}
            </if>
            <if test="abnormalCauseValue != null  and abnormalCauseValue != ''">
                and abnormal_cause_value = #{abnormalCauseValue}
            </if>
            <if test="abnormalCauseLevel != null  and abnormalCauseLevel != ''">
                and abnormal_cause_level = #{abnormalCauseLevel}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
        </where>
    </select>

    <select id="selectPatientBlacklistAbnormalCauseById" parameterType="Long"
            resultMap="PatientBlacklistAbnormalCauseResult">
            <include refid="selectPatientBlacklistAbnormalCauseVo"/>
            where id = #{id}
    </select>

    <insert id="insertPatientBlacklistAbnormalCause" parameterType="PatientBlacklistAbnormalCause" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_blacklist_abnormal_cause
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="parentId != null">parent_id,
                    </if>
                    <if test="abnormalCauseCode != null">abnormal_cause_code,
                    </if>
                    <if test="abnormalCauseValue != null">abnormal_cause_value,
                    </if>
                    <if test="abnormalCauseLevel != null">abnormal_cause_level,
                    </if>
                    <if test="status != null">status,
                    </if>
                    <if test="delFlag != null">del_flag,
                    </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="parentId != null">#{parentId},
                    </if>
                    <if test="abnormalCauseCode != null">#{abnormalCauseCode},
                    </if>
                    <if test="abnormalCauseValue != null">#{abnormalCauseValue},
                    </if>
                    <if test="abnormalCauseLevel != null">#{abnormalCauseLevel},
                    </if>
                    <if test="status != null">#{status},
                    </if>
                    <if test="delFlag != null">#{delFlag},
                    </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="updatePatientBlacklistAbnormalCause" parameterType="PatientBlacklistAbnormalCause">
        update patient_blacklist_abnormal_cause
        <trim prefix="SET" suffixOverrides=",">
                    <if test="parentId != null">parent_id =
                        #{parentId},
                    </if>
                    <if test="abnormalCauseCode != null">abnormal_cause_code =
                        #{abnormalCauseCode},
                    </if>
                    <if test="abnormalCauseValue != null">abnormal_cause_value =
                        #{abnormalCauseValue},
                    </if>
                    <if test="abnormalCauseLevel != null">abnormal_cause_level =
                        #{abnormalCauseLevel},
                    </if>
                    <if test="status != null">status =
                        #{status},
                    </if>
                    <if test="delFlag != null">del_flag =
                        #{delFlag},
                    </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="deletePatientBlacklistAbnormalCauseById" parameterType="Long">
        delete from patient_blacklist_abnormal_cause where id = #{id}
    </delete>

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