<?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="pwc.taxtech.atms.dao.CitSalaryAdvanceMapper">
  <sql id="QueryCondition">
    1 = 1
        <if test="@com.github.pagehelper.util.StringUtil@isNotEmpty(citPreviewSalaryAdvance.period)">
          AND period= #{citPreviewSalaryAdvance.period,jdbcType=VARCHAR}
        </if>
    <if test="citPreviewSalaryAdvance.poSubjectName!=null and citPreviewSalaryAdvance.poSubjectName != '' ">
      AND po_subject_name &gt;= #{citPreviewSalaryAdvance.poSubjectName,jdbcType=INTEGER}
    </if>
    <if test="citPreviewSalaryAdvance.periodStart!=null and citPreviewSalaryAdvance.periodStart!= '' and citPreviewSalaryAdvance.periodEnd!= null and citPreviewSalaryAdvance.periodEnd!= ''">
      AND period  between  ${citPreviewSalaryAdvance.periodStart} and ${citPreviewSalaryAdvance.periodEnd}
    </if>
    <if test="citPreviewSalaryAdvance.periodStart == null and citPreviewSalaryAdvance.periodStart != '' and citPreviewSalaryAdvance.periodEnd != null and citPreviewSalaryAdvance.periodEnd != ''">
      AND period  &lt; ${citPreviewSalaryAdvance.periodEnd} or period = ${citPreviewSalaryAdvance.periodEnd}
    </if>
    <if test="citPreviewSalaryAdvance.periodStart != null and citPreviewSalaryAdvance.periodStart != '' and citPreviewSalaryAdvance.periodEnd == null and citPreviewSalaryAdvance.periodEnd  != '' ">
      AND period  &gt; ${citPreviewSalaryAdvance.periodStart} or period = ${citPreviewSalaryAdvance.periodStart}
    </if>
  </sql>

  <insert id="insertBatch" parameterType="java.util.List">
    insert into cit_salary_advance
    (<include refid="Base_Column_List"/>)
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
        <choose>
          <when test="item.id != null">#{item.id,jdbcType=BIGINT},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.organizationId != null">#{item.organizationId,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.projectId != null">#{item.projectId,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.period != null">#{item.period,jdbcType=INTEGER},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.source != null">#{item.source,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.poNo != null">#{item.poNo,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.poRow != null">#{item.poRow,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.poCreateTime != null">#{item.poCreateTime,jdbcType=TIMESTAMP},</when>
          <otherwise>CURRENT_TIMESTAMP,</otherwise>
        </choose>
        <choose>
          <when test="item.ladingBillPerson != null">#{item.ladingBillPerson,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.purchasePerson != null">#{item.purchasePerson,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.poSubjectCode != null">#{item.poSubjectCode,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.poSubjectName != null">#{item.poSubjectName,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.costCenterCode != null">#{item.costCenterCode,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.costCenter != null">#{item.costCenter,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.supplier != null">#{item.supplier,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.item != null">#{item.item,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.standardMoney != null">#{item.standardMoney,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.currency != null">#{item.currency,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.orderAmount != null">#{item.orderAmount,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.executedServiceSchedule != null">#{item.executedServiceSchedule,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.coupaTotalAccept != null">#{item.coupaTotalAccept,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.advance != null">#{item.advance,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.unexecutedServiceSchedule != null">#{item.unexecutedServiceSchedule,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.approvedStandardInvoiceAmount != null">#{item.approvedStandardInvoiceAmount,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
         <choose>
          <when test="item.paidInvoiceAmount != null">#{item.paidInvoiceAmount,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.usableInvoiceAmount != null">#{item.usableInvoiceAmount,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.usableBalance != null">#{item.usableBalance,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
         <choose>
          <when test="item.advanceWriteOff != null">#{item.advanceWriteOff,jdbcType=DECIMAL},</when>
          <otherwise>0,</otherwise>
        </choose>
        <choose>
          <when test="item.subjectCode != null">#{item.subjectCode,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.subjectDescription != null">#{item.subjectDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.auxiliarySubject != null">#{item.auxiliarySubject,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.auxiliarySubjectDescription != null">#{item.auxiliarySubjectDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.profitCenter != null">#{item.profitCenter,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.profitCenterDescription != null">#{item.profitCenterDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.product != null">#{item.product,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.productDescription != null">#{item.productDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.project != null">#{item.project,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.projectDescription != null">#{item.projectDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.company != null">#{item.company,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.companyDescription != null">#{item.companyDescription,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.segment1 != null">#{item.segment1,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.segment1Description != null">#{item.segment1Description,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.segment2 != null">#{item.segment2,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.segment2Description != null">#{item.segment2Description,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.createdBy != null">#{item.createdBy,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.updatedBy != null">#{item.updatedBy,jdbcType=VARCHAR},</when>
          <otherwise>'',</otherwise>
        </choose>
        <choose>
          <when test="item.createTime != null">#{item.createTime,jdbcType=TIMESTAMP},</when>
          <otherwise>CURRENT_TIMESTAMP,</otherwise>
        </choose>
        <choose>
          <when test="item.updateTime != null">#{item.updateTime,jdbcType=TIMESTAMP},</when>
          <otherwise>CURRENT_TIMESTAMP,</otherwise>
        </choose>
        <choose>
          <when test="item.month != null">#{item.month,jdbcType=INTEGER},</when>
          <otherwise>0,</otherwise>
        </choose>
      </trim>
    </foreach>;
    SELECT 1 FROM DUAL;
  </insert>



  <select id ="selectByCondition" parameterType="pwc.taxtech.atms.entity.CitSalaryAdvance" resultType="pwc.taxtech.atms.entity.CitSalaryAdvance">
    select
    organization_id  organizationId,
    project_id projectId,
    period ,
    source,
    po_no  poNo,
    po_subject_code poSubjectCode,
    po_subject_name poSubjectName,
    advance advance,
    approved_standard_invoice_amount approvedStandardInvoiceAmount,
    created_by createdBy,
    create_time createTime,
    remark,
    credit_prepaid_accounts as creditPrepaidAccounts,
    debit_advance_gene as debitAdvanceGene,

    ledger_id ledgerId,
    exchange_rate exchangeRate,
    reclassify_amount reclassifyAmount ,
    check_one checkOne,
    advance_write_off advanceWriteOff,
    usable_balance usableBalance,
    usable_invoice_amount usableInvoiceAmount,
    paid_invoice_amount paidInvoiceAmount,
    approved_standard_invoice_amount approvedStandardInvoiceAmount,
    unexecuted_service_schedule unexecutedServiceSchedule,
    advance advance ,
    coupa_total_accept coupaTotalAccept,
    executed_service_schedule executedServiceSchedule,
    order_amount orderAmount,
    currency currency,
    standard_money standardMoney,
    item item
    supplier supplier,
    cost_center costCenter,
    cost_center_code costCenterCode,
    po_subject_code poSubjectCode,
    purchase_person  purchasePerson,
    lading_bill_person ladingBillPerson,
    po_row poRow,
    po_no poNo,
    po_create_time poCreateTime,
    from cit_salary_advance
    WHERE
    <include refid="QueryCondition"/>
  </select>
</mapper>