|
@@ -10,7 +10,6 @@ package com.kioor.room.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
|
import com.kioor.common.constant.Constant;
|
|
import com.kioor.common.constant.Constant;
|
|
import com.kioor.common.dto.SysRegionDTO;
|
|
import com.kioor.common.dto.SysRegionDTO;
|
|
import com.kioor.common.page.PageData;
|
|
import com.kioor.common.page.PageData;
|
|
@@ -18,11 +17,10 @@ import com.kioor.common.service.SysRegionService;
|
|
import com.kioor.common.service.impl.BaseServiceImpl;
|
|
import com.kioor.common.service.impl.BaseServiceImpl;
|
|
import com.kioor.common.utils.ConvertUtils;
|
|
import com.kioor.common.utils.ConvertUtils;
|
|
import com.kioor.room.dao.HousingEstateDao;
|
|
import com.kioor.room.dao.HousingEstateDao;
|
|
-import com.kioor.room.dto.HousingEstateDTO;
|
|
|
|
-import com.kioor.room.dto.BuildingInitDTO;
|
|
|
|
-import com.kioor.room.dto.UnitInfoDTO;
|
|
|
|
|
|
+import com.kioor.room.dto.*;
|
|
import com.kioor.room.entity.*;
|
|
import com.kioor.room.entity.*;
|
|
import com.kioor.room.service.*;
|
|
import com.kioor.room.service.*;
|
|
|
|
+import com.kioor.user.dto.UserRoomDTO;
|
|
import com.kioor.user.service.UserService;
|
|
import com.kioor.user.service.UserService;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -129,71 +127,99 @@ public class HousingEstateServiceImpl extends BaseServiceImpl<HousingEstateDao,
|
|
updateById(entity);
|
|
updateById(entity);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// /**
|
|
|
|
+// * 初始化小区内信息(旧)
|
|
|
|
+// * @param buildingInitDTOList 楼栋列表
|
|
|
|
+// */
|
|
|
|
+// @Override
|
|
|
|
+// public void buildingInit(List<BuildingInitDTO> buildingInitDTOList) {
|
|
|
|
+// Map<Long, BuildingEntity> buildingsMap = new HashMap<>();
|
|
|
|
+// Map<Long, UnitEntity> unitsMap = new HashMap<>();
|
|
|
|
+// List<FloorEntity> floorsList = new ArrayList<>();
|
|
|
|
+// List<RoomEntity> roomsList = new ArrayList<>();
|
|
|
|
+//
|
|
|
|
+// //遍历楼栋
|
|
|
|
+// for (BuildingInitDTO estateInit : buildingInitDTOList) {
|
|
|
|
+// Long housingEstateId = estateInit.getHousingEstateId();
|
|
|
|
+// String buildingNum = estateInit.getBuildingNum();
|
|
|
|
+// //创建楼栋
|
|
|
|
+// Long buildingId = IdWorker.getId();
|
|
|
|
+// BuildingEntity buildingEntity = buildingsMap.computeIfAbsent(buildingId,
|
|
|
|
+// k -> new BuildingEntity(buildingId,housingEstateId, buildingNum));
|
|
|
|
+//
|
|
|
|
+// //遍历楼栋下的单元
|
|
|
|
+// for (UnitInfoDTO unitInfo : estateInit.getUnitInfo()) {
|
|
|
|
+// String unitNum = unitInfo.getUnitNum();
|
|
|
|
+// int floorCount = unitInfo.getFloorCount();
|
|
|
|
+// int apartmentPerFloor = unitInfo.getApartmentPerFloor();
|
|
|
|
+// //创建单元
|
|
|
|
+// Long unitId = IdWorker.getId();
|
|
|
|
+// UnitEntity unitEntity = unitsMap.computeIfAbsent(unitId,
|
|
|
|
+// k -> new UnitEntity(IdWorker.getId(),housingEstateId, buildingEntity.getId(), unitNum));
|
|
|
|
+//
|
|
|
|
+// //遍历楼层
|
|
|
|
+// for (int floor = 1; floor <= floorCount; floor++) {
|
|
|
|
+// //创建楼层
|
|
|
|
+// FloorEntity floorEntity = new FloorEntity(IdWorker.getId(),housingEstateId, unitEntity.getId(), floor);
|
|
|
|
+// floorsList.add(floorEntity);
|
|
|
|
+// //遍历该楼层每一户
|
|
|
|
+// for (int apartment = 1; apartment <= apartmentPerFloor; apartment++) {
|
|
|
|
+// RoomEntity roomEntity = new RoomEntity(IdWorker.getId(),housingEstateId, buildingId, unitId, floorEntity.getId(), apartment, buildingNum + "-" + unitNum + "-" + floor + String.format("%02d", apartment));
|
|
|
|
+// roomsList.add(roomEntity);
|
|
|
|
+//
|
|
|
|
+// // 检查是否需要批量保存房间
|
|
|
|
+// if (roomsList.size() >= BATCH_SIZE) {
|
|
|
|
+// roomService.insertBatch(roomsList);
|
|
|
|
+// roomsList.clear();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 批量保存剩余的房间
|
|
|
|
+// if (!roomsList.isEmpty()) {
|
|
|
|
+// roomService.insertBatch(roomsList);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 批量保存楼栋、单元和楼层(如果有必要的话,应先检查是否有新增数据)
|
|
|
|
+// for (BuildingEntity building : buildingsMap.values()) {
|
|
|
|
+// buildingService.insertBatch(Collections.singletonList(building));
|
|
|
|
+// }
|
|
|
|
+// for (UnitEntity unit : unitsMap.values()) {
|
|
|
|
+// unitService.insertBatch(Collections.singletonList(unit));
|
|
|
|
+// }
|
|
|
|
+// if (!floorsList.isEmpty()) {
|
|
|
|
+// floorService.insertBatch(floorsList);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 初始化小区内信息
|
|
|
|
- * @param buildingInitDTOList 楼栋列表
|
|
|
|
|
|
+ * 初始化房屋信息(新)
|
|
|
|
+ * @param dto 房屋信息
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void buildingInit(List<BuildingInitDTO> buildingInitDTOList) {
|
|
|
|
- Map<Long, BuildingEntity> buildingsMap = new HashMap<>();
|
|
|
|
- Map<Long, UnitEntity> unitsMap = new HashMap<>();
|
|
|
|
- List<FloorEntity> floorsList = new ArrayList<>();
|
|
|
|
- List<RoomEntity> roomsList = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- //遍历楼栋
|
|
|
|
- for (BuildingInitDTO estateInit : buildingInitDTOList) {
|
|
|
|
- Long housingEstateId = estateInit.getHousingEstateId();
|
|
|
|
- String buildingNum = estateInit.getBuildingNum();
|
|
|
|
- //创建楼栋
|
|
|
|
- Long buildingId = IdWorker.getId();
|
|
|
|
- BuildingEntity buildingEntity = buildingsMap.computeIfAbsent(buildingId,
|
|
|
|
- k -> new BuildingEntity(buildingId,housingEstateId, buildingNum));
|
|
|
|
-
|
|
|
|
- //遍历楼栋下的单元
|
|
|
|
- for (UnitInfoDTO unitInfo : estateInit.getUnitInfo()) {
|
|
|
|
- String unitNum = unitInfo.getUnitNum();
|
|
|
|
- int floorCount = unitInfo.getFloorCount();
|
|
|
|
- int apartmentPerFloor = unitInfo.getApartmentPerFloor();
|
|
|
|
- //创建单元
|
|
|
|
- Long unitId = IdWorker.getId();
|
|
|
|
- UnitEntity unitEntity = unitsMap.computeIfAbsent(unitId,
|
|
|
|
- k -> new UnitEntity(IdWorker.getId(),housingEstateId, buildingEntity.getId(), unitNum));
|
|
|
|
-
|
|
|
|
- //遍历楼层
|
|
|
|
- for (int floor = 1; floor <= floorCount; floor++) {
|
|
|
|
- //创建楼层
|
|
|
|
- FloorEntity floorEntity = new FloorEntity(IdWorker.getId(),housingEstateId, unitEntity.getId(), floor);
|
|
|
|
- floorsList.add(floorEntity);
|
|
|
|
- //遍历该楼层每一户
|
|
|
|
- for (int apartment = 1; apartment <= apartmentPerFloor; apartment++) {
|
|
|
|
- RoomEntity roomEntity = new RoomEntity(IdWorker.getId(),housingEstateId, buildingId, unitId, floorEntity.getId(), apartment, buildingNum + "-" + unitNum + "-" + floor + String.format("%02d", apartment));
|
|
|
|
- roomsList.add(roomEntity);
|
|
|
|
-
|
|
|
|
- // 检查是否需要批量保存房间
|
|
|
|
- if (roomsList.size() >= BATCH_SIZE) {
|
|
|
|
- roomService.insertBatch(roomsList);
|
|
|
|
- roomsList.clear();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ public Long roomInit(UserRoomDTO dto) {
|
|
|
|
+ //校验该小区此楼栋是否已存在,如果不存在就新增
|
|
|
|
+ Long buildingId = buildingService.saveOrUpdate(new BuildingDTO(dto.getHousingEstateId(), dto.getBuildingNum()));
|
|
|
|
|
|
- // 批量保存剩余的房间
|
|
|
|
- if (!roomsList.isEmpty()) {
|
|
|
|
- roomService.insertBatch(roomsList);
|
|
|
|
- }
|
|
|
|
|
|
+ Long unitId = unitService.saveOrUpdate(new UnitDTO(dto.getHousingEstateId(), buildingId, dto.getUnitNum()));
|
|
|
|
|
|
- // 批量保存楼栋、单元和楼层(如果有必要的话,应先检查是否有新增数据)
|
|
|
|
- for (BuildingEntity building : buildingsMap.values()) {
|
|
|
|
- buildingService.insertBatch(Collections.singletonList(building));
|
|
|
|
- }
|
|
|
|
- for (UnitEntity unit : unitsMap.values()) {
|
|
|
|
- unitService.insertBatch(Collections.singletonList(unit));
|
|
|
|
- }
|
|
|
|
- if (!floorsList.isEmpty()) {
|
|
|
|
- floorService.insertBatch(floorsList);
|
|
|
|
|
|
+ Long floorId = floorService.saveOrUpdate(new FloorDTO(dto.getHousingEstateId(), unitId, dto.getFloorNum()));
|
|
|
|
+
|
|
|
|
+ //校验房屋是否已存在
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("floorId", floorId);
|
|
|
|
+ params.put("roomNum", dto.getRoomNum());
|
|
|
|
+ List<RoomDTO> roomDTOS = roomService.list(params);
|
|
|
|
+ if(!roomDTOS.isEmpty()){
|
|
|
|
+ return roomDTOS.get(0).getId();
|
|
}
|
|
}
|
|
|
|
+ RoomEntity roomEntity = new RoomEntity(dto.getHousingEstateId(), buildingId, unitId, floorId, dto.getRoomNum(), dto.getBuildingNum() + "-" + dto.getUnitNum() + "-" + dto.getFloorNum() + String.format("%02d", dto.getRoomNum()));
|
|
|
|
+ roomService.insert(roomEntity);
|
|
|
|
+ return roomEntity.getId();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -247,6 +273,20 @@ public class HousingEstateServiceImpl extends BaseServiceImpl<HousingEstateDao,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 校验小区重名
|
|
|
|
+ *
|
|
|
|
+ * @param name
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean checkName(String name) {
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("name", name);
|
|
|
|
+ List<HousingEstateEntity> list = baseDao.getList(params);
|
|
|
|
+ return !list.isEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 校验小区创建者和初始化的人是否是同一人
|
|
* 校验小区创建者和初始化的人是否是同一人
|
|
*
|
|
*
|