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.service.JobService;
|
||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||
import me.zhengjie.utils.ThrowableUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -64,7 +65,11 @@ public class JobController {
|
|||
@DeleteMapping(value = "/job/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
jobService.delete(id);
|
||||
try {
|
||||
jobService.delete(id);
|
||||
}catch (Throwable e){
|
||||
ThrowableUtil.throwForeignKeyException(e, "该岗位存在用户关联,请取消关联后再试");
|
||||
}
|
||||
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
|
||||
public Map buildTree(List<MenuDTO> menuDTOS) {
|
||||
List<MenuDTO> trees = new ArrayList<MenuDTO>();
|
||||
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (MenuDTO menuDTO : menuDTOS) {
|
||||
|
||||
if ("0".equals(menuDTO.getPid().toString())) {
|
||||
if (menuDTO.getPid() == 0) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
|
||||
for (MenuDTO it : menuDTOS) {
|
||||
if (it.getPid().equals(menuDTO.getId())) {
|
||||
if (menuDTO.getChildren() == null) {
|
||||
menuDTO.setChildren(new ArrayList<MenuDTO>());
|
||||
}
|
||||
menuDTO.getChildren().add(it);
|
||||
ids.add(it.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
return map;
|
||||
}
|
||||
|
@ -201,7 +203,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
|
||||
// 如果不是外链
|
||||
if(!menuDTO.getIFrame()){
|
||||
if(menuDTO.getPid().equals(0L)){
|
||||
if(menuDTO.getPid() == 0){
|
||||
//一级目录需要加斜杠,不然访问 会跳转404页面
|
||||
menuVo.setPath("/" + menuDTO.getPath());
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
|
||||
|
@ -215,7 +217,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenus(menuDTOList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if(menuDTO.getPid().equals(0L)){
|
||||
} else if(menuDTO.getPid() == 0){
|
||||
MenuVo menuVo1 = new MenuVo();
|
||||
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
|
||||
smallint=Integer
|
||||
mediumint=Integer
|
||||
|
|
Loading…
Reference in New Issue