<?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.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.mapper.DqaDataAnalysisMapper">
<select id="selectCountByTableNameAndUnitId" resultType="java.util.Map">
    SELECT COUNT(a.id) as 'conunt',IFNULL(MAX(a.ZHGXSJ),'') 'zhgsxj' FROM
    up_country_qh.${countryTableName} a
    inner JOIN depot_qh.org_info b on
    <choose>
    <when  test=" countryTableName =='ODS_UP_CWBBXXJK' or countryTableName == 'ODS_UP_CNSPTXXXJK'" >
        a.TYKQBM = b.tykqbm
    </when>
    <otherwise >
        a.DEP_KQDM = b.org_id
    </otherwise>
    </choose>
    where b.unit_info_id = #{unitId}
</select>
<select id="selectCountByTableName" resultType="java.util.Map">
    SELECT b.unit_info_id as 'unitId',COUNT(a.id) as 'conunt',IFNULL(MAX(a.ZHGXSJ),'') 'zhgsxj' FROM up_country_qh.${countryTableName} a
    inner JOIN depot_qh.org_info b on
    <choose>
        <when  test=" countryTableName =='ODS_UP_CWBBXXJK' or countryTableName == 'ODS_UP_CNSPTXXXJK'" >
            a.TYKQBM = b.tykqbm
        </when>
    <otherwise >
        a.DEP_KQDM = b.org_id
    </otherwise>
    </choose>
    GROUP BY b.unit_info_id
</select>
    <select id="findCountPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        SUM(data_record_count) AS data_record_count,
        MAX(last_update_time) AS last_update_time
    FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        LEFT JOIN dev_dict city ON city.id = b.zcdz_city
        left JOIN dev_dict area ON area.id = b.zcdz_area
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
        where  ${ew.sqlSegment}
    </if>
    GROUP BY
        a.interface_name
    </select>
    <select id="findCountDetailPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        b.dwmc as "unitName",
        SUM(data_record_count) AS data_record_count,
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        LEFT JOIN dev_dict city ON city.id = b.zcdz_city
        left JOIN dev_dict area ON area.id = b.zcdz_area
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
        where  ${ew.sqlSegment}
    </if>
        GROUP BY
        a.interface_name,b.dwmc
    </select>
    <select id="findComplePage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        a.interface_number,
        a.interface_field_count,
        a.interface_field_count-a.non_null_field_count as non_null_field_count,
        (a.interface_field_count-a.non_null_field_count)/a.interface_field_count*100 as "compleRate",
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a

        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        a.interface_name,
        a.interface_number,
        a.interface_field_count,
        a.non_null_field_count
    </select>
    <select id="findCompleDetailPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        b.dwmc as "unitName",
        SUM(interface_field_count) AS interface_field_count,
        SUM(interface_field_count)-SUM(non_null_field_count) AS non_null_field_count,
        (SUM(interface_field_count)-SUM(non_null_field_count))/SUM(interface_field_count)*100 AS "compleRate",
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        a.interface_name,b.dwmc
    </select>
    <select id="findAccuracyPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        a.interface_number,
        a.interface_field_count,
        a.error_data_count,
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        a.interface_name,
        a.interface_number,
        a.interface_field_count,
        a.error_data_count
    </select>
    <select id="findAccuracyDetailPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        b.dwmc as "unitName",
        SUM(interface_field_count) AS interface_field_count,
        SUM(error_data_count) AS error_data_count,
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        a.interface_name,b.dwmc
    </select>
    <select id="findAtuoPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        b.dwmc AS "unitName",
        city.DICT_LABEL as zcdzCityName,
        SUM(data_record_count) AS data_record_count,
        (SELECT COUNT(m1.interface_name) FROM biz_dqa_data_analysis m1 where m1.unit_info_id = a.unit_info_id and m1.data_record_count = 0 ) AS 'noDataCount',
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        LEFT JOIN dev_dict city ON city.id = b.zcdz_city
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        b.dwmc,city.DICT_LABEL
    </select>
    <select id="findAtuoDetailPage" resultType ="com.unis.dataQualityAssessmen.info.modular.dqaDataAnalysis.entity.vo.DqaDataAnalysisVo">
        SELECT
        a.interface_name,
        SUM(data_record_count) AS data_record_count,
        MAX(last_update_time) AS last_update_time
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        a.interface_name
    </select>
    <select id="exportByEntity" resultType ="java.util.Map">
        SELECT
        ROW_NUMBER() OVER (ORDER BY b.dwmc) AS "number",
        b.dwmc AS "unitName",
        SUM(data_record_count) AS "dateRecordCount",
        (SELECT COUNT(m1.interface_name) FROM biz_dqa_data_analysis m1 where m1.unit_info_id = a.unit_info_id and m1.data_record_count = 0 ) AS 'noDataCount',
        MAX(last_update_time) AS "lastUpdateDate"
        FROM
        biz_dqa_data_analysis a
        LEFT JOIN biz_unit_info b ON a.unit_info_id = b.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where  ${ew.sqlSegment}
        </if>
        GROUP BY
        b.dwmc
    </select>
</mapper>