<?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.CloseStoreFileDetailMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.CloseStoreFileDetailDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="close_store_id" jdbcType="BIGINT" property="closeStoreId" />
    <result column="approve_complete" jdbcType="BIT" property="approveComplete" />
    <result column="mail_number" jdbcType="VARCHAR" property="mailNumber" />
    <result column="mail_status" jdbcType="BIT" property="mailStatus" />
    <result column="mail_address" jdbcType="VARCHAR" property="mailAddress" />
    <result column="mail_addressee" jdbcType="VARCHAR" property="mailAddressee" />
    <result column="mail_mobile" jdbcType="VARCHAR" property="mailMobile" />
    <result column="bank_account" jdbcType="VARCHAR" property="bankAccount" />
    <result column="bank_opening" jdbcType="VARCHAR" property="bankOpening" />
    <result column="refund_account" jdbcType="VARCHAR" property="refundAccount" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
  </resultMap>

  <update id="insertOrUpdateMailAddress" parameterType="com.cool.store.request.close.file.CloseStoreMailAddressRequest">
    INSERT INTO zxjp_close_store_file_detail
    (close_store_id, mail_address, mail_addressee, mail_mobile)
    VALUES
      (#{closeStoreId}, #{mailAddress}, #{mailAddressee}, #{mailMobile})
    ON DUPLICATE KEY UPDATE
        mail_address = VALUES(mail_address),
        mail_addressee = VALUES(mail_addressee),
        mail_mobile = VALUES(mail_mobile)
  </update>

  <update id="insertOrUpdateMailInfo" parameterType="com.cool.store.request.close.file.CloseStoreMailInfoRequest">
    INSERT INTO zxjp_close_store_file_detail
    (close_store_id, mail_number, mail_company, mail_status)
    VALUES
      (#{request.closeStoreId}, #{request.mailNumber}, #{request.mailCompany}, #{mailStatus})
    ON DUPLICATE KEY UPDATE
        mail_number = VALUES(mail_number),
        mail_company = VALUES(mail_company),
        mail_status = VALUES(mail_status)
  </update>

    <update id="insertOrUpdateFileInfoSelective">
        INSERT INTO zxjp_close_store_file_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="request.closeStoreId != null">close_store_id,</if>
            <if test="request.bankAccount != null">bank_account,</if>
            <if test="request.bankOpening != null">bank_opening,</if>
            <if test="request.refundAccount != null">refund_account,</if>
            <if test="approveComplete != null">approve_complete,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="request.closeStoreId != null">#{request.closeStoreId},</if>
            <if test="request.bankAccount != null">#{request.bankAccount},</if>
            <if test="request.bankOpening != null">#{request.bankOpening},</if>
            <if test="request.refundAccount != null">#{request.refundAccount},</if>
            <if test="approveComplete != null">#{approveComplete},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim suffixOverrides=",">
            <if test="request.bankAccount != null">bank_account = VALUES(bank_account),</if>
            <if test="request.bankOpening != null">bank_opening = VALUES(bank_opening),</if>
            <if test="request.refundAccount != null">refund_account = VALUES(refund_account),</if>
            <if test="approveComplete != null">approve_complete = VALUES(approve_complete),</if>
        </trim>
    </update>
</mapper>