From fa62ace6af5ecc2f3030fa86d2ce222a1392f1a6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 23 Feb 2022 22:36:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=8D=E6=94=AF=E6=8C=81=E6=A0=B9=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/dept/vo/dept/DeptBaseVO.java | 3 +-- .../module/system/service/dept/DeptServiceImpl.java | 13 ++++++++++++- yudao-ui-admin/src/views/system/dept/index.vue | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java index 2609f90678..699a276941 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java @@ -20,8 +20,7 @@ public class DeptBaseVO { @Size(max = 30, message = "部门名称长度不能超过30个字符") private String name; - @ApiModelProperty(value = "父菜单 ID", required = true, example = "1024") - @NotNull(message = "父菜单 ID 不能为空") + @ApiModelProperty(value = "父菜单 ID", example = "1024") private Long parentId; @ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index c8f57291df..c641ccfa41 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -71,6 +72,10 @@ public class DeptServiceImpl implements DeptService { @Resource private DeptProducer deptProducer; + @Resource + @Lazy // 注入自己,所以延迟加载 + private DeptService self; + @Override @PostConstruct @TenantIgnore // 初始化缓存,无需租户过滤 @@ -97,7 +102,7 @@ public class DeptServiceImpl implements DeptService { @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) public void schedulePeriodicRefresh() { - initLocalCache(); + self.initLocalCache(); } /** @@ -124,6 +129,9 @@ public class DeptServiceImpl implements DeptService { @Override public Long createDept(DeptCreateReqVO reqVO) { // 校验正确性 + if (reqVO.getParentId() == null) { + reqVO.setParentId(DeptIdEnum.ROOT.getId()); + } checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); // 插入部门 DeptDO dept = DeptConvert.INSTANCE.convert(reqVO); @@ -136,6 +144,9 @@ public class DeptServiceImpl implements DeptService { @Override public void updateDept(DeptUpdateReqVO reqVO) { // 校验正确性 + if (reqVO.getParentId() == null) { + reqVO.setParentId(DeptIdEnum.ROOT.getId()); + } checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); // 更新部门 DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO); diff --git a/yudao-ui-admin/src/views/system/dept/index.vue b/yudao-ui-admin/src/views/system/dept/index.vue index fc77dc56f9..27a7ff498a 100644 --- a/yudao-ui-admin/src/views/system/dept/index.vue +++ b/yudao-ui-admin/src/views/system/dept/index.vue @@ -57,7 +57,7 @@ - + @@ -152,9 +152,6 @@ export default { form: {}, // 表单校验 rules: { - parentId: [ - { required: true, message: "上级部门不能为空", trigger: "blur" } - ], name: [ { required: true, message: "部门名称不能为空", trigger: "blur" } ], @@ -278,6 +275,9 @@ export default { this.reset(); getDept(row.id).then(response => { this.form = response.data; + if (this.form.parentId === 0) { // 无父部门时,标记为 undefined,避免展示为 Unknown + this.form.parentId = undefined; + } this.open = true; this.title = "修改部门"; });