| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package com.zhongzheng.controller.top;
- import cn.hutool.core.lang.Validator;
- import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
- import com.zhongzheng.common.annotation.Log;
- import com.zhongzheng.common.constant.UserConstants;
- import com.zhongzheng.common.core.controller.BaseController;
- import com.zhongzheng.common.core.domain.AjaxResult;
- import com.zhongzheng.common.core.domain.model.TopLoginUser;
- import com.zhongzheng.common.core.page.TableDataInfo;
- import com.zhongzheng.common.enums.BusinessType;
- import com.zhongzheng.common.utils.SecurityUtils;
- import com.zhongzheng.common.utils.ServletUtils;
- import com.zhongzheng.common.utils.poi.ExcelUtil;
- import com.zhongzheng.framework.web.service.TokenService;
- import com.zhongzheng.framework.web.service.TopSysPermissionService;
- import com.zhongzheng.modules.top.domain.TopSysRole;
- import com.zhongzheng.modules.top.service.ITopSysRoleService;
- import com.zhongzheng.modules.top.service.ITopSysUserService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- /**
- * 角色信息Controller
- *
- * @author ruoyi
- * @date 2023-03-10
- */
- @Api(value = "角色信息控制器", tags = {"角色信息管理"})
- @RequiredArgsConstructor(onConstructor_ = @Autowired)
- @RestController
- @RequestMapping("/system/top/role")
- public class TopSysRoleController extends BaseController {
- @Autowired
- private ITopSysRoleService topSysRoleService;
- @Autowired
- private TokenService tokenService;
- @Autowired
- private TopSysPermissionService topSysPermissionService;
- @Autowired
- private ITopSysUserService topSysUserService;
- @ApiOperation("角色列表")
- @PreAuthorize("@ss.hasPermi('system:role:list')")
- @GetMapping("/list")
- public TableDataInfo list(TopSysRole role)
- {
- startPage();
- List<TopSysRole> list = topSysRoleService.selectRoleList(role);
- return getDataTable(list);
- }
- @Log(title = "角色管理", businessType = BusinessType.EXPORT)
- @PreAuthorize("@ss.hasPermi('system:role:export')")
- @GetMapping("/export")
- public AjaxResult export(TopSysRole role)
- {
- List<TopSysRole> list = topSysRoleService.selectRoleList(role);
- ExcelUtil<TopSysRole> util = new ExcelUtil<TopSysRole>(TopSysRole.class);
- return util.exportExcel(list, "角色数据");
- }
- /**
- * 根据角色编号获取详细信息
- */
- @ApiOperation("根据角色编号获取详细信息")
- @PreAuthorize("@ss.hasPermi('system:role:query')")
- @GetMapping(value = "/{roleId}")
- public AjaxResult getInfo(@PathVariable Long roleId)
- {
- return AjaxResult.success(topSysRoleService.selectRoleById(roleId));
- }
- /**
- * 新增角色
- */
- @ApiOperation("新增角色")
- @ApiOperationSupport(ignoreParameters = {"createBy","createTime","dataScope","delFlag","updateTime"
- ,"flag","params","roleId","updateBy","deptIds","deptCheckStrictly","menuCheckStrictly"})
- @PreAuthorize("@ss.hasPermi('system:role:add')")
- @Log(title = "角色管理", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@Validated @RequestBody TopSysRole role)
- {
- if (UserConstants.NOT_UNIQUE.equals(topSysRoleService.checkRoleNameUnique(role)))
- {
- return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
- }
- else if (UserConstants.NOT_UNIQUE.equals(topSysRoleService.checkRoleKeyUnique(role)))
- {
- return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
- }
- role.setCreateBy(SecurityUtils.getUsername());
- return toAjax(topSysRoleService.insertRole(role));
- }
- /**
- * 修改保存角色
- */
- @ApiOperation("修改保存角色")
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "角色管理", businessType = BusinessType.UPDATE)
- @PostMapping("/edit")
- public AjaxResult edit(@Validated @RequestBody TopSysRole role)
- {
- topSysRoleService.checkRoleAllowed(role);
- if (UserConstants.NOT_UNIQUE.equals(topSysRoleService.checkRoleNameUnique(role)))
- {
- return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
- }
- else if (UserConstants.NOT_UNIQUE.equals(topSysRoleService.checkRoleKeyUnique(role)))
- {
- return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
- }
- role.setUpdateBy(SecurityUtils.getUsername());
- if (topSysRoleService.updateRole(role) > 0)
- {
- // 更新缓存用户权限
- TopLoginUser loginUser = tokenService.getTopLoginUser(ServletUtils.getRequest());
- if (Validator.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
- {
- loginUser.setPermissions(topSysPermissionService.getMenuPermission(loginUser.getUser()));
- loginUser.setUser(topSysUserService.selectUserByUserName(loginUser.getUser().getUserName()));
- tokenService.setTopLoginUser(loginUser);
- }
- return AjaxResult.success();
- }
- return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
- }
- /**
- * 修改保存数据权限
- */
- @ApiOperation("修改保存数据权限")
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "角色管理", businessType = BusinessType.UPDATE)
- @PostMapping("/dataScope")
- public AjaxResult dataScope(@RequestBody TopSysRole role)
- {
- topSysRoleService.checkRoleAllowed(role);
- return toAjax(topSysRoleService.authDataScope(role));
- }
- /**
- * 状态修改
- */
- @ApiOperation("状态修改")
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "角色管理", businessType = BusinessType.UPDATE)
- @PostMapping("/changeStatus")
- public AjaxResult changeStatus(@RequestBody TopSysRole role)
- {
- topSysRoleService.checkRoleAllowed(role);
- role.setUpdateBy(SecurityUtils.getUsername());
- return toAjax(topSysRoleService.updateRoleStatus(role));
- }
- /**
- * 删除角色
- */
- @ApiOperation("删除角色")
- @PreAuthorize("@ss.hasPermi('system:role:remove')")
- @Log(title = "角色管理", businessType = BusinessType.DELETE)
- @PostMapping("/delete/{roleIds}")
- public AjaxResult remove(@PathVariable Long[] roleIds)
- {
- return toAjax(topSysRoleService.deleteRoleByIds(roleIds));
- }
- /**
- * 获取角色选择框列表
- */
- @ApiOperation("获取角色选择框列表")
- @PreAuthorize("@ss.hasPermi('system:role:query')")
- @GetMapping("/optionselect")
- public AjaxResult optionselect()
- {
- return AjaxResult.success(topSysRoleService.selectRoleAll());
- }
- }
|