Browse Source

数据中心首页统计列表逻辑修改

lxz 1 year ago
parent
commit
5ddba66490

+ 39 - 0
src/main/java/com/sooka/sponest/data/index/domain/MenuInfo.java

@@ -0,0 +1,39 @@
+package com.sooka.sponest.data.index.domain;
+
+import com.sooka.sponest.data.base.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 菜单信息对象
+ */
+@Data
+@ApiModel(description = "菜单信息对象")
+public class MenuInfo extends BaseBusinessEntity {
+
+    /**
+     * 菜单信息
+     */
+    @ApiModelProperty(value = "分类信息", required = false)
+    private String subclassS;
+
+    /**
+     * 表名和类型
+     */
+    @ApiModelProperty(value = "表名和类型", required = false)
+    private String tableNameAndType;
+
+    /**
+     * 菜单信息
+     */
+    @ApiModelProperty(value = "表名", required = false)
+    private String tableName;
+
+    /**
+     * 菜单信息
+     */
+    @ApiModelProperty(value = "类型", required = false)
+    private String type;
+
+}

+ 10 - 57
src/main/java/com/sooka/sponest/data/index/mapper/IndexViewMapper.java

@@ -1,6 +1,8 @@
 package com.sooka.sponest.data.index.mapper;
 
 import com.sooka.sponest.data.index.domain.IndexViewInfo;
+import com.sooka.sponest.data.index.domain.MenuInfo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -12,7 +14,14 @@ public interface IndexViewMapper {
      *
      * @return
      */
-    Long getBasicDataList(IndexViewInfo menuId);
+    List<MenuInfo> getBasicDataList(MenuInfo menuInfo);
+
+    /**
+     * 获取基础数据条数
+     * @param menuInfo
+     * @return
+     */
+    Long getBasicDataCount(MenuInfo menuInfo);
 
     /**
      * 获取林业数据
@@ -64,62 +73,6 @@ public interface IndexViewMapper {
     List<Map<String, Object>> getFire();
 
     /**
-     * 获取林业数据条数
-     *
-     * @return
-     */
-    Long getForestCount();
-
-    /**
-     * 获取应急数据条数
-     *
-     * @return
-     */
-    Long getEmergencyCount();
-
-    /**
-     * 获取环保数据条数
-     *
-     * @return
-     */
-    Long getEnvironmentCount();
-
-    /**
-     * 获取消防数据条数
-     *
-     * @return
-     */
-    Long getFirecontrolCount();
-
-    /**
-     * 获取农业数据条数
-     *
-     * @return
-     */
-    Long getFarmCount();
-
-    /**
-     * 获取交通数据条数
-     *
-     * @return
-     */
-    Long getTrafficCount();
-
-    /**
-     * 获取资源数据条数
-     *
-     * @return
-     */
-    Long getResourcesCount();
-
-    /**
-     * 获取水利数据条数
-     *
-     * @return
-     */
-    Long getHydraulicCount();
-
-    /**
      * 获取一网通办数据列表
      *
      * @return

+ 72 - 69
src/main/java/com/sooka/sponest/data/index/service/impl/IndexViewServiceImpl.java

@@ -4,6 +4,7 @@ import com.sooka.sponest.data.base.service.impl.BaseServiceImpl;
 import com.sooka.sponest.data.commandcenter.domian.CommandCenterBO;
 import com.sooka.sponest.data.commandcenter.service.ICommandCenterService;
 import com.sooka.sponest.data.index.domain.IndexViewInfo;
+import com.sooka.sponest.data.index.domain.MenuInfo;
 import com.sooka.sponest.data.index.mapper.IndexViewMapper;
 import com.sooka.sponest.data.index.service.IndexViewService;
 import org.apache.commons.collections4.MapUtils;
@@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class IndexViewServiceImpl extends BaseServiceImpl implements IndexViewService {
@@ -65,82 +67,83 @@ public class IndexViewServiceImpl extends BaseServiceImpl implements IndexViewSe
      *
      * @return
      */
-    @Override
     public List<IndexViewInfo> getBasicDataList() {
-        List<IndexViewInfo> basicDataList = new ArrayList<>();
-        // 通过菜单表查询各个小类 菜单ID林业 1089 应急 1680 环保 2073 消防 2074 农业 2357 交通 2360 资源 2386 水利 2456
-        Map<String, Integer> menuIdMap = new LinkedHashMap<>();
-        menuIdMap.put("林业", 1089);
-        menuIdMap.put("农业", 2357);
-        menuIdMap.put("水利", 2456);
-        menuIdMap.put("环保", 2073);
-        menuIdMap.put("应急", 1680);
-        menuIdMap.put("交通", 2360);
-        menuIdMap.put("资源", 2386);
-        menuIdMap.put("消防", 2074);
-        Set<String> keyset = menuIdMap.keySet();
-        for (String key : keyset) {
-            IndexViewInfo indexViewInfo = new IndexViewInfo();
-            setSookaDataBase(indexViewInfo);
-            indexViewInfo.setCategory(key);
-            indexViewInfo.setMenuId(menuIdMap.get(key));
-            indexViewInfo.setSubclass(indexViewMapper.getBasicDataList(indexViewInfo));
-            // 查询各个行管局的所有表统计数据量     查询的表写死,后续加表需要改sql
-            switch (key) {
-                case "林业":
-                    indexViewInfo.setCategory("林业基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getForestCount());
-                    break;
-                case "应急":
-                    indexViewInfo.setCategory("应急基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getEmergencyCount());
-                    break;
-                case "环保":
-                    indexViewInfo.setCategory("环保基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getEnvironmentCount());
-                    break;
-                case "消防":
-                    indexViewInfo.setCategory("消防基础数据");
-                    // 消防在原有的基础上将基础数据-取水口、水鹤、消火栓纳入消防,现将菜单小类固定+3
-                    indexViewInfo.setSubclass(indexViewInfo.getSubclass() + 3);
-                    indexViewInfo.setCount(indexViewMapper.getFirecontrolCount());
-                    break;
-                case "农业":
-                    indexViewInfo.setCategory("农业基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getFarmCount());
-                    break;
-                case "交通":
-                    indexViewInfo.setCategory("交通基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getTrafficCount());
-                    break;
-                case "资源":
-                    indexViewInfo.setCategory("自然资源基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getResourcesCount());
-                    break;
-                default:
-                    indexViewInfo.setCategory("水利基础数据");
-                    indexViewInfo.setCount(indexViewMapper.getHydraulicCount());
-                    break;
+        MenuInfo menu = new MenuInfo();
+        setSookaDataBase(menu);
+        List<IndexViewInfo> basicList = new ArrayList<>();
+
+// 获取菜单信息
+        List<MenuInfo> basicDataList = indexViewMapper.getBasicDataList(menu);
+
+// 存储小类计数信息,key值为小类,value为小类数
+        Map<String, Long> subclassCount = new TreeMap<>();
+        Map<String, List<MenuInfo>> resultMap = new HashMap<>();
+
+        for (MenuInfo item : basicDataList) {
+            String[] subclassS = item.getSubclassS().split(",");
+            String[] tableNameAndType = item.getTableNameAndType().split("/");
+
+            // 小类的统计次数
+            for (String subclass : subclassS) {
+                subclassCount.merge(subclass, 1L, Long::sum);
+            }
+
+            for (String subclass : subclassS) {
+                // 检查resultMap中是否已经存在对应subclass的键
+                if (!resultMap.containsKey(subclass)) {
+                    resultMap.put(subclass, new ArrayList<>());
+                }
+                // 将当前的item添加到对应subclass的列表中
+                resultMap.get(subclass).add(item);
+            }
+
+            // 将tableName和type放入MenuInfo对象中
+            item.setTableName(tableNameAndType[0]);
+            if (tableNameAndType.length > 1) {
+                item.setType(tableNameAndType[1]);
             }
-            basicDataList.add(indexViewInfo);
         }
-        // 根据查询的数据进行统计
-        Long subclass = 0L;
-        Long count = 0L;
-        for (IndexViewInfo indexViewInfo : basicDataList) {
-            Long num = indexViewInfo.getSubclass();
-            subclass += num;
+
+        for (Map.Entry<String, List<MenuInfo>> entry : resultMap.entrySet()) {
+            String subclass = entry.getKey();
+            IndexViewInfo indexViewInfo = new IndexViewInfo();
+            indexViewInfo.setCount(0L);
+
+            // 分类名称映射
+            Map<String, String> categoryMap = new HashMap<>();
+            categoryMap.put("forest", "林业基础数据");
+            categoryMap.put("emergency", "应急基础数据");
+            categoryMap.put("environment", "环保基础数据");
+            categoryMap.put("firecontrol", "消防基础数据");
+            categoryMap.put("farm", "农业基础数据");
+            categoryMap.put("traffic", "交通基础数据");
+            categoryMap.put("resources", "自然资源基础数据");
+            categoryMap.put("water", "水利基础数据");
+
+            indexViewInfo.setCategory(categoryMap.get(subclass));
+            indexViewInfo.setSubclass(subclassCount.get(subclass));
+
+            List<MenuInfo> menuInfos = entry.getValue();
+            for (MenuInfo menuInfo : menuInfos) {
+                Long dataCount = indexViewMapper.getBasicDataCount(menuInfo);
+                indexViewInfo.setCount(indexViewInfo.getCount() + dataCount);
+            }
+            basicList.add(indexViewInfo);
         }
-        for (IndexViewInfo indexViewInfo : basicDataList) {
-            Long num = indexViewInfo.getCount();
-            count += num;
+
+// 统计总的数据数量
+        long totalCount = 0;
+        for (IndexViewInfo info : basicList) {
+            totalCount += info.getCount();
         }
+
         IndexViewInfo indexViewInfo = new IndexViewInfo();
         indexViewInfo.setCategory("共有基础数据类型");
-        indexViewInfo.setSubclass(subclass);
-        indexViewInfo.setCount(count);
-        basicDataList.add(indexViewInfo);
-        return basicDataList;
+        indexViewInfo.setSubclass((long) basicDataList.size());
+        indexViewInfo.setCount(totalCount);
+        basicList.add(indexViewInfo);
+
+        return basicList;
     }
 
     /**

+ 19 - 174
src/main/resources/mapper/index/IndexViewMapper.xml

@@ -4,185 +4,30 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.sooka.sponest.data.index.mapper.IndexViewMapper">
 
-    <resultMap id="IndexViewInfoResultMap" type="com.sooka.sponest.data.index.domain.IndexViewInfo">
-        <result property="category" column="category"/>
-        <result property="subclass" column="subclass"/>
-        <result property="count" column="count"/>
+    <resultMap id="MenuInfoResultMap" type="com.sooka.sponest.data.index.domain.MenuInfo">
+        <result property="subclassS" column="subclassS"/>
+        <result property="tableNameAndType" column="tableNameAndType"/>
     </resultMap>
-
-    <select id="getBasicDataList" parameterType="String" resultType="Long">
-        SELECT count(u2.menu_id) AS subclass
-        FROM(
-                SELECT
-                    @ids AS parent_id,
-                    (SELECT @ids := GROUP_CONCAT(menu_id) FROM ${database_system}.sys_menu WHERE FIND_IN_SET(parent_id, @ids)) AS c_ids,
-            @l := @l+1 AS LEVEL
-        FROM ${database_system}.sys_menu, (SELECT @ids := #{menuId}, @l := 0 ) b
-        WHERE @ids IS NOT NULL
-            ) u1
-            JOIN ${database_system}.sys_menu u2
-        ON FIND_IN_SET(u2.menu_id, u1.parent_id) where u2.menu_id != #{menuId} AND u2.menu_type = 'C' AND STATUS = 0 AND front_type = 'front_type_data' AND u2.menu_name NOT LIKE '%统计%' AND u2.menu_name NOT LIKE '%台账%'
-        <!-- 排除林业林业巡查计划、任务、轨迹,植树造林区域、计划、任务管理、任务反馈、工作统计,野生动物统计、监测台账、林业网格层级、林长管理、林班数据图层层级、林班数据图层 -->
-        <if test="menuId == 1089">AND u2.menu_id NOT IN (2745,2751,2903,1121,1127,2608,2602,2629,2676,2675,2776,1199,2891,2897)</if>
-        <!-- 排除农业秸秆还田统计、台账 -->
-        <if test="menuId == 2357">AND u2.menu_id NOT IN (1903,1904)</if>
-        <!-- 排除水利巡查计划、任务、轨迹、督导检查、保洁员、网格、河长名录 -->
-        <if test="menuId == 2456">AND u2.menu_id NOT IN (2560,2566,3157,2677,2542,3095,2554)</if>
-        <!-- 排除环保巡查计划、任务、轨迹、环保人员,秸秆离田台账、统计 -->
-        <if test="menuId == 2073">AND u2.menu_id NOT IN (2702,2708,3193,2770,1906,1907)</if>
-        <!-- 排除交通巡查计划、任务、轨迹、交通人员、网格、路长 -->
-        <if test="menuId == 2360">AND u2.menu_id NOT IN (2688,2694,3163,2758,3101,2873)</if>
-        <!-- 排除资源巡查计划、任务、轨迹、资源人员、田长制-网格、田长 -->
-        <if test="menuId == 2386">AND u2.menu_id NOT IN (2730,2736,3169,2596,2432,2444)</if>
-        <!-- 排除消防巡查计划、任务、轨迹、消防人员 -->
-        <if test="menuId == 2074">AND u2.menu_id NOT IN (2716,2722,3187,2762)</if>
-    </select>
-
-    <!-- 林业数据条数 -->
-    <select id="getForestCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_forest_animal
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_resources
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_landing
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_channel
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_fireteam
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_trees
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_changbrand
-            UNION ALL SELECT count(*) a FROM centerdata_t_supermap_level WHERE type = '1'
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_keyfireproofplots
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 应急数据条数 -->
-    <select id="getEmergencyCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_emergency_material
-            UNION ALL SELECT count(*) a FROM centerdata_t_emergency_team
-            UNION ALL SELECT count(*) a FROM centerdata_t_emergency_warehouse
-            UNION ALL SELECT count(*) a FROM centerdata_t_emergency_idlh_enterprises
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 环保数据条数 -->
-    <select id="getEnvironmentCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_environment_source_pollution
-            UNION ALL SELECT count(*) a FROM centerdata_t_environment_key_enterprise
-            UNION ALL SELECT count(*) a FROM centerdata_t_environment_source_pollution
-            UNION ALL SELECT count(*) a FROM centerdata_t_environment_sewage_outlet
-            UNION ALL SELECT count(*) a FROM centerdata_t_environment_water_monitor
-            UNION ALL SELECT count(*) a FROM centerdata_t_straw_leave_field WHERE del_flag = '0'
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 消防数据条数 -->
-    <select id="getFirecontrolCount" resultType="Long">
+    <select id="getBasicDataList" parameterType="String" resultMap="MenuInfoResultMap">
         SELECT
-            sum( a ) count
+            SUBSTRING_INDEX(center_type, ':', 1) AS subclassS,
+            SUBSTRING_INDEX(center_type, ':', -1) AS tableNameAndType
         FROM
-            ( SELECT count(*) a FROM centerdata_t_firecontrol_fire_force
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_fire_key_places
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_fire_pressure_sensor
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_other_linkage_force
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_basic_linkage_force
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_foam_liquid
-            UNION ALL SELECT count(*) a FROM centerdata_t_firecontrol_fulltime_station
-            <!-- 消防在原有的基础上将基础数据-取水口、水鹤、消火栓纳入消防 -->
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_waterintake
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_watercrane
-            UNION ALL SELECT count(*) a FROM centerdata_t_forest_firehydrant
-            ) AS temporary_tables;
+            ${database_system}.sys_menu
+        WHERE
+            menu_type = 'C'
+          AND status = 0
+          AND visible = 0
+          AND front_type = 'front_type_data'
+          AND center_type IS NOT NULL;
     </select>
 
-    <!-- 农业数据条数 -->
-    <select id="getFarmCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_straw_still_field
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_agricultural_cooperatives WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_botany_protect_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_seed_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_chemical_fertilizer_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_plant_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_subsidy_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_contract_management WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_foodstuff_along
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_enterprise
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_filings_livestock
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_pesticide_information
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_livestock
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_village_animal_prevention
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_autumn_harvest_schedule
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_seeding_progress
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_seedling_progress
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_sowing_schedule
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_agricultural_supervise
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_technology_train
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_excrement_dispose WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_complex_modification WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_greenhouse_film WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_trashcan
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_garbage_transfer
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_cesspit_collect
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_breeding_farm
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_agricultural_machinery_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_machinery_info WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_implements_info WHERE del_flag = '0'
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 交通数据条数 -->
-    <select id="getTrafficCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_traffic_warning_sign
-            UNION ALL SELECT count(*) a FROM centerdata_t_traffic_transportation_hub
-            UNION ALL SELECT count(*) a FROM centerdata_t_traffic_bridge
-            UNION ALL SELECT count(*) a FROM centerdata_t_traffic_culvert
-            UNION ALL SELECT count(*) a FROM centerdata_t_supermap_level WHERE type = '3'
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 资源数据条数 -->
-    <select id="getResourcesCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_resources_illegal_construction
-            UNION ALL SELECT count(*) a FROM centerdata_t_resources_geologic_hazard
-            UNION ALL SELECT count(*) a FROM centerdata_t_resources_deposit
-            UNION ALL SELECT count(*) a FROM centerdata_t_farm_basic_farmland WHERE del_flag = '0'
-            UNION ALL SELECT count(*) a FROM centerdata_t_resources_land_info
-            UNION ALL SELECT count(*) a FROM centerdata_t_supermap_level WHERE type = '6'
-            ) AS temporary_tables;
-    </select>
-
-    <!-- 水利数据条数 -->
-    <select id="getHydraulicCount" resultType="Long">
-        SELECT
-            sum( a ) count
-        FROM
-            ( SELECT count(*) a FROM centerdata_t_hydraulic_channel_blueline
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_battlefield
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_garbage_station
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_reach
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_reservoir
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_river
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_outlet_sewage
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_wade_bridge_culvert
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_water_gate
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_water_project
-            UNION ALL SELECT count(*) a FROM centerdata_t_hydraulic_river_hechang
-            UNION ALL SELECT count(*) a FROM centerdata_t_supermap_level WHERE type = '2'
-            ) AS temporary_tables;
+    <select id="getBasicDataCount" parameterType="MenuInfo" resultType="Long">
+        SELECT count(*)  FROM
+        ${tableName}
+        <where>
+            <if test="type != null and type != ''">and type = #{type}</if>
+        </where>
     </select>
 
     <!--一网通办统计数据-->