<?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.iot.mapper.NgCardSwipeRecordsMapper">

    <resultMap type="NgCardSwipeRecords" id="NgCardSwipeRecordsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="cardSwipeType"    column="card_swipe_type"    />
        <result property="cardNumber"    column="card_number"    />
        <result property="deptId"    column="dept_id"    />
        <result property="cardSwipeTime"    column="card_swipe_time"    />
        <result property="amountDue"    column="amount_due"    />
        <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="selectNgCardSwipeRecordsVo">
        select id, user_id, device_number, card_swipe_type, card_number, dept_id, card_swipe_time, amount_due, area_code, remark, create_time, update_time, create_by, update_by from ng_card_swipe_records
    </sql>

    <select id="selectNgCardSwipeRecordsList" parameterType="NgCardSwipeRecords" resultMap="NgCardSwipeRecordsResult">
        <include refid="selectNgCardSwipeRecordsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="cardSwipeType != null "> and card_swipe_type = #{cardSwipeType}</if>
            <if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="cardSwipeTime != null "> and card_swipe_time = #{cardSwipeTime}</if>
            <if test="amountDue != null "> and amount_due = #{amountDue}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
        </where>
    </select>

    <select id="selectNgCardSwipeRecordsUserList" parameterType="NgCardSwipeRecords" resultMap="NgCardSwipeRecordsResult">
        <include refid="selectNgCardSwipeRecordsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="cardSwipeType != null "> and card_swipe_type = #{cardSwipeType}</if>
            card_number = #{cardNumber}
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="cardSwipeTime != null "> and card_swipe_time = #{cardSwipeTime}</if>
            <if test="amountDue != null "> and amount_due = #{amountDue}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
        </where>
    </select>

    <select id="selectNgCardSwipeRecordsById" parameterType="Long" resultMap="NgCardSwipeRecordsResult">
        <include refid="selectNgCardSwipeRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgCardSwipeRecords" parameterType="NgCardSwipeRecords" useGeneratedKeys="true" keyProperty="id">
        insert into ng_card_swipe_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="deviceNumber != null">device_number,</if>
            <if test="cardSwipeType != null">card_swipe_type,</if>
            <if test="cardNumber != null">card_number,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="cardSwipeTime != null">card_swipe_time,</if>
            <if test="amountDue != null">amount_due,</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="userId != null">#{userId},</if>
            <if test="deviceNumber != null">#{deviceNumber},</if>
            <if test="cardSwipeType != null">#{cardSwipeType},</if>
            <if test="cardNumber != null">#{cardNumber},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="cardSwipeTime != null">#{cardSwipeTime},</if>
            <if test="amountDue != null">#{amountDue},</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="updateNgCardSwipeRecords" parameterType="NgCardSwipeRecords">
        update ng_card_swipe_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="cardSwipeType != null">card_swipe_type = #{cardSwipeType},</if>
            <if test="cardNumber != null">card_number = #{cardNumber},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="cardSwipeTime != null">card_swipe_time = #{cardSwipeTime},</if>
            <if test="amountDue != null">amount_due = #{amountDue},</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="deleteNgCardSwipeRecordsById" parameterType="Long">
        delete from ng_card_swipe_records where id = #{id}
    </delete>

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