<?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.dxhy.extend.dao.ViolationLogDao">

    <select id="selectViolation" resultType="com.dxhy.extend.model.ViolationLogModel">
        select DISTINCT t.id,t.xf_tax_no,t.penalize_date,t.break_law_type,t.break_law_method,t.input_date,d.xf_name
        from t_dx_violation_taxno d right join t_dx_violation_log t on d.xf_tax_no=t.xf_tax_no
        where d.company=#{company}
        <if test="xfName !=null and xfName!=''">
            and d.xf_name like concat('%',concat(#{xfName},'%'))
        </if>
    </select>
    <select id="selectRiskSupplier" resultType="com.dxhy.extend.model.RiskSupplierVO">
        select xf_tax_no taxNo,xf_name taxName,count(1) invoiceNum,sum(total_amount) invoiceAmount
        from t_dx_record_invoice
        where illegal_supplier = '1'
        and DATE_FORMAT(create_date,'%Y-%m-%d') BETWEEN '2000-01-01' and #{currentTime}
        and gf_tax_no in
        <foreach collection="gfsh" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="taxNo!=null and taxNo!=''">
            and (xf_tax_no like concat('%',concat(#{taxNo},'%')) or xf_name like concat('%',concat(#{taxNo},'%')))
        </if>
        group by xf_tax_no
    </select>
    <select id="selectRiskSupplierCount" resultType="com.dxhy.extend.model.RiskSupplierVO">
        select count(1) supplierNum,sum(a.invoiceNum) invoiceNum,sum(a.invoiceAmount) invoiceAmount
        from (
        select xf_tax_no taxNo,xf_name taxName,count(1) invoiceNum,sum(total_amount) invoiceAmount
        from t_dx_record_invoice
        where illegal_supplier = '1'
        and DATE_FORMAT(create_date,'%Y-%m-%d') BETWEEN '2000-01-01' and #{currentTime}
        and gf_tax_no in
        <foreach collection="gfsh" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="taxNo!=null and taxNo!=''">
            and (xf_tax_no like concat('%',concat(#{taxNo},'%')) or xf_name like concat('%',concat(#{taxNo},'%')))
        </if>
        group by xf_tax_no
        ) a

    </select>
    <select id="selectRiskSupplierInfo" resultType="com.dxhy.extend.model.ViolationLogModel">
        select *
        from t_dx_violation_log
        where xf_tax_no = #{taxNo}
    </select>
    <select id="selectRiskInvoice" resultType="com.dxhy.extend.entity.ExtTdxRecordInvoice">
        select * from t_dx_record_invoice
        where (glzt in ('1','2') or invoice_status !='0' or illegal_supplier='1' or illegal_enterprise='1')
        and gf_tax_no in
        <foreach collection="gfsh" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="searchKey!=null and searchKey!=''">
            and (invoice_no like concat('%',concat(#{searchKey},'%'))
            or invoice_code like concat('%',concat(#{searchKey},'%')) or xf_name like
            concat('%',concat(#{searchKey},'%')))
        </if>
        <if test="invoiceDateStart!=null and invoiceDateStart!='' and invoiceDateEnd !=null and invoiceDateEnd !=''">
            and invoice_date between #{invoiceDateStart} and #{invoiceDateEnd}
        </if>
        <if test="invoiceType !=null and invoiceType !=''">
            and invoice_type = #{invoiceType}
        </if>
        <if test="invoiceStatus !=null and invoiceStatus !=''">
            and invoice_status = #{invoiceStatus}
        </if>
        <if test="glzt!=null and glzt !='' and glzt!='0'.toString()">
            and glzt = #{glzt}
        </if>
        <if test="glzt!=null and glzt !='' and glzt=='0'.toString()">
            and (glzt ='0' or glzt is null or glzt = '')
        </if>
        <if test="rzzt!=null and rzzt!=''">
            and rzh_yesorno = #{rzzt}
        </if>
        <if test="rzlx!=null and rzlx!=''">
            and bdk_status = #{rzlx}
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='1'.toString()">
            and illegal_supplier = '1'
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='2'.toString()">
            and invoice_status != '0'
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='3'.toString()">
            and glzt in ('1','2')
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='4'.toString()">
            and illegal_enterprise = '1'
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
        order by invoice_date desc
    </select>
    <select id="selectRiskInvoiceCount" resultType="com.dxhy.extend.entity.ExtTdxRecordInvoice">
        select count(1) id,sum(invoice_amount) invoiceAmount,sum(tax_amount) taxAmount from t_dx_record_invoice
        where (glzt in ('1','2') or invoice_status !='0' or illegal_supplier='1' or illegal_enterprise='1')
        and gf_tax_no in
        <foreach collection="gfsh" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="searchKey!=null and searchKey!=''">
            and (invoice_no like concat('%',concat(#{searchKey},'%'))
            or invoice_code like concat('%',concat(#{searchKey},'%')) or xf_name like
            concat('%',concat(#{searchKey},'%')))
        </if>
        <if test="invoiceDateStart!=null and invoiceDateStart!='' and invoiceDateEnd !=null and invoiceDateEnd !=''">
            and invoice_date between #{invoiceDateStart} and #{invoiceDateEnd}
        </if>
        <if test="invoiceType !=null and invoiceType !=''">
            and invoice_type = #{invoiceType}
        </if>
        <if test="invoiceStatus !=null and invoiceStatus !=''">
            and invoice_status = #{invoiceStatus}
        </if>
        <if test="glzt!=null and glzt !='' and glzt!='0'.toString()">
            and glzt = #{glzt}
        </if>
        <if test="glzt!=null and glzt !='' and glzt=='0'.toString()">
            and (glzt ='0' or glzt is null or glzt = '')
        </if>
        <if test="rzzt!=null and rzzt!=''">
            and rzh_yesorno != #{rzzt}
        </if>
        <if test="rzlx!=null and rzlx!=''">
            and bdk_status = #{rzlx}
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='1'.toString()">
            and illegal_supplier = '1'
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='2'.toString()">
            and invoice_status != '0'
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='3'.toString()">
            and glzt in ('1','2')
        </if>
        <if test="fxlx!=null and fxlx!='' and fxlx=='4'.toString()">
            and illegal_enterprise = '1'
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and invoice_source = #{invoiceSource}
        </if>
    </select>
    <select id="selectEnterpriseInfo" resultType="com.dxhy.extend.model.EnterpriseInfoModel">
        select *
        from t_dx_enterprise_control_rules
        where uuid = #{uuid}
    </select>
</mapper>
