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

    <resultMap type="NgIrrigationControllers" id="NgIrrigationControllersResult">
        <result property="id"    column="id"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="controllerName"    column="controller_name"    />
        <result property="controllerModel"    column="controller_model"    />
        <result property="installationDate"    column="installation_date"    />
        <result property="status"    column="status"    />
        <result property="lastMaintenance"    column="last_maintenance"    />
        <result property="areaCode"    column="area_code"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectNgIrrigationControllersVo">
        select id, serial_number, controller_name, controller_model, installation_date, status, last_maintenance, area_code, remark, create_time, update_time, create_by, update_by from ng_irrigation_controllers
    </sql>

    <select id="selectNgIrrigationControllersList" parameterType="NgIrrigationControllers" resultMap="NgIrrigationControllersResult">
        <include refid="selectNgIrrigationControllersVo"/>
        <where>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="controllerName != null  and controllerName != ''"> and controller_name like concat('%', #{controllerName}, '%')</if>
            <if test="controllerModel != null  and controllerModel != ''"> and controller_model = #{controllerModel}</if>
            <if test="installationDate != null "> and installation_date = #{installationDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lastMaintenance != null "> and last_maintenance = #{lastMaintenance}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
        </where>
    </select>

    <select id="selectNgIrrigationControllersById" parameterType="Long" resultMap="NgIrrigationControllersResult">
        <include refid="selectNgIrrigationControllersVo"/>
        where id = #{id}
    </select>


    <select id="selectNgIrrigationControllersBySerialNumber" parameterType="String" resultMap="NgIrrigationControllersResult">
        <include refid="selectNgIrrigationControllersVo"/>
        where serial_number = #{serialNumber}
    </select>

    <insert id="insertNgIrrigationControllers" parameterType="NgIrrigationControllers" useGeneratedKeys="true" keyProperty="id">
        insert into ng_irrigation_controllers
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="controllerName != null">controller_name,</if>
            <if test="controllerModel != null and controllerModel != ''">controller_model,</if>
            <if test="installationDate != null">installation_date,</if>
            <if test="status != null">status,</if>
            <if test="lastMaintenance != null">last_maintenance,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="controllerName != null">#{controllerName},</if>
            <if test="controllerModel != null and controllerModel != ''">#{controllerModel},</if>
            <if test="installationDate != null">#{installationDate},</if>
            <if test="status != null">#{status},</if>
            <if test="lastMaintenance != null">#{lastMaintenance},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateNgIrrigationControllers" parameterType="NgIrrigationControllers">
        update ng_irrigation_controllers
        <trim prefix="SET" suffixOverrides=",">
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="controllerName != null">controller_name = #{controllerName},</if>
            <if test="controllerModel != null and controllerModel != ''">controller_model = #{controllerModel},</if>
            <if test="installationDate != null">installation_date = #{installationDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="lastMaintenance != null">last_maintenance = #{lastMaintenance},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgIrrigationControllersById" parameterType="Long">
        delete from ng_irrigation_controllers where id = #{id}
    </delete>

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