<?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.TOrderInvoiceMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderInvoice">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="reject_reason" jdbcType="VARCHAR" property="rejectReason" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="invoice_type" jdbcType="INTEGER" property="invoiceType" />
    <result column="unit_name" jdbcType="VARCHAR" property="unitName" />
    <result column="tax_number" jdbcType="VARCHAR" property="taxNumber" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="banks" jdbcType="VARCHAR" property="banks" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="unit_address" jdbcType="VARCHAR" property="unitAddress" />
    <result column="invoice_remarks" jdbcType="VARCHAR" property="invoiceRemarks" />
    <result column="unit_mobile" jdbcType="VARCHAR" property="unitMobile" />
    <result column="voucher_url" jdbcType="VARCHAR" property="voucherUrl" />
    <result column="post" jdbcType="INTEGER" property="post" />
    <result column="addressee" jdbcType="VARCHAR" property="addressee" />
    <result column="addressee_mobile" jdbcType="VARCHAR" property="addresseeMobile" />
    <result column="addressee_province" jdbcType="INTEGER" property="addresseeProvince" />
    <result column="addressee_city" jdbcType="INTEGER" property="addresseeCity" />
    <result column="addressee_area" jdbcType="INTEGER" property="addresseeArea" />
    <result column="recipient_address" jdbcType="VARCHAR" property="recipientAddress" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="approval" jdbcType="INTEGER" property="approval" />
    <result column="already_amount" jdbcType="DECIMAL" property="alreadyAmount" />
  </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 Fri May 17 09:46:50 CST 2019.
    -->
    <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 Fri May 17 09:46:50 CST 2019.
    -->
    <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 Fri May 17 09:46:50 CST 2019.
    -->
    id, order_no, type, status, reject_reason, remarks, invoice_type, unit_name, tax_number, 
    amount, banks, content, unit_address, invoice_remarks, unit_mobile, voucher_url, 
    post, addressee, addressee_mobile, addressee_province, addressee_city, addressee_area, 
    recipient_address, create_time, update_time, approval, already_amount
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderInvoiceExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_order_invoice
    <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 Fri May 17 09:46:50 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from t_order_invoice
    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 Fri May 17 09:46:50 CST 2019.
    -->
    delete from t_order_invoice
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderInvoiceExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    delete from t_order_invoice
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TOrderInvoice">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    insert into t_order_invoice (id, order_no, type, 
      status, reject_reason, remarks, 
      invoice_type, unit_name, tax_number, 
      amount, banks, content, 
      unit_address, invoice_remarks, unit_mobile, 
      voucher_url, post, addressee, 
      addressee_mobile, addressee_province, addressee_city, 
      addressee_area, recipient_address, create_time, 
      update_time, approval, already_amount
      )
    values (#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, 
      #{status,jdbcType=INTEGER}, #{rejectReason,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, 
      #{invoiceType,jdbcType=INTEGER}, #{unitName,jdbcType=VARCHAR}, #{taxNumber,jdbcType=VARCHAR}, 
      #{amount,jdbcType=DECIMAL}, #{banks,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, 
      #{unitAddress,jdbcType=VARCHAR}, #{invoiceRemarks,jdbcType=VARCHAR}, #{unitMobile,jdbcType=VARCHAR}, 
      #{voucherUrl,jdbcType=VARCHAR}, #{post,jdbcType=INTEGER}, #{addressee,jdbcType=VARCHAR}, 
      #{addresseeMobile,jdbcType=VARCHAR}, #{addresseeProvince,jdbcType=INTEGER}, #{addresseeCity,jdbcType=INTEGER}, 
      #{addresseeArea,jdbcType=INTEGER}, #{recipientAddress,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{approval,jdbcType=INTEGER}, #{alreadyAmount,jdbcType=DECIMAL}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderInvoice">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    insert into t_order_invoice
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="rejectReason != null">
        reject_reason,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="invoiceType != null">
        invoice_type,
      </if>
      <if test="unitName != null">
        unit_name,
      </if>
      <if test="taxNumber != null">
        tax_number,
      </if>
      <if test="amount != null">
        amount,
      </if>
      <if test="banks != null">
        banks,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="unitAddress != null">
        unit_address,
      </if>
      <if test="invoiceRemarks != null">
        invoice_remarks,
      </if>
      <if test="unitMobile != null">
        unit_mobile,
      </if>
      <if test="voucherUrl != null">
        voucher_url,
      </if>
      <if test="post != null">
        post,
      </if>
      <if test="addressee != null">
        addressee,
      </if>
      <if test="addresseeMobile != null">
        addressee_mobile,
      </if>
      <if test="addresseeProvince != null">
        addressee_province,
      </if>
      <if test="addresseeCity != null">
        addressee_city,
      </if>
      <if test="addresseeArea != null">
        addressee_area,
      </if>
      <if test="recipientAddress != null">
        recipient_address,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="approval != null">
        approval,
      </if>
      <if test="alreadyAmount != null">
        already_amount,
      </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="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="rejectReason != null">
        #{rejectReason,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="invoiceType != null">
        #{invoiceType,jdbcType=INTEGER},
      </if>
      <if test="unitName != null">
        #{unitName,jdbcType=VARCHAR},
      </if>
      <if test="taxNumber != null">
        #{taxNumber,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        #{amount,jdbcType=DECIMAL},
      </if>
      <if test="banks != null">
        #{banks,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="unitAddress != null">
        #{unitAddress,jdbcType=VARCHAR},
      </if>
      <if test="invoiceRemarks != null">
        #{invoiceRemarks,jdbcType=VARCHAR},
      </if>
      <if test="unitMobile != null">
        #{unitMobile,jdbcType=VARCHAR},
      </if>
      <if test="voucherUrl != null">
        #{voucherUrl,jdbcType=VARCHAR},
      </if>
      <if test="post != null">
        #{post,jdbcType=INTEGER},
      </if>
      <if test="addressee != null">
        #{addressee,jdbcType=VARCHAR},
      </if>
      <if test="addresseeMobile != null">
        #{addresseeMobile,jdbcType=VARCHAR},
      </if>
      <if test="addresseeProvince != null">
        #{addresseeProvince,jdbcType=INTEGER},
      </if>
      <if test="addresseeCity != null">
        #{addresseeCity,jdbcType=INTEGER},
      </if>
      <if test="addresseeArea != null">
        #{addresseeArea,jdbcType=INTEGER},
      </if>
      <if test="recipientAddress != null">
        #{recipientAddress,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="approval != null">
        #{approval,jdbcType=INTEGER},
      </if>
      <if test="alreadyAmount != null">
        #{alreadyAmount,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TOrderInvoiceExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    select count(*) from t_order_invoice
    <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 Fri May 17 09:46:50 CST 2019.
    -->
    update t_order_invoice
    <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.type != null">
        type = #{record.type,jdbcType=INTEGER},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.rejectReason != null">
        reject_reason = #{record.rejectReason,jdbcType=VARCHAR},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.invoiceType != null">
        invoice_type = #{record.invoiceType,jdbcType=INTEGER},
      </if>
      <if test="record.unitName != null">
        unit_name = #{record.unitName,jdbcType=VARCHAR},
      </if>
      <if test="record.taxNumber != null">
        tax_number = #{record.taxNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.amount != null">
        amount = #{record.amount,jdbcType=DECIMAL},
      </if>
      <if test="record.banks != null">
        banks = #{record.banks,jdbcType=VARCHAR},
      </if>
      <if test="record.content != null">
        content = #{record.content,jdbcType=VARCHAR},
      </if>
      <if test="record.unitAddress != null">
        unit_address = #{record.unitAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.invoiceRemarks != null">
        invoice_remarks = #{record.invoiceRemarks,jdbcType=VARCHAR},
      </if>
      <if test="record.unitMobile != null">
        unit_mobile = #{record.unitMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.voucherUrl != null">
        voucher_url = #{record.voucherUrl,jdbcType=VARCHAR},
      </if>
      <if test="record.post != null">
        post = #{record.post,jdbcType=INTEGER},
      </if>
      <if test="record.addressee != null">
        addressee = #{record.addressee,jdbcType=VARCHAR},
      </if>
      <if test="record.addresseeMobile != null">
        addressee_mobile = #{record.addresseeMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.addresseeProvince != null">
        addressee_province = #{record.addresseeProvince,jdbcType=INTEGER},
      </if>
      <if test="record.addresseeCity != null">
        addressee_city = #{record.addresseeCity,jdbcType=INTEGER},
      </if>
      <if test="record.addresseeArea != null">
        addressee_area = #{record.addresseeArea,jdbcType=INTEGER},
      </if>
      <if test="record.recipientAddress != null">
        recipient_address = #{record.recipientAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.approval != null">
        approval = #{record.approval,jdbcType=INTEGER},
      </if>
      <if test="record.alreadyAmount != null">
        already_amount = #{record.alreadyAmount,jdbcType=DECIMAL},
      </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 Fri May 17 09:46:50 CST 2019.
    -->
    update t_order_invoice
    set id = #{record.id,jdbcType=INTEGER},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=INTEGER},
      status = #{record.status,jdbcType=INTEGER},
      reject_reason = #{record.rejectReason,jdbcType=VARCHAR},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      invoice_type = #{record.invoiceType,jdbcType=INTEGER},
      unit_name = #{record.unitName,jdbcType=VARCHAR},
      tax_number = #{record.taxNumber,jdbcType=VARCHAR},
      amount = #{record.amount,jdbcType=DECIMAL},
      banks = #{record.banks,jdbcType=VARCHAR},
      content = #{record.content,jdbcType=VARCHAR},
      unit_address = #{record.unitAddress,jdbcType=VARCHAR},
      invoice_remarks = #{record.invoiceRemarks,jdbcType=VARCHAR},
      unit_mobile = #{record.unitMobile,jdbcType=VARCHAR},
      voucher_url = #{record.voucherUrl,jdbcType=VARCHAR},
      post = #{record.post,jdbcType=INTEGER},
      addressee = #{record.addressee,jdbcType=VARCHAR},
      addressee_mobile = #{record.addresseeMobile,jdbcType=VARCHAR},
      addressee_province = #{record.addresseeProvince,jdbcType=INTEGER},
      addressee_city = #{record.addresseeCity,jdbcType=INTEGER},
      addressee_area = #{record.addresseeArea,jdbcType=INTEGER},
      recipient_address = #{record.recipientAddress,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      approval = #{record.approval,jdbcType=INTEGER},
      already_amount = #{record.alreadyAmount,jdbcType=DECIMAL}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderInvoice">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    update t_order_invoice
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="rejectReason != null">
        reject_reason = #{rejectReason,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="invoiceType != null">
        invoice_type = #{invoiceType,jdbcType=INTEGER},
      </if>
      <if test="unitName != null">
        unit_name = #{unitName,jdbcType=VARCHAR},
      </if>
      <if test="taxNumber != null">
        tax_number = #{taxNumber,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        amount = #{amount,jdbcType=DECIMAL},
      </if>
      <if test="banks != null">
        banks = #{banks,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="unitAddress != null">
        unit_address = #{unitAddress,jdbcType=VARCHAR},
      </if>
      <if test="invoiceRemarks != null">
        invoice_remarks = #{invoiceRemarks,jdbcType=VARCHAR},
      </if>
      <if test="unitMobile != null">
        unit_mobile = #{unitMobile,jdbcType=VARCHAR},
      </if>
      <if test="voucherUrl != null">
        voucher_url = #{voucherUrl,jdbcType=VARCHAR},
      </if>
      <if test="post != null">
        post = #{post,jdbcType=INTEGER},
      </if>
      <if test="addressee != null">
        addressee = #{addressee,jdbcType=VARCHAR},
      </if>
      <if test="addresseeMobile != null">
        addressee_mobile = #{addresseeMobile,jdbcType=VARCHAR},
      </if>
      <if test="addresseeProvince != null">
        addressee_province = #{addresseeProvince,jdbcType=INTEGER},
      </if>
      <if test="addresseeCity != null">
        addressee_city = #{addresseeCity,jdbcType=INTEGER},
      </if>
      <if test="addresseeArea != null">
        addressee_area = #{addresseeArea,jdbcType=INTEGER},
      </if>
      <if test="recipientAddress != null">
        recipient_address = #{recipientAddress,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="approval != null">
        approval = #{approval,jdbcType=INTEGER},
      </if>
      <if test="alreadyAmount != null">
        already_amount = #{alreadyAmount,jdbcType=DECIMAL},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderInvoice">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri May 17 09:46:50 CST 2019.
    -->
    update t_order_invoice
    set order_no = #{orderNo,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      reject_reason = #{rejectReason,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      invoice_type = #{invoiceType,jdbcType=INTEGER},
      unit_name = #{unitName,jdbcType=VARCHAR},
      tax_number = #{taxNumber,jdbcType=VARCHAR},
      amount = #{amount,jdbcType=DECIMAL},
      banks = #{banks,jdbcType=VARCHAR},
      content = #{content,jdbcType=VARCHAR},
      unit_address = #{unitAddress,jdbcType=VARCHAR},
      invoice_remarks = #{invoiceRemarks,jdbcType=VARCHAR},
      unit_mobile = #{unitMobile,jdbcType=VARCHAR},
      voucher_url = #{voucherUrl,jdbcType=VARCHAR},
      post = #{post,jdbcType=INTEGER},
      addressee = #{addressee,jdbcType=VARCHAR},
      addressee_mobile = #{addresseeMobile,jdbcType=VARCHAR},
      addressee_province = #{addresseeProvince,jdbcType=INTEGER},
      addressee_city = #{addresseeCity,jdbcType=INTEGER},
      addressee_area = #{addresseeArea,jdbcType=INTEGER},
      recipient_address = #{recipientAddress,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      approval = #{approval,jdbcType=INTEGER},
      already_amount = #{alreadyAmount,jdbcType=DECIMAL}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="checkApplyAmount" resultType="java.lang.String">
  select ifnull(sum(amount),0) from t_order_invoice
	where order_no= #{orderNo,jdbcType=VARCHAR}  and status !=4
	<if test="id != null">
	and id != #{id,jdbcType=INTEGER}
	</if>
  </select>
  <select id="financeOrderInvoiceList" resultType="com.goafanti.order.bo.TOrderInvoiceBo">
      	  select a.id,a.unit_name as unitName,a.order_no as orderNo,c.name,b.project_status as projectStatus,a.amount,
     ifnull(d.sumAmount,0) as sumAmount, date_format(a.create_time,'%Y-%m-%d %H:%i:%S')as createTime ,a.status,b.process_status processStatus,
     b.settlement_amount as settlementAmount, (b.total_amount-b.settlement_amount) as notAmount from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no left join admin c on b.salesman_id=c.id
	left join (select order_no,sum(amount)as  sumAmount from t_order_invoice where status =2 group by order_no) d
	on a.order_no=d.order_no left join department e on b.order_dep=e.id 
	where a.status in (1,2) and a.approval in (0,2) 
	<if test="type !=null">
	and a.`type`= #{type,jdbcType=INTEGER} 
	</if>
	<if test="financeId !=null">
	and e.finance_id= #{financeId,jdbcType=VARCHAR}
	</if>
	<if test="orderNo !=null">
	and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="name !=null">
	and c.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>
	<if test="orderDep !=null">
	and b.order_dep= #{orderDep,jdbcType=VARCHAR}
	</if>
	<if test="status !=null">
	and a.status= #{status,jdbcType=INTEGER}
	</if>
	<if test="approval !=null">
	and a.approval= #{approval,jdbcType=INTEGER}
	</if>
	<if test="aDep !=null">
	and b.order_dep in 
	 <foreach collection="aDep" index="index" item="depid" open="(" separator="," close=")">
            #{depid}
        </foreach>
	</if>
	order by a.status ,a.create_time desc
	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  
  <select id="financeOrderInvoiceCount" resultType="java.lang.Integer">
  	select count(*) from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no 
	left join admin c on b.salesman_id=c.id
	 left join department e on b.order_dep=e.id
	where a.status in (1,2) and a.approval in (0,2) 
	<if test="type !=null">
	and a.`type`= #{type,jdbcType=INTEGER} 
	</if>
	<if test="financeId !=null">
	and e.finance_id= #{financeId,jdbcType=VARCHAR}
	</if>
	<if test="orderNo !=null">
	and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="name !=null">
	and c.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>
	<if test="orderDep !=null">
	and b.order_dep= #{orderDep,jdbcType=VARCHAR}
	</if>
	<if test="status !=null">
	and a.status= #{status,jdbcType=INTEGER}
	</if>
	<if test="approval !=null">
	and a.approval= #{approval,jdbcType=INTEGER}
	</if>
	<if test="aDep !=null">
	and b.order_dep in 
	 <foreach collection="aDep" index="index" item="depid" open="(" separator="," close=")">
            #{depid}
        </foreach>
	</if>
  </select>
  
  <select id="salesmanOrderInvoiceList" resultType="com.goafanti.order.bo.TOrderInvoiceBo">
    select a.id ,a.order_no as orderNo,b.contract_no contractNo,a.amount,date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createTime,
	a.reject_reason as  rejectReason,a.status ,a.approval from t_order_invoice a left join t_order_new b 
	on a.order_no=b.order_no where a.status !=4
	<if test="orderNo !=null">
	and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	order by a.create_time desc
	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  
  <select id="salesmanOrderInvoiceCount" resultType="java.lang.Integer">
   select count(*) from t_order_invoice where status !=4
	<if test="orderNo !=null">
	and order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
  </select>
  
  <select id="approvalOrderInvoiceList" resultType="com.goafanti.order.bo.TOrderInvoiceBo">
      	select a.id,a.unit_name as unitName,a.order_no as orderNo,c.name,b.project_status as projectStatus,a.amount,b.process_status processStatus,
     ifnull(d.sumAmount,0) as sumAmount, date_format(a.create_time,'%Y-%m-%d %H:%i:%S')as createTime ,a.status, a.approval,
     b.settlement_amount as settlementAmount, (b.total_amount-b.settlement_amount) as notAmount from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no left join admin c on b.salesman_id=c.id
	left join (select order_no,sum(amount)as  sumAmount from t_order_invoice where status =2 group by order_no) d
	on a.order_no=d.order_no where 1=1
	<if test="status ==null"> 
	and a.status in(1,2)
	</if>
	<if test="status != null">
	 and a.status = #{status,jdbcType=INTEGER}
	</if>
	<if test="approval ==null and special==null">
	 and a.approval in(1,2)
	</if>
	<if test="approval != null">
	 and a.approval = #{approval,jdbcType=INTEGER}
	</if>
	<if test="type !=null">
	and a.type= #{type,jdbcType=INTEGER}
	</if>
	<if test="orderNo !=null">
	and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="name !=null">
	and c.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>
	<if test="userName !=null">
	and a.unit_name like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
	</if>
	<if test="orderDep !=null">
	and b.order_dep= #{orderDep,jdbcType=VARCHAR}
	</if>
	<if test="aDep !=null">
	and c.department_id= #{aDep,jdbcType=VARCHAR}
	</if>
	order by a.approval,a.status,a.create_time desc
	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  
  <select id="approvalOrderInvoiceCount" resultType="java.lang.Integer">
  	   select count(*) from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no left join admin c on b.salesman_id=c.id
	where  1=1
	<if test="status ==null"> 
	and a.status in(1,2)
	</if>
	<if test="status != null">
	 and a.status = #{status,jdbcType=INTEGER}
	</if>
	<if test="approval ==null and special==null">
	 and a.approval in(1,2)
	</if>
	<if test="approval != null">
	 and a.approval = #{approval,jdbcType=INTEGER}
	</if>
	<if test="type !=null">
	and a.type= #{type,jdbcType=INTEGER}
	</if>
	<if test="orderNo !=null">
	and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="name !=null">
	and c.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>
	<if test="userName !=null">
	and a.unit_name like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
	</if>
	<if test="orderDep !=null">
	and b.order_dep= #{orderDep,jdbcType=VARCHAR}
	</if>
	<if test="aDep !=null">
	and c.department_id= #{aDep,jdbcType=VARCHAR}
	</if>
  </select>
  
  <select id="selectByInvoiceDitails" parameterType="java.lang.Integer"  resultType="com.goafanti.order.bo.TOrderInvoiceDetails">
    	select a.id ,a.order_no as orderNo,a.`type`,a.status,a.reject_reason as rejectReason,a.remarks,a.invoice_type as invoiceType,
	a.unit_name as unitName,a.tax_number as taxNumber,a.amount,a.banks,a.content,a.unit_address as unitAddress,
	a.invoice_remarks as invoiceRemarks,a.unit_mobile as unitMobile,a.voucher_url as voucherUrl ,a.post,a.addressee,
	a.addressee_area as addresseeArea,a.addressee_city as addresseeCity,a.addressee_province as addresseeProvince,
	a.addressee_mobile as addresseeMobile,a.recipient_address as recipientAddress,a.create_time,a.update_time,a.approval,
	a.already_amount as alreadyAmount,b.contract_no as contractNo from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no
    where id = #{id,jdbcType=INTEGER}
  </select>
  
  <select id="getInvoiceDetails" parameterType="java.lang.String"  resultType="com.goafanti.order.bo.TOrderInvoiceDetails">
    	select a.id ,a.order_no as orderNo,a.`type`,a.status,a.reject_reason as rejectReason,a.remarks,a.invoice_type as invoiceType,
	a.unit_name as unitName,a.tax_number as taxNumber,a.amount,a.banks,a.content,a.unit_address as unitAddress,
	a.invoice_remarks as invoiceRemarks,a.unit_mobile as unitMobile,a.voucher_url as voucherUrl ,a.post,a.addressee,
	a.addressee_area as addresseeArea,a.addressee_city as addresseeCity,a.addressee_province as addresseeProvince,
	a.addressee_mobile as addresseeMobile,a.recipient_address as recipientAddress,a.create_time,a.update_time,a.approval,
	a.already_amount as alreadyAmount,b.contract_no as contractNo from t_order_invoice a 
	left join t_order_new b on a.order_no=b.order_no
    where a.order_no= #{orderNo,jdbcType=VARCHAR}
    and a.create_time=(select max(create_time) from t_order_invoice where order_no= #{orderNo,jdbcType=VARCHAR}) 
  </select>
  <select id="conutAmountByOrderNo"  resultType="java.math.BigDecimal">
  select ifnull(sum(a.amount),0) amount from t_order_invoice a
	where a.status=2 and a.order_no= #{orderNo,jdbcType=VARCHAR}
  </select>
  <select id="selectByOrderNo" resultType="com.goafanti.order.bo.InvoiceBo">
  select date_format(a.create_time,'%Y-%m-%d %H:%i:%S') createTime,a.amount from t_order_invoice a
where a.status=2 and a.order_no=  #{orderNo,jdbcType=VARCHAR}
  </select>
</mapper>