170 lines
4.8 KiB
Java
170 lines
4.8 KiB
Java
package com.eden.room.service.impl;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Collections;
|
|
import java.util.stream.Collectors;
|
|
|
|
import com.eden.room.domain.Project;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import com.eden.common.exception.ServiceException;
|
|
import com.eden.room.domain.Building;
|
|
import com.eden.room.mapper.BuildingMapper;
|
|
import com.eden.room.service.IBuildingService;
|
|
|
|
/**
|
|
* 楼宇信息服务实现类
|
|
*/
|
|
@Service
|
|
public class BuildingServiceImpl implements IBuildingService {
|
|
|
|
@Autowired
|
|
private BuildingMapper buildingMapper;
|
|
|
|
/**
|
|
* 查询楼宇信息列表
|
|
*
|
|
* @param building 楼宇信息查询条件
|
|
* @return 楼宇信息集合
|
|
*/
|
|
@Override
|
|
public List<Building> selectBuildingList(Building building) {
|
|
return buildingMapper.selectBuildingList(building);
|
|
}
|
|
|
|
/**
|
|
* 根据楼宇ID查询楼宇信息
|
|
*
|
|
* @param id 楼宇ID
|
|
* @return 楼宇信息
|
|
*/
|
|
@Override
|
|
public Building selectBuildingById(Long id) {
|
|
return buildingMapper.selectBuildingById(id);
|
|
}
|
|
|
|
/**
|
|
* 新增楼宇信息
|
|
*
|
|
* @param building 楼宇信息
|
|
* @return 结果
|
|
*/
|
|
@Override
|
|
public int insertBuilding(Building building) {
|
|
// 检查楼宇名称是否唯一
|
|
if (checkBuildingNameExists(building)) {
|
|
throw new ServiceException("楼宇名称'" + building.getBuildingName() + "'已存在");
|
|
}
|
|
|
|
// 检查楼宇编码是否唯一
|
|
if (checkBuildingCodeExists(building)) {
|
|
throw new ServiceException("楼宇编码'" + building.getBuildingCode() + "'已存在");
|
|
}
|
|
|
|
return buildingMapper.insertBuilding(building);
|
|
}
|
|
|
|
/**
|
|
* 修改楼宇信息
|
|
*
|
|
* @param building 楼宇信息
|
|
* @return 结果
|
|
*/
|
|
@Override
|
|
public int updateBuilding(Building building) {
|
|
// // 检查楼宇名称是否唯一
|
|
// if (checkBuildingNameExists(building)) {
|
|
// throw new ServiceException("楼宇名称'" + building.getBuildingName() + "'已存在");
|
|
// }
|
|
//
|
|
// // 检查楼宇编码是否唯一
|
|
// if (checkBuildingCodeExists(building)) {
|
|
// throw new ServiceException("楼宇编码'" + building.getBuildingCode() + "'已存在");
|
|
// }
|
|
|
|
return buildingMapper.updateBuilding(building);
|
|
}
|
|
|
|
/**
|
|
* 批量删除楼宇信息
|
|
*
|
|
* @param ids 需要删除的楼宇ID数组
|
|
* @return 结果
|
|
*/
|
|
@Override
|
|
public int deleteBuildingByIds(List<Long> ids) {
|
|
for (Long id : ids) {
|
|
if (buildingMapper.checkBuildingHasFloors(id)) {
|
|
throw new ServiceException("楼宇下存在楼层信息,不允许删除");
|
|
}
|
|
}
|
|
return buildingMapper.deleteBuildingByIds(ids);
|
|
}
|
|
|
|
/**
|
|
* 删除楼宇信息
|
|
*
|
|
* @param id 楼宇ID
|
|
* @return 结果
|
|
*/
|
|
@Override
|
|
public int deleteBuildingById(Long id) {
|
|
if (buildingMapper.checkBuildingHasFloors(id)) {
|
|
throw new ServiceException("楼宇下存在楼层信息,不允许删除");
|
|
}
|
|
return buildingMapper.deleteBuildingById(id);
|
|
}
|
|
|
|
/**
|
|
* 楼宇统计信息
|
|
*
|
|
* @param id 楼宇ID
|
|
* @return 楼宇信息
|
|
*/
|
|
@Override
|
|
public Building selectBuildingStatistics(Long id) {
|
|
return buildingMapper.selectBuildingStatistics(id);
|
|
}
|
|
|
|
/**
|
|
* 检查楼宇名称是否存在
|
|
*
|
|
* @param building 楼宇信息
|
|
* @return 结果
|
|
*/
|
|
public boolean checkBuildingNameExists(Building building) {
|
|
return buildingMapper.checkBuildingNameExists(building) > 0;
|
|
}
|
|
|
|
@Override
|
|
public List<Building> getBuildByIds(List<String> ids) {
|
|
return buildingMapper.getBuildByIds(ids);
|
|
}
|
|
|
|
/**
|
|
* 检查楼宇编码是否存在
|
|
*
|
|
* @param building 楼宇信息
|
|
* @return 结果
|
|
*/
|
|
private boolean checkBuildingCodeExists(Building building) {
|
|
return buildingMapper.checkBuildingCodeExists(building) > 0;
|
|
}
|
|
|
|
@Override
|
|
public Map<String, Long> getBuildingIdsByNames(String projectId, Set<String> buildingNames) {
|
|
if (projectId == null || buildingNames == null || buildingNames.isEmpty()) {
|
|
return Collections.emptyMap();
|
|
}
|
|
|
|
List<Building> buildings = buildingMapper.selectBuildingListByNames(projectId, buildingNames);
|
|
return buildings.stream()
|
|
.collect(Collectors.toMap(
|
|
Building::getBuildingName,
|
|
Building::getId,
|
|
(existing, replacement) -> existing
|
|
));
|
|
}
|
|
} |