101captain
2022-01-14 6fc1e7f179acaeec4df755f72895b3b4fb50d4bb
springcloud_k8s_panzhihuazhihuishequ/service_grid/src/main/java/com/panzhihua/service_grid/service/impl/EventServiceImpl.java
@@ -1,10 +1,15 @@
package com.panzhihua.service_grid.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.panzhihua.common.model.vos.community.screen.event.EventComprehensiveGovernanceStatisticsVO;
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;
@@ -1295,7 +1300,7 @@
    @Override
    public R<ComActVO> actList() {
        return communityService.listCommunityAll();
        return communityService.listCommunityAll(null);
    }
    @Override
@@ -2619,6 +2624,173 @@
        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);
                    }
                }
            });
        }
        // 查询所有小区
        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();
        List<StatisticsCommVO> eventTypeCircleDrawData = new ArrayList<>();
        if (!eventResultList.isEmpty()) {
            Map<Integer, List<EventGridIncidentStatisticsVO>> collect = eventResultList.stream().collect(Collectors.groupingBy(EventGridIncidentStatisticsVO::getType));
            for (Map.Entry<Integer, List<EventGridIncidentStatisticsVO>> entry : collect.entrySet()) {
                StatisticsCommVO temp = new StatisticsCommVO();
                int size = entry.getValue().size();
                Integer eventTotal = statisticsVO.getEventTotal();
                temp.setFiled(entry.getKey().toString());
                temp.setNum(size);
                temp.setPercent(new BigDecimal(size/eventTotal).setScale(2));
                eventTypeCircleDrawData.add(temp);
            }
        }
        statisticsVO.setEventTypeCircleDrawData(eventTypeCircleDrawData);
        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 +2816,34 @@
    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);
    }
    /**
     * 西区大数据分析平台-综合治理栏
     * @return
     */
    @Override
    public R getComprehensiveGovernanceStatics() {
        EventComprehensiveGovernanceStatisticsVO governanceStatisticsVO = this.baseMapper.selectComprehensiveGovernanceStatics();
        governanceStatisticsVO.generateGovernanceTotal();
        return R.ok(governanceStatisticsVO);
    }
}