修复角色菜单临时接口
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package com.cool.store.dao;
|
package com.cool.store.dao;
|
||||||
|
|
||||||
|
import com.cool.store.constants.CommonConstants;
|
||||||
import com.cool.store.entity.SysMenuDO;
|
import com.cool.store.entity.SysMenuDO;
|
||||||
import com.cool.store.mapper.SysMenuMapper;
|
import com.cool.store.mapper.SysMenuMapper;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -24,8 +26,28 @@ public class SysMenuDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Long addMenu(SysMenuDO param){
|
public Long addMenu(SysMenuDO param){
|
||||||
|
Integer sort = sysMenuMapper.selectMaxSort();
|
||||||
|
param.setSort(sort + 1);
|
||||||
sysMenuMapper.insertSelective(param);
|
sysMenuMapper.insertSelective(param);
|
||||||
return param.getId();
|
return param.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
* @param idList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Integer batchDeleteMenu(List<Long> idList){
|
||||||
|
if(CollectionUtils.isNotEmpty(idList)){
|
||||||
|
return CommonConstants.ZERO;
|
||||||
|
}
|
||||||
|
return sysMenuMapper.batchDeleteMenu(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer batchUpdateMenu(List<SysMenuDO> updateList) {
|
||||||
|
if(CollectionUtils.isEmpty(updateList)){
|
||||||
|
return CommonConstants.ZERO;
|
||||||
|
}
|
||||||
|
return sysMenuMapper.batchUpdateMenu(updateList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,11 @@ public interface SysMenuMapper {
|
|||||||
* 默认更新方法,根据主键更新,不会把null值更新到数据库,避免覆盖之前有值的
|
* 默认更新方法,根据主键更新,不会把null值更新到数据库,避免覆盖之前有值的
|
||||||
* dateTime:2023-06-08 04:38
|
* dateTime:2023-06-08 04:38
|
||||||
*/
|
*/
|
||||||
int updateByPrimaryKeySelective(SysMenuDO record);
|
int batchUpdateMenu(@Param("recordList") List<SysMenuDO> recordList);
|
||||||
|
|
||||||
List<SysMenuDO> selectMenuAll(@Param("list") List<Long> parentIds, @Param("platformType") String platformType);
|
List<SysMenuDO> selectMenuAll(@Param("list") List<Long> parentIds, @Param("platformType") String platformType);
|
||||||
|
|
||||||
|
Integer selectMaxSort();
|
||||||
|
|
||||||
|
Integer batchDeleteMenu(@Param("list") List<Long> idList);
|
||||||
}
|
}
|
||||||
@@ -155,71 +155,73 @@
|
|||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<update id="updateByPrimaryKeySelective">
|
<update id="batchUpdateMenu">
|
||||||
update sys_menu
|
<foreach collection="recordList" separator=";" item="record">
|
||||||
<set>
|
update sys_menu
|
||||||
<if test="parentId != null">
|
<set>
|
||||||
parent_id = #{parentId},
|
<if test="record.parentId != null">
|
||||||
</if>
|
parent_id = #{record.parentId},
|
||||||
<if test="code != null">
|
</if>
|
||||||
code = #{code},
|
<if test="record.code != null">
|
||||||
</if>
|
code = #{record.code},
|
||||||
<if test="name != null">
|
</if>
|
||||||
name = #{name},
|
<if test="record.name != null">
|
||||||
</if>
|
name = #{record.name},
|
||||||
<if test="alias != null">
|
</if>
|
||||||
alias = #{alias},
|
<if test="record.alias != null">
|
||||||
</if>
|
alias = #{record.alias},
|
||||||
<if test="path != null">
|
</if>
|
||||||
path = #{path},
|
<if test="record.path != null">
|
||||||
</if>
|
path = #{record.path},
|
||||||
<if test="perms != null">
|
</if>
|
||||||
perms = #{perms},
|
<if test="record.perms != null">
|
||||||
</if>
|
perms = #{record.perms},
|
||||||
<if test="source != null">
|
</if>
|
||||||
source = #{source},
|
<if test="record.source != null">
|
||||||
</if>
|
source = #{record.source},
|
||||||
<if test="sort != null">
|
</if>
|
||||||
sort = #{sort},
|
<if test="record.sort != null">
|
||||||
</if>
|
sort = #{record.sort},
|
||||||
<if test="category != null">
|
</if>
|
||||||
category = #{category},
|
<if test="record.category != null">
|
||||||
</if>
|
category = #{record.category},
|
||||||
<if test="action != null">
|
</if>
|
||||||
action = #{action},
|
<if test="record.action != null">
|
||||||
</if>
|
action = #{record.action},
|
||||||
<if test="remark != null">
|
</if>
|
||||||
remark = #{remark},
|
<if test="record.remark != null">
|
||||||
</if>
|
remark = #{record.remark},
|
||||||
<if test="platform != null">
|
</if>
|
||||||
platform = #{platform},
|
<if test="record.platform != null">
|
||||||
</if>
|
platform = #{record.platform},
|
||||||
<if test="isDeleted != null">
|
</if>
|
||||||
is_deleted = #{isDeleted},
|
<if test="record.isDeleted != null">
|
||||||
</if>
|
is_deleted = #{record.isDeleted},
|
||||||
<if test="type != null">
|
</if>
|
||||||
type = #{type},
|
<if test="record.type != null">
|
||||||
</if>
|
type = #{record.type},
|
||||||
<if test="target != null">
|
</if>
|
||||||
target = #{target},
|
<if test="record.target != null">
|
||||||
</if>
|
target = #{record.target},
|
||||||
<if test="component != null">
|
</if>
|
||||||
component = #{component},
|
<if test="record.component != null">
|
||||||
</if>
|
component = #{record.component},
|
||||||
<if test="icon != null">
|
</if>
|
||||||
icon = #{icon},
|
<if test="record.icon != null">
|
||||||
</if>
|
icon = #{record.icon},
|
||||||
<if test="menuType != null">
|
</if>
|
||||||
menu_type = #{menuType},
|
<if test="record.menuType != null">
|
||||||
</if>
|
menu_type = #{record.menuType},
|
||||||
<if test="env != null">
|
</if>
|
||||||
env = #{env},
|
<if test="record.env != null">
|
||||||
</if>
|
env = #{record.env},
|
||||||
<if test="commonFunctionsIcon != null">
|
</if>
|
||||||
common_functions_icon = #{commonFunctionsIcon},
|
<if test="record.commonFunctionsIcon != null">
|
||||||
</if>
|
common_functions_icon = #{record.commonFunctionsIcon},
|
||||||
</set>
|
</if>
|
||||||
where id = #{id}
|
</set>
|
||||||
|
where id = #{record.id}
|
||||||
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<select id="selectMenuAll" resultMap="BaseResultMap">
|
<select id="selectMenuAll" resultMap="BaseResultMap">
|
||||||
@@ -228,7 +230,7 @@
|
|||||||
from
|
from
|
||||||
sys_menu
|
sys_menu
|
||||||
where
|
where
|
||||||
platform=#{platformType}
|
platform=#{platformType} and is_deleted = '0'
|
||||||
<if test="list!=null and list.size>0">
|
<if test="list!=null and list.size>0">
|
||||||
and parent_id in
|
and parent_id in
|
||||||
<foreach collection="list" item="parentId" open="(" close=")" separator=",">
|
<foreach collection="list" item="parentId" open="(" close=")" separator=",">
|
||||||
@@ -236,4 +238,23 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectMaxSort" resultType="java.lang.Integer">
|
||||||
|
select sort
|
||||||
|
from sys_menu
|
||||||
|
order by sort desc
|
||||||
|
limit 0,1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="batchDeleteMenu">
|
||||||
|
update
|
||||||
|
sys_menu
|
||||||
|
set
|
||||||
|
is_deleted = '1'
|
||||||
|
where
|
||||||
|
id in
|
||||||
|
<foreach collection="list" open="(" item="item" separator="," close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -143,7 +143,7 @@
|
|||||||
select
|
select
|
||||||
<include refid="Base_Column_List"/>
|
<include refid="Base_Column_List"/>
|
||||||
from
|
from
|
||||||
sys_role
|
sys_role and deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getRoleDetail" resultMap="BaseResultMap">
|
<select id="getRoleDetail" resultMap="BaseResultMap">
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.cool.store.dto.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangchenbiao
|
||||||
|
* @FileName: IdParamDTO
|
||||||
|
* @Description:
|
||||||
|
* @date 2023-08-01 11:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IdParamDTO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.cool.store.dto.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangchenbiao
|
||||||
|
* @FileName: IdParamDTO
|
||||||
|
* @Description:
|
||||||
|
* @date 2023-08-01 11:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IdsParamDTO {
|
||||||
|
|
||||||
|
private List<Long> ids;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -33,13 +33,15 @@ public class AddMenuDTO {
|
|||||||
|
|
||||||
private String env;
|
private String env;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
public static SysMenuDO convertDO(AddMenuDTO param, MenuTypeEnum menuTypeEnum){
|
public static SysMenuDO convertDO(AddMenuDTO param, MenuTypeEnum menuTypeEnum){
|
||||||
SysMenuDO sysMenuDO = new SysMenuDO();
|
SysMenuDO sysMenuDO = new SysMenuDO();
|
||||||
sysMenuDO.setParentId(param.getParentId());
|
sysMenuDO.setParentId(param.getParentId());
|
||||||
sysMenuDO.setName(param.getName());
|
sysMenuDO.setName(param.getName());
|
||||||
sysMenuDO.setCode(param.getName());
|
sysMenuDO.setCode(param.getName());
|
||||||
sysMenuDO.setPath(param.getPath());
|
sysMenuDO.setPath(param.getPath());
|
||||||
sysMenuDO.setType(null);
|
sysMenuDO.setType(param.getType());
|
||||||
sysMenuDO.setSource("menu");
|
sysMenuDO.setSource("menu");
|
||||||
sysMenuDO.setAction(1);
|
sysMenuDO.setAction(1);
|
||||||
sysMenuDO.setPlatform("PC");
|
sysMenuDO.setPlatform("PC");
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class MenuAuthTreeVO {
|
|||||||
//属于菜单下时候
|
//属于菜单下时候
|
||||||
if (CollectionUtils.isNotEmpty(parentMenuList)) {
|
if (CollectionUtils.isNotEmpty(parentMenuList)) {
|
||||||
List<MenuAuthTreeVO> voList = convertVO(parentMenuList);
|
List<MenuAuthTreeVO> voList = convertVO(parentMenuList);
|
||||||
List<MenuAuthTreeVO> authorityList = convertVO(parentMenuList);
|
List<MenuAuthTreeVO> authorityList = convertVO(parentAuthList);
|
||||||
data.setAuthorityList(authorityList);
|
data.setAuthorityList(authorityList);
|
||||||
List<MenuAuthTreeVO> menuList = voList.stream().filter(vo -> MenuTypeEnum.MENU.getCode().equals(vo.getMenuType())).collect(Collectors.toList());
|
List<MenuAuthTreeVO> menuList = voList.stream().filter(vo -> MenuTypeEnum.MENU.getCode().equals(vo.getMenuType())).collect(Collectors.toList());
|
||||||
data.setChildren(menuList);
|
data.setChildren(menuList);
|
||||||
|
|||||||
@@ -36,4 +36,15 @@ public interface MenuService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Long addMenu(AddMenuDTO param, MenuTypeEnum menuType);
|
Long addMenu(AddMenuDTO param, MenuTypeEnum menuType);
|
||||||
|
|
||||||
|
|
||||||
|
Long deleteMenuAuth(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单排序
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer sortMenu(List<Long> ids);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import com.cool.store.entity.SysRoleMenuDO;
|
|||||||
import com.cool.store.enums.MenuTypeEnum;
|
import com.cool.store.enums.MenuTypeEnum;
|
||||||
import com.cool.store.enums.PlatFormTypeEnum;
|
import com.cool.store.enums.PlatFormTypeEnum;
|
||||||
import com.cool.store.service.MenuService;
|
import com.cool.store.service.MenuService;
|
||||||
|
import com.cool.store.utils.CommonNodeUtils;
|
||||||
import com.cool.store.vo.menu.MenuAuthTreeVO;
|
import com.cool.store.vo.menu.MenuAuthTreeVO;
|
||||||
import com.cool.store.vo.menu.MenuTreeVO;
|
import com.cool.store.vo.menu.MenuTreeVO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -64,6 +66,33 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
return sysMenuDAO.addMenu(AddMenuDTO.convertDO(param, menuType));
|
return sysMenuDAO.addMenu(AddMenuDTO.convertDO(param, menuType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long deleteMenuAuth(Long id) {
|
||||||
|
List<SysMenuDO> sysMenuDOList = sysMenuDAO.selectMenuAll(null, PlatFormTypeEnum.PC.getCode());
|
||||||
|
List<Long> idList = ListUtils.emptyIfNull(sysMenuDOList)
|
||||||
|
.stream()
|
||||||
|
.map(SysMenuDO::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, List<Long>> parentGroupMap = ListUtils.emptyIfNull(sysMenuDOList)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(SysMenuDO::getParentId, Collectors.mapping(SysMenuDO::getId, Collectors.toList())));
|
||||||
|
List<Long> allChildList = CommonNodeUtils.getAllChildListContainSelf(0L,id, idList, parentGroupMap);
|
||||||
|
sysMenuDAO.batchDeleteMenu(allChildList);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer sortMenu(List<Long> ids) {
|
||||||
|
List<SysMenuDO> list = new LinkedList<>();
|
||||||
|
for (int i = 1; i <= ids.size(); i++) {
|
||||||
|
SysMenuDO sysMenuDO = new SysMenuDO();
|
||||||
|
sysMenuDO.setSort(i);
|
||||||
|
sysMenuDO.setId(ids.get(i - 1));
|
||||||
|
list.add(sysMenuDO);
|
||||||
|
}
|
||||||
|
return sysMenuDAO.batchUpdateMenu(list);
|
||||||
|
}
|
||||||
|
|
||||||
private void getParentNode(Long menuId, Map<Long, Long> idMap, Set<Long> authMenuList) {
|
private void getParentNode(Long menuId, Map<Long, Long> idMap, Set<Long> authMenuList) {
|
||||||
Long parentId = idMap.get(menuId);
|
Long parentId = idMap.get(menuId);
|
||||||
authMenuList.add(parentId);
|
authMenuList.add(parentId);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.cool.store.controller;
|
package com.cool.store.controller;
|
||||||
|
|
||||||
import com.cool.store.context.CurrentUserHolder;
|
import com.cool.store.context.CurrentUserHolder;
|
||||||
|
import com.cool.store.dto.common.IdParamDTO;
|
||||||
|
import com.cool.store.dto.common.IdsParamDTO;
|
||||||
import com.cool.store.dto.menu.AddMenuDTO;
|
import com.cool.store.dto.menu.AddMenuDTO;
|
||||||
import com.cool.store.enums.MenuTypeEnum;
|
import com.cool.store.enums.MenuTypeEnum;
|
||||||
import com.cool.store.response.ResponseResult;
|
import com.cool.store.response.ResponseResult;
|
||||||
@@ -53,4 +55,16 @@ public class MenuController {
|
|||||||
return ResponseResult.success(menuService.addMenu(param, MenuTypeEnum.AUTH));
|
return ResponseResult.success(menuService.addMenu(param, MenuTypeEnum.AUTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除菜单或权限")
|
||||||
|
@PostMapping(path = "/menu/auth/delete")
|
||||||
|
public ResponseResult deleteMenuAuth(@RequestBody IdParamDTO param){
|
||||||
|
return ResponseResult.success(menuService.deleteMenuAuth(param.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("排序")
|
||||||
|
@PostMapping(path = "/menu/sort")
|
||||||
|
public ResponseResult sortMenu(@RequestBody IdsParamDTO param){
|
||||||
|
return ResponseResult.success(menuService.sortMenu(param.getIds()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user