From 0db9efb5af748eb0f77dab3ecb11ee12d8824a9c Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Thu, 18 Nov 2021 15:01:46 +0800
Subject: [PATCH] 1.统计

---
 src/main/java/org/springblade/modules/information/mapper/InformationMapper.xml |  690 ++++++++++++++++++++++++---------------------------------
 1 files changed, 289 insertions(+), 401 deletions(-)

diff --git a/src/main/java/org/springblade/modules/information/mapper/InformationMapper.xml b/src/main/java/org/springblade/modules/information/mapper/InformationMapper.xml
index f5d00b7..d8a5c81 100644
--- a/src/main/java/org/springblade/modules/information/mapper/InformationMapper.xml
+++ b/src/main/java/org/springblade/modules/information/mapper/InformationMapper.xml
@@ -190,161 +190,6 @@
         group by jurisdiction
     </select>
 
-    <!--    &lt;!&ndash;统计上个月和这个月交社保的人数以及缴纳金额&ndash;&gt;-->
-    <!--    <select id="selectTo" resultType="java.util.HashMap">-->
-    <!--        SELECT IFNULL(A.lastmonth, 0) AS lastmonth,-->
-    <!--        IFNULL(B.thismouth, 0) AS thismouth,-->
-    <!--        IFNULL(A.amount, 0) AS lastamount,-->
-    <!--        IFNULL(B.amount, 0) AS thisamount,-->
-    <!--        IFNULL( C.userthismouth, 0 ) AS userthismouth,-->
-    <!--        IFNULL( D.userlastmouth, 0 ) AS userlastmouth,-->
-    <!--        IFNULL( E.userpcthismouth, 0 ) AS userpcthismouth,-->
-    <!--        IFNULL( F.userpclastmouth, 0 ) AS userpclastmouth-->
-    <!--        FROM (-->
-    <!--        SELECT COUNT(*) AS lastmonth,-->
-    <!--        amount,-->
-    <!--        deptid-->
-    <!--        FROM-->
-    <!--        sys_socil-->
-    <!--        WHERE-->
-    <!--        deptid IN ( SELECT i.departmentid FROM sys_information i LEFT JOIN sys_jurisdiction j ON j.id= i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY i.departmentid )-->
-    <!--        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( insuredtime, '%Y%m' ) ) = 1-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and deptid =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        amount,-->
-    <!--        deptid-->
-    <!--        ) A-->
-    <!--        left JOIN (-->
-    <!--        SELECT COUNT(*) AS thismouth,-->
-    <!--        amount,-->
-    <!--        deptid-->
-    <!--        FROM-->
-    <!--        sys_socil-->
-    <!--        WHERE-->
-    <!--        deptid IN ( SELECT i.departmentid FROM sys_information i LEFT JOIN sys_jurisdiction j ON j.id= i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY i.departmentid )-->
-    <!--        AND DATE_FORMAT( insuredtime, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and deptid =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        amount,-->
-    <!--        deptid-->
-    <!--        ) B ON A.deptid = B.deptid-->
-    <!--        LEFT JOIN (-->
-    <!--        SELECT COUNT(*) AS userthismouth,-->
-    <!--        dept_id-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        dept_id IN (-->
-    <!--        SELECT-->
-    <!--        i.departmentid-->
-    <!--        FROM-->
-    <!--        sys_information i-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        i.departmentid-->
-    <!--        )-->
-    <!--        AND DATE_FORMAT( update_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' ) AND status=1-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        dept_id-->
-    <!--        ) C ON C.dept_id = A.deptid-->
-    <!--        LEFT JOIN(-->
-    <!--        SELECT COUNT(*) AS userlastmouth,-->
-    <!--        dept_id-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        dept_id IN (-->
-    <!--        SELECT-->
-    <!--        i.departmentid-->
-    <!--        FROM-->
-    <!--        sys_information i-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        i.departmentid-->
-    <!--        )-->
-    <!--        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( update_time, '%Y%m' ) ) = 1 AND status=1-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        dept_id-->
-    <!--        ) D ON D.dept_id = A.deptid-->
-    <!--        LEFT JOIN (-->
-    <!--        SELECT COUNT(*) AS userpcthismouth,-->
-    <!--        dept_id-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        dept_id IN (-->
-    <!--        SELECT-->
-    <!--        i.departmentid-->
-    <!--        FROM-->
-    <!--        sys_information i-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        i.departmentid-->
-    <!--        )-->
-    <!--        AND DATE_FORMAT( update_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' ) AND dispatch=0-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        dept_id-->
-    <!--        ) E ON E.dept_id = A.deptid-->
-    <!--        LEFT JOIN(-->
-    <!--        SELECT COUNT(*) AS userpclastmouth,dept_id-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        dept_id IN (-->
-    <!--        SELECT i.departmentid-->
-    <!--        FROM-->
-    <!--        sys_information i-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = i.jurisdiction-->
-    <!--        where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and i.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        i.departmentid-->
-    <!--        )-->
-    <!--        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( update_time, '%Y%m' ) ) = 1 AND dispatch=0-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--        GROUP BY-->
-    <!--        dept_id-->
-    <!--        ) F ON F.dept_id = A.deptid-->
-    <!--    </select> -->
     <!--统计上个月和这个月交社保的人数以及缴纳金额-->
     <select id="selectTo" resultType="java.util.HashMap">
         SELECT
@@ -452,27 +297,52 @@
         ) F ON F.dept_id = H.departmentid
         LEFT JOIN (
         SELECT
-        COUNT(*) AS usernum,
-        dept_id
+        J.znum+J.fznum as usernum,
+        J.dept_id
         FROM
-        blade_user
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
         WHERE
-        STATUS = 1
-        AND is_deleted = 0 AND role_id='1412226235153731586'
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
         GROUP BY
-        dept_id
-        ) I ON I.dept_id = H.departmentid
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J) I ON I.dept_id = H.departmentid
         LEFT JOIN (
         SELECT
         COUNT( * ) AS userpcthismouth,
         dept_id
         FROM
-        blade_user
+        sys_dispatcher
         WHERE
-        DATE_FORMAT( update_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )
-        AND dispatch = 0
-        AND STATUS = 1
-        AND is_deleted = 0 AND role_id='1412226235153731586'
+        DATE_FORMAT( dispatcherTime, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )
+        AND STATUS = 0
         GROUP BY
         dept_id
         ) G ON G.dept_id = H.departmentid
@@ -481,12 +351,10 @@
         COUNT( * ) AS userpclastmouth,
         dept_id
         FROM
-        blade_user
+        sys_dispatcher
         WHERE
-        PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( update_time, '%Y%m' ) ) = 1
-        AND dispatch = 0
-        AND STATUS = 1
-        AND is_deleted = 0 AND role_id='1412226235153731586'
+        PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( dispatcherTime, '%Y%m' ) ) = 1
+        AND STATUS = 0
         GROUP BY
         dept_id
         ) J ON J.dept_id = H.departmentid
@@ -495,16 +363,16 @@
         COUNT(*) AS userpcnum,
         dept_id
         FROM
-        blade_user
-        WHERE dispatch = 0
-        AND STATUS = 1
-        AND is_deleted = 0 AND role_id='1412226235153731586'
+        sys_dispatcher
+        WHERE STATUS = 0
         GROUP BY
         dept_id
         ) P ON P.dept_id = H.departmentid
+        LEFT JOIN blade_dept d ON H.departmentid = d.id
+        LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
@@ -626,60 +494,6 @@
     </select>
 
 
-    <!--总保安数量-->
-    <!--    <select id="queryCountB" resultType="java.util.HashMap">-->
-    <!--        SELECT-->
-    <!--        C.thisnum,-->
-    <!--        C.lastnum,-->
-    <!--        d.dept_name AS deptname,-->
-    <!--        j.dept_name AS jurname-->
-    <!--        FROM-->
-    <!--        (-->
-    <!--        SELECT-->
-    <!--        IFNULL( A.thisnum, 0 ) AS thisnum,-->
-    <!--        IFNULL( B.lastnum, 0 ) AS lastnum,-->
-    <!--        A.dept_id,-->
-    <!--        A.jurisdiction-->
-    <!--        FROM-->
-    <!--        (-->
-    <!--        SELECT-->
-    <!--        COUNT( * ) AS thisnum,-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        role_id = '1412226235153731586' and status=1 and is_deleted=0-->
-    <!--        AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )-->
-    <!--        GROUP BY-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        ) A-->
-    <!--        LEFT JOIN (-->
-    <!--        SELECT-->
-    <!--        COUNT( * ) AS lastnum,-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        FROM-->
-    <!--        blade_user-->
-    <!--        WHERE-->
-    <!--        role_id = '1412226235153731586' and status=1 and is_deleted=0-->
-    <!--        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( create_time, '%Y%m' ) ) = 1-->
-    <!--        GROUP BY-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        ) B ON A.dept_id = B.dept_id-->
-    <!--        ) C-->
-    <!--        LEFT JOIN blade_dept d ON C.dept_id = d.id-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = C.jurisdiction-->
-    <!--        WHERE 1 =1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and C.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and C.dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--    </select>-->
     <select id="queryCountB" resultType="java.util.HashMap">
         SELECT IFNULL(A.thisnum, 0) AS thisnum,
         IFNULL(B.lastnum, 0) AS lastnum,
@@ -706,22 +520,51 @@
         AND is_deleted = 0
         AND PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(rtime, '%Y%m')) = 1
         GROUP BY dept_id
-        ) B ON B.dept_id = H.departmentid LEFT JOIN (
+        ) B ON B.dept_id = H.departmentid
+        LEFT JOIN (
         SELECT
-        COUNT( * ) AS num,
-        dept_id
+        J.znum+J.fznum as num,
+        J.dept_id
         FROM
-        blade_user
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
         WHERE
-        role_id = '1412226235153731586'
-        AND STATUS = 1
-        AND is_deleted = 0
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
         GROUP BY
-        dept_id
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J
         ) C ON C.dept_id = H.departmentid
-        where 1=1
+        LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
+        WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
@@ -788,7 +631,7 @@
         LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
@@ -803,10 +646,11 @@
         IFNULL( C.num, 0 ) AS num,
         H.departmentid,
         H.jurisdiction,
-        d.dept_name AS deptname,
+        H.enterpriseName AS deptname,
         j.dept_name AS jurname
         FROM
-        ( SELECT departmentid, jurisdiction FROM sys_information GROUP BY departmentid, jurisdiction ) H
+        ( SELECT departmentid, jurisdiction,enterpriseName FROM sys_information GROUP BY departmentid,
+        jurisdiction,enterpriseName ) H
         LEFT JOIN (
         SELECT
         COUNT(*) AS thisnum,
@@ -851,11 +695,10 @@
         GROUP BY
         dept_id
         ) C ON H.departmentid = C.dept_id
-        LEFT JOIN blade_dept d ON H.departmentid = d.id
         LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
@@ -909,10 +752,10 @@
         LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and C.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
-            and C.deptid =#{deptid}
+            and H.departmentid =#{deptid}
         </if>
     </select>
 
@@ -961,7 +804,7 @@
         LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
@@ -978,78 +821,47 @@
         ( SELECT departmentid, jurisdiction FROM sys_information GROUP BY departmentid, jurisdiction ) H
         LEFT JOIN (
         SELECT
-        SUM(num) AS thisnum,
+        COUNT(*) AS thisnum,
         dept_id
         FROM
         sys_dispatcher
         WHERE
         DATE_FORMAT( dispatcherTime, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )
+        AND `status`=0
         GROUP BY
         dept_id
         ) G ON G.dept_id = H.departmentid
         LEFT JOIN (
         SELECT
-        SUM(num) AS lastnum,
+        COUNT(*) AS lastnum,
         dept_id
         FROM
         sys_dispatcher
         WHERE
         PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( dispatcherTime, '%Y%m' ) ) = 1
+        AND `status`=0
         GROUP BY
         dept_id
         ) J ON J.dept_id = H.departmentid
         LEFT JOIN (
         SELECT
-        SUM(num) AS num,
+        COUNT(*) AS num,
         dept_id
         FROM
         sys_dispatcher
+        where `status`=0
         GROUP BY
         dept_id
         ) C ON C.dept_id = H.departmentid
+        LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction
         WHERE 1 = 1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}
         </if>
     </select>
-    <!--    <select id="queryCountPq" resultType="java.util.HashMap">-->
-    <!--        SELECT C.thisnum,-->
-    <!--        C.lastnum,-->
-    <!--        d.dept_name as deptname,-->
-    <!--        j.dept_name as jurname-->
-    <!--        FROM (-->
-    <!--        SELECT IFNULL(A.thisnum, 0) AS thisnum,-->
-    <!--        IFNULL(B.lastnum, 0) AS lastnum,-->
-    <!--        A.dept_id,-->
-    <!--        A.jurisdiction-->
-    <!--        FROM (-->
-    <!--        SELECT SUM(num) AS thisnum,-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        FROM sys_dispatcher-->
-    <!--        WHERE DATE_FORMAT( dispatcherTime, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )-->
-    <!--        GROUP BY dept_id, jurisdiction-->
-    <!--        ) A-->
-    <!--        left JOIN (-->
-    <!--        SELECT SUM(num) AS lastnum,-->
-    <!--        dept_id,-->
-    <!--        jurisdiction-->
-    <!--        FROM sys_dispatcher-->
-    <!--        WHERE PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( dispatcherTime, '%Y%m' ) ) = 1-->
-    <!--        GROUP BY dept_id, jurisdiction-->
-    <!--        ) B ON A.dept_id = B.dept_id) C-->
-    <!--        LEFT JOIN blade_dept d ON C.dept_id = d.id-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = C.jurisdiction where 1=1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and C.jurisdiction =#{jurisdiction}-->
-    <!--        </if>-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and C.dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--    </select>-->
 
 
     <!--查询本年所有月份的总人数-->
@@ -1248,55 +1060,8 @@
             AND H.departmentid = #{deptid}
         </if>
     </select>
-    <!--    <select id="selectExtype" resultType="java.util.HashMap">-->
-    <!--        SELECT COUNT-->
-    <!--        (*) as num,-->
-    <!--        d.dept_name,-->
-    <!--        u.real_name,-->
-    <!--        j.dept_name AS jurname-->
-    <!--        FROM blade_user u-->
-    <!--        LEFT JOIN blade_dept d ON d.id = u.dept_id-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = u.jurisdiction-->
-    <!--        WHERE u.examination_type = 1 and u.is_deleted=0 and u.status = 1-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and u.jurisdiction in (${jurisdiction})-->
-    <!--        </if>-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and u.dept_id =#{deptid}-->
-    <!--        </if>-->
-    <!--        <if test="type!=null and type=='1'.toString()">-->
-    <!--            and to_days(u.update_time) = to_days(now())-->
-    <!--        </if>-->
-    <!--        <if test="type!=null and type=='2'.toString()">-->
-    <!--            and DATE_FORMAT(u.update_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )-->
-    <!--        </if>-->
-    <!--        GROUP BY d.dept_name,u.real_name,-->
-    <!--        j.dept_name-->
-    <!--    </select>-->
-    <!--表现差的数量-->
-    <!--    <select id="selectBx" resultType="java.util.HashMap">-->
-    <!--        SELECT IFNULL(COUNT( * ),0) AS num,-->
-    <!--        d.dept_name,-->
-    <!--        j.dept_name AS jurname-->
-    <!--        FROM sys_performance u-->
-    <!--        LEFT JOIN blade_dept d ON d.id = u.departmentid-->
-    <!--        LEFT JOIN sys_jurisdiction j ON j.id = u.jurisdiction-->
-    <!--        WHERE score = 3-->
-    <!--        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">-->
-    <!--            and u.jurisdiction in(${jurisdiction})-->
-    <!--        </if>-->
-    <!--        <if test="deptid!=null and deptid!=''">-->
-    <!--            and u.departmentid =#{deptid}-->
-    <!--        </if>-->
-    <!--        <if test="type!=null and type=='1'.toString()">-->
-    <!--            and to_days(u.time) = to_days(now())-->
-    <!--        </if>-->
-    <!--        <if test="type!=null and type=='2'.toString()">-->
-    <!--            and DATE_FORMAT(u.time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )-->
-    <!--        </if>-->
-    <!--        GROUP BY d.dept_name,-->
-    <!--        j.dept_name-->
-    <!--    </select>-->
+
+    <!--表现差-->
     <select id="selectBx" resultType="java.util.HashMap">
         SELECT
         IFNULL( J.num, 0 ) AS num
@@ -1416,7 +1181,7 @@
 
     <select id="selectLi" resultType="java.util.HashMap">
         SELECT
-        IFNULL( J.num, 0 ) AS num,
+        IFNULL( V.num, 0 ) AS num,
         IFNULL( B.cznum, 0 ) AS cznum,
         IFNULL( D.wpaiqnum, 0 ) AS wpaiqnum,
         IFNULL( E.sbnum, 0 ) AS sbnum,
@@ -1429,20 +1194,47 @@
         A.stats,
         j.dept_name AS jurname
         FROM
-        ( SELECT jurisdiction, departmentid,enterpriseName,stats,create_time FROM sys_information ) A
+        ( SELECT jurisdiction, departmentid,enterpriseName,stats,create_time FROM sys_information where state !=1) A
         LEFT JOIN (
         SELECT
-        COUNT( * ) AS num,
-        dept_id
+        J.znum+J.fznum as num,
+        J.dept_id
         FROM
-        blade_user
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
         WHERE
-        role_id = '1412226235153731586'
-        AND STATUS = 1
-        AND is_deleted = 0
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
         GROUP BY
-        dept_id
-        ) J ON J.dept_id = A.departmentid
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J
+        ) V ON V.dept_id = A.departmentid
         LEFT JOIN (
         SELECT
         COUNT( * ) AS cznum,
@@ -1542,9 +1334,11 @@
         GROUP BY
         dept_id
         ) G ON G.dept_id = A.departmentid
-        LEFT JOIN sys_jurisdiction j ON j.id = A.jurisdiction WHERE 1=1
+        LEFT JOIN blade_dept d ON A.departmentid = d.id
+        LEFT JOIN sys_jurisdiction j ON j.id = A.jurisdiction
+        WHERE 1 =1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and A.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and A.enterpriseName like concat(concat('%', #{deptid}),'%')
@@ -1572,7 +1366,9 @@
         GROUP BY stats
     </select>
     <select id="seCountUm" resultType="java.lang.String">
-        SELECT COUNT(*) as mnum FROM `blade_user` WHERE status=1 AND sex=1
+        SELECT COUNT(*) as mnum FROM `blade_user` WHERE status=1 and
+        role_id = '1412226235153731586'
+        and is_deleted = 0 AND sex='1'
         <if test="deptid!=null and deptid!=''">
             and dept_id=#{deptid}
         </if>
@@ -1581,7 +1377,8 @@
         </if>
     </select>
     <select id="seCountUg" resultType="java.lang.String">
-        SELECT COUNT(*) as gnum FROM `blade_user` WHERE status=1 AND sex=2
+        SELECT COUNT(*) as gnum FROM `blade_user` WHERE status=1 and role_id = '1412226235153731586' and is_deleted = 0
+        AND sex='2'
         <if test="deptid!=null and deptid!=''">
             and dept_id=#{deptid}
         </if>
@@ -1770,7 +1567,7 @@
         A.departmentid,
         A.stats,
         A.jurisdiction,
-        A.dept_name as jurname,
+        j.dept_name as jurname,
         IFNULL( B.num, 0 ) AS fwnum,
         IFNULL( C.znum, 0 ) AS znum,
         IFNULL( D.dqnum, 0 ) AS dqnum,
@@ -1778,19 +1575,8 @@
         IFNULL( F.pqnum, 0 ) AS pqnum
         FROM
         (
-        SELECT
-        i.enterpriseName,
-        i.departmentid,
-        i.stats,
-        i.jurisdiction,
-        j.dept_name,
-        i.create_time
-        FROM
-        sys_information i
-        LEFT JOIN sys_jurisdiction j ON i.jurisdiction = j.id
-        WHERE
-        i.enterpriseName IS NOT NULL
-        ) A
+        SELECT enterpriseName,jurisdiction, departmentid,stats FROM sys_information WHERE stats!=1 GROUP BY
+        enterpriseName,jurisdiction,departmentid,stats) A
         LEFT JOIN
         (
         SELECT COUNT( * ) AS num, dept_id FROM sys_dispatcher_unit
@@ -1801,10 +1587,44 @@
         ON A.departmentid = B.dept_id
         LEFT JOIN
         (
-        SELECT COUNT( * ) AS znum, dept_id FROM blade_user WHERE role_id = '1412226235153731586'
-        and status=1
-        and is_deleted = 0
-        GROUP BY dept_id
+        SELECT
+        J.znum+J.fznum as znum,
+        J.dept_id
+        FROM
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J
         ) C
         ON A.departmentid = C.dept_id
         LEFT JOIN
@@ -1824,18 +1644,20 @@
         ON A.departmentid = E.dept_id
         LEFT JOIN
         (
-        SELECT COUNT( * ) AS pqnum, dept_id FROM blade_user
-        where
-        dispatch = 0
-        and role_id = '1412226235153731586'
-        and status= 1
-        and is_deleted = 0
-        GROUP BY dept_id
+        SELECT
+        SUM(num) AS pqnum,
+        dept_id
+        FROM
+        sys_dispatcher
+        GROUP BY
+        dept_id
         ) F
         ON A.departmentid = F.dept_id
-        where 1=1
-        <if test="jurisdiction!=null and jurisdiction!=''and jurisdiction!='1372091709474910209'">
-            AND A.jurisdiction in(${jurisdiction})
+        LEFT JOIN blade_dept d ON A.departmentid = d.id
+        LEFT JOIN sys_jurisdiction j ON j.id = A.jurisdiction
+        WHERE 1 =1
+        <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and A.enterpriseName like concat('%', #{deptid},'%')
@@ -1958,7 +1780,7 @@
         u.jurisdiction,
         j.dept_name AS jurname
         FROM sys_information u
-        LEFT JOIN sys_jurisdiction j ON j.id = u.jurisdiction WHERE u.stats!=0
+        LEFT JOIN sys_jurisdiction j ON j.id = u.jurisdiction WHERE u.stats!=1
         ) A
         LEFT JOIN (
         SELECT COUNT(*) AS cznum,
@@ -1978,11 +1800,44 @@
         AND is_deleted = 0
         GROUP BY dept_id
         ) C ON C.dept_id = A.departmentid
-        LEFT JOIN (SELECT COUNT(*) AS znum, dept_id
-        FROM blade_user
-        WHERE role_id = '1412226235153731586' AND `status`=1
-        AND is_deleted = 0
-        GROUP BY dept_id) D ON D.dept_id = A.departmentid where 1=1
+        LEFT JOIN (SELECT
+        J.znum+J.fznum as znum,
+        J.dept_id
+        FROM
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J )D ON D.dept_id = A.departmentid where 1=1
         <if test="jurisdiction!=null and jurisdiction != '' and jurisdiction != '1372091709474910209'">
             and A.jurisdiction in(${jurisdiction})
         </if>
@@ -2042,7 +1897,7 @@
         AND is_deleted = 0
         GROUP BY
         dept_id
-        ) E ON E.dept_id = i.departmentid where 1=1 AND i.stats!=0
+        ) E ON E.dept_id = i.departmentid where 1=1 AND i.stats!=1
         <if test="jurisdiction!=null and jurisdiction != '' and jurisdiction != '1372091709474910209'">
             and i.jurisdiction in(${jurisdiction})
         </if>
@@ -2101,7 +1956,7 @@
         dept_id
         ) D ON D.dept_id = i.departmentid
         LEFT JOIN ( SELECT COUNT( * ) fwnum, dept_id FROM sys_dispatcher_unit GROUP BY dept_id ) E ON i.departmentid =
-        E.dept_id WHERE 1 =1 AND i.stats!=0
+        E.dept_id WHERE 1 =1 AND i.stats!=1
         <if test="jurisdiction!=null and jurisdiction != '' and jurisdiction != '1372091709474910209'">
             and i.jurisdiction in(${jurisdiction})
         </if>
@@ -3118,28 +2973,61 @@
     <select id="seleP" resultType="java.util.HashMap">
         SELECT
         IFNULL(G.pnum, 0) AS pnum,
-        IFNULL(J.wpnum, 0) AS wpnum
+        IFNULL(K.wpnum, 0) AS wpnum
         FROM (SELECT departmentid, jurisdiction FROM sys_information GROUP BY departmentid, jurisdiction) H
         LEFT JOIN (
         SELECT COUNT(*) AS pnum,
         dept_id
-        FROM blade_user
-        WHERE dispatch = 0
-        AND STATUS = 1
-        AND is_deleted = 0
+        FROM sys_dispatcher
+        WHERE  STATUS = 0
         GROUP BY dept_id
         ) G ON G.dept_id = H.departmentid
         LEFT JOIN (
-        SELECT COUNT(*) AS wpnum,
-        dept_id
-        FROM blade_user
-        WHERE dispatch = 1
-        AND STATUS = 1
-        AND is_deleted = 0
-        GROUP BY dept_id
-        ) J ON J.dept_id = H.departmentid where 1=1
+        SELECT
+        J.znum+J.fznum as wpnum,
+        J.dept_id
+        FROM
+        (
+        SELECT
+        A.znum,
+        IFNULL( B.znum, 0 ) AS fznum,
+        A.dept_id
+        FROM
+        (
+        SELECT
+        COUNT( * ) AS znum,
+        bu.dept_id
+        FROM
+        blade_user bu
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.dispatch = 1
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bu.dept_id
+        ) A
+        LEFT JOIN (
+        SELECT
+        IFNULL( COUNT( * ), 0 ) AS znum,
+        bd.parent_id
+        FROM
+        blade_user bu
+        LEFT JOIN blade_dept bd ON bu.dept_id = bd.id
+        WHERE
+        bu.`status` = 1
+        AND bu.is_deleted = 0
+        AND bu.dispatch = 1
+        AND bu.role_id = '1412226235153731586'
+        GROUP BY
+        bd.parent_id
+        ) B ON B.parent_id = A.dept_id
+        ) J
+        ) K ON K.dept_id = H.departmentid
+        LEFT JOIN blade_dept d ON H.departmentid = d.id
+        LEFT JOIN sys_jurisdiction j ON j.id = H.jurisdiction where 1=1
         <if test="jurisdiction!=null and jurisdiction!='' and jurisdiction!='1372091709474910209'">
-            and H.jurisdiction =#{jurisdiction}
+            and (j.id = #{jurisdiction} or j.parent_id = #{jurisdiction})
         </if>
         <if test="deptid!=null and deptid!=''">
             and H.departmentid =#{deptid}

--
Gitblit v1.9.3