|
@@ -3,18 +3,27 @@ package cn.iocoder.yudao.module.system.service.dept;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.pms.IotTreeDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
|
|
+import cn.iocoder.yudao.module.system.dal.mysql.pms.IotTreeMapper;
|
|
|
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
|
|
+import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
|
|
+import cn.iocoder.yudao.module.system.service.pms.IotTreeService;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
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.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -36,10 +45,13 @@ public class DeptServiceImpl implements DeptService {
|
|
|
|
|
|
@Resource
|
|
|
private DeptMapper deptMapper;
|
|
|
+ @Resource
|
|
|
+ private IotTreeMapper iotTreeMapper;
|
|
|
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Long createDept(DeptSaveReqVO createReqVO) {
|
|
|
if (createReqVO.getParentId() == null) {
|
|
|
createReqVO.setParentId(DeptDO.PARENT_ID_ROOT);
|
|
@@ -52,12 +64,24 @@ public class DeptServiceImpl implements DeptService {
|
|
|
// 插入部门
|
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
|
deptMapper.insert(dept);
|
|
|
+ //插入pms树
|
|
|
+ IotTreeDO iotTreeDO = new IotTreeDO();
|
|
|
+ iotTreeDO.setType("dept");
|
|
|
+ iotTreeDO.setOriginId(dept.getId());
|
|
|
+ iotTreeDO.setName(dept.getName());
|
|
|
+ List<IotTreeDO> iotTreeDOS = iotTreeMapper.selectListByOriginId(dept.getParentId(),"dept");
|
|
|
+// if (CollUtil.isNotEmpty(iotTreeDOS)) {
|
|
|
+ iotTreeDO.setParentId(CollUtil.isNotEmpty(iotTreeDOS) ? iotTreeDOS.get(0).getId() : 0);
|
|
|
+ iotTreeMapper.insert(iotTreeDO);
|
|
|
+// }
|
|
|
+
|
|
|
return dept.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void updateDept(DeptSaveReqVO updateReqVO) {
|
|
|
if (updateReqVO.getParentId() == null) {
|
|
|
updateReqVO.setParentId(DeptDO.PARENT_ID_ROOT);
|
|
@@ -68,15 +92,23 @@ public class DeptServiceImpl implements DeptService {
|
|
|
validateParentDept(updateReqVO.getId(), updateReqVO.getParentId());
|
|
|
// 校验部门名的唯一性
|
|
|
validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
|
|
-
|
|
|
// 更新部门
|
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
|
+ //更新pms树
|
|
|
+ List<IotTreeDO> iotTreeDOS = iotTreeMapper.selectListByOriginId(updateObj.getId(),"dept");
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(iotTreeDOS)) {
|
|
|
+ throw new ServiceException(ErrorCodeConstants.DEPT_NOT_FOUND.getCode(),"无该部门");
|
|
|
+ }
|
|
|
+ IotTreeDO iotTreeDO = iotTreeDOS.get(0);
|
|
|
+ iotTreeDO.setName(updateObj.getName());
|
|
|
+ iotTreeMapper.updateById(iotTreeDO);
|
|
|
deptMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void deleteDept(Long id) {
|
|
|
// 校验是否存在
|
|
|
validateDeptExists(id);
|
|
@@ -86,6 +118,8 @@ public class DeptServiceImpl implements DeptService {
|
|
|
}
|
|
|
// 删除部门
|
|
|
deptMapper.deleteById(id);
|
|
|
+ //删除pms树
|
|
|
+ iotTreeMapper.deleteByMap(ImmutableMap.of("origin_id", id));
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|