mirror of https://github.com/elunez/eladmin
修复菜单查询数据重复的问题#112
parent
2b1af497f5
commit
0859790272
|
@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
import me.zhengjie.modules.system.domain.Job;
|
||||||
import me.zhengjie.modules.system.service.JobService;
|
import me.zhengjie.modules.system.service.JobService;
|
||||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||||
|
import me.zhengjie.utils.ThrowableUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -64,7 +65,11 @@ public class JobController {
|
||||||
@DeleteMapping(value = "/job/{id}")
|
@DeleteMapping(value = "/job/{id}")
|
||||||
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
|
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
|
||||||
public ResponseEntity delete(@PathVariable Long id){
|
public ResponseEntity delete(@PathVariable Long id){
|
||||||
jobService.delete(id);
|
try {
|
||||||
|
jobService.delete(id);
|
||||||
|
}catch (Throwable e){
|
||||||
|
ThrowableUtil.throwForeignKeyException(e, "该岗位存在用户关联,请取消关联后再试");
|
||||||
|
}
|
||||||
return new ResponseEntity(HttpStatus.OK);
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package me.zhengjie.modules.system.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2018-12-17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MenuSmallDTO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
}
|
|
@ -166,24 +166,26 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Override
|
@Override
|
||||||
public Map buildTree(List<MenuDTO> menuDTOS) {
|
public Map buildTree(List<MenuDTO> menuDTOS) {
|
||||||
List<MenuDTO> trees = new ArrayList<MenuDTO>();
|
List<MenuDTO> trees = new ArrayList<MenuDTO>();
|
||||||
|
Set<Long> ids = new HashSet<>();
|
||||||
for (MenuDTO menuDTO : menuDTOS) {
|
for (MenuDTO menuDTO : menuDTOS) {
|
||||||
|
if (menuDTO.getPid() == 0) {
|
||||||
if ("0".equals(menuDTO.getPid().toString())) {
|
|
||||||
trees.add(menuDTO);
|
trees.add(menuDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MenuDTO it : menuDTOS) {
|
for (MenuDTO it : menuDTOS) {
|
||||||
if (it.getPid().equals(menuDTO.getId())) {
|
if (it.getPid().equals(menuDTO.getId())) {
|
||||||
if (menuDTO.getChildren() == null) {
|
if (menuDTO.getChildren() == null) {
|
||||||
menuDTO.setChildren(new ArrayList<MenuDTO>());
|
menuDTO.setChildren(new ArrayList<MenuDTO>());
|
||||||
}
|
}
|
||||||
menuDTO.getChildren().add(it);
|
menuDTO.getChildren().add(it);
|
||||||
|
ids.add(it.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map map = new HashMap();
|
Map map = new HashMap();
|
||||||
map.put("content",trees.size() == 0?menuDTOS:trees);
|
if(trees.size() == 0){
|
||||||
|
trees = menuDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
map.put("content",trees);
|
||||||
map.put("totalElements",menuDTOS!=null?menuDTOS.size():0);
|
map.put("totalElements",menuDTOS!=null?menuDTOS.size():0);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +203,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
|
|
||||||
// 如果不是外链
|
// 如果不是外链
|
||||||
if(!menuDTO.getIFrame()){
|
if(!menuDTO.getIFrame()){
|
||||||
if(menuDTO.getPid().equals(0L)){
|
if(menuDTO.getPid() == 0){
|
||||||
//一级目录需要加斜杠,不然访问 会跳转404页面
|
//一级目录需要加斜杠,不然访问 会跳转404页面
|
||||||
menuVo.setPath("/" + menuDTO.getPath());
|
menuVo.setPath("/" + menuDTO.getPath());
|
||||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
|
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
|
||||||
|
@ -215,7 +217,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
menuVo.setRedirect("noredirect");
|
menuVo.setRedirect("noredirect");
|
||||||
menuVo.setChildren(buildMenus(menuDTOList));
|
menuVo.setChildren(buildMenus(menuDTOList));
|
||||||
// 处理是一级菜单并且没有子菜单的情况
|
// 处理是一级菜单并且没有子菜单的情况
|
||||||
} else if(menuDTO.getPid().equals(0L)){
|
} else if(menuDTO.getPid() == 0){
|
||||||
MenuVo menuVo1 = new MenuVo();
|
MenuVo menuVo1 = new MenuVo();
|
||||||
menuVo1.setMeta(menuVo.getMeta());
|
menuVo1.setMeta(menuVo.getMeta());
|
||||||
// 非外链
|
// 非外链
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package me.zhengjie.modules.system.service.mapper;
|
||||||
|
|
||||||
|
import me.zhengjie.mapper.EntityMapper;
|
||||||
|
import me.zhengjie.modules.system.domain.Menu;
|
||||||
|
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||||
|
import me.zhengjie.modules.system.service.dto.MenuSmallDTO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2018-12-17
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface MenuSmallMapper extends EntityMapper<MenuSmallDTO, Menu> {
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#数据库类型转换成java类型
|
#数据库类型转Java类型
|
||||||
tinyint=Integer
|
tinyint=Integer
|
||||||
smallint=Integer
|
smallint=Integer
|
||||||
mediumint=Integer
|
mediumint=Integer
|
||||||
|
|
Loading…
Reference in New Issue