| | |
| | | import com.ruoyi.common.core.web.page.TableDataInfo; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.domain.SysDept; |
| | | import com.ruoyi.system.api.domain.SysRole; |
| | |
| | | @Resource |
| | | private SysMenuMapper menuMapper; |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @ApiOperation(value = "获取角色列表", tags = {"管理后台-系统用户管理"}) |
| | | @Resource |
| | | private ISysUserService sysUserService; |
| | | |
| | | |
| | | @ApiOperation(value = "获取角色列表", tags = {"管理后台-账号管理", "门店后台-账号管理"}) |
| | | @GetMapping("/list") |
| | | public AjaxResult list() { |
| | | List<SysRole> list = roleService.list(new LambdaQueryWrapper<SysRole>().eq(SysRole::getDelFlag, 0).eq(SysRole::getStatus, 0)); |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserService.getById(userid); |
| | | LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<SysRole>().eq(SysRole::getDelFlag, 0).eq(SysRole::getStatus, 0); |
| | | if(sysUser.getRoleType() == 2){ |
| | | wrapper.eq(SysRole::getShopId, sysUser.getObjectId()); |
| | | } |
| | | List<SysRole> list = roleService.list(wrapper); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/listPage") |
| | | @ApiOperation(value = "获取角色列表", tags = {"管理后台-角色管理"}) |
| | | @ApiOperation(value = "获取角色列表", tags = {"管理后台-权限管理", "门店后台-权限管理"}) |
| | | public AjaxResult listPage(String name, BasePage basePage) { |
| | | PageInfo<SysRole> pageInfo = new PageInfo<>(basePage.getPageCurr(), basePage.getPageSize()); |
| | | LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<SysRole>().eq(SysRole::getStatus, 0).eq(SysRole::getDelFlag, 0); |
| | | if (StringUtils.isNotEmpty(name)) { |
| | | wrapper.like(SysRole::getRoleName, name); |
| | | } |
| | | |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserService.getById(userid); |
| | | if(sysUser.getRoleType() == 2){ |
| | | wrapper.eq(SysRole::getShopId, sysUser.getObjectId()); |
| | | } |
| | | PageInfo<SysRole> page = roleService.page(pageInfo, wrapper.orderByDesc(SysRole::getCreateTime)); |
| | | for (SysRole record : page.getRecords()) { |
| | | long count = sysUserRoleService.count(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getRoleId, record.getRoleId())); |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/roleAdd") |
| | | @ApiOperation(value = "添加角色", tags = {"管理后台-角色管理"}) |
| | | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 |
| | | @ApiOperation(value = "添加角色", tags = {"管理后台-权限管理", "门店后台-权限管理"}) |
| | | public AjaxResult roleAdd(@Validated @RequestBody RoleAddDto dto) { |
| | | SysRole role = new SysRole(); |
| | | role.setRoleName(dto.getRoleName()); |
| | | long count = roleService.count(Wrappers.lambdaQuery(SysRole.class) |
| | | .eq(SysRole::getRoleName, dto.getRoleName())); |
| | | LambdaQueryWrapper<SysRole> wrapper = Wrappers.lambdaQuery(SysRole.class) |
| | | .eq(SysRole::getRoleName, dto.getRoleName()); |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserService.getById(userid); |
| | | if(sysUser.getRoleType() == 2){ |
| | | wrapper.eq(SysRole::getShopId, sysUser.getObjectId()); |
| | | } |
| | | |
| | | long count = roleService.count(wrapper); |
| | | if (count > 0) { |
| | | return AjaxResult.error("角色已存在,请重新输入"); |
| | | } |
| | |
| | | role.setRemark(dto.getRemark()); |
| | | role.setCreateBy(SecurityUtils.getUsername()); |
| | | role.setCreateTime(new Date()); |
| | | |
| | | if(sysUser.getRoleType() == 2){ |
| | | role.setShopId(sysUser.getObjectId()); |
| | | } |
| | | roleService.insertRole(role); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/roleInfo") |
| | | @ApiOperation(value = "角色详情", tags = {"管理后台-角色管理"}) |
| | | @ApiOperation(value = "角色详情", tags = {"管理后台-权限管理"}) |
| | | public AjaxResult roleInfo(@RequestParam Long id) { |
| | | SysRole role = roleService.selectRoleById(id); |
| | | RoleInfoVo roleInfoVo = new RoleInfoVo(); |
| | |
| | | |
| | | |
| | | @PostMapping("/roleUpdate") |
| | | @ApiOperation(value = "编辑角色", tags = {"管理后台-角色管理"}) |
| | | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 |
| | | @ApiOperation(value = "编辑角色", tags = {"管理后台-权限管理"}) |
| | | public AjaxResult roleUpdate(@Validated @RequestBody RoleUpdateDto dto) { |
| | | SysRole role = new SysRole(); |
| | | role.setRoleName(dto.getRoleName()); |
| | |
| | | */ |
| | | @Log(title = "角色管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{roleIds}") |
| | | @ApiOperation(value = "删除角色", tags = {"管理后台-角色管理"}) |
| | | @ApiOperation(value = "删除角色", tags = {"管理后台-权限管理"}) |
| | | public AjaxResult remove(@PathVariable Long[] roleIds) { |
| | | return toAjax(roleService.deleteRoleByIds(roleIds)); |
| | | } |