<?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.hzs.bonus.detail.mapper.CuMemberLevelMapper">

    <!-- 删除自动升级的等级升级记录 -->
    <delete id="deleteCuMemberGrade">
        delete
        from cu_member_level
        where period = #{period}
          and up_type = 1
    </delete>

    <!-- 批量插入等级记录 -->
    <insert id="saveBatchCuMemberLevel">
        insert ALL
        <foreach item="item" index="index" collection="cuMemberLevelList" separator=" ">
            into CU_MEMBER_LEVEL (
            pk_member, period, up_type, old_level, new_level,
            upgrade_time, pk_creator, pk_country
            )
            values (
            #{item.pkMember}, #{item.period}, #{item.upType}, #{item.oldLevel}, #{item.newLevel},
            #{item.upgradeTime}, #{item.pkCreator}, #{item.pkCountry}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

</mapper>
