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