修复角色菜单临时接口
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.cool.store.dao;
|
||||
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.entity.SysMenuDO;
|
||||
import com.cool.store.mapper.SysMenuMapper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -24,8 +26,28 @@ public class SysMenuDAO {
|
||||
}
|
||||
|
||||
public Long addMenu(SysMenuDO param){
|
||||
Integer sort = sysMenuMapper.selectMaxSort();
|
||||
param.setSort(sort + 1);
|
||||
sysMenuMapper.insertSelective(param);
|
||||
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值更新到数据库,避免覆盖之前有值的
|
||||
* 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);
|
||||
|
||||
Integer selectMaxSort();
|
||||
|
||||
Integer batchDeleteMenu(@Param("list") List<Long> idList);
|
||||
}
|
||||
@@ -155,71 +155,73 @@
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update sys_menu
|
||||
<set>
|
||||
<if test="parentId != null">
|
||||
parent_id = #{parentId},
|
||||
</if>
|
||||
<if test="code != null">
|
||||
code = #{code},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="alias != null">
|
||||
alias = #{alias},
|
||||
</if>
|
||||
<if test="path != null">
|
||||
path = #{path},
|
||||
</if>
|
||||
<if test="perms != null">
|
||||
perms = #{perms},
|
||||
</if>
|
||||
<if test="source != null">
|
||||
source = #{source},
|
||||
</if>
|
||||
<if test="sort != null">
|
||||
sort = #{sort},
|
||||
</if>
|
||||
<if test="category != null">
|
||||
category = #{category},
|
||||
</if>
|
||||
<if test="action != null">
|
||||
action = #{action},
|
||||
</if>
|
||||
<if test="remark != null">
|
||||
remark = #{remark},
|
||||
</if>
|
||||
<if test="platform != null">
|
||||
platform = #{platform},
|
||||
</if>
|
||||
<if test="isDeleted != null">
|
||||
is_deleted = #{isDeleted},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
type = #{type},
|
||||
</if>
|
||||
<if test="target != null">
|
||||
target = #{target},
|
||||
</if>
|
||||
<if test="component != null">
|
||||
component = #{component},
|
||||
</if>
|
||||
<if test="icon != null">
|
||||
icon = #{icon},
|
||||
</if>
|
||||
<if test="menuType != null">
|
||||
menu_type = #{menuType},
|
||||
</if>
|
||||
<if test="env != null">
|
||||
env = #{env},
|
||||
</if>
|
||||
<if test="commonFunctionsIcon != null">
|
||||
common_functions_icon = #{commonFunctionsIcon},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
<update id="batchUpdateMenu">
|
||||
<foreach collection="recordList" separator=";" item="record">
|
||||
update sys_menu
|
||||
<set>
|
||||
<if test="record.parentId != null">
|
||||
parent_id = #{record.parentId},
|
||||
</if>
|
||||
<if test="record.code != null">
|
||||
code = #{record.code},
|
||||
</if>
|
||||
<if test="record.name != null">
|
||||
name = #{record.name},
|
||||
</if>
|
||||
<if test="record.alias != null">
|
||||
alias = #{record.alias},
|
||||
</if>
|
||||
<if test="record.path != null">
|
||||
path = #{record.path},
|
||||
</if>
|
||||
<if test="record.perms != null">
|
||||
perms = #{record.perms},
|
||||
</if>
|
||||
<if test="record.source != null">
|
||||
source = #{record.source},
|
||||
</if>
|
||||
<if test="record.sort != null">
|
||||
sort = #{record.sort},
|
||||
</if>
|
||||
<if test="record.category != null">
|
||||
category = #{record.category},
|
||||
</if>
|
||||
<if test="record.action != null">
|
||||
action = #{record.action},
|
||||
</if>
|
||||
<if test="record.remark != null">
|
||||
remark = #{record.remark},
|
||||
</if>
|
||||
<if test="record.platform != null">
|
||||
platform = #{record.platform},
|
||||
</if>
|
||||
<if test="record.isDeleted != null">
|
||||
is_deleted = #{record.isDeleted},
|
||||
</if>
|
||||
<if test="record.type != null">
|
||||
type = #{record.type},
|
||||
</if>
|
||||
<if test="record.target != null">
|
||||
target = #{record.target},
|
||||
</if>
|
||||
<if test="record.component != null">
|
||||
component = #{record.component},
|
||||
</if>
|
||||
<if test="record.icon != null">
|
||||
icon = #{record.icon},
|
||||
</if>
|
||||
<if test="record.menuType != null">
|
||||
menu_type = #{record.menuType},
|
||||
</if>
|
||||
<if test="record.env != null">
|
||||
env = #{record.env},
|
||||
</if>
|
||||
<if test="record.commonFunctionsIcon != null">
|
||||
common_functions_icon = #{record.commonFunctionsIcon},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{record.id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="selectMenuAll" resultMap="BaseResultMap">
|
||||
@@ -228,7 +230,7 @@
|
||||
from
|
||||
sys_menu
|
||||
where
|
||||
platform=#{platformType}
|
||||
platform=#{platformType} and is_deleted = '0'
|
||||
<if test="list!=null and list.size>0">
|
||||
and parent_id in
|
||||
<foreach collection="list" item="parentId" open="(" close=")" separator=",">
|
||||
@@ -236,4 +238,23 @@
|
||||
</foreach>
|
||||
</if>
|
||||
</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>
|
||||
@@ -143,7 +143,7 @@
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from
|
||||
sys_role
|
||||
sys_role and deleted = 0
|
||||
</select>
|
||||
|
||||
<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 type;
|
||||
|
||||
public static SysMenuDO convertDO(AddMenuDTO param, MenuTypeEnum menuTypeEnum){
|
||||
SysMenuDO sysMenuDO = new SysMenuDO();
|
||||
sysMenuDO.setParentId(param.getParentId());
|
||||
sysMenuDO.setName(param.getName());
|
||||
sysMenuDO.setCode(param.getName());
|
||||
sysMenuDO.setPath(param.getPath());
|
||||
sysMenuDO.setType(null);
|
||||
sysMenuDO.setType(param.getType());
|
||||
sysMenuDO.setSource("menu");
|
||||
sysMenuDO.setAction(1);
|
||||
sysMenuDO.setPlatform("PC");
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MenuAuthTreeVO {
|
||||
//属于菜单下时候
|
||||
if (CollectionUtils.isNotEmpty(parentMenuList)) {
|
||||
List<MenuAuthTreeVO> voList = convertVO(parentMenuList);
|
||||
List<MenuAuthTreeVO> authorityList = convertVO(parentMenuList);
|
||||
List<MenuAuthTreeVO> authorityList = convertVO(parentAuthList);
|
||||
data.setAuthorityList(authorityList);
|
||||
List<MenuAuthTreeVO> menuList = voList.stream().filter(vo -> MenuTypeEnum.MENU.getCode().equals(vo.getMenuType())).collect(Collectors.toList());
|
||||
data.setChildren(menuList);
|
||||
|
||||
@@ -36,4 +36,15 @@ public interface MenuService {
|
||||
* @return
|
||||
*/
|
||||
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.PlatFormTypeEnum;
|
||||
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.MenuTreeVO;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -64,6 +66,33 @@ public class MenuServiceImpl implements MenuService {
|
||||
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) {
|
||||
Long parentId = idMap.get(menuId);
|
||||
authMenuList.add(parentId);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
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.enums.MenuTypeEnum;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
@@ -53,4 +55,16 @@ public class MenuController {
|
||||
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