<?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.fastbee.crop.mapper.AgricultureCropYieldMapper">

    <resultMap type="AgricultureCropYield" id="AgricultureCropYieldResult">
        <result property="id"    column="id"    />
        <result property="yieldValue"    column="yield_value"    />
        <result property="harvestYear"    column="harvest_year"    />
        <result property="cropType"    column="crop_type"    />
        <result property="harvestMonth"    column="harvest_month"    />
    </resultMap>

    <sql id="selectAgricultureCropYieldVo">
        select id, yield_value, harvest_year, crop_type, harvest_month from agriculture_crop_yield
    </sql>

    <select id="selectAgricultureCropYieldList" parameterType="AgricultureCropYield" resultMap="AgricultureCropYieldResult">
        <include refid="selectAgricultureCropYieldVo"/>
        <where>
            <if test="yieldValue != null "> and yield_value = #{yieldValue}</if>
            <if test="harvestYear != null  and harvestYear != ''"> and harvest_year = #{harvestYear}</if>
            <if test="cropType != null  and cropType != ''"> and crop_type = #{cropType}</if>
            <if test="harvestMonth != null  and harvestMonth != ''"> and harvest_month = #{harvestMonth}</if>
        </where>
    </select>

    <select id="selectAgricultureCropYieldById" parameterType="Long" resultMap="AgricultureCropYieldResult">
        <include refid="selectAgricultureCropYieldVo"/>
        where id = #{id}
    </select>

    <insert id="insertAgricultureCropYield" parameterType="AgricultureCropYield" useGeneratedKeys="true" keyProperty="id">
        insert into agriculture_crop_yield
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="yieldValue != null">yield_value,</if>
            <if test="harvestYear != null">harvest_year,</if>
            <if test="cropType != null">crop_type,</if>
            <if test="harvestMonth != null">harvest_month,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yieldValue != null">#{yieldValue},</if>
            <if test="harvestYear != null">#{harvestYear},</if>
            <if test="cropType != null">#{cropType},</if>
            <if test="harvestMonth != null">#{harvestMonth},</if>
        </trim>
    </insert>

    <update id="updateAgricultureCropYield" parameterType="AgricultureCropYield">
        update agriculture_crop_yield
        <trim prefix="SET" suffixOverrides=",">
            <if test="yieldValue != null">yield_value = #{yieldValue},</if>
            <if test="harvestYear != null">harvest_year = #{harvestYear},</if>
            <if test="cropType != null">crop_type = #{cropType},</if>
            <if test="harvestMonth != null">harvest_month = #{harvestMonth},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAgricultureCropYieldById" parameterType="Long">
        delete from agriculture_crop_yield where id = #{id}
    </delete>

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