修改的地方
下拉选项的排序和列表的排序不一样
上级菜单清空无效
sort为0时,自动生成
修改记录
代码
MenuMapper.xml
修改
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as 'value', id as 'key' from blade_menu where is_deleted = 0 and category = 1 order by sort asc
</select>
新增
<select id="getMaxSort" resultType="java.lang.Integer">
SELECT if(MAX(sort), MAX(sort)+1, 1) AS max_sort from blade_menu WHERE parent_id = #{param1} and is_deleted = 0
</select>
MenuMapper.java
/**
* 获取最大排序
* @param parentId 父节点Id
* @return
*/
Integer getMaxSort(Long parentId);
MenuServiceImpl.java
public Integer getMaxSort(Long parentId) {
return baseMapper.getMaxSort(parentId);
}
@Override
public boolean saveOrUpdate(Menu entity) {
if (Func.isEmpty(entity.getSort()) || (entity.getSort() == 0)) {
Long parentId = Func.isEmpty(entity.getParentId()) ? 0L : entity.getParentId();
entity.setSort(getMaxSort(parentId));
}
if (Func.isEmpty(entity.getParentId()) || (entity.getParentId() < 0)) {
entity.setParentId(0L);
}
return super.saveOrUpdate(entity);
}