<?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.ruoyi.hywz.mapper.AdsMatHyxtStampTaxContractInvoiceDMapper">
	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="adsMatHyxtStampTaxContractInvoiceDMap" type="com.ruoyi.hywz.entity.AdsMatHyxtStampTaxContractInvoiceD">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="warningType" column="warning_type"/>
        <result property="warningStatusDesc" column="warning_status_desc"/>
        <result property="warningLevel" column="warning_level"/>
        <result property="warningTime" column="warning_time"/>
        <result property="warningRemark" column="warning_remark"/>
    </resultMap>

    <select id="queryWarningListNew" parameterType="com.ruoyi.hywz.entity.AdsMatHyxtStampTaxContractInvoiceD"
            resultType="com.ruoyi.hywz.entity.AdsMatHyxtStampTaxContractInvoiceD">

        select
            ci.id,
            wr.rule,
            wr.level,
            wr.description,
            ci.warning_status_desc warningStatusDesc,
            ci.warning_time warningTime,
            ci.warning_remark warningRemark
        from ads_mat_hyxt_stamp_tax_contract_invoice_d ci
                 left join ads_mat_hyxt_stamp_tax_warning_rule_d wr on wr.warning_type = ci.warning_type
        where business_id = #{businessId}

    </select>


    <delete id="deleteErrorData">
        delete from ads_mat_hyxt_stamp_tax_contract_invoice_d a
        where exists(
                      select 1 from(
                                       select
                                           id,
                                           row_number() over(partition by business_id,warning_type order by warning_status_desc asc,warning_time desc,id desc) as rn
                                       from ads_mat_hyxt_stamp_tax_contract_invoice_d
                                   ) b where a.id=b.id and b.rn > 1
                  )
    </delete>


    <select id="findContractIdByStatu" resultType="String">
        select
            a.id
        from ads_mat_hyxt_stamp_tax_contract_d a
        inner join ads_mat_hyxt_stamp_tax_contract_invoice_d b on a.id=b.business_id
        where b.warning_status_desc='未处理'
    </select>

    <select id="findInvoiceIdByStatu" resultType="String">
        select
            a.id
        from ads_mat_hyxt_stamp_tax_invoice_d a
        inner join ads_mat_hyxt_stamp_tax_contract_invoice_d b on a.id=b.business_id
        where b.warning_status_desc='未处理'
    </select>
</mapper>
