<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
<mapper namespace="com.iamberry.wechat.service.mapper.WarrantyMapper">

    <!-- 查询质保卡集合 -->
    <select id="listWarrantyCard" parameterType="WarrantyCard" resultType="WarrantyCard">
        SELECT
          *
        FROM
          tb_iamberry_warranty_card
        <where>
            <if test="userOpenId != null and userOpenId != ''">
                user_open_id = #{userOpenId}
            </if>
            <if test="cardTypeState != null and cardTypeState != ''">
              AND card_type_state = #{cardTypeState}
            </if>
            <if test="cardSalesTime != null">
                AND card_sales_time = #{cardSalesTime}
            </if>
        </where>
        order by card_id DESC
        <if test="page!=null and page.pageSize>0 ">
            LIMIT ${page.recordBegin},${page.pageSize}
        </if>
    </select>

    <!-- 批量添加质保卡信息 -->
    <insert id="addWarrantyCardList" parameterType="ArrayList">
        <selectKey resultType="int" keyProperty="cardId" order="AFTER">
            SELECT
            LAST_INSERT_ID()
        </selectKey>
        INSERT INTO tb_iamberry_warranty_card
        (
        user_open_id,product_type,product_child_type,card_no,card_product_name,
        card_watero,card_sales_time,card_end_time,card_create_date,card_province,
        card_city,card_district,card_type_state
        )
        VALUES
        <foreach collection="list" item="item" index="index" separator="," >
            (
            #{item.userOpenId},#{item.productType},#{item.productChildType},#{item.cardNo},
            #{item.cardProductName},#{item.cardWatero},#{item.cardSalesTime},#{item.cardEndTime},
            #{item.cardCreateDate},#{item.cardProvince},#{item.cardCity},#{item.cardDistrict},
            #{item.cardTypeState}
            )
        </foreach>
    </insert>
</mapper>