<?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.goafanti.common.dao.TOrderRefundMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderRefund">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="refund_status" jdbcType="INTEGER" property="refundStatus" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="initiate" jdbcType="VARCHAR" property="initiate" />
    <result column="accept" jdbcType="VARCHAR" property="accept" />
    <result column="reason" jdbcType="VARCHAR" property="reason" />
    <result column="result" jdbcType="VARCHAR" property="result" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.goafanti.common.model.TOrderRefundWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    <result column="reason_attachment_url" jdbcType="LONGVARCHAR" property="reasonAttachmentUrl" />
    <result column="contract_url" jdbcType="LONGVARCHAR" property="contractUrl" />
    <result column="application_url" jdbcType="LONGVARCHAR" property="applicationUrl" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    id, order_no, refund_status, create_time, initiate, accept, reason, result
  </sql>
  <sql id="Blob_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    reason_attachment_url, contract_url, application_url
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.goafanti.common.model.TOrderRefundExample" resultMap="ResultMapWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from t_order_refund
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderRefundExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_order_refund
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from t_order_refund
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    delete from t_order_refund
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderRefundExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    delete from t_order_refund
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TOrderRefundWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    insert into t_order_refund (id, order_no, refund_status, 
      create_time, initiate, accept, 
      reason, result, reason_attachment_url, 
      contract_url, application_url)
    values (#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{refundStatus,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{initiate,jdbcType=VARCHAR}, #{accept,jdbcType=VARCHAR}, 
      #{reason,jdbcType=VARCHAR}, #{result,jdbcType=VARCHAR}, #{reasonAttachmentUrl,jdbcType=LONGVARCHAR}, 
      #{contractUrl,jdbcType=LONGVARCHAR}, #{applicationUrl,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderRefundWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    insert into t_order_refund
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="refundStatus != null">
        refund_status,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="initiate != null">
        initiate,
      </if>
      <if test="accept != null">
        accept,
      </if>
      <if test="reason != null">
        reason,
      </if>
      <if test="result != null">
        result,
      </if>
      <if test="reasonAttachmentUrl != null">
        reason_attachment_url,
      </if>
      <if test="contractUrl != null">
        contract_url,
      </if>
      <if test="applicationUrl != null">
        application_url,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="refundStatus != null">
        #{refundStatus,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="initiate != null">
        #{initiate,jdbcType=VARCHAR},
      </if>
      <if test="accept != null">
        #{accept,jdbcType=VARCHAR},
      </if>
      <if test="reason != null">
        #{reason,jdbcType=VARCHAR},
      </if>
      <if test="result != null">
        #{result,jdbcType=VARCHAR},
      </if>
      <if test="reasonAttachmentUrl != null">
        #{reasonAttachmentUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="contractUrl != null">
        #{contractUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="applicationUrl != null">
        #{applicationUrl,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TOrderRefundExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    select count(*) from t_order_refund
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.refundStatus != null">
        refund_status = #{record.refundStatus,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.initiate != null">
        initiate = #{record.initiate,jdbcType=VARCHAR},
      </if>
      <if test="record.accept != null">
        accept = #{record.accept,jdbcType=VARCHAR},
      </if>
      <if test="record.reason != null">
        reason = #{record.reason,jdbcType=VARCHAR},
      </if>
      <if test="record.result != null">
        result = #{record.result,jdbcType=VARCHAR},
      </if>
      <if test="record.reasonAttachmentUrl != null">
        reason_attachment_url = #{record.reasonAttachmentUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.contractUrl != null">
        contract_url = #{record.contractUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.applicationUrl != null">
        application_url = #{record.applicationUrl,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    set id = #{record.id,jdbcType=INTEGER},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      refund_status = #{record.refundStatus,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      initiate = #{record.initiate,jdbcType=VARCHAR},
      accept = #{record.accept,jdbcType=VARCHAR},
      reason = #{record.reason,jdbcType=VARCHAR},
      result = #{record.result,jdbcType=VARCHAR},
      reason_attachment_url = #{record.reasonAttachmentUrl,jdbcType=LONGVARCHAR},
      contract_url = #{record.contractUrl,jdbcType=LONGVARCHAR},
      application_url = #{record.applicationUrl,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    set id = #{record.id,jdbcType=INTEGER},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      refund_status = #{record.refundStatus,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      initiate = #{record.initiate,jdbcType=VARCHAR},
      accept = #{record.accept,jdbcType=VARCHAR},
      reason = #{record.reason,jdbcType=VARCHAR},
      result = #{record.result,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderRefundWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="refundStatus != null">
        refund_status = #{refundStatus,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="initiate != null">
        initiate = #{initiate,jdbcType=VARCHAR},
      </if>
      <if test="accept != null">
        accept = #{accept,jdbcType=VARCHAR},
      </if>
      <if test="reason != null">
        reason = #{reason,jdbcType=VARCHAR},
      </if>
      <if test="result != null">
        result = #{result,jdbcType=VARCHAR},
      </if>
      <if test="reasonAttachmentUrl != null">
        reason_attachment_url = #{reasonAttachmentUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="contractUrl != null">
        contract_url = #{contractUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="applicationUrl != null">
        application_url = #{applicationUrl,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.goafanti.common.model.TOrderRefundWithBLOBs">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    set order_no = #{orderNo,jdbcType=VARCHAR},
      refund_status = #{refundStatus,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      initiate = #{initiate,jdbcType=VARCHAR},
      accept = #{accept,jdbcType=VARCHAR},
      reason = #{reason,jdbcType=VARCHAR},
      result = #{result,jdbcType=VARCHAR},
      reason_attachment_url = #{reasonAttachmentUrl,jdbcType=LONGVARCHAR},
      contract_url = #{contractUrl,jdbcType=LONGVARCHAR},
      application_url = #{applicationUrl,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderRefund">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 20 15:20:39 CST 2018.
    -->
    update t_order_refund
    set order_no = #{orderNo,jdbcType=VARCHAR},
      refund_status = #{refundStatus,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      initiate = #{initiate,jdbcType=VARCHAR},
      accept = #{accept,jdbcType=VARCHAR},
      reason = #{reason,jdbcType=VARCHAR},
      result = #{result,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!-- 财务专员查看自己处理的退款数据  -->
  <select id="getRefundList" parameterType="Map" resultType="com.goafanti.order.bo.OrderRefundBo">
  select r.id as id , r.create_time as createTime, r.order_no as orderNo, u.nickname as buyName, u.id as buyid, o.order_status as orderStatus,
  	a.name as saleName, a.id as saleId, o.liquidation_status as liquidationStatus ,reason as reason,refund_status as  refundStatus,
  	o.refund_amount as refundAmount, o.contract_no as contractNo
  	from t_order_refund r
  	 left join t_order_new o on r.order_no = o.order_no
  	 left join `user` u on o.buyer_id = u.id
  	 left join admin a on o.salesman_id = a.id
  	where accept = #{r.accept,jdbcType=VARCHAR}
  	<if test='r.refundStatus != null and r.refundStatus != ""'>
  		and r.refund_status = #{r.refundStatus,jdbcType=INTEGER} - 1
  	</if>
  	<if test='r.refundStatus == null or r.refundStatus == ""'>
  		and refund_status &lt; 2
  	</if>
  	<if test='r.departmentId != null and r.departmentId != ""'>
  	and a.department_id = #{r.departmentId,jdbcType=INTEGER}
  	</if>
  	<if test='r.id != null and r.id != ""'>
  		and r.id= #{r.id,jdbcType=INTEGER}
  	</if>
  	<if test='r.orderNo != null and r.orderNo != ""'>
  		and r.order_no = #{r.orderNo,jdbcType=VARCHAR}
  	</if>
  	<if test='r.buyName != null and r.buyName != ""'>
	  	<bind name="a" value="'%' + r.buyName + '%'"/>
  		and u.nickname like #{a,jdbcType=VARCHAR}
  	</if>
  	<if test='r.startTime != null and r.startTime != "" and r.endTime != null and r.endTime != ""'>
	  	and o.sign_time between #{r.startTime,jdbcType=VARCHAR} and #{r.endTime,jdbcType=VARCHAR}
	</if>
	order by r.refund_status, o.order_status
  	<if test="page_sql!=null">
	 ${page_sql}
	</if>
  </select>
  <select id="getRefundCount" parameterType="Map" resultType="java.lang.Integer">
  select count(*)
  	from t_order_refund r
  	 left join t_order_new o on r.order_no = o.order_no
  	 left join `user` u on o.buyer_id = u.id
  	 left join admin a on o.salesman_id = a.id
  	where accept = #{r.accept,jdbcType=VARCHAR}
  	<if test='r.refundStatus != null and r.refundStatus != ""'>
  		and r.refund_status = #{r.refundStatus,jdbcType=INTEGER}
  	</if>
  	<if test='r.refundStatus == null or r.refundStatus == ""'>
  		and r.refund_status &lt; 2
  	</if>
  	<if test='r.departmentId != null and r.departmentId != ""'>
  	and a.department_id = #{r.departmentId,jdbcType=INTEGER}
  	</if>
  	<if test='r.id != null and r.id != ""'>
  		and r.id= #{r.id,jdbcType=INTEGER}
  	</if>
  	<if test='r.orderNo != null and r.orderNo != ""'>
  		and r.order_no = #{r.orderNo,jdbcType=VARCHAR}
  	</if>
  	<if test='r.buyName != null and r.buyName != ""'>
	  	<bind name="a" value="'%' + r.buyName + '%'"/>
  		and u.nickname like #{a,jdbcType=VARCHAR}
  	</if>
  	<if test='r.startTime != null and r.startTime != "" and r.endTime != null and r.endTime != ""'>
	  	and o.sign_time between #{r.startTime,jdbcType=VARCHAR} and #{r.endTime,jdbcType=VARCHAR}
	</if>
  </select>
  <!-- 修改退款数据 -->
  <update id="updateRefundById" parameterType="com.goafanti.common.model.TOrderRefund">
  update t_order_refund
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="refundStatus != null">
        refund_status = #{refundStatus,jdbcType=INTEGER},
      </if>
      <if test="initiate != null">
        initiate = #{initiate,jdbcType=VARCHAR},
      </if>
      <if test="accept != null">
        accept = #{accept,jdbcType=VARCHAR},
      </if>
      <if test="reason != null">
        reason = #{reason,jdbcType=VARCHAR},
      </if>
      <if test="result != null">
        result = #{result,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="checkOrderNo" resultType="java.lang.Integer">
	select count(*) from t_order_refund
	where refund_status=0
	and order_no= #{orderNo,jdbcType=VARCHAR}  
  </select>
</mapper>