<?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.zhyc.module.biosafety.mapper.SwDiseaseMapper">
    
    <resultMap type="SwDisease" id="SwDiseaseResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="comment"    column="comment"    />
        <result property="pid"    column="pid"    />
    </resultMap>

    <sql id="selectSwDiseaseVo">
        select id, name, comment, pid from sw_disease
    </sql>

    <select id="selectSwDiseaseList" parameterType="SwDisease" resultMap="SwDiseaseResult">
        <include refid="selectSwDiseaseVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="pid != null "> and pid = #{pid}</if>
        </where>
    </select>
    
    <select id="selectSwDiseaseById" parameterType="Long" resultMap="SwDiseaseResult">
        <include refid="selectSwDiseaseVo"/>
        where id = #{id}
    </select>

    <insert id="insertSwDisease" parameterType="SwDisease" useGeneratedKeys="true" keyProperty="id">
        insert into sw_disease
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="comment != null">comment,</if>
            <if test="pid != null">pid,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="comment != null">#{comment},</if>
            <if test="pid != null">#{pid},</if>
         </trim>
    </insert>

    <update id="updateSwDisease" parameterType="SwDisease">
        update sw_disease
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="pid != null">pid = #{pid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSwDiseaseById" parameterType="Long">
        delete from sw_disease where id = #{id}
    </delete>

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