瀏覽代碼

建筑树

lin 4 年之前
父節點
當前提交
df5b0c3849

+ 2 - 0
src/main/java/com/zoniot/ccrc/dao/BuildingMapper.java

@@ -28,5 +28,7 @@ public interface BuildingMapper {
     BuildingDto getById(@Param("buildingId") Integer buildingId);
 
     int countBycCommunityId(@Param("communityId") Integer communityId);
+
+    List<Building> findBySiteId(@Param("siteId") Integer siteId);
 }
 

+ 65 - 1
src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java

@@ -7,6 +7,7 @@ import com.zoniot.ccrc.commom.model.BuildingData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.commom.utils.TreeUtil;
 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.BuildingMapper;
 import com.zoniot.ccrc.dao.CommunityMapper;
@@ -101,7 +102,70 @@ public class BuildingServiceImpl implements BuildingService {
 
     @Override
     public List<BuildingSelectDto> area(Integer sysId) {
-        return null;
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        List<Integer> ids = newArrayList();
+        List<Integer> communityIds = newArrayList();
+        List<BuildingSelectDto> buildingSelectDtoArrayList = newArrayList();
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId());
+
+        if (buildingList != null && buildingList.size() > 0) {
+            buildingList.forEach(building -> {
+                ids.add(building.getProvince());
+                ids.add(building.getCity());
+                ids.add(building.getRegion());
+                communityIds.add(building.getCommunityId());
+            });
+        }
+
+        //查询所有的小区
+        if (communityIds.size() > 0) {
+            List<Community> communityList = communityMapper.findByIds(communityIds.stream().distinct().collect(Collectors.toList()));
+            if (communityList != null && communityList.size() > 0) {
+                for (Community community : communityList) {
+                    BuildingSelectDto buildingSelectDto = new BuildingSelectDto();
+                    buildingSelectDto.setCode(community.getId());
+                    buildingSelectDto.setName(community.getName());
+                    buildingSelectDto.setStatus(0);
+                    buildingSelectDto.setNum(0);
+                    buildingSelectDto.setDimensionCode("COMMUNITY");
+                    if (community.getRegion() != null) {
+                        //区关联建筑,把区id设置成建筑的父类id
+                        buildingSelectDto.setPid(community.getRegion());
+                    } else {
+                        if (community.getCity() != null) {
+                            //市关联建筑,把市id设置成建筑的父类id
+                            buildingSelectDto.setPid(community.getCity());
+                        } else {
+                            if (community.getProvince() != null) {
+                                //省关联建筑,把省id设置成建筑的父类id
+                                buildingSelectDto.setPid(community.getProvince());
+                            }
+                        }
+                    }
+                    buildingSelectDtoArrayList.add(buildingSelectDto);
+                }
+            }
+        }
+        //查询所有建筑的区域
+        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);
     }
 
 

+ 13 - 0
src/main/resources/mapper/BuildingMapper.xml

@@ -218,5 +218,18 @@
     <select id="countBycCommunityId" resultType="int">
         select count(1) from sc_building where status = 1 and community_id = #{communityId}
     </select>
+
+    <select id="findBySiteId" resultMap="BaseResultMap">
+        select
+        b.id,
+        b.name,
+        b.province,
+        b.city,
+        b.region,
+        b.community_id
+        from sc_building b
+        where b.status = 1
+        <if test="siteId != null"> and b.site_id=#{siteId} </if>
+    </select>
 </mapper>