<?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.base.mapper.BasSheepVarietyMapper">

    <resultMap type="BasSheepVariety" id="BasSheepVarietyResult">
        <result property="id" column="id"/>
        <result property="variety" column="variety"/>
    </resultMap>

    <sql id="selectBasSheepVarietyVo">
        select id, variety
        from bas_sheep_variety
    </sql>

    <select id="selectBasSheepVarietyList" parameterType="BasSheepVariety" resultMap="BasSheepVarietyResult">
        <include refid="selectBasSheepVarietyVo"/>
        <where>
            <if test="variety != null  and variety != ''">and variety = #{variety}</if>
        </where>
    </select>

    <select id="selectBasSheepVarietyById" parameterType="Long" resultMap="BasSheepVarietyResult">
        <include refid="selectBasSheepVarietyVo"/>
        where id = #{id}
    </select>

    <insert id="insertBasSheepVariety" parameterType="BasSheepVariety" useGeneratedKeys="true" keyProperty="id">
        insert into bas_sheep_variety
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="variety != null">variety,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="variety != null">#{variety},</if>
        </trim>
    </insert>

    <update id="updateBasSheepVariety" parameterType="BasSheepVariety">
        update bas_sheep_variety
        <trim prefix="SET" suffixOverrides=",">
            <if test="variety != null">variety = #{variety},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBasSheepVarietyById" parameterType="Long">
        delete
        from bas_sheep_variety
        where id = #{id}
    </delete>

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

    <select id="selectIdByName" parameterType="string" resultType="java.lang.Long">
        SELECT id
        FROM bas_sheep_variety
        WHERE variety = #{varietyName} LIMIT 1
    </select>

    <select id="selectByVarietyName" parameterType="String" resultMap="BasSheepVarietyResult">
        SELECT id, variety
        FROM bas_sheep_variety
        WHERE variety = #{varietyName} LIMIT 1
    </select>
</mapper>