@@ -1,8 +1,14 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.entity.Menu; | |||
import com.tuoheng.admin.query.MenuQuery; | |||
import com.tuoheng.admin.service.menu.IMenuService; | |||
import com.tuoheng.common.core.annotation.Log; | |||
import com.tuoheng.common.core.common.BaseController; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.tuoheng.common.core.enums.LogType; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* @Author ChengWang | |||
@@ -11,4 +17,45 @@ import org.springframework.web.bind.annotation.RestController; | |||
@RestController | |||
@RequestMapping("/menu") | |||
public class MenuController extends BaseController { | |||
@Autowired | |||
private IMenuService menuService; | |||
/** | |||
* 获取菜单列表 | |||
* | |||
* @param menuQuery 查询条件 | |||
* @return | |||
*/ | |||
// @RequiresPermissions("sys:menu:index") | |||
@GetMapping("/index") | |||
public JsonResult index(MenuQuery menuQuery) { | |||
return menuService.getList(menuQuery); | |||
} | |||
/** | |||
* 获取菜单详情 | |||
* | |||
* @param menuId 菜单ID | |||
* @return | |||
*/ | |||
@GetMapping("/info/{menuId}") | |||
public JsonResult info(@PathVariable("menuId") Integer menuId) { | |||
return menuService.info(menuId); | |||
} | |||
/** | |||
* 添加菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "菜单管理", logType = LogType.INSERT) | |||
// @RequiresPermissions("sys:menu:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Menu entity) { | |||
return menuService.edit(entity); | |||
} | |||
} |
@@ -83,7 +83,7 @@ public class Menu { | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
@@ -95,7 +95,7 @@ public class Menu { | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
private String updateUser; | |||
/** | |||
* 更新时间 |
@@ -67,7 +67,7 @@ public class OpPermissions { | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
@@ -79,7 +79,7 @@ public class OpPermissions { | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
private String updateUser; | |||
/** | |||
* 更新时间 |
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.tuoheng.common.core.common.BaseEntity; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
@@ -41,7 +40,7 @@ public class OpRolePermission{ | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
@@ -53,7 +52,7 @@ public class OpRolePermission{ | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
private String updateUser; | |||
/** | |||
* 更新时间 |
@@ -61,7 +61,7 @@ public class Role { | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
@@ -73,7 +73,7 @@ public class Role { | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
private String updateUser; | |||
/** | |||
* 更新时间 |
@@ -45,7 +45,7 @@ public class RoleMenu { | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
@@ -57,7 +57,7 @@ public class RoleMenu { | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
private String updateUser; | |||
/** | |||
* 更新时间 |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.admin.query; | |||
import com.tuoheng.common.core.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* 菜单查询条件 | |||
*/ | |||
@Data | |||
public class MenuQuery extends BaseQuery { | |||
/** | |||
* 菜单名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 上级ID | |||
*/ | |||
private Integer parentId; | |||
/** | |||
* 菜单类型 1pc 2小程序 | |||
*/ | |||
private Integer menuType; | |||
} |
@@ -1,11 +1,18 @@ | |||
package com.tuoheng.admin.service.menu; | |||
import com.tuoheng.admin.entity.Menu; | |||
import com.tuoheng.admin.query.MenuQuery; | |||
import com.tuoheng.common.core.common.IBaseService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/12/16 | |||
*/ | |||
public interface IMenuService{ | |||
JsonResult getList(MenuQuery menuQuery); | |||
JsonResult info(Integer menuId); | |||
JsonResult edit(Menu entity); | |||
} |
@@ -1,14 +1,145 @@ | |||
package com.tuoheng.admin.service.menu; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.tuoheng.admin.entity.Menu; | |||
import com.tuoheng.admin.entity.OpPermissions; | |||
import com.tuoheng.admin.enums.ClientEnum; | |||
import com.tuoheng.admin.mapper.MenuMapper; | |||
import com.tuoheng.admin.mapper.OpPermissionsMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.query.MenuQuery; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.menu.MenuListVo; | |||
import com.tuoheng.admin.vo.menu.MenuindexVo; | |||
import com.tuoheng.common.core.common.BaseServiceImpl; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/12/16 | |||
*/ | |||
@Service | |||
public class MenuServiceImpl implements IMenuService{ | |||
@Autowired | |||
private MenuMapper menuMapper; | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private OpPermissionsMapper permissionsMapper; | |||
/** | |||
* 获取菜单列表 | |||
* @param menuQuery | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getList(MenuQuery menuQuery) { | |||
QueryWrapper<Menu> queryWrapper = new QueryWrapper<>(); | |||
MenuindexVo vo = new MenuindexVo(); | |||
QueryWrapper<OpPermissions> queryWrapper1 = new QueryWrapper<>(); | |||
// 查询条件 | |||
if (1 == menuQuery.getMenuType()) { | |||
queryWrapper.eq("client_id", ClientEnum.ADMIN.getDescription()); | |||
queryWrapper1.eq("client_id", ClientEnum.ADMIN.getDescription()); | |||
} else { | |||
queryWrapper.eq("client_id", ClientEnum.API.getDescription()); | |||
queryWrapper1.eq("client_id", ClientEnum.API.getDescription()); | |||
} | |||
if (!StringUtils.isEmpty(menuQuery.getName())) { | |||
queryWrapper1.like("name", menuQuery.getName()); | |||
} | |||
queryWrapper1.eq("mark",1); | |||
//返回权限 | |||
List<OpPermissions> opPermissions = permissionsMapper.selectList(queryWrapper1); | |||
vo.setPermissionList(opPermissions); | |||
// 菜单名称 | |||
if (!StringUtils.isEmpty(menuQuery.getName())) { | |||
queryWrapper.like("name", menuQuery.getName()); | |||
} | |||
queryWrapper.eq("mark", 1); | |||
queryWrapper.orderByAsc("sort"); | |||
// 查询分页数据 | |||
List<Menu> menuList = menuMapper.selectList(queryWrapper); | |||
List<MenuListVo> menuListVoList = new ArrayList<>(); | |||
if (!menuList.isEmpty()) { | |||
menuList.forEach(item -> { | |||
MenuListVo menuListVo = new MenuListVo(); | |||
BeanUtils.copyProperties(item, menuListVo); | |||
// // 是否有子级 | |||
// if (item.getType() == 0) { | |||
// menuListVo.setHasChildren(true); | |||
// } | |||
menuListVoList.add(menuListVo); | |||
}); | |||
} | |||
vo.setMenuListVoList(menuListVoList); | |||
return JsonResult.success(vo); | |||
} | |||
@Override | |||
public JsonResult info(Integer menuId) { | |||
if (menuId == null && menuId <= 0) { | |||
return JsonResult.error("记录ID不能为空"); | |||
} | |||
Object result = menuMapper.selectById(menuId); | |||
return JsonResult.success(result); | |||
} | |||
@Override | |||
public JsonResult edit(Menu entity) { | |||
if(entity == null){ | |||
return JsonResult.error("实体对象不存在"); | |||
} | |||
boolean result = false; | |||
// if (entity.getId() != null && entity.getId() > 0) { | |||
// // 修改记录 | |||
// entity.setUpdateUser(CurrentUserUtil.getUserId()); | |||
// entity.setUpdateTime(DateUtils.now()); | |||
// result = this.updateById(entity); | |||
// if (!result) { | |||
// return JsonResult.error(); | |||
// } | |||
// } | |||
// else { | |||
// // 新增记录 | |||
// //entity.setTenantId(ShiroUtils.getTenantId()); | |||
// entity.setCreateUser(ShiroUtils.getUserId()); | |||
// entity.setCreateTime(DateUtils.now()); | |||
// entity.setMark(1); | |||
// result = this.save(entity); | |||
// if (!result) { | |||
// return JsonResult.error(); | |||
// } | |||
// //新增菜单直接讲菜单跟当前用户的租户进行关联 | |||
// RoleMenu roleMenu = new RoleMenu(); | |||
// Integer tenantId = ShiroUtils.getTenantId(); | |||
// Tenant tenant = tenantMapper.selectById(tenantId); | |||
// if (null!=tenant) { | |||
// roleMenu.setRoleId(tenant.getRoleId()); | |||
// roleMenu.setMenuId(entity.getId()); | |||
// roleMenuMapper.insert(roleMenu); | |||
// } | |||
// | |||
// } | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,95 @@ | |||
package com.tuoheng.admin.vo.menu; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
/** | |||
* 菜单列表Vo | |||
*/ | |||
@Data | |||
public class MenuListVo { | |||
/** | |||
* 菜单ID | |||
*/ | |||
private Integer id; | |||
/** | |||
* 父级ID | |||
*/ | |||
private Integer parentId; | |||
/** | |||
* 菜单名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 图标 | |||
*/ | |||
private String menuIcon; | |||
/** | |||
* 菜单路径 | |||
*/ | |||
private String path; | |||
/** | |||
* 菜单组件 | |||
*/ | |||
private String component; | |||
/** | |||
* 目标 | |||
*/ | |||
private String target; | |||
/** | |||
* 是否可见:0可见 1不可见 | |||
*/ | |||
private Integer isHidden; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 是否有子级 | |||
*/ | |||
private boolean hasChildren; | |||
private Integer status; | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.tuoheng.admin.vo.menu; | |||
import com.tuoheng.admin.entity.OpPermissions; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/28 15:31 | |||
*/ | |||
@Data | |||
public class MenuindexVo { | |||
/** | |||
* 菜单集合 | |||
*/ | |||
private List<MenuListVo> menuListVoList; | |||
/** | |||
* 权限集合 | |||
*/ | |||
private List<OpPermissions> permissionList; | |||
} |