<?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.PaymentNodeMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.PaymentNode">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="tid" jdbcType="INTEGER" property="tid" />
    <result column="cid" jdbcType="INTEGER" property="cid" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <result column="project_type" jdbcType="INTEGER" property="projectType" />
    <result column="dun_type" jdbcType="INTEGER" property="dunType" />
    <result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
    <result column="quantity" jdbcType="INTEGER" property="quantity" />
    <result column="total_amount" jdbcType="DECIMAL" property="totalAmount" />
    <result column="party_amount" jdbcType="DECIMAL" property="partyAmount" />
    <result column="party_time" jdbcType="TIMESTAMP" property="partyTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="dun_status" jdbcType="INTEGER" property="dunStatus" />
    <result column="effective_count" jdbcType="INTEGER" property="effectiveCount" />
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="status" jdbcType="INTEGER" property="status" />
  </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 13:58:53 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 13:58:53 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 13:58:53 CST 2020.
    -->
    id, tid, cid, company_name, project_type, dun_type, unit_price, quantity, total_amount,
    party_amount, party_time, create_time, dun_status, effective_count, start_time, status
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.PaymentNodeExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from payment_node
    <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 13:58:53 CST 2020.
    -->
    select
    <include refid="Base_Column_List" />
    from payment_node
    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 13:58:53 CST 2020.
    -->
    delete from payment_node
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.PaymentNodeExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    delete from payment_node
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.PaymentNode">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    insert into payment_node (id, tid, cid,
      company_name, project_type, dun_type,
      unit_price, quantity, total_amount,
      party_amount, party_time, create_time,
      dun_status, effective_count, start_time,
      status)
    values (#{id,jdbcType=INTEGER}, #{tid,jdbcType=INTEGER}, #{cid,jdbcType=INTEGER},
      #{companyName,jdbcType=VARCHAR}, #{projectType,jdbcType=INTEGER}, #{dunType,jdbcType=INTEGER},
      #{unitPrice,jdbcType=DECIMAL}, #{quantity,jdbcType=INTEGER}, #{totalAmount,jdbcType=DECIMAL},
      #{partyAmount,jdbcType=DECIMAL}, #{partyTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP},
      #{dunStatus,jdbcType=INTEGER}, #{effectiveCount,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP},
      #{status,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.PaymentNode">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    insert into payment_node
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="cid != null">
        cid,
      </if>
      <if test="companyName != null">
        company_name,
      </if>
      <if test="projectType != null">
        project_type,
      </if>
      <if test="dunType != null">
        dun_type,
      </if>
      <if test="unitPrice != null">
        unit_price,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="totalAmount != null">
        total_amount,
      </if>
      <if test="partyAmount != null">
        party_amount,
      </if>
      <if test="partyTime != null">
        party_time,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="dunStatus != null">
        dun_status,
      </if>
      <if test="effectiveCount != null">
        effective_count,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="status != null">
        status,
      </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="cid != null">
        #{cid,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="projectType != null">
        #{projectType,jdbcType=INTEGER},
      </if>
      <if test="dunType != null">
        #{dunType,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        #{unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="totalAmount != null">
        #{totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyAmount != null">
        #{partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyTime != null">
        #{partyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dunStatus != null">
        #{dunStatus,jdbcType=INTEGER},
      </if>
      <if test="effectiveCount != null">
        #{effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="startTime != null">
        #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.PaymentNodeExample" 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 13:58:53 CST 2020.
    -->
    select count(*) from payment_node
    <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 13:58:53 CST 2020.
    -->
    update payment_node
    <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.cid != null">
        cid = #{record.cid,jdbcType=INTEGER},
      </if>
      <if test="record.companyName != null">
        company_name = #{record.companyName,jdbcType=VARCHAR},
      </if>
      <if test="record.projectType != null">
        project_type = #{record.projectType,jdbcType=INTEGER},
      </if>
      <if test="record.dunType != null">
        dun_type = #{record.dunType,jdbcType=INTEGER},
      </if>
      <if test="record.unitPrice != null">
        unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="record.quantity != null">
        quantity = #{record.quantity,jdbcType=INTEGER},
      </if>
      <if test="record.totalAmount != null">
        total_amount = #{record.totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.partyAmount != null">
        party_amount = #{record.partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.partyTime != null">
        party_time = #{record.partyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.dunStatus != null">
        dun_status = #{record.dunStatus,jdbcType=INTEGER},
      </if>
      <if test="record.effectiveCount != null">
        effective_count = #{record.effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="record.startTime != null">
        start_time = #{record.startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </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 13:58:53 CST 2020.
    -->
    update payment_node
    set id = #{record.id,jdbcType=INTEGER},
      tid = #{record.tid,jdbcType=INTEGER},
      cid = #{record.cid,jdbcType=INTEGER},
      company_name = #{record.companyName,jdbcType=VARCHAR},
      project_type = #{record.projectType,jdbcType=INTEGER},
      dun_type = #{record.dunType,jdbcType=INTEGER},
      unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      quantity = #{record.quantity,jdbcType=INTEGER},
      total_amount = #{record.totalAmount,jdbcType=DECIMAL},
      party_amount = #{record.partyAmount,jdbcType=DECIMAL},
      party_time = #{record.partyTime,jdbcType=TIMESTAMP},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      dun_status = #{record.dunStatus,jdbcType=INTEGER},
      effective_count = #{record.effectiveCount,jdbcType=INTEGER},
      start_time = #{record.startTime,jdbcType=TIMESTAMP},
      status = #{record.status,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.PaymentNode">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    update payment_node
    <set>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="cid != null">
        cid = #{cid,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="projectType != null">
        project_type = #{projectType,jdbcType=INTEGER},
      </if>
      <if test="dunType != null">
        dun_type = #{dunType,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        unit_price = #{unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="quantity != null">
        quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="totalAmount != null">
        total_amount = #{totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyAmount != null">
        party_amount = #{partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyTime != null">
        party_time = #{partyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dunStatus != null">
        dun_status = #{dunStatus,jdbcType=INTEGER},
      </if>
      <if test="effectiveCount != null">
        effective_count = #{effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.PaymentNode">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 07 13:58:53 CST 2020.
    -->
    update payment_node
    set tid = #{tid,jdbcType=INTEGER},
      cid = #{cid,jdbcType=INTEGER},
      company_name = #{companyName,jdbcType=VARCHAR},
      project_type = #{projectType,jdbcType=INTEGER},
      dun_type = #{dunType,jdbcType=INTEGER},
      unit_price = #{unitPrice,jdbcType=DECIMAL},
      quantity = #{quantity,jdbcType=INTEGER},
      total_amount = #{totalAmount,jdbcType=DECIMAL},
      party_amount = #{partyAmount,jdbcType=DECIMAL},
      party_time = #{partyTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      dun_status = #{dunStatus,jdbcType=INTEGER},
      effective_count = #{effectiveCount,jdbcType=INTEGER},
      start_time = #{startTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>


    <select id="selectByTid" resultType="com.goafanti.organization.bo.OutPaymentNode">
  select id,tid,cid,company_name companyName,unit_price unitPrice,quantity,total_amount totalAmount,create_time createTime,status,
   party_amount partyAmount, date_format(party_time,'%Y-%m-%d')partyTimes,project_type projectType,dun_type dunType
   from payment_node where tid= #{tid}
   <if test="status !=null">
   and dun_status = #{status}
   </if>
  </select>
  <select id="selectByStatus" resultType="com.goafanti.organization.bo.OutPaymentNode">
    select id,tid,cid,company_name companyName,unit_price unitPrice,quantity,total_amount totalAmount,create_time createTime ,
   party_amount partyAmount,party_time partyTime, date_format(party_time,'%Y-%m-%d')partyTimes,project_type projectType,dun_type dunType
   from payment_node where dun_status = #{status}
  </select>

  <select id="selectBytidGetEmail" resultType="com.goafanti.common.bo.paymentNodeEmailBo">
    select a.tid,b.order_no orderNo,o.contract_no contractNo ,c.salesman_id salesmanId, c.salesman_name salesmanName,
           c.buyer_name userName,d.email
    from payment_node a left join t_order_task b on a.tid=b.id left join t_order_new o on b.order_no =o.order_no
    left join t_order_mid c on b.order_no=c.order_no left join admin d on  c.salesman_id=d.id
    where a.tid= #{tid} limit 1
  </select>

   <select id="selectByTidAndCid" resultType="com.goafanti.organization.bo.OutPaymentNode">
    select id,tid,cid,company_name companyName,unit_price unitPrice,quantity,total_amount totalAmount,create_time createTime,
   party_amount partyAmount, date_format(party_time,'%Y-%m-%d')partyTimes,project_type projectType,dun_type dunType
   from payment_node where 1=1
   <if test="cid !=null">
   and  tid= #{tid}
   </if>
   <if test="cid !=null">
   and cid = #{cid}
   </if>
  </select>
  <select id="selectByCid" resultType="java.lang.Integer">
  select count(*) from payment_node where cid= #{tpcId}
  </select>
    <delete id="deleteByParam" parameterType="java.lang.Integer">
    delete from payment_node
    where 1=1
    <if test="tpcId !=null">
    and cid= #{tpcId}
    </if>
    <if test="tid !=null">
    and tid= #{tid}
    </if>
  </delete>

  <update id="updateByCid">
    update payment_node
    <set>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="projectType != null">
        project_type = #{projectType,jdbcType=INTEGER},
      </if>
      <if test="dunType != null">
        dun_type = #{dunType,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        unit_price = #{unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="quantity != null">
        quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="totalAmount != null">
        total_amount = #{totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyAmount != null">
        party_amount = #{partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="partyTime != null">
        party_time = #{partyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dunStatus != null">
        dun_status = #{dunStatus,jdbcType=INTEGER},
      </if>
      <if test="effectiveCount != null">
        effective_count = #{effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
    </set>
    where cid = #{cid,jdbcType=INTEGER}
  </update>

</mapper>
