<?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="beilv.carinformation.mapper.CarInformationMapper">

    <resultMap type="CarInformation" id="CarInformationResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="totalNumber"    column="total_number"    />
        <result property="originalPrice"    column="original_price"    />
        <result property="memberPrice"    column="member_price"    />
        <result property="point"    column="point"    />
        <result property="expirationDate"    column="expiration_date"    />
        <result property="notes"    column="notes"    />
        <result property="cardState"    column="card_state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCarInformationVo">
        select id, name, type, total_number, original_price,member_price, point, expiration_date, notes, card_state, create_by, create_time, update_by, update_time from card_information
    </sql>

    <select id="selectCarInformationList" parameterType="CarInformation" resultMap="CarInformationResult">
        <include refid="selectCarInformationVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="totalNumber != null "> and total_number = #{totalNumber}</if>
            <if test="originalPrice != null "> and original_price = #{originalPrice}</if>
            <if test="memberPrice != null "> and member_price = #{memberPrice}</if>
            <if test="point != null "> and point = #{point}</if>
            <if test="expirationDate != null "> and expiration_date = #{expirationDate}</if>
            <if test="notes != null  and notes != ''"> and notes = #{notes}</if>
            <if test="cardState != null  and cardState != ''"> and card_state = #{cardState}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectCarInformationById" parameterType="Long" resultMap="CarInformationResult">
        <include refid="selectCarInformationVo"/>
        where id = #{id}
    </select>

    <insert id="insertCarInformation" parameterType="CarInformation">
        insert into card_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="totalNumber != null">total_number,</if>
            <if test="originalPrice != null">original_price,</if>
            <if test="memberPrice != null">member_price,</if>
            <if test="point != null">point,</if>
            <if test="expirationDate != null">expiration_date,</if>
            <if test="notes != null">notes,</if>
            <if test="cardState != null">card_state,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="totalNumber != null">#{totalNumber},</if>
            <if test="originalPrice != null">#{originalPrice},</if>
            <if test="memberPrice != null">#{memberPrice},</if>
            <if test="point != null">#{point},</if>
            <if test="expirationDate != null">#{expirationDate},</if>
            <if test="notes != null">#{notes},</if>
            <if test="cardState != null">#{cardState},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCarInformation" parameterType="CarInformation">
        update card_information
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="totalNumber != null">total_number = #{totalNumber},</if>
            <if test="originalPrice != null">original_price = #{originalPrice},</if>
            <if test="memberPrice != null">member_price = #{memberPrice},</if>
            <if test="point != null">point = #{point},</if>
            <if test="expirationDate != null">expiration_date = #{expirationDate},</if>
            <if test="notes != null">notes = #{notes},</if>
            <if test="cardState != null">card_state = #{cardState},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCarInformationById" parameterType="Long">
        delete from card_information where id = #{id}
    </delete>

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

</mapper>
