From e94307cfc3ffd44adcc7fd729f200e4222a97663 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期一, 20 十二月 2021 13:48:02 +0800
Subject: [PATCH] 12/7 大屏相关

---
 springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java |  176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java
index a1038a9..3413a61 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java
@@ -2,9 +2,12 @@
 
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import javax.annotation.Resource;
 
+import com.panzhihua.common.model.vos.community.StatisticsCommVO;
+import com.panzhihua.common.model.vos.community.bigscreen.GridsGovernanceStatisticsVO;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -2619,6 +2622,160 @@
         return R.ok(drawEventVO);
     }
 
+    @Override
+    public R getCivilDrawListNew(ScreenDrawEventListDTO eventListDTO) {
+        GridsGovernanceStatisticsVO statisticsVO = new GridsGovernanceStatisticsVO();
+        // 返回事件列表结果集
+        List<EventGridIncidentStatisticsVO> eventResultList = new ArrayList<>();
+        // 返回小区列表结果集
+        List<CivilVillageStatisticsVO> villageResultList = new ArrayList<>();
+        // 返回人口统计
+        ScreenDrawEventPopulationTotalVO drawEventPopulationTotalVO = new ScreenDrawEventPopulationTotalVO();
+        //年龄段统计
+        List<StatisticsCommVO> ageGroupStatistics = new ArrayList<>();
+        // 查询所有事件
+        List<EventGridIncidentStatisticsVO> gridIncidentList =
+                this.baseMapper.getGridsGovernanceEventList(eventListDTO.getCommunityId());
+        if (!gridIncidentList.isEmpty()) {
+            gridIncidentList.forEach(gridIncident -> {
+                // 拆分事件经纬度
+                Double lng = 0.0;// 经度
+                Double lat = 0.0;// 纬度
+                String[] lngLatString = gridIncident.getLatLng().split(",");
+                if (gridIncident.getEventType().equals(1)) {
+                    lat = Double.parseDouble(lngLatString[0]);
+                    lng = Double.parseDouble(lngLatString[1]);
+                } else {
+                    lat = Double.parseDouble(lngLatString[1]);
+                    lng = Double.parseDouble(lngLatString[0]);
+                }
+                // 判断绘制的图形类型
+                if (eventListDTO.getType().equals(ScreenDrawEventListDTO.type.yx)) {
+                    // 判断这个点是否在圆形范围内
+                    if (GisPointUtil.isInCircle(eventListDTO.getCenterLng(), eventListDTO.getCenterLat(), lng, lat,
+                            eventListDTO.getRadius())) {
+                        if (eventResultList.size() <= eventListDTO.getCount()) {
+                            eventResultList.add(gridIncident);
+                        }
+                        countGridIncidentData(statisticsVO, gridIncident);
+                    }
+                } else {// 多边形类型
+                    if (GisPointUtil.isInPolygon(lng, lat, eventListDTO.getLngLatList())) {
+                        if (eventResultList.size() <= eventListDTO.getCount()) {
+                            eventResultList.add(gridIncident);
+                        }
+                        countGridIncidentData(statisticsVO, gridIncident);
+                    }
+                }
+            });
+        }
+        statisticsVO.setGridIncidentList(eventResultList);
+        // 查询所有小区
+        List<CivilVillageStatisticsVO> villageStatisticsList =
+                this.baseMapper.getCivilScreenVillageList(eventListDTO.getCommunityId());
+        if (!villageStatisticsList.isEmpty()) {
+            List<Long> villageIds = villageStatisticsList.stream().map(CivilVillageStatisticsVO::getVillageId).collect(Collectors.toList());
+            ageGroupStatistics = this.baseMapper.selectStatisticsForAge(villageIds);
+            villageStatisticsList.forEach(village -> {
+                // 判断绘制的图形类型
+                if (eventListDTO.getType().equals(ScreenDrawEventListDTO.type.yx)) {
+                    // 判断这个点是否在圆形范围内
+                    if (GisPointUtil.isInCircle(eventListDTO.getCenterLng(), eventListDTO.getCenterLat(),
+                            Double.parseDouble(village.getLng()), Double.parseDouble(village.getLat()),
+                            eventListDTO.getRadius())) {
+                        fillVillageResultList(villageResultList, drawEventPopulationTotalVO, village);
+                    }
+                } else {// 多边形类型
+                    if (GisPointUtil.isInPolygon(Double.parseDouble(village.getLng()),
+                            Double.parseDouble(village.getLat()), eventListDTO.getLngLatList())) {
+                        fillVillageResultList(villageResultList, drawEventPopulationTotalVO, village);
+                    }
+                }
+            });
+        }
+        statisticsVO.setVillageStatisticsList(villageResultList);
+        statisticsVO.setDrawEventPopulationTotalVO(drawEventPopulationTotalVO);
+        statisticsVO.setAgeGroupStatistics(ageGroupStatistics);
+        statisticsVO.generateStatisticsData();
+        return R.ok(statisticsVO);
+    }
+
+    private void fillVillageResultList(List<CivilVillageStatisticsVO> villageResultList,
+                                       ScreenDrawEventPopulationTotalVO drawEventPopulationTotalVO, CivilVillageStatisticsVO village) {
+        villageResultList.add(village);
+        ScreenDrawEventPopulationTotalVO populationTotalVO =
+                this.baseMapper.getVillagePopulationTotalNew(village.getVillageId());
+        if (populationTotalVO != null) {
+            drawEventPopulationTotalVO.setVillageTotal(drawEventPopulationTotalVO.getVillageTotal() + 1);
+            drawEventPopulationTotalVO.setPopulationTotal(drawEventPopulationTotalVO.getPopulationTotal() + populationTotalVO.getPopulationTotal());
+            drawEventPopulationTotalVO.setBuildTotal(drawEventPopulationTotalVO.getBuildTotal() + populationTotalVO.getBuildTotal());
+            drawEventPopulationTotalVO.setHouseTotal(drawEventPopulationTotalVO.getHouseTotal() + populationTotalVO.getHouseTotal());
+            drawEventPopulationTotalVO.setLocalTotal(drawEventPopulationTotalVO.getLocalTotal() + populationTotalVO.getLocalTotal());
+            drawEventPopulationTotalVO.setOutTotal(drawEventPopulationTotalVO.getOutTotal() + populationTotalVO.getOutTotal());
+            drawEventPopulationTotalVO.setDisabilityTotal(drawEventPopulationTotalVO.getDisabilityTotal() + populationTotalVO.getDisabilityTotal());
+            drawEventPopulationTotalVO.setLowSecurityTotal(drawEventPopulationTotalVO.getLowSecurityTotal() + populationTotalVO.getLowSecurityTotal());
+            drawEventPopulationTotalVO.setElderTotal(drawEventPopulationTotalVO.getElderTotal() + populationTotalVO.getElderTotal());
+            drawEventPopulationTotalVO.setSpecialSituationTotal(drawEventPopulationTotalVO.getSpecialSituationTotal() + populationTotalVO.getSpecialSituationTotal());
+            drawEventPopulationTotalVO.setOtherTotal(drawEventPopulationTotalVO.getOtherTotal() + populationTotalVO.getOtherTotal());
+            drawEventPopulationTotalVO.setSpecialHelpTotal(drawEventPopulationTotalVO.getSpecialHelpTotal() + populationTotalVO.getSpecialHelpTotal());
+            drawEventPopulationTotalVO.setVeteransTotal(drawEventPopulationTotalVO.getVeteransTotal() + populationTotalVO.getVeteransTotal());
+            drawEventPopulationTotalVO.setOldTotal(drawEventPopulationTotalVO.getOldTotal() + populationTotalVO.getOldTotal());
+            drawEventPopulationTotalVO.setPensionTotal(drawEventPopulationTotalVO.getPensionTotal() + populationTotalVO.getPensionTotal());
+            drawEventPopulationTotalVO.setRentingHouseTotal(drawEventPopulationTotalVO.getRentingHouseTotal() + populationTotalVO.getRentingHouseTotal());
+            drawEventPopulationTotalVO.setVolunteerTotal(drawEventPopulationTotalVO.getVolunteerTotal() + populationTotalVO.getVolunteerTotal());
+            drawEventPopulationTotalVO.setAverageAge(drawEventPopulationTotalVO.getAverageAge() + populationTotalVO.getAverageAge());
+        }
+    }
+
+    private void countGridIncidentData(GridsGovernanceStatisticsVO statisticsVO, EventGridIncidentStatisticsVO gridIncident) {
+        switch (gridIncident.getType()) {
+            case 1:
+                statisticsVO.setEventZATotal(statisticsVO.getEventZATotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventZADeal(statisticsVO.getEventZADeal() + 1);
+                }
+                break;
+            case 2:
+                statisticsVO.setEventMSTotal(statisticsVO.getEventMSTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventMSDeal(statisticsVO.getEventMSDeal() + 1);
+                }
+                break;
+            case 3:
+                statisticsVO.setEventMDTotal(statisticsVO.getEventMDTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventMDDeal(statisticsVO.getEventMDDeal() + 1);
+                }
+                break;
+            case 5:
+                statisticsVO.setEventTFTotal(statisticsVO.getEventTFTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventTFDeal(statisticsVO.getEventTFDeal() + 1);
+                }
+                break;
+            case 6:
+                statisticsVO.setEventTSTotal(statisticsVO.getEventTSTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventTSDeal(statisticsVO.getEventTSDeal() + 1);
+                }
+                break;
+            case 9:
+                statisticsVO.setEventFJTotal(statisticsVO.getEventFJTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setEventFJDeal(statisticsVO.getEventFJDeal() + 1);
+                }
+                break;
+            case 10:
+                statisticsVO.setOtherTotal(statisticsVO.getOtherTotal() + 1);
+                if (gridIncident.getStatus().equals(1)) {
+                    statisticsVO.setOtherDeal(statisticsVO.getOtherDeal() + 1);
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
     /**
      * 大屏-根据小区id查询小区统计人数
      * 
@@ -2644,4 +2801,23 @@
     public R gridMemberStatisticsAll(MemberStatisticsAdminDTO statisticsAdminDTO) {
         return R.ok(eventGridMemberRelationMapper.gridMemberStatisticsAll(statisticsAdminDTO));
     }
+
+    /**
+     * 大屏-新根据小区id查询小区统计人数
+     *
+     * @param villageId
+     *            小区id
+     * @return 小区统计数据
+     */
+    @Override
+    public R civilVillageStatisticsNew(Long villageId) {
+        GridsGovernanceStatisticsVO statisticsVO = new GridsGovernanceStatisticsVO();
+        List<Long> villageIds = new ArrayList<>();
+        villageIds.add(villageId);
+        List<StatisticsCommVO> ageGroupStatistics = this.baseMapper.selectStatisticsForAge(villageIds);
+        ScreenDrawEventPopulationTotalVO populationTotalVO = this.baseMapper.getVillagePopulationTotalNew(villageId);
+        statisticsVO.setAgeGroupStatistics(ageGroupStatistics);
+        statisticsVO.setDrawEventPopulationTotalVO(populationTotalVO);
+        return R.ok(statisticsVO);
+    }
 }

--
Gitblit v1.7.1