fix(system): 修正部门修改和删除逻辑以适应工厂场景

- 调整`DeptApi`和`DeptApiImpl`中的方法命名,从`updateDept`改为`updateFactoryDept`,以明确其对工厂部门信息的修改。- 在`DeptService`和`DeptServiceImpl`中新增`updateFactoryDept`方法,实现对工厂部门信息的更新。
- 在`DeptServiceImpl`中添加`validateFactoryDeptExists`方法,用于校验工厂部门是否存在。
- 错误码常量新增`FACTORY_DEPT_NOT_FOUND`,用于标识当前工厂不存在对应部门的错误。

BREAKING CHANGE: 方法命名的变更及新增可能会影响调用系统部门修改和删除逻辑的客户端。
This commit is contained in:
furongxin 2024-09-23 17:08:37 +08:00
parent 21d5133171
commit 43714e792d
5 changed files with 35 additions and 13 deletions

View File

@ -53,8 +53,8 @@ public interface DeptApi {
CommonResult<Long> createDept(@RequestBody DeptRespDTO deptRespDTO);
@PostMapping(PREFIX + "/update")
@Operation(summary = "修改部门信息")
void updateDept(@RequestBody DeptRespDTO deptRespDTO);
@Operation(summary = "修改工厂部门信息")
void updateFactoryDept(@RequestBody DeptRespDTO deptRespDTO);
@PostMapping(PREFIX + "/delete")
@Operation(summary = "删除部门信息")

View File

@ -53,6 +53,7 @@ public interface ErrorCodeConstants {
ErrorCode DEPT_EXISTS_USER = new ErrorCode(1_002_004_005, "部门中存在员工,无法删除");
ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1_002_004_006, "部门({})不处于开启状态,不允许选择");
ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1_002_004_007, "不能设置自己的子部门为父部门");
ErrorCode FACTORY_DEPT_NOT_FOUND = new ErrorCode(1_002_004_008, "当前工厂没有对应部门");
// ========== 职称模块 1-002-005-000 ==========
ErrorCode POST_NOT_FOUND = new ErrorCode(1_002_005_000, "当前职称不存在");

View File

@ -74,18 +74,10 @@ public class DeptApiImpl implements DeptApi {
}
@Override
public void updateDept(DeptRespDTO deptRespDTO) {
public void updateFactoryDept(DeptRespDTO deptRespDTO) {
DeptDO deptDO = deptService.getDeptByFactoryId(deptRespDTO.getFactoryId());
if (deptDO != null) {
DeptSaveReqVO deptSaveReqVO = BeanUtils.toBean(deptDO, DeptSaveReqVO.class);
deptSaveReqVO.setLeaderUserId(deptRespDTO.getLeaderUserId());
deptSaveReqVO.setName(deptRespDTO.getName());
deptService.updateDept(deptSaveReqVO);
}
DeptSaveReqVO deptSaveReqVO = BeanUtils.toBean(deptRespDTO, DeptSaveReqVO.class);
deptService.updateFactoryDept(deptSaveReqVO);
}
@Override

View File

@ -30,6 +30,12 @@ public interface DeptService {
*/
void updateDept(DeptSaveReqVO updateReqVO);
/**
* 更新工厂部门
* @param updateReqVO 更新信息
*/
void updateFactoryDept(DeptSaveReqVO updateReqVO);
/**
* 删除部门
*

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
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;
@ -128,6 +129,17 @@ public class DeptServiceImpl implements DeptService {
deptMapper.updateById(updateObj);
}
@Override
public void updateFactoryDept(DeptSaveReqVO updateReqVO) {
// 校验自己存在
validateFactoryDeptExists(updateReqVO.getFactoryId());
DeptDO update = BeanUtils.toBean(updateReqVO, DeptDO.class);
deptMapper.update(update, new LambdaQueryWrapperX<DeptDO>()
.eq(DeptDO::getFactoryId, updateReqVO.getFactoryId()));
}
@Override
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
allEntries = true) // allEntries 清空所有缓存因为操作一个部门涉及到多个缓存
@ -153,6 +165,17 @@ public class DeptServiceImpl implements DeptService {
}
}
@VisibleForTesting
void validateFactoryDeptExists(Long factoryId) {
if (factoryId == null) {
return;
}
DeptDO dept = deptMapper.selectOne(DeptDO::getFactoryId, factoryId);
if (dept == null) {
throw exception(FACTORY_DEPT_NOT_FOUND);
}
}
@VisibleForTesting
void validateParentDept(Long id, Long parentId) {
if (parentId == null || DeptDO.PARENT_ID_ROOT.equals(parentId)) {