|
@@ -1,5 +1,9 @@
|
|
|
package org.dromara.backstage.basics.service.impl;
|
|
package org.dromara.backstage.basics.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
|
|
+import org.dromara.backstage.basics.domain.PtRoom;
|
|
|
|
|
+import org.dromara.backstage.basics.mapper.PtRoomMapper;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
@@ -13,9 +17,8 @@ import org.dromara.backstage.basics.domain.PtArea;
|
|
|
import org.dromara.backstage.basics.mapper.PtAreaMapper;
|
|
import org.dromara.backstage.basics.mapper.PtAreaMapper;
|
|
|
import org.dromara.backstage.basics.service.IPtAreaService;
|
|
import org.dromara.backstage.basics.service.IPtAreaService;
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 建筑物区域Service业务层处理
|
|
* 建筑物区域Service业务层处理
|
|
@@ -29,6 +32,8 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
|
|
|
|
|
private final PtAreaMapper baseMapper;
|
|
private final PtAreaMapper baseMapper;
|
|
|
|
|
|
|
|
|
|
+ private final PtRoomMapper ptRoomMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询建筑物区域
|
|
* 查询建筑物区域
|
|
|
*
|
|
*
|
|
@@ -53,6 +58,40 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
return baseMapper.selectVoList(lqw);
|
|
return baseMapper.selectVoList(lqw);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询楼层
|
|
|
|
|
+ * @param areaId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<PtAreaVo> queryListLD(Long areaId) {
|
|
|
|
|
+ PtAreaVo ptAreaVo = queryById(areaId);
|
|
|
|
|
+ if(ptAreaVo==null) return ListUtil.empty();
|
|
|
|
|
+ if("04".equals(ptAreaVo.getAreaType())) {
|
|
|
|
|
+ List<PtAreaVo> rs = new ArrayList<>();
|
|
|
|
|
+ rs.add(ptAreaVo);
|
|
|
|
|
+ return rs;
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaQueryWrapper<PtArea> lqw = Wrappers.lambdaQuery();
|
|
|
|
|
+ if(ptAreaVo.getParentId() != 0L){
|
|
|
|
|
+ lqw.likeRight(PtArea::getAncestors, ptAreaVo.getAncestors()+","+ptAreaVo.getAreaId());
|
|
|
|
|
+ }
|
|
|
|
|
+ lqw.eq(PtArea::getAreaType, "04");
|
|
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<Long, PtAreaVo> queryMapByIds(List<Long> ids) {
|
|
|
|
|
+ List<PtArea> ptAreas = baseMapper.selectBatchIds(ids);
|
|
|
|
|
+ if (ptAreas != null && !ptAreas.isEmpty()) {
|
|
|
|
|
+ return ptAreas.stream().map(e -> MapstructUtils.convert(e, PtAreaVo.class))
|
|
|
|
|
+ .filter(ptArea -> ptArea!=null&&ptArea.getAreaId() != null)
|
|
|
|
|
+ .filter(ptArea -> ptArea.getAreaId() != null)
|
|
|
|
|
+ .collect(Collectors.toMap(PtAreaVo::getAreaId, ptArea -> ptArea));
|
|
|
|
|
+ }
|
|
|
|
|
+ return MapUtil.empty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
private LambdaQueryWrapper<PtArea> buildQueryWrapper(PtAreaBo bo) {
|
|
private LambdaQueryWrapper<PtArea> buildQueryWrapper(PtAreaBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<PtArea> lqw = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<PtArea> lqw = Wrappers.lambdaQuery();
|
|
@@ -61,6 +100,10 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
return lqw;
|
|
return lqw;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 新增建筑物区域
|
|
* 新增建筑物区域
|
|
|
*
|
|
*
|
|
@@ -71,6 +114,8 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
public Boolean insertByBo(PtAreaBo bo) {
|
|
public Boolean insertByBo(PtAreaBo bo) {
|
|
|
PtArea add = MapstructUtils.convert(bo, PtArea.class);
|
|
PtArea add = MapstructUtils.convert(bo, PtArea.class);
|
|
|
validEntityBeforeSave(add);
|
|
validEntityBeforeSave(add);
|
|
|
|
|
+ //查询父节点的信息
|
|
|
|
|
+ setAncestors4Entity(bo, add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
bo.setAreaId(add.getAreaId());
|
|
bo.setAreaId(add.getAreaId());
|
|
@@ -78,6 +123,15 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
return flag;
|
|
return flag;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void setAncestors4Entity(PtAreaBo bo, PtArea add) {
|
|
|
|
|
+ if(Objects.nonNull(bo.getParentId())){
|
|
|
|
|
+ PtArea parent = baseMapper.selectById(bo.getParentId());
|
|
|
|
|
+ if(parent!=null){
|
|
|
|
|
+ add.setAncestors(parent.getAncestors()+","+parent.getAreaId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改建筑物区域
|
|
* 修改建筑物区域
|
|
|
*
|
|
*
|
|
@@ -88,6 +142,8 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
public Boolean updateByBo(PtAreaBo bo) {
|
|
public Boolean updateByBo(PtAreaBo bo) {
|
|
|
PtArea update = MapstructUtils.convert(bo, PtArea.class);
|
|
PtArea update = MapstructUtils.convert(bo, PtArea.class);
|
|
|
validEntityBeforeSave(update);
|
|
validEntityBeforeSave(update);
|
|
|
|
|
+ //查询父节点的信息
|
|
|
|
|
+ setAncestors4Entity(bo, update);
|
|
|
return baseMapper.updateById(update) > 0;
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -101,6 +157,13 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
if (baseMapper.selectCount(lqw) > 0) {
|
|
if (baseMapper.selectCount(lqw) > 0) {
|
|
|
throw new ServiceException("区域名称重复");
|
|
throw new ServiceException("区域名称重复");
|
|
|
}
|
|
}
|
|
|
|
|
+ //父节点不能是楼层 04
|
|
|
|
|
+ if(entity.getParentId()!=null){
|
|
|
|
|
+ PtArea ptArea = baseMapper.selectById(entity.getParentId());
|
|
|
|
|
+ if(ptArea!=null && "04".equals(ptArea.getAreaType())){
|
|
|
|
|
+ throw new ServiceException("楼层不能作为父节点");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -119,6 +182,13 @@ public class PtAreaServiceImpl implements IPtAreaService {
|
|
|
if (baseMapper.selectCount(lqw) > 0) {
|
|
if (baseMapper.selectCount(lqw) > 0) {
|
|
|
throw new ServiceException("请先删除子节点");
|
|
throw new ServiceException("请先删除子节点");
|
|
|
}
|
|
}
|
|
|
|
|
+ //下面有房间也不能删除
|
|
|
|
|
+ LambdaQueryWrapper<PtRoom> ptRoomLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ ptRoomLambdaQueryWrapper.in(PtRoom::getAreaId, ids);
|
|
|
|
|
+ Long aLong = ptRoomMapper.selectCount(ptRoomLambdaQueryWrapper);
|
|
|
|
|
+ if(aLong>0){
|
|
|
|
|
+ throw new ServiceException("请先删除房间");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
}
|