<?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.yinet.system.mapper.TouchScreenHaoMapper">
    <select id="selectNum" resultType="HashMap">
        SET DATEFIRST 1
        SELECT
        	SUM( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 THEN 1 ELSE 0 END ) ) AS today,
			SUM ( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 AND states = '1' THEN 1 ELSE 0 END ) ) AS blz,
			SUM ( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 AND time_callServer IS NULL THEN 1 ELSE 0 END ) ) AS deng,
			SUM ( ( CASE WHEN DATEDIFF( MONTH, time_enterServer, GETDATE( ) ) = 0 THEN 1 ELSE 0 END ) ) AS month,
			(select COUNT(*) from zbstat where (DATEPART(wk, time_enterServer) = DATEPART(wk, GETDATE())) AND (DATEPART(yy, time_enterServer) = DATEPART(yy, GETDATE())))  AS week
		FROM
			zbstat
		WHERE
			time_enterServer IS NOT NULL
			AND queue_id IS NOT NULL
    </select>
    <select id="selectCallNum" resultType="HashMap">
        SELECT
        	SUM( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 THEN 1 ELSE 0 END ) ) AS today,
			SUM ( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 AND states = '1' THEN 1 ELSE 0 END ) ) AS blz,
			SUM ( ( CASE WHEN DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0 AND time_callServer IS NULL THEN 1 ELSE 0 END ) ) AS deng,
			SUM ( ( CASE WHEN DATEDIFF( MONTH, time_enterServer, GETDATE( ) ) = 0 THEN 1 ELSE 0 END ) ) AS month,
			SUM ( ( CASE WHEN DATEDIFF( WEEK, time_enterServer, GETDATE( ) ) = 0 THEN 1 ELSE 0 END ) ) AS week
		FROM
			zbstat
		WHERE
			DATEDIFF( DAY, time_enterServer, GETDATE( ) ) = 0
			AND time_enterServer IS NOT NULL
			AND queue_id IS NOT NULL
    </select>
    <select id="selectCount" resultType="Integer">
		select count(*) from zbstat where queue_id IS NOT NULL
	</select>
    <select id="selectPieNum" resultType="HashMap">
        SELECT
        isnull( SUM ( CASE WHEN queue_id = '5' THEN 1 ELSE 0 END ), 0 ) AS '市场主体(自贸区)',
        isnull( SUM ( CASE WHEN queue_id = '6' THEN 1 ELSE 0 END ), 0 ) AS '项目投资(自贸区)',
        isnull( SUM ( CASE WHEN queue_id = '7' THEN 1 ELSE 0 END ), 0 ) AS '经发局(正定新区)',
        isnull( SUM ( CASE WHEN queue_id = '8' THEN 1 ELSE 0 END ), 0 ) AS '建设局(正定新区)',
        isnull( SUM ( CASE WHEN queue_id = '9' THEN 1 ELSE 0 END ), 0 ) AS '市场主体',
        isnull( SUM ( CASE WHEN queue_id = '10' THEN 1 ELSE 0 END ), 0 ) AS '环境保护',
        isnull( SUM ( CASE WHEN queue_id = '11' THEN 1 ELSE 0 END ), 0 ) AS '项目投资',
        isnull( SUM ( CASE WHEN queue_id = '12' THEN 1 ELSE 0 END ), 0 ) AS '社会事务',
        isnull( SUM ( CASE WHEN queue_id = '13' THEN 1 ELSE 0 END ), 0 ) AS '交通城管',
        isnull( SUM ( CASE WHEN queue_id = '14' THEN 1 ELSE 0 END ), 0 ) AS '涉农水利',
        isnull( SUM ( CASE WHEN queue_id = '15' THEN 1 ELSE 0 END ), 0 ) AS '个体',
        isnull( SUM ( CASE WHEN queue_id = '16' THEN 1 ELSE 0 END ), 0 ) AS '公司',
        isnull( SUM ( CASE WHEN queue_id = '17' THEN 1 ELSE 0 END ), 0 ) AS '代办公司'
        FROM
        zbstat
        WHERE
        time_enterServer IS NOT NULL
        AND queue_id IS NOT NULL
        <!--市场主体 自贸区 5-->

        <!--项目投资 自贸区 6 -->

        <!--经发局 		7-->

        <!--建设局		8-->

        <!--市场主体 	9-->

        <!--环境保护 	10-->

        <!--项目投资 	11-->

        <!--社会事务 	12-->

        <!--交通城管 	13-->

        <!--涉农水利 	14-->

        <!--个体 		15 -->

        <!--公司  		16-->

        <!--代办公司 	17-->
    </select>
</mapper>