From 43714e792d37f5c617fe6277fc500ffbe07186e3 Mon Sep 17 00:00:00 2001 From: furongxin <419481438@qq.com> Date: Mon, 23 Sep 2024 17:08:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(system):=20=E4=BF=AE=E6=AD=A3=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E4=BF=AE=E6=94=B9=E5=92=8C=E5=88=A0=E9=99=A4=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A5=E9=80=82=E5=BA=94=E5=B7=A5=E5=8E=82=E5=9C=BA?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整`DeptApi`和`DeptApiImpl`中的方法命名,从`updateDept`改为`updateFactoryDept`,以明确其对工厂部门信息的修改。- 在`DeptService`和`DeptServiceImpl`中新增`updateFactoryDept`方法,实现对工厂部门信息的更新。 - 在`DeptServiceImpl`中添加`validateFactoryDeptExists`方法,用于校验工厂部门是否存在。 - 错误码常量新增`FACTORY_DEPT_NOT_FOUND`,用于标识当前工厂不存在对应部门的错误。 BREAKING CHANGE: 方法命名的变更及新增可能会影响调用系统部门修改和删除逻辑的客户端。 --- .../yudao/module/system/api/dept/DeptApi.java | 4 ++-- .../system/enums/ErrorCodeConstants.java | 1 + .../module/system/api/dept/DeptApiImpl.java | 14 +++-------- .../system/service/dept/DeptService.java | 6 +++++ .../system/service/dept/DeptServiceImpl.java | 23 +++++++++++++++++++ 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java index 7ddbabdd..e5f2f663 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java @@ -53,8 +53,8 @@ public interface DeptApi { CommonResult 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 = "删除部门信息") diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 690d3328..2f1de939 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -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, "当前职称不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java index 832256a5..de37f2f3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java @@ -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 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java index bb7a5689..3ccccb35 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java @@ -30,6 +30,12 @@ public interface DeptService { */ void updateDept(DeptSaveReqVO updateReqVO); + /** + * 更新工厂部门 + * @param updateReqVO 更新信息 + */ + void updateFactoryDept(DeptSaveReqVO updateReqVO); + /** * 删除部门 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 117d2e12..b5166d29 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -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() + .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)) {