<?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.ThirdPartyCompanyMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ThirdPartyCompany">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="tid" jdbcType="INTEGER" property="tid" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <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="material" jdbcType="INTEGER" property="material" />
    <result column="urgent" jdbcType="INTEGER" property="urgent" />
    <result column="audit" jdbcType="INTEGER" property="audit" />
    <result column="assets" jdbcType="VARCHAR" property="assets" />
    <result column="income" jdbcType="VARCHAR" property="income" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="cid" jdbcType="INTEGER" property="cid" />
    <result column="party_amount" jdbcType="DECIMAL" property="partyAmount" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="patent_name_type" jdbcType="INTEGER" property="patentNameType" />
    <result column="official_amount" jdbcType="DECIMAL" property="officialAmount" />
    <result column="start_type" jdbcType="INTEGER" property="startType" />
    <result column="patent_type" jdbcType="INTEGER" property="patentType" />
  </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 Thu Oct 22 16:26:31 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 Thu Oct 22 16:26:31 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 Thu Oct 22 16:26:31 CST 2020.
    -->
    id, tid, company_name, unit_price, quantity, total_amount, material, urgent, audit,
    assets, income, remarks, create_time, cid, party_amount, type, patent_name_type,
    official_amount, start_type, patent_type
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.ThirdPartyCompanyExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from third_party_company
    <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 Thu Oct 22 16:26:31 CST 2020.
    -->
    select
    <include refid="Base_Column_List" />
    from third_party_company
    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 Thu Oct 22 16:26:31 CST 2020.
    -->
    delete from third_party_company
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.ThirdPartyCompanyExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    delete from third_party_company
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.ThirdPartyCompany">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    insert into third_party_company (id, tid, company_name,
      unit_price, quantity, total_amount,
      material, urgent, audit,
      assets, income, remarks,
      create_time, cid, party_amount,
      type, patent_name_type, official_amount,
      start_type, patent_type)
    values (#{id,jdbcType=INTEGER}, #{tid,jdbcType=INTEGER}, #{companyName,jdbcType=VARCHAR},
      #{unitPrice,jdbcType=DECIMAL}, #{quantity,jdbcType=INTEGER}, #{totalAmount,jdbcType=DECIMAL},
      #{material,jdbcType=INTEGER}, #{urgent,jdbcType=INTEGER}, #{audit,jdbcType=INTEGER},
      #{assets,jdbcType=VARCHAR}, #{income,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP}, #{cid,jdbcType=INTEGER}, #{partyAmount,jdbcType=DECIMAL},
      #{type,jdbcType=INTEGER}, #{patentNameType,jdbcType=INTEGER}, #{officialAmount,jdbcType=DECIMAL},
      #{startType,jdbcType=INTEGER}, #{patentType,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.ThirdPartyCompany">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    insert into third_party_company
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="companyName != null">
        company_name,
      </if>
      <if test="unitPrice != null">
        unit_price,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="totalAmount != null">
        total_amount,
      </if>
      <if test="material != null">
        material,
      </if>
      <if test="urgent != null">
        urgent,
      </if>
      <if test="audit != null">
        audit,
      </if>
      <if test="assets != null">
        assets,
      </if>
      <if test="income != null">
        income,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="cid != null">
        cid,
      </if>
      <if test="partyAmount != null">
        party_amount,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="patentNameType != null">
        patent_name_type,
      </if>
      <if test="officialAmount != null">
        official_amount,
      </if>
      <if test="startType != null">
        start_type,
      </if>
      <if test="patentType != null">
        patent_type,
      </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="companyName != null">
        #{companyName,jdbcType=VARCHAR},
      </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="material != null">
        #{material,jdbcType=INTEGER},
      </if>
      <if test="urgent != null">
        #{urgent,jdbcType=INTEGER},
      </if>
      <if test="audit != null">
        #{audit,jdbcType=INTEGER},
      </if>
      <if test="assets != null">
        #{assets,jdbcType=VARCHAR},
      </if>
      <if test="income != null">
        #{income,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cid != null">
        #{cid,jdbcType=INTEGER},
      </if>
      <if test="partyAmount != null">
        #{partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="patentNameType != null">
        #{patentNameType,jdbcType=INTEGER},
      </if>
      <if test="officialAmount != null">
        #{officialAmount,jdbcType=DECIMAL},
      </if>
      <if test="startType != null">
        #{startType,jdbcType=INTEGER},
      </if>
      <if test="patentType != null">
        #{patentType,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.ThirdPartyCompanyExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    select count(*) from third_party_company
    <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 Thu Oct 22 16:26:31 CST 2020.
    -->
    update third_party_company
    <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.companyName != null">
        company_name = #{record.companyName,jdbcType=VARCHAR},
      </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.material != null">
        material = #{record.material,jdbcType=INTEGER},
      </if>
      <if test="record.urgent != null">
        urgent = #{record.urgent,jdbcType=INTEGER},
      </if>
      <if test="record.audit != null">
        audit = #{record.audit,jdbcType=INTEGER},
      </if>
      <if test="record.assets != null">
        assets = #{record.assets,jdbcType=VARCHAR},
      </if>
      <if test="record.income != null">
        income = #{record.income,jdbcType=VARCHAR},
      </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.cid != null">
        cid = #{record.cid,jdbcType=INTEGER},
      </if>
      <if test="record.partyAmount != null">
        party_amount = #{record.partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=INTEGER},
      </if>
      <if test="record.patentNameType != null">
        patent_name_type = #{record.patentNameType,jdbcType=INTEGER},
      </if>
      <if test="record.officialAmount != null">
        official_amount = #{record.officialAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.startType != null">
        start_type = #{record.startType,jdbcType=INTEGER},
      </if>
      <if test="record.patentType != null">
        patent_type = #{record.patentType,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 Thu Oct 22 16:26:31 CST 2020.
    -->
    update third_party_company
    set id = #{record.id,jdbcType=INTEGER},
      tid = #{record.tid,jdbcType=INTEGER},
      company_name = #{record.companyName,jdbcType=VARCHAR},
      unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      quantity = #{record.quantity,jdbcType=INTEGER},
      total_amount = #{record.totalAmount,jdbcType=DECIMAL},
      material = #{record.material,jdbcType=INTEGER},
      urgent = #{record.urgent,jdbcType=INTEGER},
      audit = #{record.audit,jdbcType=INTEGER},
      assets = #{record.assets,jdbcType=VARCHAR},
      income = #{record.income,jdbcType=VARCHAR},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      cid = #{record.cid,jdbcType=INTEGER},
      party_amount = #{record.partyAmount,jdbcType=DECIMAL},
      type = #{record.type,jdbcType=INTEGER},
      patent_name_type = #{record.patentNameType,jdbcType=INTEGER},
      official_amount = #{record.officialAmount,jdbcType=DECIMAL},
      start_type = #{record.startType,jdbcType=INTEGER},
      patent_type = #{record.patentType,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ThirdPartyCompany">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    update third_party_company
    <set>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </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="material != null">
        material = #{material,jdbcType=INTEGER},
      </if>
      <if test="urgent != null">
        urgent = #{urgent,jdbcType=INTEGER},
      </if>
      <if test="audit != null">
        audit = #{audit,jdbcType=INTEGER},
      </if>
      <if test="assets != null">
        assets = #{assets,jdbcType=VARCHAR},
      </if>
      <if test="income != null">
        income = #{income,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cid != null">
        cid = #{cid,jdbcType=INTEGER},
      </if>
      <if test="partyAmount != null">
        party_amount = #{partyAmount,jdbcType=DECIMAL},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="patentNameType != null">
        patent_name_type = #{patentNameType,jdbcType=INTEGER},
      </if>
      <if test="officialAmount != null">
        official_amount = #{officialAmount,jdbcType=DECIMAL},
      </if>
      <if test="startType != null">
        start_type = #{startType,jdbcType=INTEGER},
      </if>
      <if test="patentType != null">
        patent_type = #{patentType,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.ThirdPartyCompany">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 22 16:26:31 CST 2020.
    -->
    update third_party_company
    set tid = #{tid,jdbcType=INTEGER},
      company_name = #{companyName,jdbcType=VARCHAR},
      unit_price = #{unitPrice,jdbcType=DECIMAL},
      quantity = #{quantity,jdbcType=INTEGER},
      total_amount = #{totalAmount,jdbcType=DECIMAL},
      material = #{material,jdbcType=INTEGER},
      urgent = #{urgent,jdbcType=INTEGER},
      audit = #{audit,jdbcType=INTEGER},
      assets = #{assets,jdbcType=VARCHAR},
      income = #{income,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      cid = #{cid,jdbcType=INTEGER},
      party_amount = #{partyAmount,jdbcType=DECIMAL},
      type = #{type,jdbcType=INTEGER},
      patent_name_type = #{patentNameType,jdbcType=INTEGER},
      official_amount = #{officialAmount,jdbcType=DECIMAL},
      start_type = #{startType,jdbcType=INTEGER},
      patent_type = #{patentType,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <select id="selectByTid" resultType="com.goafanti.organization.bo.OutThirdPartyCompany">
	 select a.id,a.tid,a.company_name companyName,a.unit_price unitPrice,a.quantity,a.total_amount totalAmount,a.material,a.urgent,
	a.patent_name_type patentNameType,a.audit,a.assets,a.income,a.remarks,a.cid,b.cost_reduction costReduction,b.official_cost officialCost,
	a.type,a.party_amount partyAmount ,op.amount officialUnitPrice,op.proportion85 reductionAmount,a.start_type startType,a.patent_type patentType
	from third_party_company a left join t_order_task b on a.tid=b.id
	left join official_fee_price op on b.patent_type =op.patent_type  and a.patent_name_type =op.`type`
 where tid= #{tid}
  </select>
<!--   <select id="selectByTidPuls" resultType="com.goafanti.organization.bo.ProjectTypePuls">
 select a.id,a.official_cost officialCost,a.cost_reduction costReduction ,a.commodity_quantity quantity ,a.patent_type patentType,b.patent_name_type projectType,
 c.amount officialAmount,c.proportion85 from t_order_task a left join t_order_outsource b on a.id=b.tid
left join official_fee_price c on a.patent_type =c.patent_type and b.patent_name_type =c.`type`
where a.id= #{tid}
  </select> -->
  <select id="selectByTidGetListDtails" resultType="com.goafanti.organization.bo.ProjectTypePuls">
 select a.id,a.official_cost officialCost,a.cost_reduction costReduction ,a.commodity_quantity quantity ,a.patent_type patentType,b.patent_name_type projectType,
 c.amount officialAmount,c.proportion85 from t_order_task x  left join t_order_task a  on x.order_no =a.order_no left join t_order_outsource b on a.id=b.tid
left join official_fee_price c on a.patent_type =c.patent_type and b.patent_name_type =c.`type`
where x.id=  #{tid}
  </select>


   <select id="selectPaymentList" resultType="com.goafanti.organization.bo.outPaymentList">
		    select a.id, c.contract_no contractNo,b.order_no orderNo,d.buyer_name userName, d.dep_name depName,f.party_amount costAmount,
		a.choose_type chooseType,a.payment_amount paymentAmount,a.application_amount applicationAmount,a.tid,a.company_name companyName,
		date_format(a.create_time,'%Y-%m-%d %H:%i:%S')createTime,a.aname,d.finance_name financeName,b.cname, b.commodity_name pname,
		b.project_status projectStatus,a.status,bp.`type` projectType,b.cost_reduction costReduction ,b.official_cost  officialCost,c.total_amount totalAmount,
		c.settlement_amount settlementAmount,a.process_status processStatus
		from t_order_payment a left join t_order_task b on a.tid=b.id left join t_order_new c on b.order_no=c.order_no
		left join business_project bp on b.commodity_id=bp.id
		left join t_order_mid d on b.order_no=d.order_no left join t_task_mid f on a.tid=f.tid
		where 1=1
		<if test="lvl==0">
		and d.finance_id= #{aid}
		</if>
		<if test="lvl==1">
		and d.finance_id in (select id from admin where superior_id= #{aid} )
		</if>
		<if test="lvl==3">
		and b.task_receiver= #{aid}
		</if>
		<if test="lvl==4">
		and a.choose_type =2
		</if>
		<if test="contractNo !=null">
		and c.contract_no like concat('%', #{contractNo},'%')
		</if>
		<if test="orderNo !=null">
		and c.order_no like concat('%', #{orderNo} ,'%')
		</if>
		<if test="userName !=null">
		and d.buyer_name like concat('%', #{userName},'%')
		</if>
		<if test="deps !=null">
		and c.order_dep in
          <foreach close=")" collection="deps" item="depId" open="(" separator=",">
            #{depId}
          </foreach>
		</if>
		<if test="aname !=null">
		and a.aname like concat('%',#{aname},'%')
		</if>
		<if test="financeName !=null">
		and d.finance_name like concat('%',#{financeName},'%')
		</if>
		<if test="cname !=null">
		and b.cname like concat('%',#{cname},'%')
		</if>
		<if test="pname !=null">
		and b.commodity_name like concat('%',#{pname},'%')
		</if>
		<if test="status !=null">
		and a.status= #{status}
		</if>
     <if test="thchId != null">
       and b.task_receiver = #{thchId,jdbcType=VARCHAR}
     </if>
		order by a.status,a.create_time desc
		<if test="lvl==4">
		,a.process_status
		</if>
	  	<if test="page_sql!=null">
				${page_sql}
		</if>
  </select>

   <select id="selectPaymentCount" resultType="java.lang.Integer">
		select count(*)
		from t_order_payment a left join t_order_task b on a.tid=b.id left join t_order_new c on b.order_no=c.order_no
		left join t_order_mid d on b.order_no=d.order_no
		where 1=1
		<if test="lvl==0">
		and d.finance_id= #{aid}
		</if>
		<if test="lvl==1">
		and d.finance_id in (select id from admin where superior_id= #{aid} )
		</if>
		<if test="lvl==3">
		and b.task_receiver= #{aid}
		</if>
		<if test="lvl==4">
		and choose_type =2
		</if>
		<if test="contractNo !=null">
		and c.contract_no like concat('%', #{contractNo},'%')
		</if>
		<if test="orderNo !=null">
		and c.order_no like concat('%', #{orderNo} ,'%')
		</if>
		<if test="userName !=null">
		and d.buyer_name like concat('%', #{userName},'%')
		</if>
		<if test="deps !=null">
		and c.order_dep in
          <foreach close=")" collection="deps" item="depId" open="(" separator=",">
            #{depId}
          </foreach>
		</if>
		<if test="aname !=null">
		and a.aname like concat('%',#{aname},'%')
		</if>
		<if test="financeName !=null">
		and d.finance_name like concat('%',#{financeName},'%')
		</if>
		<if test="cname !=null">
		and b.cname like concat('%',#{cname},'%')
		</if>
		<if test="pname !=null">
		and b.commodity_name like concat('%',#{pname},'%')
		</if>
		<if test="status !=null">
		and a.status= #{status}
		</if>
     <if test="thchId != null">
       and b.task_receiver = #{thchId,jdbcType=VARCHAR}
     </if>
  </select>
 <select id="selectNodeList" resultType="com.goafanti.organization.bo.outNodeList">
	  select c.contract_no contractNo,c.order_no orderNo,d.buyer_name userName,
	b.cname,b.commodity_name pname,c.order_status orderStatus,b.project_status projectStatus,
	b.set_up_amount projectAmount,e.cost_amount costAmount,e.party_amount partyAmount,b.task_receiver,
	c.liquidation_status liquidationStatus,a.dun_type dunType,a.project_type projectType,a.tid,
	a.total_amount NodeAmount,date_format(a.start_time,'%Y-%m-%d %H:%i:%S')startTime,a.status
	from payment_node a
	left join t_order_task b on a.tid=b.id
	left join t_order_new c on b.order_no=c.order_no
	left join t_order_mid d on b.order_no=d.order_no
	left join t_task_mid e on b.id=e.tid
	where 1=1
	<if test="lvl==0">
	 and b.task_receiver= #{aid}
	</if>
	 <if test="lvl==1">
	 and c.finance_id= #{aid}
	</if>
	 <if test="lvl==2">
	  and c.finance_id in (select id from admin where superior_id= #{aid})
	</if>
	 <if test="userName != null">
	 and d.buyer_name like concat('%',#{userName},'%')
	</if>
	 <if test="contractNo != null">
	 and c.contract_no like concat('%',#{contractNo},'%')
	</if>
	 <if test="orderNo != null">
	 and c.order_no like concat('%',#{orderNo},'%')
	</if>
	 <if test="cname !=null">
	 and b.cname like concat('%',#{cname},'%')
	</if>
	 <if test="pname !=null">
	 and b.commodity_name like concat('%',#{pname},'%')
	</if>
	 <if test="status !=null">
	 and a.status= #{status}
	</if>
	 <if test="startTime !=null and endTime != null">
	and a.start_time  between #{startTime} and #{endTime}
	</if>
	order by a.status ,a.create_time desc
	<if test="page_sql!=null">
				${page_sql}
		</if>
</select>
  <select id="selectNodeCount" resultType="java.lang.Integer">
	  select count(*)
	from payment_node a
	left join t_order_task b on a.tid=b.id
	left join t_order_new c on b.order_no=c.order_no
	left join t_order_mid d on b.order_no=d.order_no
	where 1=1
	<if test="lvl==0">
	 and b.task_receiver= #{aid}
	</if>
	 <if test="lvl==1">
	 and c.finance_id= #{aid}
	</if>
	 <if test="lvl==2">
	  and c.finance_id in (select id from admin where superior_id= #{aid})
	</if>
	 <if test="userName != null">
	 and d.buyer_name like concat('%',#{userName},'%')
	</if>
	 <if test="contractNo != null">
	 and c.contract_no like concat('%',#{contractNo},'%')
	</if>
	 <if test="orderNo != null">
	 and c.order_no like concat('%',#{orderNo},'%')
	</if>
	 <if test="cname !=null">
	 and b.cname like concat('%',#{cname},'%')
	</if>
	 <if test="pname !=null">
	 and b.commodity_name like concat('%',#{pname},'%')
	</if>
	 <if test="status !=null">
	 and a.status= #{status}
	</if>
	 <if test="startTime !=null and endTime != null">
	and a.start_time  between #{startTime} and #{endTime}
	</if>
</select>

<select id="softWritingPriceList" resultType="com.goafanti.common.model.SoftWritingPrice">
	  select a.id,a.cid,b.company_name companyName,a.material,a.unit_price unitPrice,a.urgent,a.remarks,
	a.status,date_format(a.create_time,'%Y-%m-%d %H:%i:%s')createTimes
	from soft_writing_price a left join company_library b on a.cid=b.id
	where 1=1
	<if test="s.companyName != null">
	and b.company_name like concat('%',#{s.companyName},'%')
	</if>
	<if test="s.material != null">
	and a.material= #{s.material}
	</if>
	<if test="s.urgent != null">
	and a.urgent= #{s.urgent}
	</if>
	<if test="page_sql!=null">
	${page_sql}
	</if>
  </select>

    <select id="softWritingPriceCount" resultType="java.lang.Integer">
	  select count(*)
	from soft_writing_price a left join company_library b on a.cid=b.id
	where 1=1
	<if test="s.companyName != null">
	and b.company_name like concat('%',#{s.companyName},'%')
	</if>
	<if test="s.material != null">
	and a.material= #{s.material}
	</if>
	<if test="s.urgent != null">
	and a.urgent= #{s.urgent}
	</if>
  </select>

  <select id="selectListOfficialFeePrice" resultType="com.goafanti.common.model.OfficialFeePrice">
  select id,type,patent_type patentType,amount,proportion85,remarks,date_format(create_time, '%Y-%m-%d %H:%i:%S') createTimes
	 from official_fee_price where 1=1
	 <if test="type != null">
	 and type= #{type}
	 </if>
	 <if test="patentType != null">
	 and patent_type= #{patentType}
	 </if>
	order by patent_type
	 <if test="page_sql!=null">
	${page_sql}
	</if>
  </select>

   <select id="countListOfficialFeePrice" resultType="java.lang.Integer" >
  select count(*)
	  from official_fee_price where 1=1
	 <if test="type != null">
	 and type= #{type}
	 </if>
	 <if test="patentType != null">
	 and patent_type= #{patentType}
	 </if>
  </select>
     <delete id="deleteByTid" >
	delete from third_party_company
 where tid= #{tid}
  </delete>


</mapper>
