菜单管理
parent
a0f1160b3f
commit
fdcc4b3a81
|
|
@ -18,7 +18,7 @@ import lombok.Setter;
|
|||
@Setter
|
||||
@Constraint
|
||||
public class MenuAddParam implements Constrained {
|
||||
@NotNull
|
||||
@NotNull(message = "未指定客户端")
|
||||
private ClientCode clientCode;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ public class MenuService extends ServiceImpl<MenuMapper, MenuEntity> implements
|
|||
|
||||
Integer sort = menuEntity.getSort();
|
||||
if (sort == null || sort == 0) {
|
||||
Integer maxSort = this.getOne(Wrappers.<MenuEntity>query().eq("pid", pid).orderByDesc("sort").select("IFNULL(MAX(sort),0) sort")).getSort();
|
||||
Integer maxSort = this.getOne(Wrappers.<MenuEntity>query().eq("pid", pid).select("IFNULL(MAX(sort),0) sort")).getSort();
|
||||
menuEntity.setSort(maxSort + 1);
|
||||
} else {
|
||||
this.update(Wrappers.<MenuEntity>lambdaUpdate().eq(MenuEntity::getPid, pid).ge(MenuEntity::getSort, sort).setIncrBy(MenuEntity::getSort, 1));
|
||||
|
|
@ -108,29 +109,27 @@ public class MenuService extends ServiceImpl<MenuMapper, MenuEntity> implements
|
|||
}
|
||||
Long oldPid = oldMenuEntity.getPid();
|
||||
if (pid != null && !pid.equals(oldPid)) {
|
||||
MenuEntity parent = this.getById(pid);
|
||||
MenuEntity parent;
|
||||
if (pid == 0) {
|
||||
parent = new MenuEntity()
|
||||
.setTier(0)
|
||||
.setBreadcrumb(new LinkedList<>())
|
||||
.setId(0L);
|
||||
} else {
|
||||
parent = this.getById(pid);
|
||||
}
|
||||
Assert.notNull(parent, () -> Exceptions.exception("上级菜单不存在"));
|
||||
String title = menuEntity.getTitle();
|
||||
List<String> breadcrumb = parent.getBreadcrumb();
|
||||
breadcrumb.add(StrUtil.isBlank(title) ? oldMenuEntity.getTitle() : title);
|
||||
menuEntity.setBreadcrumb(breadcrumb)
|
||||
.setTier(parent.getTier() + 1);
|
||||
|
||||
this.modifyChild(menuEntity);
|
||||
}
|
||||
|
||||
Integer sort = menuEntity.getSort();
|
||||
if (sort != null && sort != 0) {
|
||||
List<MenuEntity> list = this.list(Wrappers.<MenuEntity>lambdaQuery()
|
||||
.eq(MenuEntity::getPid, pid == null ? oldPid : pid)
|
||||
.ge(MenuEntity::getSort, sort)
|
||||
.ne(MenuEntity::getId, id)
|
||||
.select(MenuEntity::getSort, MenuEntity::getId)
|
||||
);
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item -> item.setSort(sort + 1));
|
||||
this.updateBatchById(list);
|
||||
}
|
||||
this.update(Wrappers.<MenuEntity>lambdaUpdate().eq(MenuEntity::getPid, pid).ge(MenuEntity::getSort, sort).setIncrBy(MenuEntity::getSort, 1));
|
||||
}
|
||||
|
||||
this.updateById(menuEntity);
|
||||
|
|
|
|||
Loading…
Reference in New Issue