TreatySoaInfoMapper.xml 20.3 KB
<?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="cn.com.polysoft.template.dao.TreatySoaInfoMapper" >

    <insert id="saveTreatySoaInfo" keyProperty="recordId" useGeneratedKeys="true" parameterType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        insert into treaty_soa_info(
        record_id,
        treaty_name,
        treaty_no,
        uw_year,
        treaty_period_start,
        treaty_period_end,
        account_category,
        account_no,
        account_period,
        class_code,
        account_currency,
        reins_code,
        reins_name,
        vat_flag,
        your_share,
        ri_premium,
        ri_commission,
        tax,
        fee_of_uw,
        fee_of_loss,
        paid_loss,
        cash_loss,
        survey_fee,
        premium_reserves_petained,
        loss_reserves_retained,
        profit_commission,
        interest,
        engineering_fee,
        brokerage,
        vat,
        vat_surtax,
        vat_deducion,
        brokerage_vat,
        balance,
        outstanding_losses,
        exchangerate_cny,
        premium_cny,
        vat_cny,
        issue_date,
        remarks,
        creator,
        authorizer,
        create_time,
        check_status,
        send_date,
        business_treaty_no,
        business_treaty_name,
        serial_number,
        batch_id,
        itemid,
        fail_reason,
        settle_date,
        other_itemid
        ) values (
          #{recordId},
          #{treatyName},
          #{treatyNo},
          #{uwYear},
          #{treatyPeriodStart},
          #{treatyPeriodEnd},
          #{accountCategory},
          #{accountNo},
          #{accountPeriod},
          #{classCode},
          #{accountCurrency},
          #{reinsCode},
          #{reinsName},
          #{vatFlag},
          #{yourShare},
          #{riPremium},
          #{riCommission},
          #{tax},
          #{feeOfUw},
          #{feeOfLoss},
          #{paidLoss},
          #{cashLoss},
          #{surveyFee},
          #{premiumReservesPetained},
          #{lossReservesRetained},
          #{profitCommission},
          #{interest},
          #{engineeringFee},
          #{brokerage},
          #{vat},
          #{vatSurtax},
          #{vatDeducion},
          #{brokerageVat},
          #{balance},
          #{outstandingLosses},
          #{exchangerateCny},
          #{premiumCny},
          #{vatCny},
          #{issueDate},
          #{remarks},
          #{creator},
          #{authorizer},
          #{createTime},
          #{checkStatus},
          #{sendDate},
          #{businessTreatyNo},
          #{businessTreatyName},
          #{serialNumber},
          #{batchId},
          #{itemid},
          #{failReason},
          #{settleDate},
          #{otherItemid}
        )
    </insert>

    <select id="queryByCondition" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select * from treaty_soa_info t where 1 = 1 and t.check_status = #{checkStatus} and send_date = #{checkDate} and t.bill_num is null
    </select>

    <select id="queryByCondition2" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select * from treaty_soa_info t where 1 = 1 and t.check_status = #{checkStatus} and t.record_id = #{billId} and t.bill_num is null
    </select>

    <select id="queryCheckData" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select * from treaty_soa_info t where 1 = 1 and t.check_status = #{checkStatus} and send_date = #{checkDate} and t.account_currency = #{accountCurrency}
    </select>

    <select id="queryCurrency" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select t.account_currency from treaty_soa_info t where t.check_status = #{checkStatus} and t.send_date = #{checkDate} group by t.account_currency
    </select>
    <select id="queryCurrency3" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select t.batch_id from treaty_soa_info t where  t.send_date = #{checkDate}
    </select>

    <update id="updateFailReason">
        update treaty_soa_info set fail_reason = #{failReason},check_status = #{checkStatus} where serial_number = #{serialNumber}
    </update>
    <update id="updateBillNum">
        update treaty_soa_info set bill_num = #{billNum},check_status = #{checkStatus},submit_business_time=#{submitTime} where serial_number = #{serialNumber}
    </update>

    <select id="queryCountByCheckDate" parameterType="String" resultType="int">
        select count(1) num from treaty_soa_info where send_date = #{checkDate} and check_status = #{checkStatus}
    </select>

    <!--<update id="updateCheckStatus">-->
        <!--update treaty_soa_info set check_status = #{checkStatus},check_time = now() where record_id = #{recordId}-->
    <!--</update>-->
    <update id="updateCheckStatus">
        update treaty_soa_info set check_status = #{checkStatus},fail_reason = #{msg},check_time = #{timestamp} where record_id = #{recordId}
    </update>

    <select id="querySumByCurrencyAndCheckDate" resultType="cn.com.polysoft.template.dto.property.CheckDetailInfoDTO">
        select t.currency,sum(cast(t.balance as numeric)) balance,sum(cast(t.ri_premium as numeric)) ri_premium,
        sum(t.ri_commission) ri_commission,sum(t.tax) tax,sum(t.fee_of_uw) fee_of_uw,
        sum(t.fee_of_loss) fee_of_loss,sum(t.paid_loss) paid_loss,sum(t.cash_loss) cash_loss,
        sum(t.survey_fee) survey_fee,sum(t.premium_reserves_retained) premium_reserves_retained,
        sum(t.loss_reserves_retained) loss_reserves_retained,sum(t.profit_commission) profit_commission,
        sum(t.interest) interest,sum(t.engineering_fee) engineering_fee,sum(t.brokerage) brokerage,
        sum(t.vat) vat,sum(t.vat_surtax) vat_surtax,sum(t.vat_deducion) vat_deducion,sum(t.brokerage_vat) brokerage_vat,
        sum(t.outstanding_losses) outstanding_losses
        from installment_details t
        inner join treaty_soa_info a on t.treaty_fac_id = a.record_id and t.bill_type = #{billType} and t.currency_type = #{currencyType}
        where a.send_date = #{checkDate} and t.currency = #{currency} and (a.check_status = #{checkStatusInit} or a.check_status = #{checkStatusFail})
        group by t.currency
    </select>
    <select id="querySumByCurrencyAndCheckDateOfTreaty" resultType="cn.com.polysoft.template.dto.property.CheckDetailInfoDTO">
        SELECT s.balance FROM treaty_soa_info s
            WHERE
             s.send_date = #{checkDate}
            AND s.account_currency = #{currency}
            AND (
             s.check_status = #{checkStatusInit}
             OR s.check_status = #{checkStatusFail}
            )
    </select>
    <select id="selectTreatySoaInfo" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select * from treaty_soa_info t where t.check_status = #{checkStatus}
    </select>
    <select id="queryListByCondition" parameterType="cn.com.polysoft.template.dto.property.QueryListDTO" resultType="cn.com.polysoft.template.vo.PropertyDataListVO">
        select t.record_id,t.batch_id,t.account_no,t.treaty_no,t.bill_num,t.business_treaty_no,
        <!--case when t.account_category = '01' then '季度账单'
        when t.account_category = '02' then '特殊账单'
        when t.account_category = '03' then '超赔预付保费账单'
        when t.account_category = '04' then '超赔调整保费账单'
        when t.account_category = '05' then '超赔赔款账单'
        when t.account_category = '06' then '损失分担账单'
        when t.account_category = '07' then '关门账单' else '' end--> account_category,
        '合约账单' account_type,to_char(t.create_time,'yyyy-MM-dd') create_time,to_char(t.check_time,'yyyy-MM-dd') check_time,
      <!--case when t.check_status = '-1' then '财险账单接收失败'
        when t.check_status = '0' then '财险账单接收成功'
        when t.check_status = '1' then '核查成功'
        when t.check_status = '2' then '核查失败'    to_date(to_char(t.submit_business_time,'yyyy-MM-dd'),'yyyy-MM-dd')
        when t.check_status = '3' then '业务系统处理成功'
        when t.check_status = '4' then '业务系统处理失败' else '' end--> fail_reason check_status,
        t.check_status check_status_code,to_char(t.submit_business_time,'yyyy-MM-dd HH24:mm:ss')submit_business_time
        from treaty_soa_info t
        <where>
            <if test="batchId != null and batchId != ''">and t.batch_id like #{batchId}</if>
            <if test="treatyNo != null and treatyNo != ''">and t.treaty_no like #{treatyNo}</if>
            <if test="businessTreatyNo != null and businessTreatyNo != ''">and t.business_treaty_no like #{businessTreatyNo}</if>
            <if test="accountNo != null and accountNo != ''">and t.account_no like #{accountNo}</if>
            <if test="currency != null and currency != ''">and t.account_currency = #{currency}</if>
            <if test="accountCategory != null and accountCategory != ''">and t.account_category = #{accountCategory}</if>
            <if test="checkTimeStart != null and checkTimeStart != ''">and to_date(to_char(t.check_time,'yyyy-MM-dd'),'yyyy-MM-dd') >= to_date(#{checkTimeStart},'yyyy-MM-dd')</if>
            <if test="checkTimeEnd != null and checkTimeEnd != ''">and to_date(to_char(t.check_time,'yyyy-MM-dd'),'yyyy-MM-dd') &lt;= to_date(#{checkTimeEnd},'yyyy-MM-dd')</if>
            <if test="checkStatus != null and checkStatus != ''">and t.check_status = #{checkStatus}</if>
            <if test="pageType==1 and checkStatus == null ">and t.check_status in ('3','4')</if>
            <if test="pageType==1 and checkStatus == '' ">and t.check_status in ('3','4')</if>
            <if test="createTimeStart != null and createTimeStart != ''">and to_date(to_char(t.create_time,'yyyy-MM-dd'),'yyyy-MM-dd') >= to_date(#{createTimeStart},'yyyy-MM-dd')</if>
            <if test="createTimeEnd != null and createTimeEnd != ''">and to_date(to_char(t.create_time,'yyyy-MM-dd'),'yyyy-MM-dd') &lt;= to_date(#{createTimeEnd},'yyyy-MM-dd')</if>
            <if test="billNum != null and billNum != ''">and t.bill_num like #{billNum}</if>
            <if test="submitBusinessTimeStart != null and submitBusinessTimeStart != ''">and to_date(to_char(t.submit_business_time,'yyyy-MM-dd'),'yyyy-MM-dd') >= to_date(#{submitBusinessTimeStart},'yyyy-MM-dd')</if>
            <if test="submitBusinessTimeEnd != null and submitBusinessTimeEnd != ''">and to_date(to_char(t.submit_business_time,'yyyy-MM-dd'),'yyyy-MM-dd') &lt;= to_date(#{submitBusinessTimeEnd},'yyyy-MM-dd')</if>
        </where>
        order by t.create_time desc,t.account_no
    </select>

    <select id="getFailReasonByCondition" resultType="string">
        select t.fail_reason from treaty_soa_info t where t.batch_id = #{batchId} and t.account_no = #{accountNo}
    </select>

    <select id="getInfoById" resultType="cn.com.polysoft.template.vo.TreatySoaInfoVO">
        select t.record_id,t.batch_id,'合约账单' account_type,
        case when t.account_category = '01' then '季度账单'
        when t.account_category = '02' then '特殊账单'
        when t.account_category = '03' then '超赔预付保费账单'
        when t.account_category = '04' then '超赔调整保费账单'
        when t.account_category = '05' then '超赔赔款账单'
        when t.account_category = '06' then '损失分担账单'
        when t.account_category = '07' then '关门账单' else '' end account_category_name,
        t.account_category,t.itemid,
        t.account_no,t.uw_year,t.account_period,t.account_currency,t.treaty_no,
        t.treaty_name,t.class_code,t.treaty_period_start,t.treaty_period_end,
        t.creator,t.vat_flag,t.your_share,t.authorizer,t.issue_date,
        to_char(t.create_time,'yyyy-MM-dd') create_time,to_char(t.check_time,'yyyy-MM-dd') check_time,
        to_char(t.submit_business_time,'yyyy-MM-dd') submit_business_time,
        t.ri_premium,t.vat,t.balance,t.exchangerate_cny,t.premium_cny,t.vat_cny,t.outstanding_losses,
        t.ri_commission,t.paid_loss,t.premium_reserves_petained,t.fee_of_uw,t.cash_loss,
        t.loss_reserves_retained,t.fee_of_loss,t.tax,t.remarks,t.profit_commission,t.interest,
        t.engineering_fee,t.survey_fee,t.business_treaty_no,t.business_treaty_name,b.startdate myPeriodStart,
        b.enddate myPeriodEnd,t.settle_date,t.bill_num
        from treaty_soa_info t
		left join inwardtreatyinfo b on t.business_treaty_no = b.treatyid
        where t.record_id = #{recordId}
    </select>

    <update id="updateTreatyInfo" parameterType="cn.com.polysoft.template.dto.property.TreatySoaInfoDTO">
        update treaty_soa_info
        <set>
            <!--<if test="treatyName != null" and treatyName != ''>treaty_name = #{treatyName},</if>-->
            <!--<if test="treatyName == null or treatyName == ''">treaty_name = null,</if>-->
            <!--<if test="treatyNo != null">treaty_no = #{treatyNo},</if>-->
            <if test="uwYear != null and uwYear != ''">uw_year = #{uwYear},</if>
            <if test="uwYear == null or uwYear == ''">uw_year = #{uwYear},</if>
            <!--<if test="treatyPeriodStart != null">treaty_period_start = #{treatyPeriodStart},</if>-->
            <!--<if test="treatyPeriodEnd != null">treaty_period_end = #{treatyPeriodEnd},</if>-->
            <if test="accountCategory != null and accountCategory != ''">account_category = #{accountCategory},</if>
            <if test="accountCategory == null or accountCategory == ''">account_category = null,</if>
            <!--<if test="accountNo != null">account_no = #{accountNo},</if>-->
            <if test="accountPeriod != null and accountPeriod != ''">account_period = #{accountPeriod},</if>
            <if test="accountPeriod == null or accountPeriod == ''">account_period = null,</if>
            <!--<if test="classCode != null">class_code = #{classCode},</if>-->
            <if test="accountCurrency != null and accountCurrency != ''">account_currency = #{accountCurrency},</if>
            <if test="accountCurrency == null or accountCurrency == ''">account_currency = null,</if>
            <!--<if test="reinsCode != null">reins_code = #{reinsCode},</if>-->
            <!--<if test="reinsName != null">reins_name = #{reinsName},</if>-->
            <if test="vatFlag != null and vatFlag != ''">vat_flag = #{vatFlag},</if>
            <if test="vatFlag == null or vatFlag == ''">vat_flag = null,</if>
            <if test="yourShare != null or yourShare == null">your_share = #{yourShare},</if>
            <if test="riPremium != null or riPremium == null">ri_premium = #{riPremium},</if>
            <if test="riCommission != null or riCommission == null">ri_commission = #{riCommission},</if>
            <if test="tax != null or tax == null">tax = #{tax},</if>
            <if test="feeOfUw != null or feeOfUw == null">fee_of_uw = #{feeOfUw},</if>
            <if test="feeOfLoss != null or feeOfLoss == null">fee_of_loss = #{feeOfLoss},</if>
            <if test="paidLoss != null or paidLoss == null">paid_loss = #{paidLoss},</if>
            <if test="cashLoss != null or cashLoss == null">cash_loss = #{cashLoss},</if>
            <if test="surveyFee != null or surveyFee == null">survey_fee = #{surveyFee},</if>
            <if test="premiumReservesPetained != null or premiumReservesPetained == null">premium_reserves_petained = #{premiumReservesPetained},</if>
            <if test="lossReservesRetained != null or lossReservesRetained == null">loss_reserves_retained = #{lossReservesRetained},</if>
            <if test="profitCommission != null or profitCommission == null">profit_commission = #{profitCommission},</if>
            <if test="engineeringFee != null or engineeringFee == null">engineering_fee = #{engineeringFee},</if>
            <!--<if test="brokerage != null">brokerage = #{brokerage},</if>-->
            <if test="vat != null or vat == null">vat = #{vat},</if>
            <!--<if test="vatSurtax != null">vat_surtax = #{vatSurtax},</if>-->
            <!--<if test="vatDeducion != null">vat_deducion = #{vatDeducion},</if>-->
            <!--<if test="brokerageVat != null">brokerage_vat = #{brokerageVat},</if>-->
            <if test="balance != null or balance == null">balance = #{balance},</if>
            <if test="outstandingLosses != null or outstandingLosses == null">outstanding_losses = #{outstandingLosses},</if>
            <if test="exchangerateCny != null or exchangerateCny == null">exchangerate_cny = #{exchangerateCny},</if>
            <if test="premiumCny != null or premiumCny == null">premium_cny = #{premiumCny},</if>
            <if test="vatCny != null or vatCny == null">vat_cny = #{vatCny},</if>
            <!--<if test="issueDate != null">issue_date = #{issueDate},</if>-->
            <if test="remarks != null and remarks != ''">remarks = #{remarks},</if>
            <if test="remarks == null or remarks == ''">remarks = null,</if>
            <!--<if test="creator != null">creator = #{creator},</if>-->
            <!--<if test="authorizer != null">authorizer = #{authorizer},</if>-->
            <if test="settleDate != null and settleDate != ''">settle_date = #{settleDate},</if>
            <if test="settleDate == null or settleDate == ''">settle_date = null,</if>
            <if test="itemid != null and itemid !=''">itemid = #{itemid},</if>
            <if test="itemid == null or itemid == ''">itemid = null,</if>
            <if test="interest != null or interest == null">interest = #{interest},</if>
            <if test="businessTreatyNo != null and businessTreatyNo != ''">business_treaty_no = #{businessTreatyNo},</if>
            <if test="businessTreatyNo == null or businessTreatyNo == ''">business_treaty_no = null,</if>
            <if test="businessTreatyName != null and businessTreatyName != ''">business_treaty_name = #{businessTreatyName},</if>
            <if test="businessTreatyName == null or businessTreatyName == ''">business_treaty_name = null,</if>
        </set>
        where record_id = #{recordId}
    </update>

    <select id="queryBatchId" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select t.* from treaty_soa_info t where t.account_no=#{accountNo}
    </select>

    <select id="getByRecordId" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select * from treaty_soa_info t where t.record_id = #{recordId}
    </select>
    <select id="getStatusByBatchId" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select check_status from treaty_soa_info t where t.batch_id = #{batchId} group by check_status
    </select>
    <select id="getfailReasonByBatchIdStatus" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select t.fail_reason from treaty_soa_info t where t.check_status = #{checkStatus} and t.batch_id = #{batchId} GROUP by t.fail_reason
    </select>

    <select id="getfailData" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        SELECT * FROM treaty_soa_info s WHERE (s.ri_premium is null or s.ri_premium = '0')
            AND (s.ri_commission is null or s.ri_commission = '0')
            AND (s.tax is null or s.tax = '0')
            AND (s.fee_of_uw is null or s.fee_of_uw = '0')
            AND (s.fee_of_loss is null or s.fee_of_loss = '0')
            AND (s.paid_loss is null or s.paid_loss = '0')
            AND (s.cash_loss is null or s.cash_loss = '0')
            AND (s.survey_fee is null or s.survey_fee = '0')
            AND (s.premium_reserves_petained is null or s.premium_reserves_petained = '0')
            AND (s.loss_reserves_retained is null or s.loss_reserves_retained = '0')
            AND (s.profit_commission is null or s.profit_commission = '0')
            AND (s.interest is null or s.interest = '0')
            AND (s.engineering_fee is null or s.engineering_fee = '0')
            AND (s.brokerage is null or s.brokerage = '0')
            AND (s.vat is null or s.vat = '0')
            AND (s.vat_surtax is null or s.vat_surtax = '0')
            AND (s.vat_deducion is null or s.vat_deducion = '0')
            AND (s.brokerage_vat is null or s.brokerage_vat = '0')
            AND (s.brokerage_vat is null or s.brokerage_vat = '0')

            AND s.balance='0'
            AND s.outstanding_losses!='0'
            <!--AND s.treaty_no !='OP201905'-->
    </select>
    <select id="getStatusListByBatchId" resultType="cn.com.polysoft.template.entity.TreatySoaInfoEntity">
        select check_status from treaty_soa_info t where t.batch_id = #{batchId} GROUP BY check_status
    </select>
</mapper>