Pu Zhibing
2025-01-04 9c7ddd3a1126bdd057300bc9c79e1a83f591212c
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java
@@ -27,6 +27,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -73,6 +74,9 @@
    
    @Resource
    private TokenService tokenService;
    @Autowired
    private ISysMenuService menuService;
    
    
    
@@ -122,12 +126,21 @@
        }
        user.setCreateBy(SecurityUtils.getUsername());
        user.setPassword(SecurityUtils.encryptPassword("a123456"));
        user.setRoleType(1);
        user.setRoleType(sysUser1.getRoleType());
        userService.insertUser(user);
        SysUserRole sysUserRole = new SysUserRole();
        sysUserRole.setRoleId(user.getRoleId());
        sysUserRole.setUserId(user.getUserId());
        userRoleService.insertSysUserRole(sysUserRole);
        //添加门店员工关系数据
        if(2 == user.getRoleType()){
            UserShop userShop = new UserShop();
            userShop.setUserId(user.getUserId());
            userShop.setShopId(user.getObjectId());
            userShop.setRoleType(2);
            userShop.setRoleId(user.getRoleId());
            userShopService.save(userShop);
        }
        return AjaxResult.success();
    }
    
@@ -215,6 +228,17 @@
        user.setUpdateBy(SecurityUtils.getUsername());
        user.setUpdateTime(new Date());
        userService.updateUser(user);
        //添加门店员工关系数据
        if(2 == user.getRoleType()){
            userShopService.remove(new LambdaQueryWrapper<UserShop>().eq(UserShop::getUserId, user.getUserId()).eq(UserShop::getShopId, user.getObjectId()));
            UserShop userShop = new UserShop();
            userShop.setUserId(user.getUserId());
            userShop.setShopId(user.getObjectId());
            userShop.setRoleType(2);
            userShop.setRoleId(user.getRoleId());
            userShopService.save(userShop);
        }
        return success();
    }
@@ -312,7 +336,7 @@
        }
        // 角色集合
        Set<String> roles = permissionService.getRolePermission(sysUser);
        // 权限集合
        // 权限集合getRolePermission
        Set<String> permissions = permissionService.getMenuPermission(sysUser);
        LoginUser sysUserVo = new LoginUser();
        sysUserVo.setSysUser(sysUser);
@@ -592,7 +616,7 @@
    @ResponseBody
    @GetMapping("/switchShop")
    @ApiOperation(value = "切换门店", tags = {"门店后台-首页"})
    public R switchShop(@PathVariable("shopId") Integer shopId){
    public R<Set<String>> switchShop(@PathVariable("shopId") Integer shopId){
        Long userid = tokenService.getLoginUser().getUserid();
        UserShop one = userShopService.getOne(new LambdaQueryWrapper<UserShop>().eq(UserShop::getUserId, userid).eq(UserShop::getShopId, shopId));
        if(null == one){
@@ -601,6 +625,9 @@
        SysUser sysUser = userService.getById(userid);
        sysUser.setObjectId(shopId);
        userService.updateById(sysUser);
        return R.ok();
        //查询用户权限列表
        Long roleId = one.getRoleId();
        Set<String> rolePerms = menuService.selectMenuPermsByRoleId(roleId);
        return R.ok(rolePerms);
    }
}