fuliqi
2024-03-20 6eae571797421e5dda9d8d934394089a19178554
临时切换角色按钮
7个文件已修改
117 ■■■■■ 已修改文件
ycl-server/src/main/java/com/ycl/platform/controller/TMonitorVideoController.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/system/controller/SysRoleController.java 90 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/system/controller/SysUserController.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/system/mapper/SysUserRoleMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/system/service/ISysRoleService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/system/service/impl/SysRoleServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/resources/mapper/system/SysUserRoleMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/controller/TMonitorVideoController.java
@@ -31,7 +31,7 @@
    /**
     * 查询设备资产列表
     */
    @PreAuthorize("@ss.hasPermi('system:video:list')")
//    @PreAuthorize("@ss.hasPermi('system:video:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMonitorVideo tMonitorVideo)
    {
@@ -43,7 +43,7 @@
    /**
     * 导出设备资产列表
     */
    @PreAuthorize("@ss.hasPermi('system:video:export')")
//    @PreAuthorize("@ss.hasPermi('system:video:export')")
    @Log(title = "设备资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMonitorVideo tMonitorVideo)
@@ -56,7 +56,7 @@
    /**
     * 获取设备资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:video:query')")
//    @PreAuthorize("@ss.hasPermi('system:video:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
@@ -66,7 +66,7 @@
    /**
     * 新增设备资产
     */
    @PreAuthorize("@ss.hasPermi('system:video:add')")
//    @PreAuthorize("@ss.hasPermi('system:video:add')")
    @Log(title = "设备资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMonitorVideo tMonitorVideo)
@@ -77,7 +77,7 @@
    /**
     * 修改设备资产
     */
    @PreAuthorize("@ss.hasPermi('system:video:edit')")
//    @PreAuthorize("@ss.hasPermi('system:video:edit')")
    @Log(title = "设备资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMonitorVideo tMonitorVideo)
@@ -88,7 +88,7 @@
    /**
     * 删除设备资产
     */
    @PreAuthorize("@ss.hasPermi('system:video:remove')")
//    @PreAuthorize("@ss.hasPermi('system:video:remove')")
    @Log(title = "设备资产", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
ycl-server/src/main/java/com/ycl/system/controller/SysRoleController.java
@@ -1,6 +1,7 @@
package com.ycl.system.controller;
import annotation.Log;
import ch.qos.logback.core.rolling.helper.IntegerTokenConverter;
import com.ycl.system.AjaxResult;
import com.ycl.system.domain.SysUserRole;
import com.ycl.system.entity.SysDept;
@@ -9,15 +10,19 @@
import com.ycl.system.model.LoginUser;
import com.ycl.system.page.TableDataInfo;
import com.ycl.system.service.*;
import com.ycl.utils.SecurityUtils;
import com.ycl.utils.StringUtils;
import com.ycl.utils.poi.ExcelUtil;
import enumeration.BusinessType;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -27,7 +32,7 @@
 */
@RestController
@RequestMapping("/system/role")
public class SysRoleController extends BaseController{
public class SysRoleController extends BaseController {
    @Autowired
    private ISysRoleService roleService;
@@ -45,8 +50,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRole role)
    {
    public TableDataInfo list(SysRole role) {
        startPage();
        List<SysRole> list = roleService.selectRoleList(role);
        return getDataTable(list);
@@ -55,8 +59,7 @@
    @Log(title = "角色管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:role:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRole role)
    {
    public void export(HttpServletResponse response, SysRole role) {
        List<SysRole> list = roleService.selectRoleList(role);
        ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
        util.exportExcel(response, list, "角色数据");
@@ -67,8 +70,7 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable Long roleId)
    {
    public AjaxResult getInfo(@PathVariable Long roleId) {
        roleService.checkRoleDataScope(roleId);
        return success(roleService.selectRoleById(roleId));
    }
@@ -79,14 +81,10 @@
    @PreAuthorize("@ss.hasPermi('system:role:add')")
    @Log(title = "角色管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysRole role)
    {
        if (!roleService.checkRoleNameUnique(role))
        {
    public AjaxResult add(@Validated @RequestBody SysRole role) {
        if (!roleService.checkRoleNameUnique(role)) {
            return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
        }
        else if (!roleService.checkRoleKeyUnique(role))
        {
        } else if (!roleService.checkRoleKeyUnique(role)) {
            return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
        }
        role.setCreateBy(getUsername());
@@ -100,26 +98,20 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysRole role)
    {
    public AjaxResult edit(@Validated @RequestBody SysRole role) {
        roleService.checkRoleAllowed(role);
        roleService.checkRoleDataScope(role.getRoleId());
        if (!roleService.checkRoleNameUnique(role))
        {
        if (!roleService.checkRoleNameUnique(role)) {
            return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
        }
        else if (!roleService.checkRoleKeyUnique(role))
        {
        } else if (!roleService.checkRoleKeyUnique(role)) {
            return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
        }
        role.setUpdateBy(getUsername());
        if (roleService.updateRole(role) > 0)
        {
        if (roleService.updateRole(role) > 0) {
            // 更新缓存用户权限
            LoginUser loginUser = getLoginUser();
            if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
            {
            if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) {
                loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
                loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
                tokenService.setLoginUser(loginUser);
@@ -135,8 +127,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping("/dataScope")
    public AjaxResult dataScope(@RequestBody SysRole role)
    {
    public AjaxResult dataScope(@RequestBody SysRole role) {
        roleService.checkRoleAllowed(role);
        roleService.checkRoleDataScope(role.getRoleId());
        return toAjax(roleService.authDataScope(role));
@@ -148,8 +139,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysRole role)
    {
    public AjaxResult changeStatus(@RequestBody SysRole role) {
        roleService.checkRoleAllowed(role);
        roleService.checkRoleDataScope(role.getRoleId());
        role.setUpdateBy(getUsername());
@@ -162,8 +152,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:remove')")
    @Log(title = "角色管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
    public AjaxResult remove(@PathVariable Long[] roleIds) {
        return toAjax(roleService.deleteRoleByIds(roleIds));
    }
@@ -172,8 +161,7 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
    public AjaxResult optionselect() {
        return success(roleService.selectRoleAll());
    }
@@ -182,8 +170,7 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/authUser/allocatedList")
    public TableDataInfo allocatedList(SysUser user)
    {
    public TableDataInfo allocatedList(SysUser user) {
        startPage();
        List<SysUser> list = userService.selectAllocatedList(user);
        return getDataTable(list);
@@ -194,8 +181,7 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/authUser/unallocatedList")
    public TableDataInfo unallocatedList(SysUser user)
    {
    public TableDataInfo unallocatedList(SysUser user) {
        startPage();
        List<SysUser> list = userService.selectUnallocatedList(user);
        return getDataTable(list);
@@ -207,8 +193,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.GRANT)
    @PutMapping("/authUser/cancel")
    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
    {
    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) {
        return toAjax(roleService.deleteAuthUser(userRole));
    }
@@ -218,8 +203,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.GRANT)
    @PutMapping("/authUser/cancelAll")
    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
    {
    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) {
        return toAjax(roleService.deleteAuthUsers(roleId, userIds));
    }
@@ -229,8 +213,7 @@
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.GRANT)
    @PutMapping("/authUser/selectAll")
    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
    {
    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) {
        roleService.checkRoleDataScope(roleId);
        return toAjax(roleService.insertAuthUsers(roleId, userIds));
    }
@@ -240,11 +223,26 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping(value = "/deptTree/{roleId}")
    public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
    {
    public AjaxResult deptTree(@PathVariable("roleId") Long roleId) {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
        ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
        return ajax;
    }
    //TODO
    @GetMapping("/exchange/{roleId}")
    public AjaxResult exchange(@PathVariable Integer roleId) {
        roleService.exchange(roleId);
        // 更新缓存用户权限
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        List<SysRole> roles = user.getRoles();
        SysRole sysRole = roles.get(0);
        sysRole.setRoleId(Long.parseLong(roleId+""));
        user.setRoles(Arrays.asList(sysRole));
        loginUser.setUser(user);
        tokenService.setLoginUser(loginUser);
        return success();
    }
}
ycl-server/src/main/java/com/ycl/system/controller/SysUserController.java
@@ -5,6 +5,7 @@
import com.ycl.system.entity.SysDept;
import com.ycl.system.entity.SysRole;
import com.ycl.system.entity.SysUser;
import com.ycl.system.model.LoginUser;
import com.ycl.system.page.TableDataInfo;
import com.ycl.system.service.ISysDeptService;
import com.ycl.system.service.ISysPostService;
@@ -45,6 +46,7 @@
    @Autowired
    private ISysPostService postService;
    /**
     * 获取用户列表
     */
ycl-server/src/main/java/com/ycl/system/mapper/SysUserRoleMapper.java
@@ -62,4 +62,6 @@
     * @return 结果
     */
    public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
    void exchange(@Param("roleId")Integer roleId,@Param("userId") Long userId);
}
ycl-server/src/main/java/com/ycl/system/service/ISysRoleService.java
@@ -171,4 +171,6 @@
     * @return 结果
     */
    public int insertAuthUsers(Long roleId, Long[] userIds);
    void exchange(Integer roleId);
}
ycl-server/src/main/java/com/ycl/system/service/impl/SysRoleServiceImpl.java
@@ -418,4 +418,10 @@
        }
        return userRoleMapper.batchUserRole(list);
    }
    @Override
    public void exchange(Integer roleId) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        userRoleMapper.exchange(roleId,userId);
    }
}
ycl-server/src/main/resources/mapper/system/SysUserRoleMapper.xml
@@ -41,4 +41,7 @@
             #{userId}
            </foreach> 
    </delete>
    <update id="exchange">
        update sys_user_role set role_id = #{roleId} where user_id = #{userId}
    </update>
</mapper>