<?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.core.job.dao.TDxViolationTaxnoDao">

    <select id="selectCompanyByViolationStatus" resultType="com.dxhy.core.job.entity.SysDept">
        select distinct company, db_name
        from sys_dept
        where org_type = '1'
          and violation_status = '1'
          and del_flag = '0'
    </select>
    <select id="selectTaxnoByCompany" resultType="java.lang.String">
        select distinct taxno
        from sys_dept
        where company = #{company}
          and org_type = '5'
          and del_flag = '0'
    </select>
    <select id="selectViolationTaxno" resultType="com.dxhy.core.job.entity.TDxViolationTaxno" databaseId="mysql">
        select gf_tax_no,xf_tax_no,xf_name,#{company} as company
        from t_dx_record_invoice
        where gf_tax_no in
        <foreach collection="gfshList" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and create_date > #{createDate}
        and invoice_type in ('01','03','14')
        group by gf_tax_no, xf_tax_no
    </select>
    <select id="selectViolationTaxno" resultType="com.dxhy.core.job.entity.TDxViolationTaxno" databaseId="oracle">
        select t.gf_tax_no,t.xf_tax_no,t.xf_name,#{company} as company
        from t_dx_record_invoice t
        where t.gf_tax_no in
        <foreach collection="gfshList" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and invoice_type in ('01','03','14')
        and to_char(t.create_date,'yyyy-mm-dd') > #{createDate}
        and t.id = (select max(id) from t_dx_record_invoice sys where t.gf_tax_no = sys.gf_tax_no and t.xf_tax_no =
        sys.xf_tax_no)
    </select>
    <delete id="deleteTaxno">
        delete
        from t_dx_violation_taxno
        where company = #{company}
    </delete>
    <select id="selectViolationTaxnoByXf" resultType="com.dxhy.core.job.entity.TDxViolationTaxno" databaseId="mysql">
        SELECT id, gf_tax_no, xf_tax_no, company, xf_name
        FROM t_dx_violation_taxno
        GROUP BY xf_tax_no
    </select>
    <select id="selectViolationTaxnoByXf" resultType="com.dxhy.core.job.entity.TDxViolationTaxno" databaseId="oracle">
        SELECT t.id, t.gf_tax_no, t.xf_tax_no, t.company, t.xf_name
        FROM t_dx_violation_taxno t
        where t.id = (select max(id) from t_dx_violation_taxno tt where t.xf_tax_no = tt.xf_tax_no)
    </select>
</mapper>
