|
|
|
@ -3,17 +3,16 @@ package com.mh.system.service.space.impl;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.mh.common.core.domain.SpaceTreeSelect; |
|
|
|
|
import com.mh.common.core.domain.TreeSelect; |
|
|
|
|
import com.mh.common.core.domain.entity.AreaInfo; |
|
|
|
|
import com.mh.common.core.domain.entity.BuildingInfo; |
|
|
|
|
import com.mh.common.core.domain.entity.FloorInfo; |
|
|
|
|
import com.mh.common.core.domain.entity.HouseInfo; |
|
|
|
|
import com.mh.common.core.domain.entity.*; |
|
|
|
|
import com.mh.common.utils.StringUtils; |
|
|
|
|
import com.mh.system.mapper.SysParamsMapper; |
|
|
|
|
import com.mh.system.mapper.space.AreaInfoMapper; |
|
|
|
|
import com.mh.system.mapper.space.BuildingInfoMapper; |
|
|
|
|
import com.mh.system.mapper.space.FloorInfoMapper; |
|
|
|
|
import com.mh.system.mapper.space.HouseInfoMapper; |
|
|
|
|
import com.mh.system.service.space.IHouseInfoService; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
@ -43,6 +42,9 @@ public class HouseInfoServiceImpl implements IHouseInfoService {
|
|
|
|
|
@Resource |
|
|
|
|
private HouseInfoMapper houseInfoMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private SysParamsMapper sysParamsMapper; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<HouseInfo> selectHouseInfoList(HouseInfo houseInfo) { |
|
|
|
|
if (houseInfo == null) { |
|
|
|
@ -80,30 +82,62 @@ public class HouseInfoServiceImpl implements IHouseInfoService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int insertHouseInfo(HouseInfo houseInfo) { |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getAreaId())) { |
|
|
|
|
throw new RuntimeException("没有对应的区域id"); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getBuildingId())) { |
|
|
|
|
throw new RuntimeException("没有对应的楼栋id"); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getFloorId())) { |
|
|
|
|
throw new RuntimeException("没有对应的楼层id"); |
|
|
|
|
} |
|
|
|
|
getAreaIdAndBuildingId(houseInfo); |
|
|
|
|
return houseInfoMapper.insert(houseInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 递归查找楼栋节点方法
|
|
|
|
|
private SpaceTreeSelect findNode(List<SpaceTreeSelect> nodes, String targetId, int nodeType) { |
|
|
|
|
for (SpaceTreeSelect node : nodes) { |
|
|
|
|
if (node.getNodeType() == nodeType && targetId.equals(node.getId())) { |
|
|
|
|
return node; |
|
|
|
|
} |
|
|
|
|
if (node.getChildren() != null && !node.getChildren().isEmpty()) { |
|
|
|
|
SpaceTreeSelect found = findNode(node.getChildren(), targetId, nodeType); |
|
|
|
|
if (found != null) { |
|
|
|
|
return found; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int updateHouseInfo(HouseInfo houseInfo) { |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getAreaId())) { |
|
|
|
|
throw new RuntimeException("没有对应的区域id"); |
|
|
|
|
getAreaIdAndBuildingId(houseInfo); |
|
|
|
|
return houseInfoMapper.updateById(houseInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getAreaIdAndBuildingId(HouseInfo houseInfo) { |
|
|
|
|
if(StringUtils.isEmpty(houseInfo.getBuildingId())) { |
|
|
|
|
// 获取完整的空间树结构
|
|
|
|
|
List<SpaceTreeSelect> spaceTree = buildTree(); |
|
|
|
|
|
|
|
|
|
// 递归查找目标楼栋节点
|
|
|
|
|
SpaceTreeSelect buildNode = findNode(spaceTree, houseInfo.getFloorId(), 3); |
|
|
|
|
|
|
|
|
|
if(buildNode != null && buildNode.getParentId() != null) { |
|
|
|
|
houseInfo.setBuildingId(buildNode.getParentId()); |
|
|
|
|
} else { |
|
|
|
|
throw new RuntimeException("未找到对应的楼栋id"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getBuildingId())) { |
|
|
|
|
throw new RuntimeException("没有对应的楼栋id"); |
|
|
|
|
if(StringUtils.isEmpty(houseInfo.getAreaId())) { |
|
|
|
|
// 获取完整的空间树结构
|
|
|
|
|
List<SpaceTreeSelect> spaceTree = buildTree(); |
|
|
|
|
|
|
|
|
|
// 递归查找目标楼栋节点
|
|
|
|
|
SpaceTreeSelect areaNode = findNode(spaceTree, houseInfo.getBuildingId(), 2); |
|
|
|
|
|
|
|
|
|
if(areaNode != null && areaNode.getParentId() != null) { |
|
|
|
|
houseInfo.setAreaId(areaNode.getParentId()); |
|
|
|
|
} else { |
|
|
|
|
throw new RuntimeException("未找到对应的区域id"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isEmpty(houseInfo.getFloorId())) { |
|
|
|
|
throw new RuntimeException("没有对应的楼层id"); |
|
|
|
|
} |
|
|
|
|
return houseInfoMapper.updateById(houseInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -119,11 +153,11 @@ public class HouseInfoServiceImpl implements IHouseInfoService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<SpaceTreeSelect> buildTree() { |
|
|
|
|
List<AreaInfo> areaInfos = areaInfoMapper.selectList(null); |
|
|
|
|
List<AreaInfo> areaInfos = areaInfoMapper.selectList(new QueryWrapper<AreaInfo>().orderByAsc("order_num")); |
|
|
|
|
if (areaInfos != null && !areaInfos.isEmpty()) { |
|
|
|
|
List<BuildingInfo> buildingInfos = buildingInfoMapper.selectList(null); |
|
|
|
|
List<FloorInfo> floorInfos = floorInfoMapper.selectList(null); |
|
|
|
|
List<HouseInfo> houseInfos = houseInfoMapper.selectList(null); |
|
|
|
|
List<BuildingInfo> buildingInfos = buildingInfoMapper.selectList(new QueryWrapper<BuildingInfo>().orderByAsc("order_num")); |
|
|
|
|
List<FloorInfo> floorInfos = floorInfoMapper.selectList(new QueryWrapper<FloorInfo>().orderByAsc("order_num")); |
|
|
|
|
List<HouseInfo> houseInfos = houseInfoMapper.selectList(new QueryWrapper<HouseInfo>().orderByAsc("order_num")); |
|
|
|
|
return buildTree(areaInfos, buildingInfos, floorInfos, houseInfos); |
|
|
|
|
} |
|
|
|
|
return List.of(); |
|
|
|
@ -135,13 +169,13 @@ public class HouseInfoServiceImpl implements IHouseInfoService {
|
|
|
|
|
List<HouseInfo> houseInfos) { |
|
|
|
|
// 房间 -> 楼层映射
|
|
|
|
|
Map<String, List<SpaceTreeSelect>> floorMap = houseInfos.stream() |
|
|
|
|
.map(r -> new SpaceTreeSelect(r.getId(), r.getHouseName(), false, r.getFloorId(), 3)) |
|
|
|
|
.map(r -> new SpaceTreeSelect(r.getId(), r.getHouseName(), false, r.getFloorId(), 4)) |
|
|
|
|
.collect(Collectors.groupingBy(SpaceTreeSelect::getParentId)); |
|
|
|
|
|
|
|
|
|
// 楼层 -> 楼栋映射
|
|
|
|
|
Map<String, List<SpaceTreeSelect>> buildingMap = floorInfos.stream() |
|
|
|
|
.map(f -> { |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(f.getId(), f.getFloorName(), false, f.getBuildingId(), 2); |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(f.getId(), f.getFloorName(), false, f.getBuildingId(), 3); |
|
|
|
|
node.setChildren(floorMap.getOrDefault(f.getId(), Collections.emptyList())); |
|
|
|
|
return node; |
|
|
|
|
}) |
|
|
|
@ -150,20 +184,26 @@ public class HouseInfoServiceImpl implements IHouseInfoService {
|
|
|
|
|
// 楼栋 -> 区域映射
|
|
|
|
|
Map<String, List<SpaceTreeSelect>> areaMap = buildingInfos.stream() |
|
|
|
|
.map(b -> { |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(b.getId(), b.getBuildingName(), false, b.getAreaId(), 1); |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(b.getId(), b.getBuildingName(), false, b.getAreaId(), 2); |
|
|
|
|
node.setChildren(buildingMap.getOrDefault(b.getId(), Collections.emptyList())); |
|
|
|
|
return node; |
|
|
|
|
}) |
|
|
|
|
.collect(Collectors.groupingBy(SpaceTreeSelect::getParentId)); |
|
|
|
|
|
|
|
|
|
// 构建区域树
|
|
|
|
|
return areaInfos.stream() |
|
|
|
|
// 区域 -> 根节点映射
|
|
|
|
|
Map<String, List<SpaceTreeSelect>> map = areaInfos.stream() |
|
|
|
|
.map(a -> { |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(a.getId(), a.getAreaName(), false, null, 0); |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(a.getId(), a.getAreaName(), false, "0", 1); |
|
|
|
|
node.setChildren(areaMap.getOrDefault(a.getId(), Collections.emptyList())); |
|
|
|
|
return node; |
|
|
|
|
}) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
.collect(Collectors.groupingBy(SpaceTreeSelect::getParentId)); |
|
|
|
|
List<SysParams> sysParams = sysParamsMapper.selectSysParamsList(); |
|
|
|
|
return sysParams.stream().map(r -> { |
|
|
|
|
SpaceTreeSelect node = new SpaceTreeSelect(r.getId(), r.getProName(), false, null, 0); |
|
|
|
|
node.setChildren(map.getOrDefault(r.getId(), Collections.emptyList())); |
|
|
|
|
return node; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|