Commit d114bca7 authored by 赵啸非's avatar 赵啸非

添加菜单资源配置

parent 2e031457
......@@ -27,4 +27,12 @@ import java.util.List;
public interface MenuDao extends ICRUDDao<MenuEntity,Long> {
List<MenuEntity> getListByUserId(Long userId);
/**
* 查询子节点
*
* @param
* @return
*/
List<MenuEntity> selectChildrenMenuById(String menuId);
}
\ No newline at end of file
......@@ -28,6 +28,12 @@ import java.util.List;
@Repository("menuDao")
public class MenuDaoImpl extends BaseCRUDDaoMybatis<MenuEntity,Long> implements MenuDao {
@Override
public List<MenuEntity> selectChildrenMenuById(String menuId) {
return getSqlSession().selectList(getSqlId("selectChildrenMenuById"), menuId);
}
@Override
public List<MenuEntity> getListByUserId(Long userId) {
ParamDto param = new ParamDto();
......
......@@ -133,6 +133,10 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
@Override
protected void saveBefore(MenuEntity entity, Context context) throws AppException {
MenuEntity parentMenuEntity = this.get(entity.getParentId());
if (!ObjectUtils.isEmpty(parentMenuEntity)) {
entity.setAncestors(parentMenuEntity.getAncestors() + "," + entity.getParentId());
}
MenuQuery query = new MenuQuery();
query.setParentId(entity.getParentId());
Comparator<Integer> comparator = Comparator.comparing(Integer::intValue);
......@@ -144,6 +148,38 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
super.saveBefore(entity, context);
}
@Override
protected void updateBefore(MenuEntity entity, Context context) throws AppException {
MenuEntity newParentEntity = this.get(entity.getParentId());
MenuEntity oldEntity = this.get(entity.getId());
if (!ObjectUtils.isEmpty(newParentEntity) && !ObjectUtils.isEmpty(oldEntity)) {
String newAncestors = newParentEntity.getAncestors() + "," + newParentEntity.getId();
String oldAncestors = oldEntity.getAncestors();
entity.setAncestors(newAncestors);
updateMenuChildren(entity.getId(), newAncestors, oldAncestors, context);
}
super.updateBefore(entity, context);
}
/**
* 修改子元素关系
*
* @param menuId 被修改的菜单信息业务ID
* @param newAncestors 新的父ID集合
* @param oldAncestors 旧的父ID集合
*/
public void updateMenuChildren(Long menuId, String newAncestors, String oldAncestors, Context context) {
List<MenuEntity> children = getDao().selectChildrenMenuById(menuId.toString());
for (MenuEntity child : children) {
child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
}
if (children.size() > 0) {
this.updateAfter(children, context);
}
}
@Override
public boolean hasChildByMenuId(Long menuId) {
List<MenuEntity> list = this.find(new MenuQuery().parentId(menuId));
......@@ -223,6 +259,15 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
}
}
@Override
protected void removeBefore(Long[] ids, Context context) throws AppException {
//有子节点 禁止删除
if (hasChildByMenuId(ids[0])) {
throw new AppException("存在下级菜单信息业务,不允许删除");
}
super.removeBefore(ids, context);
}
/**
* 判断是否有子节点
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment