<?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.cool.store.mapper.fees.ShopAllocationInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.fees.ShopAllocationInfoDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="expense_type" jdbcType="VARCHAR" property="expenseType" />
    <result column="payee_name" jdbcType="VARCHAR" property="payeeName" />
    <result column="payee_code" jdbcType="VARCHAR" property="payeeCode" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="fail_reason" jdbcType="VARCHAR" property="failReason" />
    <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>

  <!-- 批量新增 -->
  <insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO zxjp_fees_shop_allocation_info (shop_id, expense_type, payee_name, payee_code, amount, status, fail_reason, create_user_id, update_user_id)
    VALUES
    <foreach collection="list" item="item" separator=",">
      (#{item.shopId}, #{item.expenseType}, #{item.payeeName}, #{item.payeeCode}, #{item.amount}, #{item.status}, #{item.failReason}, #{item.createUserId}, #{item.updateUserId})
    </foreach>
  </insert>

  <!-- 批量更新 -->
  <update id="updateBatch" parameterType="java.util.List">
    UPDATE zxjp_fees_shop_allocation_info
    <trim prefix="SET" suffixOverrides=",">
      <trim prefix="shop_id = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.shopId}
        </foreach>
      </trim>
      <trim prefix="expense_type = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.expenseType}
        </foreach>
      </trim>
      <trim prefix="payee_name = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.payeeName}
        </foreach>
      </trim>
      <trim prefix="payee_code = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.payeeCode}
        </foreach>
      </trim>
      <trim prefix="amount = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.amount}
        </foreach>
      </trim>
      <trim prefix="status = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.status}
        </foreach>
      </trim>
      <trim prefix="fail_reason = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.failReason}
        </foreach>
      </trim>
      <trim prefix="update_user_id = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.updateUserId}
        </foreach>
      </trim>
    </trim>
    WHERE id IN
    <foreach collection="list" item="item" open="(" separator="," close=")">
      #{item.id}
    </foreach>
  </update>

  <insert id="insertOrUpdateBatch" parameterType="java.util.List">
    INSERT INTO zxjp_fees_shop_allocation_info
    (id, shop_id, expense_type, payee_name, payee_code, amount, status, fail_reason, create_user_id, update_user_id)
    VALUES
    <foreach collection="list" item="item" separator=",">
      (#{item.id}, #{item.shopId}, #{item.expenseType}, #{item.payeeName}, #{item.payeeCode}, #{item.amount}, #{item.status}, #{item.failReason}, #{item.createUserId}, #{item.updateUserId})
    </foreach>
    ON DUPLICATE KEY UPDATE
      expense_type = VALUES(expense_type),
      payee_name = VALUES(payee_name),
      payee_code = VALUES(payee_code),
      amount = VALUES(amount),
      status = VALUES(status),
      fail_reason = VALUES(fail_reason),
      update_user_id = VALUES(update_user_id)
  </insert>
</mapper>