Commit fa62ace6af5ecc2f3030fa86d2ce222a1392f1a6

Authored by YunaiV
1 parent 95bb9744

【修复】修复不支持根部门的问题

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 { @@ -20,8 +20,7 @@ public class DeptBaseVO {
20 @Size(max = 30, message = "部门名称长度不能超过30个字符") 20 @Size(max = 30, message = "部门名称长度不能超过30个字符")
21 private String name; 21 private String name;
22 22
23 - @ApiModelProperty(value = "父菜单 ID", required = true, example = "1024")  
24 - @NotNull(message = "父菜单 ID 不能为空") 23 + @ApiModelProperty(value = "父菜单 ID", example = "1024")
25 private Long parentId; 24 private Long parentId;
26 25
27 @ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024") 26 @ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024")
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; @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableMap;
17 import com.google.common.collect.ImmutableMultimap; 17 import com.google.common.collect.ImmutableMultimap;
18 import com.google.common.collect.Multimap; 18 import com.google.common.collect.Multimap;
19 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
  20 +import org.springframework.context.annotation.Lazy;
20 import org.springframework.scheduling.annotation.Scheduled; 21 import org.springframework.scheduling.annotation.Scheduled;
21 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
22 import org.springframework.validation.annotation.Validated; 23 import org.springframework.validation.annotation.Validated;
@@ -71,6 +72,10 @@ public class DeptServiceImpl implements DeptService { @@ -71,6 +72,10 @@ public class DeptServiceImpl implements DeptService {
71 @Resource 72 @Resource
72 private DeptProducer deptProducer; 73 private DeptProducer deptProducer;
73 74
  75 + @Resource
  76 + @Lazy // 注入自己,所以延迟加载
  77 + private DeptService self;
  78 +
74 @Override 79 @Override
75 @PostConstruct 80 @PostConstruct
76 @TenantIgnore // 初始化缓存,无需租户过滤 81 @TenantIgnore // 初始化缓存,无需租户过滤
@@ -97,7 +102,7 @@ public class DeptServiceImpl implements DeptService { @@ -97,7 +102,7 @@ public class DeptServiceImpl implements DeptService {
97 102
98 @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) 103 @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD)
99 public void schedulePeriodicRefresh() { 104 public void schedulePeriodicRefresh() {
100 - initLocalCache(); 105 + self.initLocalCache();
101 } 106 }
102 107
103 /** 108 /**
@@ -124,6 +129,9 @@ public class DeptServiceImpl implements DeptService { @@ -124,6 +129,9 @@ public class DeptServiceImpl implements DeptService {
124 @Override 129 @Override
125 public Long createDept(DeptCreateReqVO reqVO) { 130 public Long createDept(DeptCreateReqVO reqVO) {
126 // 校验正确性 131 // 校验正确性
  132 + if (reqVO.getParentId() == null) {
  133 + reqVO.setParentId(DeptIdEnum.ROOT.getId());
  134 + }
127 checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); 135 checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
128 // 插入部门 136 // 插入部门
129 DeptDO dept = DeptConvert.INSTANCE.convert(reqVO); 137 DeptDO dept = DeptConvert.INSTANCE.convert(reqVO);
@@ -136,6 +144,9 @@ public class DeptServiceImpl implements DeptService { @@ -136,6 +144,9 @@ public class DeptServiceImpl implements DeptService {
136 @Override 144 @Override
137 public void updateDept(DeptUpdateReqVO reqVO) { 145 public void updateDept(DeptUpdateReqVO reqVO) {
138 // 校验正确性 146 // 校验正确性
  147 + if (reqVO.getParentId() == null) {
  148 + reqVO.setParentId(DeptIdEnum.ROOT.getId());
  149 + }
139 checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); 150 checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
140 // 更新部门 151 // 更新部门
141 DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO); 152 DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO);
yudao-ui-admin/src/views/system/dept/index.vue
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body> 57 <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
58 <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 58 <el-form ref="form" :model="form" :rules="rules" label-width="80px">
59 <el-row> 59 <el-row>
60 - <el-col :span="24" v-if="form.parentId !== 0"> 60 + <el-col :span="24">
61 <el-form-item label="上级部门" prop="parentId"> 61 <el-form-item label="上级部门" prop="parentId">
62 <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" /> 62 <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" />
63 </el-form-item> 63 </el-form-item>
@@ -152,9 +152,6 @@ export default { @@ -152,9 +152,6 @@ export default {
152 form: {}, 152 form: {},
153 // 表单校验 153 // 表单校验
154 rules: { 154 rules: {
155 - parentId: [  
156 - { required: true, message: "上级部门不能为空", trigger: "blur" }  
157 - ],  
158 name: [ 155 name: [
159 { required: true, message: "部门名称不能为空", trigger: "blur" } 156 { required: true, message: "部门名称不能为空", trigger: "blur" }
160 ], 157 ],
@@ -278,6 +275,9 @@ export default { @@ -278,6 +275,9 @@ export default {
278 this.reset(); 275 this.reset();
279 getDept(row.id).then(response => { 276 getDept(row.id).then(response => {
280 this.form = response.data; 277 this.form = response.data;
  278 + if (this.form.parentId === 0) { // 无父部门时,标记为 undefined,避免展示为 Unknown
  279 + this.form.parentId = undefined;
  280 + }
281 this.open = true; 281 this.open = true;
282 this.title = "修改部门"; 282 this.title = "修改部门";
283 }); 283 });