<?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.CloseStoreFileInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.CloseStoreFileInfoDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="close_store_id" jdbcType="BIGINT" property="closeStoreId" />
    <result column="file_code" jdbcType="VARCHAR" property="fileCode" />
    <result column="file_name" jdbcType="VARCHAR" property="fileName" />
    <result column="mail_status" jdbcType="INTEGER" property="mailStatus" />
    <result column="approve_status" jdbcType="INTEGER" property="approveStatus" />
    <result column="approve_opinion" jdbcType="INTEGER" property="approveOpinion" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="urls" jdbcType="VARCHAR" property="urls" />
    <result column="file_status" jdbcType="TINYINT" property="fileStatus" />
  </resultMap>

  <update id="updateBatch" parameterType="java.util.List">
    UPDATE zxjp_close_store_file_info
    <trim prefix="SET" suffixOverrides=",">
      <trim prefix="mail_status = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.mailStatus}
        </foreach>
      </trim>
      <trim prefix="approve_status = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.approveStatus}
        </foreach>
      </trim>
      <trim prefix="approve_opinion = CASE" suffix="END,">
        <foreach collection="list" item="item">
          WHEN id = #{item.id} THEN #{item.approveOpinion}
        </foreach>
      </trim>
    </trim>
    WHERE id IN
    <foreach collection="list" item="item" open="(" separator="," close=")">
      #{item.id}
    </foreach>
  </update>

  <insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO zxjp_close_store_file_info (close_store_id, file_code, file_name, mail_status, approve_status, approve_opinion)
    VALUES
    <foreach collection="list" item="item" separator=",">
      (#{item.closeStoreId}, #{item.fileCode}, #{item.fileName}, #{item.mailStatus}, #{item.approveStatus}, #{item.approveOpinion})
    </foreach>
  </insert>

  <update id="updateFile">
    UPDATE zxjp_close_store_file_info
    SET urls = #{urls},
        file_status = CASE WHEN file_status = 2 THEN 5 WHEN file_status = 5 THEN 5 ELSE 3 END,
        approve_status = NULL
        <if test="receivedFile != null">
          , received_file = #{receivedFile}
        </if>
    WHERE id = #{id} AND file_status IN (0, 2, 3, 5)
  </update>

  <update id="updateFileStatusToApproveStatus">
    UPDATE zxjp_close_store_file_info
    SET file_status = approve_status
    WHERE close_store_id = #{closeStoreId}
  </update>
</mapper>