<?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.waterele.mapper.MaCardinfoMapper">
    
    <resultMap type="MaCardinfo" id="MaCardinfoResult">
        <result property="id"    column="id"    />
        <result property="cardNum"    column="card_num"    />
        <result property="areaCode"    column="area_code"    />
        <result property="cardId"    column="card_id"    />
        <result property="addressInfo"    column="address_info"    />
        <result property="cardtype"    column="cardType"    />
        <result property="mcusn"    column="mcuSn"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMaCardinfoVo">
        select id, card_num, area_code, card_id, address_info, cardType, mcuSn, create_time, update_time from ma_cardinfo
    </sql>

    <select id="selectMaCardinfoList" parameterType="MaCardinfo" resultMap="MaCardinfoResult">
        <include refid="selectMaCardinfoVo"/>
        <where>  
            <if test="cardNum != null  and cardNum != ''"> and card_num = #{cardNum}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="cardId != null  and cardId != ''"> and card_id = #{cardId}</if>
            <if test="addressInfo != null  and addressInfo != ''"> and address_info = #{addressInfo}</if>
            <if test="cardtype != null "> and cardType = #{cardtype}</if>
            <if test="mcusn != null  and mcusn != ''"> and mcuSn = #{mcusn}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectMaCardinfoById" parameterType="Long" resultMap="MaCardinfoResult">
        <include refid="selectMaCardinfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMaCardinfo" parameterType="MaCardinfo" useGeneratedKeys="true" keyProperty="id">
        insert into ma_cardinfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cardNum != null">card_num,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="cardId != null">card_id,</if>
            <if test="addressInfo != null">address_info,</if>
            <if test="cardtype != null">cardType,</if>
            <if test="mcusn != null">mcuSn,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cardNum != null">#{cardNum},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="cardId != null">#{cardId},</if>
            <if test="addressInfo != null">#{addressInfo},</if>
            <if test="cardtype != null">#{cardtype},</if>
            <if test="mcusn != null">#{mcusn},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMaCardinfo" parameterType="MaCardinfo">
        update ma_cardinfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="cardNum != null">card_num = #{cardNum},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="cardId != null">card_id = #{cardId},</if>
            <if test="addressInfo != null">address_info = #{addressInfo},</if>
            <if test="cardtype != null">cardType = #{cardtype},</if>
            <if test="mcusn != null">mcuSn = #{mcusn},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMaCardinfoById" parameterType="Long">
        delete from ma_cardinfo where id = #{id}
    </delete>

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