<?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.TOrderPaymentMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderPayment">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="tid" jdbcType="INTEGER" property="tid" />
    <result column="node_id" jdbcType="INTEGER" property="nodeId" />
    <result column="payment_type" jdbcType="INTEGER" property="paymentType" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <result column="quantity" jdbcType="INTEGER" property="quantity" />
    <result column="payment_status" jdbcType="INTEGER" property="paymentStatus" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="payment_amount" jdbcType="DECIMAL" property="paymentAmount" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="tpc_id" jdbcType="INTEGER" property="tpcId" />
    <result column="application_amount" jdbcType="DECIMAL" property="applicationAmount" />
    <result column="choose_type" jdbcType="INTEGER" property="chooseType" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="aname" jdbcType="VARCHAR" property="aname" />
  </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 Jul 07 11:46:04 CST 2020.
    -->
    <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 Jul 07 11:46:04 CST 2020.
    -->
    <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 Jul 07 11:46:04 CST 2020.
    -->
    id, tid, node_id, payment_type, company_name, quantity, payment_status, status, payment_amount, 
    remarks, create_time, tpc_id, application_amount, choose_type, aid, aname
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderPaymentExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_order_payment
    <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="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    select 
    <include refid="Base_Column_List" />
    from t_order_payment
    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 Jul 07 11:46:04 CST 2020.
    -->
    delete from t_order_payment
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderPaymentExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    delete from t_order_payment
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TOrderPayment">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    insert into t_order_payment (id, tid, node_id, 
      payment_type, company_name, quantity, 
      payment_status, status, payment_amount, 
      remarks, create_time, tpc_id, 
      application_amount, choose_type, aid, 
      aname)
    values (#{id,jdbcType=INTEGER}, #{tid,jdbcType=INTEGER}, #{nodeId,jdbcType=INTEGER}, 
      #{paymentType,jdbcType=INTEGER}, #{companyName,jdbcType=VARCHAR}, #{quantity,jdbcType=INTEGER}, 
      #{paymentStatus,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{paymentAmount,jdbcType=DECIMAL}, 
      #{remarks,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{tpcId,jdbcType=INTEGER}, 
      #{applicationAmount,jdbcType=DECIMAL}, #{chooseType,jdbcType=INTEGER}, #{aid,jdbcType=VARCHAR}, 
      #{aname,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderPayment">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    insert into t_order_payment
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="nodeId != null">
        node_id,
      </if>
      <if test="paymentType != null">
        payment_type,
      </if>
      <if test="companyName != null">
        company_name,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="paymentStatus != null">
        payment_status,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="paymentAmount != null">
        payment_amount,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="tpcId != null">
        tpc_id,
      </if>
      <if test="applicationAmount != null">
        application_amount,
      </if>
      <if test="chooseType != null">
        choose_type,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="aname != null">
        aname,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="tid != null">
        #{tid,jdbcType=INTEGER},
      </if>
      <if test="nodeId != null">
        #{nodeId,jdbcType=INTEGER},
      </if>
      <if test="paymentType != null">
        #{paymentType,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="paymentStatus != null">
        #{paymentStatus,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="paymentAmount != null">
        #{paymentAmount,jdbcType=DECIMAL},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="tpcId != null">
        #{tpcId,jdbcType=INTEGER},
      </if>
      <if test="applicationAmount != null">
        #{applicationAmount,jdbcType=DECIMAL},
      </if>
      <if test="chooseType != null">
        #{chooseType,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="aname != null">
        #{aname,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TOrderPaymentExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    select count(*) from t_order_payment
    <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 Jul 07 11:46:04 CST 2020.
    -->
    update t_order_payment
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.tid != null">
        tid = #{record.tid,jdbcType=INTEGER},
      </if>
      <if test="record.nodeId != null">
        node_id = #{record.nodeId,jdbcType=INTEGER},
      </if>
      <if test="record.paymentType != null">
        payment_type = #{record.paymentType,jdbcType=INTEGER},
      </if>
      <if test="record.companyName != null">
        company_name = #{record.companyName,jdbcType=VARCHAR},
      </if>
      <if test="record.quantity != null">
        quantity = #{record.quantity,jdbcType=INTEGER},
      </if>
      <if test="record.paymentStatus != null">
        payment_status = #{record.paymentStatus,jdbcType=INTEGER},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.paymentAmount != null">
        payment_amount = #{record.paymentAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.tpcId != null">
        tpc_id = #{record.tpcId,jdbcType=INTEGER},
      </if>
      <if test="record.applicationAmount != null">
        application_amount = #{record.applicationAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.chooseType != null">
        choose_type = #{record.chooseType,jdbcType=INTEGER},
      </if>
      <if test="record.aid != null">
        aid = #{record.aid,jdbcType=VARCHAR},
      </if>
      <if test="record.aname != null">
        aname = #{record.aname,jdbcType=VARCHAR},
      </if>
    </set>
    <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 Jul 07 11:46:04 CST 2020.
    -->
    update t_order_payment
    set id = #{record.id,jdbcType=INTEGER},
      tid = #{record.tid,jdbcType=INTEGER},
      node_id = #{record.nodeId,jdbcType=INTEGER},
      payment_type = #{record.paymentType,jdbcType=INTEGER},
      company_name = #{record.companyName,jdbcType=VARCHAR},
      quantity = #{record.quantity,jdbcType=INTEGER},
      payment_status = #{record.paymentStatus,jdbcType=INTEGER},
      status = #{record.status,jdbcType=INTEGER},
      payment_amount = #{record.paymentAmount,jdbcType=DECIMAL},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      tpc_id = #{record.tpcId,jdbcType=INTEGER},
      application_amount = #{record.applicationAmount,jdbcType=DECIMAL},
      choose_type = #{record.chooseType,jdbcType=INTEGER},
      aid = #{record.aid,jdbcType=VARCHAR},
      aname = #{record.aname,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderPayment">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    update t_order_payment
    <set>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="nodeId != null">
        node_id = #{nodeId,jdbcType=INTEGER},
      </if>
      <if test="paymentType != null">
        payment_type = #{paymentType,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="quantity != null">
        quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="paymentStatus != null">
        payment_status = #{paymentStatus,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="paymentAmount != null">
        payment_amount = #{paymentAmount,jdbcType=DECIMAL},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="tpcId != null">
        tpc_id = #{tpcId,jdbcType=INTEGER},
      </if>
      <if test="applicationAmount != null">
        application_amount = #{applicationAmount,jdbcType=DECIMAL},
      </if>
      <if test="chooseType != null">
        choose_type = #{chooseType,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="aname != null">
        aname = #{aname,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderPayment">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 11:46:04 CST 2020.
    -->
    update t_order_payment
    set tid = #{tid,jdbcType=INTEGER},
      node_id = #{nodeId,jdbcType=INTEGER},
      payment_type = #{paymentType,jdbcType=INTEGER},
      company_name = #{companyName,jdbcType=VARCHAR},
      quantity = #{quantity,jdbcType=INTEGER},
      payment_status = #{paymentStatus,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      payment_amount = #{paymentAmount,jdbcType=DECIMAL},
      remarks = #{remarks,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      tpc_id = #{tpcId,jdbcType=INTEGER},
      application_amount = #{applicationAmount,jdbcType=DECIMAL},
      choose_type = #{chooseType,jdbcType=INTEGER},
      aid = #{aid,jdbcType=VARCHAR},
      aname = #{aname,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  
    <insert id="insertSelectiveGetId" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderPayment" useGeneratedKeys="true">
     insert into t_order_payment
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="nodeId != null">
        node_id,
      </if>
      <if test="paymentType != null">
        payment_type,
      </if>
      <if test="companyName != null">
        company_name,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="paymentStatus != null">
        payment_status,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="paymentAmount != null">
        payment_amount,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="tpcId != null">
        tpc_id,
      </if>
      <if test="applicationAmount != null">
        application_amount,
      </if>
      <if test="chooseType != null">
        choose_type,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="aname != null">
        aname,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="tid != null">
        #{tid,jdbcType=INTEGER},
      </if>
      <if test="nodeId != null">
        #{nodeId,jdbcType=INTEGER},
      </if>
      <if test="paymentType != null">
        #{paymentType,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="paymentStatus != null">
        #{paymentStatus,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="paymentAmount != null">
        #{paymentAmount,jdbcType=DECIMAL},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="tpcId != null">
        #{tpcId,jdbcType=INTEGER},
      </if>
      <if test="applicationAmount != null">
        #{applicationAmount,jdbcType=DECIMAL},
      </if>
      <if test="chooseType != null">
        #{chooseType,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="aname != null">
        #{aname,jdbcType=VARCHAR},
      </if>
    </trim>
     <selectKey keyProperty="id" order="AFTER" resultType="int">
        SELECT LAST_INSERT_ID()
    </selectKey>
  </insert>
  <select id="selectByidGetDetails" resultType="com.goafanti.organization.bo.outOrderPayment">
select a.id,a.tid,a.node_id nodeId,a.payment_type paymentType,a.company_name companyName,a.quantity,
	a.payment_status paymentStatus,a.status,a.payment_amount paymentAmount,a.remarks ,
	d.finance_name financeName ,c.order_no orderNo,a.application_amount applicationAmount
	 from t_order_payment a
	 left join t_order_task c on a.tid=c.id left join t_order_mid d on c.order_no=d.order_no where a.id= #{id}
  </select>
  
  <select id="selectByTid" resultType="com.goafanti.organization.bo.outOrderPayment">
		select a.id,a.tid,a.node_id nodeId,a.payment_type paymentType,a.company_name companyName,a.quantity,choose_type chooseType,tpc.id tpcId,
	  a.payment_status paymentStatus, a.status,a.payment_amount paymentAmount,a.remarks ,tpc.company_name tpcName,d.finance_name financeName ,
	  c.order_no orderNo,date_format(a.create_time,'%Y-%m-%d %H:%i:%s')createTimes,a.application_amount applicationAmount 
	 from t_order_payment a	 left join t_order_task c on a.tid=c.id left join t_order_mid d on c.order_no=d.order_no 
	 left join third_party_company tpc on tpc.id=a.tpc_id where  a.tid= #{id}
  </select>
  <select id="selectList" resultType="com.goafanti.organization.bo.outOrderPayment">
  select a.id,a.tid,a.node_id nodeId,a.payment_type paymentType,a.company_name companyName,a.quantity,
	  a.payment_status paymentStatus, a.status,a.payment_amount paymentAmount,a.remarks , b.quantity NodeQuantity,
	  b.party_amount NodePartyAmount,b.total_amount NodeTotalAmount,d.finance_name financeName ,c.order_no orderNo
	  ,a.application_amount applicationAmount
	 from t_order_payment a left join payment_node b on a.node_id=b.id
	 left join t_order_task c on b.tid=c.id left join t_order_mid d on c.order_no=d.order_no where a.status !=4
	 <if test="tpcId != null">
	 and a.tpc_id= #{tpcId}
	 </if>
	 <if test="nodeId != null">
	 and a.node_id= #{nodeId}
	 </if>
	 <if test="chooseType != null">
	 and a.choose_type= #{chooseType}
	 </if>
  </select>
  
  <update id="updateByids">
  	 update t_order_payment set status=3
	 where id in 
  <foreach item="item" collection="list" separator="," open="(" close=")" index="">
       #{item}
     </foreach>
  </update>
  
</mapper>