Quellcode durchsuchen

获取小区、区域树使用本地(不调用接口)

zhoujiangyuan vor 4 Jahren
Ursprung
Commit
b7d8be0153

+ 23 - 4
smart-city-platform/src/main/java/com/bz/smart_city/commom/util/TreeUtil.java

@@ -1,10 +1,8 @@
 package com.bz.smart_city.commom.util;
 
-import com.bz.smart_city.dto.AreaDto;
-import com.bz.smart_city.dto.ChannelDto;
-import com.bz.smart_city.dto.CustomerDto;
-import com.bz.smart_city.dto.OrganizationDto;
+import com.bz.smart_city.dto.*;
 import com.bz.smart_city.entity.Permission;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 
 import java.util.List;
@@ -145,4 +143,25 @@ public class TreeUtil {
     }
 
 
+    public static List<BuildingSelectDto>  getBuildingSelect(List<BuildingSelectDto> list, Integer id, String dimensionCode, Integer leve) {
+        List<BuildingSelectDto> temList = newArrayList();
+        if (list != null) {
+            for (BuildingSelectDto buildingSelectDto : list) {
+                if (id.equals(buildingSelectDto.getPid()) && !StringUtils.equals(dimensionCode,buildingSelectDto.getDimensionCode())) {
+                    List<BuildingSelectDto> chidren = getBuildingSelect(list, buildingSelectDto.getCode(), buildingSelectDto.getDimensionCode(), ++leve);
+                    BuildingSelectDto tempBuildingSelectDto = new BuildingSelectDto();
+                    BeanUtils.copyProperties(buildingSelectDto, tempBuildingSelectDto);
+                    tempBuildingSelectDto.setChildren(chidren);
+                    temList.add(tempBuildingSelectDto);
+                    leve--;
+                }
+            }
+        }
+        if(temList.size() > 0){
+            return temList;
+        }else {
+            return null;
+        }
+    }
+
 }

+ 9 - 2
smart-city-platform/src/main/java/com/bz/smart_city/controller/CommunityManagerController.java

@@ -4,6 +4,7 @@ import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.dto.BuildingSelectDto;
 import com.bz.smart_city.dto.CommunityDto;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.entity.Community;
@@ -28,8 +29,14 @@ public class CommunityManagerController {
 	@Autowired
 	CommunityService communityService;
 
+	@GetMapping("getAreaTree")
+	@ApiOperation(value = "获取区域树形列表")
+	public AjaxMessage<List<BuildingSelectDto>> getAreaTree() {
+		List<BuildingSelectDto> list = communityService.getAreaTree();
+		return new AjaxMessage<>(ResultStatus.OK, list);
+	}
 
-/*	@GetMapping("queryCommunity")
+	@GetMapping("queryCommunity")
 	@ApiOperation(value = "查询小区")
 	public AjaxMessage<List<CommunityDto>> queryCommunity(
 			@ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String name,
@@ -53,7 +60,7 @@ public class CommunityManagerController {
         List<CommunityDto> list = communityService.queryList(param);
         
         return new AjaxMessage<>(ResultStatus.OK, list);
-	}*/
+	}
 
 	@GetMapping("getCommunityPage")
 	@ApiOperation(value = "获取小区列表分页", notes = "权限:sys:community:query")

+ 7 - 7
smart-city-platform/src/main/java/com/bz/smart_city/controller/common/CommonController.java

@@ -45,13 +45,13 @@ public class CommonController {
         return new AjaxMessage<>(ResultStatus.OK, list);
     }
 
-//    @GetMapping("/getAllArea")
-//    @ApiOperation(value = "获取所有的省市区")
-//    public AjaxMessage<List<AreaDto>> getAllArea(
-//    ) {
-//        List<AreaDto> list = areaMapper.getAllArea();
-//        return new AjaxMessage<>(ResultStatus.OK, TreeUtil.getArea(list, 100000, 1));
-//    }
+    @GetMapping("/getAllArea")
+    @ApiOperation(value = "获取所有的省市区")
+    public AjaxMessage<List<AreaDto>> getAllArea(
+    ) {
+        List<AreaDto> list = areaMapper.getAllArea();
+        return new AjaxMessage<>(ResultStatus.OK, TreeUtil.getArea(list, 100000, 1));
+    }
 
 
 }

+ 4 - 4
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PaySyncDataController.java

@@ -41,7 +41,7 @@ public class PaySyncDataController {
     }
 
 
-    @GetMapping("system/community/queryCommunity")
+/*    @GetMapping("system/community/queryCommunity")
     @ApiOperation(value = "查询小区")
     public AjaxMessage<List<CommunityDto>> queryCommunity(
             @ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String name,
@@ -59,14 +59,14 @@ public class PaySyncDataController {
 
 
         return paySyncDataService.queryCommunity(param);
-    }
+    }*/
 
-    @GetMapping("common/getAllArea")
+/*    @GetMapping("common/getAllArea")
     @ApiOperation(value = "获取所有的省市区")
     public AjaxMessage<List<AreaDto>> getAllArea(
     ) {
         return paySyncDataService.getAllArea();
-    }
+    }*/
 
 
     @GetMapping("/install/getMeterTypes")

+ 42 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/BuildingSelectDto.java

@@ -0,0 +1,42 @@
+package com.bz.smart_city.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Created by ZJY on 2020-10-10 17:10
+ */
+
+@Data
+public class BuildingSelectDto implements Serializable {
+    private static final long serialVersionUID = -3204557875996317038L;
+    @ApiModelProperty(value = "code", position = 1)
+    private Integer code;
+
+    @ApiModelProperty(value = "父类", position = 2)
+    private Integer pid;
+
+    @ApiModelProperty(value = "名称", position = 3)
+    private String name;
+
+    @ApiModelProperty(value="维度编码", position = 4)
+    private String dimensionCode;
+
+    @ApiModelProperty(value = "状态", position = 5)
+    private Integer status;
+
+    @ApiModelProperty(value = "数量统计", position = 6)
+    private Integer num;
+
+    @ApiModelProperty(value = "经度", position = 7)
+    private Double longitude;
+
+    @ApiModelProperty(value = "纬度", position = 8)
+    private Double latitude;
+
+    @ApiModelProperty(value = "子类", position = 9)
+    private List<BuildingSelectDto> children;
+}

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/CommunityService.java

@@ -1,6 +1,7 @@
 package com.bz.smart_city.service;
 
 import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.dto.BuildingSelectDto;
 import com.bz.smart_city.dto.CommunityDto;
 import com.bz.smart_city.entity.Community;
 import org.apache.ibatis.annotations.Param;
@@ -34,4 +35,6 @@ public interface CommunityService {
     Community findByNameV2(@Param("siteId") Integer siteId, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region, @Param("communityName") String communityName);
 
     List<Community> getMaxCodeBySiteId(Integer siteId);
+
+    List<BuildingSelectDto> getAreaTree();
 }

+ 54 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/CommunityServiceImpl.java

@@ -2,10 +2,15 @@ package com.bz.smart_city.service.impl;
 
 import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.util.TreeUtil;
 import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.commom.util.Util;
+import com.bz.smart_city.dao.AreaMapper;
 import com.bz.smart_city.dao.CommunityMapper;
+import com.bz.smart_city.dto.BuildingSelectDto;
 import com.bz.smart_city.dto.CommunityDto;
 import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.entity.Area;
 import com.bz.smart_city.entity.Community;
 import com.bz.smart_city.entity.ProgramItem;
 import com.bz.smart_city.service.CommunityService;
@@ -18,6 +23,8 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 
+import static com.google.common.collect.Lists.newArrayList;
+
 @Slf4j
 @Service
 public class CommunityServiceImpl implements CommunityService{
@@ -25,6 +32,8 @@ public class CommunityServiceImpl implements CommunityService{
     @Resource
     private CommunityMapper communityMapper;
 
+    @Resource
+    private AreaMapper areaMapper;
 
     @Override
     public int insert(Community community){
@@ -184,4 +193,49 @@ public class CommunityServiceImpl implements CommunityService{
     public List<Community> getMaxCodeBySiteId(Integer siteId){
         return  communityMapper.getMaxCodeBySiteId(siteId);
     }
+
+
+    @Override
+    public List<BuildingSelectDto> getAreaTree() {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+
+        List<Integer> ids = newArrayList();
+        List<BuildingSelectDto> buildingSelectDtoArrayList = newArrayList();
+
+        List<CommunityDto> communityList =newArrayList();
+        if (loginUser.getSiteType() != 2) {
+            communityList = communityMapper.findBySiteId(loginUser.getSiteId());
+        }else {
+            communityList = communityMapper.findByCustomerId(loginUser.getCustomerId());
+        }
+
+
+        if (communityList != null && communityList.size() > 0) {
+            communityList.forEach(community -> {
+                ids.add(community.getProvince());
+                ids.add(community.getCity());
+                ids.add(community.getRegion());
+            });
+        }
+        //查询所有建筑的区域
+        List<Area> areaList = newArrayList();
+        if (ids.size() > 0) {
+            areaList = areaMapper.findByIds(Util.removeDuplicate(ids));
+        }
+        if (areaList != null && areaList.size() > 0) {
+            areaList.forEach(area -> {
+                BuildingSelectDto buildingSelectDto = new BuildingSelectDto();
+                buildingSelectDto.setCode(area.getId());
+                buildingSelectDto.setPid(area.getParentId());
+                buildingSelectDto.setName(area.getName());
+                buildingSelectDto.setStatus(0);
+                if(area.getLevelType() == 1)buildingSelectDto.setDimensionCode("PROVINCE");
+                if(area.getLevelType() == 2)buildingSelectDto.setDimensionCode("CITY");
+                if(area.getLevelType() == 3)buildingSelectDto.setDimensionCode("REGION");
+
+                buildingSelectDtoArrayList.add(buildingSelectDto);
+            });
+        }
+        return TreeUtil.getBuildingSelect(buildingSelectDtoArrayList, 100000, "", 1);
+    }
 }