<?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.rechargecard.mapper.NgIrrigationAreaMapper">

    <resultMap type="NgIrrigationArea" id="NgIrrigationAreaResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="serialNo"    column="serial_no"    />
        <result property="apiv3Key"    column="apiv3_key"    />
        <result property="publicKey"    column="public_key"    />
        <result property="privateKey"    column="private_key"    />
    </resultMap>

    <sql id="selectNgIrrigationAreaVo">
        select id, name, merchant_id, serial_no, apiv3_key, public_key, private_key from ng_Irrigation_area
    </sql>

    <select id="selectNgIrrigationAreaList" parameterType="NgIrrigationArea" resultMap="NgIrrigationAreaResult">
        <include refid="selectNgIrrigationAreaVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="merchantId != null  and merchantId != ''"> and merchant_id = #{merchantId}</if>
            <if test="serialNo != null  and serialNo != ''"> and serial_no = #{serialNo}</if>
            <if test="apiv3Key != null  and apiv3Key != ''"> and apiv3_key = #{apiv3Key}</if>
            <if test="publicKey != null  and publicKey != ''"> and public_key = #{publicKey}</if>
            <if test="privateKey != null  and privateKey != ''"> and private_key = #{privateKey}</if>
        </where>
    </select>

    <select id="selectNgIrrigationAreaById" parameterType="Long" resultMap="NgIrrigationAreaResult">
        <include refid="selectNgIrrigationAreaVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgIrrigationArea" parameterType="NgIrrigationArea" useGeneratedKeys="true" keyProperty="id">
        insert into ng_Irrigation_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="serialNo != null">serial_no,</if>
            <if test="apiv3Key != null">apiv3_key,</if>
            <if test="publicKey != null">public_key,</if>
            <if test="privateKey != null">private_key,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="serialNo != null">#{serialNo},</if>
            <if test="apiv3Key != null">#{apiv3Key},</if>
            <if test="publicKey != null">#{publicKey},</if>
            <if test="privateKey != null">#{privateKey},</if>
        </trim>
    </insert>

    <update id="updateNgIrrigationArea" parameterType="NgIrrigationArea">
        update ng_Irrigation_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="serialNo != null">serial_no = #{serialNo},</if>
            <if test="apiv3Key != null">apiv3_key = #{apiv3Key},</if>
            <if test="publicKey != null">public_key = #{publicKey},</if>
            <if test="privateKey != null">private_key = #{privateKey},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgIrrigationAreaById" parameterType="Long">
        delete from ng_Irrigation_area where id = #{id}
    </delete>

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