<?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.AgricultureCropInfoMapper">

    <resultMap type="AgricultureCropInfo" id="AgricultureCropInfoResult">
        <result property="id"    column="id"    />
        <result property="cropName"    column="crop_name"    />
        <result property="growthPeriod"    column="growth_period"    />
        <result property="plantingArea"    column="planting_area"    />
        <result property="otherInfo"    column="other_info"    />
    </resultMap>

    <sql id="selectAgricultureCropInfoVo">
        select id, crop_name, growth_period, planting_area, other_info from agriculture_crop_info
    </sql>

    <select id="selectAgricultureCropInfoList" parameterType="AgricultureCropInfo" resultMap="AgricultureCropInfoResult">
        <include refid="selectAgricultureCropInfoVo"/>
        <where>
            <if test="cropName != null  and cropName != ''"> and crop_name like concat('%', #{cropName}, '%')</if>
            <if test="growthPeriod != null  and growthPeriod != ''"> and growth_period = #{growthPeriod}</if>
            <if test="plantingArea != null "> and planting_area = #{plantingArea}</if>
            <if test="otherInfo != null  and otherInfo != ''"> and other_info = #{otherInfo}</if>
        </where>
    </select>

    <select id="selectAgricultureCropInfoById" parameterType="Long" resultMap="AgricultureCropInfoResult">
        <include refid="selectAgricultureCropInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertAgricultureCropInfo" parameterType="AgricultureCropInfo" useGeneratedKeys="true" keyProperty="id">
        insert into agriculture_crop_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cropName != null">crop_name,</if>
            <if test="growthPeriod != null">growth_period,</if>
            <if test="plantingArea != null">planting_area,</if>
            <if test="otherInfo != null">other_info,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cropName != null">#{cropName},</if>
            <if test="growthPeriod != null">#{growthPeriod},</if>
            <if test="plantingArea != null">#{plantingArea},</if>
            <if test="otherInfo != null">#{otherInfo},</if>
        </trim>
    </insert>

    <update id="updateAgricultureCropInfo" parameterType="AgricultureCropInfo">
        update agriculture_crop_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="cropName != null">crop_name = #{cropName},</if>
            <if test="growthPeriod != null">growth_period = #{growthPeriod},</if>
            <if test="plantingArea != null">planting_area = #{plantingArea},</if>
            <if test="otherInfo != null">other_info = #{otherInfo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAgricultureCropInfoById" parameterType="Long">
        delete from agriculture_crop_info where id = #{id}
    </delete>

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