<?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.produce.breed.mapper.ScBreedPlanMapper">
    
    <resultMap type="ScBreedPlan" id="ScBreedPlanResult">
        <result property="id"    column="id"    />
        <result property="ramId"    column="ram_id"    />
        <result property="eweId"    column="ewe_id"    />
        <result property="breedType"    column="breed_type"    />
    </resultMap>

    <sql id="selectScBreedPlanVo">
        select id, ram_id, ewe_id, breed_type from sc_breed_plan
    </sql>

    <select id="selectScBreedPlanList" parameterType="ScBreedPlan" resultMap="ScBreedPlanResult">
        <include refid="selectScBreedPlanVo"/>
        <where>  
            <if test="ramId != null  and ramId != ''"> and ram_id = #{ramId}</if>
            <if test="eweId != null  and eweId != ''"> and ewe_id = #{eweId}</if>
            <if test="breedType != null "> and breed_type = #{breedType}</if>
        </where>
    </select>
    
    <select id="selectScBreedPlanById" parameterType="Long" resultMap="ScBreedPlanResult">
        <include refid="selectScBreedPlanVo"/>
        where id = #{id}
    </select>

    <insert id="insertScBreedPlan" parameterType="ScBreedPlan" useGeneratedKeys="true" keyProperty="id">
        insert into sc_breed_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ramId != null">ram_id,</if>
            <if test="eweId != null">ewe_id,</if>
            <if test="breedType != null">breed_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ramId != null">#{ramId},</if>
            <if test="eweId != null">#{eweId},</if>
            <if test="breedType != null">#{breedType},</if>
         </trim>
    </insert>

    <update id="updateScBreedPlan" parameterType="ScBreedPlan">
        update sc_breed_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="ramId != null">ram_id = #{ramId},</if>
            <if test="eweId != null">ewe_id = #{eweId},</if>
            <if test="breedType != null">breed_type = #{breedType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteScBreedPlanById" parameterType="Long">
        delete from sc_breed_plan where id = #{id}
    </delete>

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