|
@@ -0,0 +1,312 @@
|
|
|
+package com.zoniot.ccrc.service.impl;
|
|
|
+
|
|
|
+import com.zoniot.ccrc.commom.utils.UserUtil;
|
|
|
+import com.zoniot.ccrc.commom.utils.Util;
|
|
|
+import com.zoniot.ccrc.dao.AreaMapper;
|
|
|
+import com.zoniot.ccrc.dao.DeviceMapper;
|
|
|
+import com.zoniot.ccrc.dto.BuildingInfoListDto;
|
|
|
+import com.zoniot.ccrc.dto.LoginUser;
|
|
|
+import com.zoniot.ccrc.dto.MapStatisticalDto;
|
|
|
+import com.zoniot.ccrc.entity.Area;
|
|
|
+import com.zoniot.ccrc.service.StatAndAnalysisService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.google.common.collect.Lists.newArrayList;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AreaMapper areaMapper;
|
|
|
+ @Resource
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MapStatisticalDto> realTimeMapStatistical(Integer sysId, Integer type, String northEast, String southWest, Integer province, Integer city, Integer region, Integer community) {
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ Double longitudeMin = 0d;
|
|
|
+ Double longitudeMax = 0d;
|
|
|
+
|
|
|
+ Double latitudeMin = 0d;
|
|
|
+ Double latitudeMax = 0d;
|
|
|
+ if (northEast != null && southWest != null) {
|
|
|
+ String[] northEastStr = StringUtils.split(northEast, ",");
|
|
|
+ String[] southWestStr = StringUtils.split(southWest, ",");
|
|
|
+
|
|
|
+ longitudeMin = Double.valueOf(southWestStr[0]);
|
|
|
+ longitudeMax = Double.valueOf(northEastStr[0]);
|
|
|
+
|
|
|
+ latitudeMin = Double.valueOf(southWestStr[1]);
|
|
|
+ latitudeMax = Double.valueOf(northEastStr[1]);
|
|
|
+ }
|
|
|
+ //设置当前站点
|
|
|
+ List<Integer> siteList = UserUtil.getUserCurrentSiteIds();
|
|
|
+
|
|
|
+ List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, null, null, province, city, region, community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
|
|
|
+ return this.mapStatistical(type, buildingInfoListDtoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public List<MapStatisticalDto> mapStatistical(Integer type, List<BuildingInfoListDto> buildingInfoListDtoList) {
|
|
|
+
|
|
|
+ List<MapStatisticalDto> list = newArrayList();
|
|
|
+ List<Integer> provinceIds = newArrayList();
|
|
|
+ List<Integer> cityIds = newArrayList();
|
|
|
+ List<Integer> regionIds = newArrayList();
|
|
|
+ List<Integer> communityIds = newArrayList();
|
|
|
+ if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
|
|
|
+ for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
|
|
|
+ if (buildingInfoListDto.getProvince() != null) provinceIds.add(buildingInfoListDto.getProvince());
|
|
|
+ if (buildingInfoListDto.getCity() != null) cityIds.add(buildingInfoListDto.getCity());
|
|
|
+ if (buildingInfoListDto.getRegion() != null) regionIds.add(buildingInfoListDto.getRegion());
|
|
|
+ if (buildingInfoListDto.getCommunity() != null) communityIds.add(buildingInfoListDto.getCommunity());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //去重
|
|
|
+ provinceIds = Util.removeDuplicate(provinceIds);
|
|
|
+ cityIds = Util.removeDuplicate(cityIds);
|
|
|
+ regionIds = Util.removeDuplicate(regionIds);
|
|
|
+ communityIds = Util.removeDuplicate(communityIds);
|
|
|
+
|
|
|
+ if (type == 1) {
|
|
|
+ //省
|
|
|
+ if (provinceIds.size() > 0) {
|
|
|
+ List<Area> areaList = areaMapper.findByIds(provinceIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == 2) {
|
|
|
+ //市
|
|
|
+ List<Area> areaList = areaMapper.findByIds(cityIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 2));
|
|
|
+ }
|
|
|
+ } else if (type == 3) {
|
|
|
+ //区
|
|
|
+ if (regionIds.size() > 0) {
|
|
|
+ List<Area> areaList = areaMapper.findByIds(regionIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 3));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (type == 4) {
|
|
|
+ //小区
|
|
|
+ if(communityIds.size() > 0){
|
|
|
+ for (Integer id : communityIds) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, id, null, null, 4));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
|
|
|
+ for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
|
|
|
+ MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
|
|
|
+ mapStatisticalDto.setId(buildingInfoListDto.getBuildingId());
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
|
|
|
+ mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
|
|
|
+ mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
|
|
|
+ mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
|
|
|
+ mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
|
|
|
+ mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
|
|
|
+ mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
|
|
|
+ mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
|
|
|
+ mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
|
|
|
+ mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
|
|
|
+ mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
|
|
|
+ mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
|
|
|
+ mapStatisticalDto.setCity(buildingInfoListDto.getCity());
|
|
|
+ mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
|
|
|
+ mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
|
|
|
+ mapStatisticalDto.setCode("BUILDING");
|
|
|
+ list.add(mapStatisticalDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if(type == 5){
|
|
|
+ //建筑
|
|
|
+ if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
|
|
|
+ for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
|
|
|
+ MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
|
|
|
+ mapStatisticalDto.setId(buildingInfoListDto.getBuildingId());
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
|
|
|
+ mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
|
|
|
+ mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
|
|
|
+ mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
|
|
|
+ mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
|
|
|
+ mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
|
|
|
+ mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
|
|
|
+ mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
|
|
|
+ mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
|
|
|
+ mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
|
|
|
+ mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
|
|
|
+ mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
|
|
|
+ mapStatisticalDto.setCity(buildingInfoListDto.getCity());
|
|
|
+ mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
|
|
|
+ mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
|
|
|
+ mapStatisticalDto.setCode("BUILDING");
|
|
|
+ list.add(mapStatisticalDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (provinceIds.size() > 1) {
|
|
|
+ //省
|
|
|
+ List<Area> areaList = areaMapper.findByIds(provinceIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 1));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (cityIds.size() > 1) {
|
|
|
+ //市
|
|
|
+ List<Area> areaList = areaMapper.findByIds(cityIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 2));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (regionIds.size() > 1) {
|
|
|
+ //区
|
|
|
+ List<Area> areaList = areaMapper.findByIds(regionIds);
|
|
|
+ for (Area area : areaList) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 3));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (communityIds.size() > 1) {
|
|
|
+ //小区
|
|
|
+ for (Integer id : communityIds) {
|
|
|
+ list.add(this.countAreaDeviceNum(buildingInfoListDtoList, id, null, null, 4));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //建筑
|
|
|
+ if (buildingInfoListDtoList.size() > 0) {
|
|
|
+ for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
|
|
|
+ MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
|
|
|
+ mapStatisticalDto.setCode("BUILDING");
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
|
|
|
+ mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
|
|
|
+ mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
|
|
|
+ mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
|
|
|
+ mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
|
|
|
+ mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
|
|
|
+ mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
|
|
|
+ mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
|
|
|
+ mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
|
|
|
+ mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
|
|
|
+ mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
|
|
|
+ mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
|
|
|
+ mapStatisticalDto.setCity(buildingInfoListDto.getCity());
|
|
|
+ mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
|
|
|
+ mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
|
|
|
+ list.add(mapStatisticalDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计地区数量
|
|
|
+ */
|
|
|
+ private MapStatisticalDto countAreaDeviceNum(List<BuildingInfoListDto> buildingInfoListDtoList, Integer areaId, String longitude, String latitude, Integer levelType) {
|
|
|
+ List<MapStatisticalDto> list = newArrayList();
|
|
|
+ Integer normalCount = 0;
|
|
|
+ Integer alarmCount = 0;
|
|
|
+ Integer faultCount = 0;
|
|
|
+ Integer offlineCount = 0;
|
|
|
+ Integer unusedCount = 0;
|
|
|
+ Integer deviceCount = 0;
|
|
|
+ MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
|
|
|
+
|
|
|
+ Integer buildingCount = 0;//建筑数
|
|
|
+ if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
|
|
|
+ for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
|
|
|
+
|
|
|
+ if (levelType == 1) {
|
|
|
+ if (areaId.equals(buildingInfoListDto.getProvince())) {
|
|
|
+ normalCount += buildingInfoListDto.getNormalCount();
|
|
|
+ alarmCount += buildingInfoListDto.getAlarmCount();
|
|
|
+ faultCount += buildingInfoListDto.getFaultCount();
|
|
|
+ offlineCount += buildingInfoListDto.getOfflineCount();
|
|
|
+ unusedCount += buildingInfoListDto.getDeviceUnusedCount();
|
|
|
+ deviceCount += buildingInfoListDto.getDeviceCount();
|
|
|
+ mapStatisticalDto.setCode("PROVINCE");
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getProvinceName());
|
|
|
+ mapStatisticalDto.setLongitude(longitude);
|
|
|
+ mapStatisticalDto.setLatitude(latitude);
|
|
|
+ buildingCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (levelType == 2) {
|
|
|
+ if (areaId.equals(buildingInfoListDto.getCity())) {
|
|
|
+ normalCount += buildingInfoListDto.getNormalCount();
|
|
|
+ alarmCount += buildingInfoListDto.getAlarmCount();
|
|
|
+ faultCount += buildingInfoListDto.getFaultCount();
|
|
|
+ offlineCount += buildingInfoListDto.getOfflineCount();
|
|
|
+ unusedCount += buildingInfoListDto.getDeviceUnusedCount();
|
|
|
+ deviceCount += buildingInfoListDto.getDeviceCount();
|
|
|
+ mapStatisticalDto.setCode("CITY");
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getCityName());
|
|
|
+ mapStatisticalDto.setLongitude(longitude);
|
|
|
+ mapStatisticalDto.setLatitude(latitude);
|
|
|
+ buildingCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (levelType == 3) {
|
|
|
+ if (areaId.equals(buildingInfoListDto.getRegion())) {
|
|
|
+ normalCount += buildingInfoListDto.getNormalCount();
|
|
|
+ alarmCount += buildingInfoListDto.getAlarmCount();
|
|
|
+ faultCount += buildingInfoListDto.getFaultCount();
|
|
|
+ offlineCount += buildingInfoListDto.getOfflineCount();
|
|
|
+ unusedCount += buildingInfoListDto.getDeviceUnusedCount();
|
|
|
+ deviceCount += buildingInfoListDto.getDeviceCount();
|
|
|
+ mapStatisticalDto.setCode("REGION");
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getRegionName());
|
|
|
+ mapStatisticalDto.setLongitude(longitude);
|
|
|
+ mapStatisticalDto.setLatitude(latitude);
|
|
|
+ buildingCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (levelType == 4) {
|
|
|
+ if (areaId.equals(buildingInfoListDto.getCommunity())) {
|
|
|
+ normalCount += buildingInfoListDto.getNormalCount();
|
|
|
+ alarmCount += buildingInfoListDto.getAlarmCount();
|
|
|
+ faultCount += buildingInfoListDto.getFaultCount();
|
|
|
+ offlineCount += buildingInfoListDto.getOfflineCount();
|
|
|
+ unusedCount += buildingInfoListDto.getDeviceUnusedCount();
|
|
|
+ deviceCount += buildingInfoListDto.getDeviceCount();
|
|
|
+ mapStatisticalDto.setCode("COMMUNITY");
|
|
|
+ mapStatisticalDto.setName(buildingInfoListDto.getCommunityName());
|
|
|
+ if (buildingInfoListDto.getLongitude() != null && buildingInfoListDto.getLatitude() != null) {
|
|
|
+ mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
|
|
|
+ mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
|
|
|
+ }
|
|
|
+ buildingCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapStatisticalDto.setId(areaId);
|
|
|
+ mapStatisticalDto.setNormalCount(normalCount);
|
|
|
+ mapStatisticalDto.setAlarmCount(alarmCount);
|
|
|
+ mapStatisticalDto.setFaultCount(faultCount);
|
|
|
+ mapStatisticalDto.setOfflineCount(offlineCount);
|
|
|
+ mapStatisticalDto.setUnusedCount(unusedCount);
|
|
|
+ mapStatisticalDto.setDeviceCount(deviceCount);
|
|
|
+ mapStatisticalDto.setBuildingCount(buildingCount);
|
|
|
+ return mapStatisticalDto;
|
|
|
+ }
|
|
|
+}
|