<?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.kmall.api.dao.ApiOrderRefundMapper">

  <resultMap type="com.kmall.api.entity.MallOrderRefund" id="orderRefundMap">
    <result property="id" column="id"/>
    <result property="orderId" column="order_id"/>
    <result property="userId" column="user_id"/>
    <result property="outRefundNo" column="out_refund_no"/>
    <result property="refundId" column="refund_id"/>
    <result property="refundType" column="refund_type"/>
    <result property="refundTime" column="refund_time"/>
    <result property="creator" column="creator"/>
    <result property="refundMoney" column="refund_money"/>
    <result property="refundStatus" column="refund_status"/>
    <result property="refundReason" column="refund_reason"/>
    <result property="approver" column="approver"/>
    <result property="approvalTime" column="approval_time"/>
    <result property="approvalRemark" column="approval_remark"/>
    <result property="createSn" column="create_sn"/>
    <result property="createTime" column="create_time"/>
    <result property="moderSn" column="moder_sn"/>
    <result property="modTime" column="mod_time"/>
    <result property="tstm" column="tstm"/>
    <result property="refundRecvAccout" column="refund_recv_accout"/>
    <result property="wechatRefundStatusDes" column="wechat_refund_status_des"/>
  </resultMap>

  <select id="queryObject" resultType="com.kmall.api.entity.MallOrderRefund">
    select
    `id`,
    `order_id`,
    `user_id`,
    `out_refund_no`,
    `refund_id`,
    `refund_type`,
    `refund_time`,
    `creator`,
    `refund_money`,
    `refund_status`,
    `refund_reason`,
    `refund_recv_accout`,
    `wechat_refund_status_des`,
    `approver`,
    `approval_time`,
    `approval_remark`,
    `create_sn`,
    `create_time`,
    `moder_sn`,
    `mod_time`,
    `tstm`
    from mall_order_refund
    where id = #{id}
  </select>

  <select id="queryObjectByOrderId" resultType="com.kmall.api.entity.MallOrderRefund">
    select
    `id`,
    `order_id`,
    `user_id`,
    `out_refund_no`,
    `refund_id`,
    `refund_type`,
    `refund_time`,
    `creator`,
    `refund_money`,
    `refund_status`,
    `refund_reason`,
    `refund_recv_accout`,
    `wechat_refund_status_des`,
    `approver`,
    `approval_time`,
    `approval_remark`,
    `create_sn`,
    `create_time`,
    `moder_sn`,
    `mod_time`,
    `tstm`
    from mall_order_refund
    where order_id = #{orderId}
  </select>

  <select id="queryList" resultType="com.kmall.api.entity.MallOrderRefund">
    select
    `id`,
    `order_id`,
    `user_id`,
    `out_refund_no`,
    `refund_id`,
    `refund_type`,
    `refund_time`,
    `creator`,
    `refund_money`,
    `refund_status`,
    `refund_reason`,
    `refund_recv_accout`,
    `wechat_refund_status_des`,
    `approver`,
    `approval_time`,
    `approval_remark`,
    `create_sn`,
    `create_time`,
    `moder_sn`,
    `mod_time`,
    `tstm`
    from mall_order_refund
    WHERE 1=1
    <if test="name != null and name.trim() != ''">
      AND name LIKE concat('%',#{name},'%')
    </if>
    <choose>
      <when test="sidx != null and sidx.trim() != ''">
        order by ${sidx} ${order}
      </when>
      <otherwise>
        order by id desc
      </otherwise>
    </choose>
    <if test="offset != null and limit != null">
      limit #{offset}, #{limit}
    </if>
  </select>

  <select id="queryTotal" resultType="int">
    select count(*) from mall_order_refund
    WHERE 1=1
    <if test="name != null and name.trim() != ''">
      AND name LIKE concat('%',#{name},'%')
    </if>
  </select>

  <insert id="save" parameterType="com.kmall.api.entity.MallOrderRefund" useGeneratedKeys="true" keyProperty="id">
    insert into mall_order_refund(
    `order_id`,
    `user_id`,
    `out_refund_no`,
    `refund_id`,
    `refund_type`,
    `refund_time`,
    `creator`,
    `refund_money`,
    `refund_status`,
    `refund_reason`,
    `refund_recv_accout`,
    `wechat_refund_status_des`,
    `approver`,
    `approval_time`,
    `approval_remark`,
    `create_sn`,
    `create_time`,
    `moder_sn`,
    `mod_time`,
    `tstm`)
    values(
    #{orderId},
    #{userId},
    #{outRefundNo},
    #{refundId},
    #{refundType},
    #{refundTime},
    #{creator},
    #{refundMoney},
    #{refundStatus},
    #{refundReason},
    #{refundRecvAccout},
    #{wechatRefundStatusDes},
    #{approver},
    #{approvalTime},
    #{approvalRemark},
    #{createSn},
    #{createTime},
    #{moderSn},
    #{modTime},
    #{tstm})
  </insert>

  <update id="update" parameterType="com.kmall.api.entity.MallOrderRefund">
    update mall_order_refund
    <set>
      <if test="orderId != null">`order_id` = #{orderId}, </if>
      <if test="userId != null">`user_id` = #{userId}, </if>
      <if test="outRefundNo != null">`out_refund_no` = #{outRefundNo}, </if>
      <if test="refundId != null">`refund_id` = #{refundId}, </if>
      <if test="refundType != null">`refund_type` = #{refundType}, </if>
      <if test="refundTime != null">`refund_time` = #{refundTime}, </if>
      <if test="creator != null">`creator` = #{creator}, </if>
      <if test="refundMoney != null">`refund_money` = #{refundMoney}, </if>
      <if test="refundStatus != null">`refund_status` = #{refundStatus}, </if>
      <if test="refundReason != null">`refund_reason` = #{refundReason}, </if>
      <if test="refundRecvAccout != null">`refund_recv_accout` = #{refundRecvAccout}, </if>
      <if test="wechatRefundStatusDes != null">`wechat_refund_status_des` = #{wechatRefundStatusDes}, </if>
      <if test="approver != null">`approver` = #{approver}, </if>
      <if test="approvalTime != null">`approval_time` = #{approvalTime}, </if>
      <if test="approvalRemark != null">`approval_remark` = #{approvalRemark}, </if>
      <if test="createSn != null">`create_sn` = #{createSn}, </if>
      <if test="createTime != null">`create_time` = #{createTime}, </if>
      <if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
      <if test="modTime != null">`mod_time` = #{modTime}, </if>
      <if test="tstm != null">`tstm` = #{tstm}</if>
    </set>
    where id = #{id}
  </update>

  <delete id="delete">
    delete from mall_order_refund where id = #{value}
  </delete>

  <delete id="deleteBatch">
    delete from mall_order_refund where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>

</mapper>