|
@@ -3,12 +3,17 @@ package cn.iocoder.yudao.module.pms.service;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
+import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifyListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifyListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifySaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifySaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoClassifyMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoClassifyMapper;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
@@ -33,6 +38,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
|
|
private IotInfoClassifyMapper iotInfoClassifyMapper;
|
|
private IotInfoClassifyMapper iotInfoClassifyMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
|
|
|
|
+ allEntries = true)
|
|
public Long createIotInfoClassify(IotInfoClassifySaveReqVO createReqVO) {
|
|
public Long createIotInfoClassify(IotInfoClassifySaveReqVO createReqVO) {
|
|
if (createReqVO.getParentId() == null) {
|
|
if (createReqVO.getParentId() == null) {
|
|
createReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
|
|
createReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
|
|
@@ -49,6 +56,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
|
|
|
|
+ allEntries = true)
|
|
public void updateIotInfoClassify(IotInfoClassifySaveReqVO updateReqVO) {
|
|
public void updateIotInfoClassify(IotInfoClassifySaveReqVO updateReqVO) {
|
|
if (updateReqVO.getParentId() == null) {
|
|
if (updateReqVO.getParentId() == null) {
|
|
updateReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
|
|
updateReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
|
|
@@ -66,6 +75,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
|
|
|
|
+ allEntries = true)
|
|
public void deleteIotInfoClassify(Long id) {
|
|
public void deleteIotInfoClassify(Long id) {
|
|
// 校验是否存在
|
|
// 校验是否存在
|
|
validateIotInfoClassifyExists(id);
|
|
validateIotInfoClassifyExists(id);
|
|
@@ -176,5 +187,30 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
|
|
}
|
|
}
|
|
return children;
|
|
return children;
|
|
}
|
|
}
|
|
|
|
+ @Override
|
|
|
|
+ @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存
|
|
|
|
+ @Cacheable(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST, key = "#id")
|
|
|
|
+ public Set<Long> getChildIotInfoClassifyIdListFromCache(Long id) {
|
|
|
|
+ List<IotInfoClassifyDO> children = getChildInfoList(id);
|
|
|
|
+ return convertSet(children, IotInfoClassifyDO::getId);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<IotInfoClassifyDO> getChildInfoList(Collection<Long> ids) {
|
|
|
|
+ List<IotInfoClassifyDO> children = new LinkedList<>();
|
|
|
|
+ // 遍历每一层
|
|
|
|
+ Collection<Long> parentIds = ids;
|
|
|
|
+ for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
|
|
|
|
+ // 查询当前层,所有的子部门
|
|
|
|
+ List<IotInfoClassifyDO> depts = iotInfoClassifyMapper.selectListByParentId(parentIds);
|
|
|
|
+ // 1. 如果没有子部门,则结束遍历
|
|
|
|
+ if (CollUtil.isEmpty(depts)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ // 2. 如果有子部门,继续遍历
|
|
|
|
+ children.addAll(depts);
|
|
|
|
+ parentIds = convertSet(depts, IotInfoClassifyDO::getId);
|
|
|
|
+ }
|
|
|
|
+ return children;
|
|
|
|
+ }
|
|
}
|
|
}
|