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

    <resultMap type="NgRechargeMachines" id="NgRechargeMachinesResult">
        <result property="id"    column="id"    />
        <result property="location"    column="location"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="areaCode"    column="area_code"    />
        <result property="installationDate"    column="installation_date"    />
        <result property="status"    column="status"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contactPhone"    column="contact_phone"    />
        <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"    />
        <result property="deviceName"    column="device_name"    />
    </resultMap>

    <sql id="selectNgRechargeMachinesVo">
        select id, location, device_model, serial_number, area_code, installation_date, status, contact_person, contact_phone, remark, create_time, update_time, create_by, update_by, device_name from ng_recharge_machines
    </sql>

    <select id="selectNgRechargeMachinesList" parameterType="NgRechargeMachines" resultMap="NgRechargeMachinesResult">
        <include refid="selectNgRechargeMachinesVo"/>
        <where>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="deviceModel != null  and deviceModel != ''"> and device_model = #{deviceModel}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="installationDate != null "> and installation_date = #{installationDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person = #{contactPerson}</if>
            <if test="contactPhone != null  and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
        </where>
    </select>

    <select id="selectNgRechargeMachinesById" parameterType="Long" resultMap="NgRechargeMachinesResult">
        <include refid="selectNgRechargeMachinesVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgRechargeMachines" parameterType="NgRechargeMachines" useGeneratedKeys="true" keyProperty="id">
        insert into ng_recharge_machines
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="location != null">location,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="installationDate != null">installation_date,</if>
            <if test="status != null">status,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="contactPhone != null">contact_phone,</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>
            <if test="deviceName != null">device_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="location != null">#{location},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="installationDate != null">#{installationDate},</if>
            <if test="status != null">#{status},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="contactPhone != null">#{contactPhone},</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>
            <if test="deviceName != null">#{deviceName},</if>
        </trim>
    </insert>

    <update id="updateNgRechargeMachines" parameterType="NgRechargeMachines">
        update ng_recharge_machines
        <trim prefix="SET" suffixOverrides=",">
            <if test="location != null">location = #{location},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="installationDate != null">installation_date = #{installationDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="contactPhone != null">contact_phone = #{contactPhone},</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>
            <if test="deviceName != null">device_name = #{deviceName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgRechargeMachinesById" parameterType="Long">
        delete from ng_recharge_machines where id = #{id}
    </delete>

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