diff --git a/src/main/java/com/cm/population/controller/api/house/HouseController.java b/src/main/java/com/cm/population/controller/api/house/HouseController.java index 37c8b38..f64a6e1 100644 --- a/src/main/java/com/cm/population/controller/api/house/HouseController.java +++ b/src/main/java/com/cm/population/controller/api/house/HouseController.java @@ -8,6 +8,7 @@ import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultList; +import com.cm.population.pojo.dtos.house.BatchHouseDTO; import com.cm.population.pojo.dtos.house.HouseDTO; import com.cm.population.pojo.vos.house.HouseVO; import com.cm.population.service.house.IHouseService; @@ -118,4 +119,16 @@ public class HouseController extends AbstractController { return houseService.listByPopulationInfoId(populationInfoId); } + @ApiOperation(value = "获取当前楼栋的所有房屋信息", notes = "获取当前楼栋的所有房屋信息接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "buildingId", value = "楼栋ID", paramType = "path"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("getAllHouse/{buildingId}") + public BatchHouseDTO getAllHouse(@PathVariable("buildingId") String buildingId) { + Map params = requestParams(); + params.put("buildingId", buildingId); + return houseService.getAllHouse(params); + } + } \ No newline at end of file diff --git a/src/main/java/com/cm/population/pojo/dtos/house/BatchHouseDTO.java b/src/main/java/com/cm/population/pojo/dtos/house/BatchHouseDTO.java new file mode 100644 index 0000000..fa3ce94 --- /dev/null +++ b/src/main/java/com/cm/population/pojo/dtos/house/BatchHouseDTO.java @@ -0,0 +1,121 @@ +package com.cm.population.pojo.dtos.house; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +/** + * @ClassName: HouseDTO + * @Description: 房院管理 + * @Author: CodeFactory + * @Date: 2023-10-25 14:47:44 + * @Version: 3.0 + **/ +@ApiModel +public class BatchHouseDTO { + + @ApiModelProperty(name = "floorCount", value = "楼层数") + private String floorCount; + @ApiModelProperty(name = "unitCount", value = "单元数") + private String unitCount; + @ApiModelProperty(name = "unitCount", value = "单元数") + private List floors; + + public String getFloorCount() { + return floorCount; + } + + public void setFloorCount(String floorCount) { + this.floorCount = floorCount; + } + + public String getUnitCount() { + return unitCount; + } + + public void setUnitCount(String unitCount) { + this.unitCount = unitCount; + } + + public List getFloors() { + return floors; + } + + public void setFloors(List floors) { + this.floors = floors; + } + + public static class Floor { + + @ApiModelProperty(name = "name", value = "所在楼层") + private String name; + @ApiModelProperty(name = "units", value = "单元信息") + private List units; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getUnits() { + return units; + } + + public void setUnits(List units) { + this.units = units; + } + } + + public static class Unit { + + @ApiModelProperty(name = "name", value = "所在楼层") + private String name; + @ApiModelProperty(name = "houses", value = "单元信息") + private List houses; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getHouses() { + return houses; + } + + public void setHouses(List houses) { + this.houses = houses; + } + } + + public static class House { + + @ApiModelProperty(name = "houseId", value = "房屋ID") + private String houseId; + @ApiModelProperty(name = "name", value = "房屋编号") + private String name; + + public String getHouseId() { + return houseId; + } + + public void setHouseId(String houseId) { + this.houseId = houseId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} diff --git a/src/main/java/com/cm/population/service/house/IHouseService.java b/src/main/java/com/cm/population/service/house/IHouseService.java index b4694f0..972b370 100644 --- a/src/main/java/com/cm/population/service/house/IHouseService.java +++ b/src/main/java/com/cm/population/service/house/IHouseService.java @@ -3,6 +3,7 @@ package com.cm.population.service.house; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultList; import com.cm.population.pojo.bos.house.HouseBO; +import com.cm.population.pojo.dtos.house.BatchHouseDTO; import com.cm.population.pojo.dtos.house.HouseDTO; import com.cm.population.pojo.pos.house.HousePO; import com.cm.population.pojo.vos.house.HouseVO; @@ -186,4 +187,6 @@ public interface IHouseService { Integer count(Map params); List listByPopulationInfoId(String populationInfoId); + + BatchHouseDTO getAllHouse(Map params); } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java index fa6d9be..6b50e30 100644 --- a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java +++ b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java @@ -4,13 +4,12 @@ import com.cm.common.base.AbstractService; import com.cm.common.pojo.ListPage; import com.cm.common.pojo.bos.UserInfoBO; import com.cm.common.result.SuccessResultList; -import com.cm.common.token.app.AppTokenManager; -import com.cm.common.token.app.entity.AppTokenUser; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.population.dao.house.IHouseDao; import com.cm.population.pojo.bos.house.HouseBO; import com.cm.population.pojo.dtos.building.BuildingDTO; +import com.cm.population.pojo.dtos.house.BatchHouseDTO; import com.cm.population.pojo.dtos.house.HouseDTO; import com.cm.population.pojo.dtos.residential.ResidentialDTO; import com.cm.population.pojo.pos.house.HousePO; @@ -21,12 +20,12 @@ import com.cm.population.service.residential.IResidentialService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * @ClassName: HouseServiceImpl @@ -171,7 +170,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { @Override public List list(Map params) { - if(null != params.get("myself")) { + if (null != params.get("myself")) { UserInfoBO userInfoBO = this.securityComponent.getCurrentUser(); params.put("creator", userInfoBO.getUserId()); } @@ -216,4 +215,78 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { return list(params); } + @Override + public BatchHouseDTO getAllHouse(Map params) { + BatchHouseDTO batchHouseDTO = new BatchHouseDTO(); + // 获取楼栋信息 + BuildingDTO buildingDTO = buildingService.get(params.get("buildingId").toString()); + if (null != buildingDTO) { + Integer floorsNum = buildingDTO.getFloorsNum(); + Integer unitNum = buildingDTO.getUnitNum(); + + batchHouseDTO.setFloorCount(floorsNum.toString()); + batchHouseDTO.setUnitCount(unitNum.toString()); + + // 获取当前楼栋下的所有房屋信息 + List houseDTOList = houseDao.list(params); + + List floorList = new ArrayList<>(); + for (int i = 1; i <= floorsNum; i++) { + BatchHouseDTO.Floor floor = new BatchHouseDTO.Floor(); + floor.setName(i + "层"); + + List unitList = new ArrayList<>(); + + for (int j = 1; j <= unitNum; j++) { + BatchHouseDTO.Unit unit = new BatchHouseDTO.Unit(); + unit.setName(j + "单元"); + + List houseList = new ArrayList<>(); + + for (HouseDTO houseDTO : houseDTOList) { + BatchHouseDTO.House house = new BatchHouseDTO.House(); + if (null != houseDTO.getAffiliationFloors()) { + if (i == houseDTO.getAffiliationFloors()) { + if (null != houseDTO.getAffiliatedUnit()) { + if (j == houseDTO.getAffiliationUnit()) { + house.setHouseId(houseDTO.getHouseId()); + house.setName(houseDTO.getHouseNum().toString()); + houseList.add(house); + } + } + } + } + } + if (houseList.size() > 0) { + unit.setHouses(houseList); + unitList.add(unit); + } else { + unit.setHouses(new ArrayList<>()); + unitList.add(unit); + } + } + floorList.add(floor); + floor.setUnits(unitList); + } + batchHouseDTO.setFloors(floorList); + } + + List floors = batchHouseDTO.getFloors(); + for (BatchHouseDTO.Floor floor : floors) { + List units = floor.getUnits(); + + boolean flag = false; + for (BatchHouseDTO.Unit unit : units) { + if (null != unit.getHouses() && unit.getHouses().size() > 0) { + flag = true; + } + } + if (!flag) { + floor.setUnits(new ArrayList<>()); + } + } + + return batchHouseDTO; + } + } \ No newline at end of file