<?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.sooka.system.medicine.plant.mapper.TGuijiMedicinePlantMapper">

    <resultMap type="TGuijiMedicinePlant" id="TGuijiMedicinePlantResult">
        <result property="id"    column="id"    />
        <result property="createTime"    column="create_time"    />
        <result property="cdTime"    column="cd_time"    />
        <result property="cdBatch"    column="cd_batch"    />
        <result property="cdOperation"    column="cd_operation"    />
        <result property="cdSource"    column="cd_source"    />
        <result property="plantName"    column="plantName"    />
        <result property="plantAddress"    column="plantAddress"    />
        <result property="plantHectare"    column="plantHectare"    />
        <result property="produceTons"    column="produceTons"    />
        <result property="produceValue"    column="produceValue"    />
        <result property="plantYear"    column="plantYear"    />
    </resultMap>

    <sql id="selectTGuijiMedicinePlantVo">
        select id, create_time, cd_time, cd_batch, cd_operation, cd_source, plantName, plantAddress, plantHectare, produceTons, produceValue, plantYear from t_guiji_medicine_plant
    </sql>

    <select id="selectTGuijiMedicinePlantList" parameterType="TGuijiMedicinePlant" resultMap="TGuijiMedicinePlantResult">
        <include refid="selectTGuijiMedicinePlantVo"/>
        <where>
            <if test="cdTime != null  and cdTime != ''"> and cd_time = #{cdTime}</if>
            <if test="cdBatch != null  and cdBatch != ''"> and cd_batch = #{cdBatch}</if>
            <if test="cdOperation != null  and cdOperation != ''"> and cd_operation = #{cdOperation}</if>
            <if test="cdSource != null  and cdSource != ''"> and cd_source = #{cdSource}</if>
            <if test="plantName != null  and plantName != ''"> and plantName like concat('%', #{plantName}, '%')</if>
            <if test="plantAddress != null  and plantAddress != ''"> and plantAddress like concat('%', #{plantAddress}, '%')</if>
            <if test="plantHectare != null  and plantHectare != ''"> and plantHectare = #{plantHectare}</if>
            <if test="produceTons != null  and produceTons != ''"> and produceTons = #{produceTons}</if>
            <if test="produceValue != null  and produceValue != ''"> and produceValue = #{produceValue}</if>
            <if test="plantYear != null  and plantYear != ''"> and plantYear like concat('%', #{plantYear}, '%')</if>
        </where>
    </select>

    <select id="selectTGuijiMedicinePlantById" parameterType="String" resultMap="TGuijiMedicinePlantResult">
        <include refid="selectTGuijiMedicinePlantVo"/>
        where id = #{id}
    </select>

    <insert id="insertTGuijiMedicinePlant" parameterType="TGuijiMedicinePlant">
        insert into t_guiji_medicine_plant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="cdTime != null">cd_time,</if>
            <if test="cdBatch != null">cd_batch,</if>
            <if test="cdOperation != null">cd_operation,</if>
            <if test="cdSource != null">cd_source,</if>
            <if test="plantName != null">plantName,</if>
            <if test="plantAddress != null">plantAddress,</if>
            <if test="plantHectare != null">plantHectare,</if>
            <if test="produceTons != null">produceTons,</if>
            <if test="produceValue != null">produceValue,</if>
            <if test="plantYear != null">plantYear,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="cdTime != null">#{cdTime},</if>
            <if test="cdBatch != null">#{cdBatch},</if>
            <if test="cdOperation != null">#{cdOperation},</if>
            <if test="cdSource != null">#{cdSource},</if>
            <if test="plantName != null">#{plantName},</if>
            <if test="plantAddress != null">#{plantAddress},</if>
            <if test="plantHectare != null">#{plantHectare},</if>
            <if test="produceTons != null">#{produceTons},</if>
            <if test="produceValue != null">#{produceValue},</if>
            <if test="plantYear != null">#{plantYear},</if>
         </trim>
    </insert>

    <update id="updateTGuijiMedicinePlant" parameterType="TGuijiMedicinePlant">
        update t_guiji_medicine_plant
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="cdTime != null">cd_time = #{cdTime},</if>
            <if test="cdBatch != null">cd_batch = #{cdBatch},</if>
            <if test="cdOperation != null">cd_operation = #{cdOperation},</if>
            <if test="cdSource != null">cd_source = #{cdSource},</if>
            <if test="plantName != null">plantName = #{plantName},</if>
            <if test="plantAddress != null">plantAddress = #{plantAddress},</if>
            <if test="plantHectare != null">plantHectare = #{plantHectare},</if>
            <if test="produceTons != null">produceTons = #{produceTons},</if>
            <if test="produceValue != null">produceValue = #{produceValue},</if>
            <if test="plantYear != null">plantYear = #{plantYear},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTGuijiMedicinePlantById" parameterType="String">
        delete from t_guiji_medicine_plant where id = #{id}
    </delete>

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

</mapper>
