24282 2 lat temu
rodzic
commit
d5c078f4dd

+ 1 - 1
hx-tenant/pom.xml

@@ -20,7 +20,7 @@
     <dependencies>
         <dependency>
             <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-system</artifactId>
+            <artifactId>ruoyi-framework</artifactId>
         </dependency>
     </dependencies>
 

+ 118 - 0
hx-tenant/src/main/java/com/fjhx/tenant/controller/tenant/RoleTenantController.java

@@ -0,0 +1,118 @@
+package com.fjhx.tenant.controller.tenant;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.annotation.TenantIgnore;
+import com.ruoyi.common.constant.DatasourceConstant;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.entity.SysRole;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.web.service.SysPermissionService;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.service.ISysRoleService;
+import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@TenantIgnore
+@DS(DatasourceConstant.SLAVE_NAME)
+@RestController
+@RequestMapping("/tenantRole")
+public class RoleTenantController extends BaseController {
+
+    @Autowired
+    private ISysRoleService roleService;
+
+    @Autowired
+    private SysPermissionService permissionService;
+
+    @Autowired
+    private ISysUserService userService;
+
+    @Autowired
+    private TokenService tokenService;
+
+    /**
+     * 角色分页
+     */
+    @GetMapping("/list")
+    public TableDataInfo list(SysRole role) {
+        startPage();
+        List<SysRole> list = roleService.selectRoleList(role);
+        return getDataTable(list);
+    }
+
+    /**
+     * 新增角色
+     */
+    @Log(title = "角色管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public void add(@Validated @RequestBody SysRole role) {
+        String tenantId = role.getTenantId();
+        if (ObjectUtil.isEmpty(tenantId)) {
+            throw new ServiceException("租户id不能为空");
+        }
+        if (!roleService.checkRoleNameUnique(role)) {
+            throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
+        } else if (!roleService.checkRoleKeyUnique(role)) {
+            throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
+        }
+        role.setCreateBy(getUsername());
+        roleService.insertRole(role);
+    }
+
+    /**
+     * 修改保存角色
+     */
+    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public void edit(@Validated @RequestBody SysRole role) {
+        String tenantId = role.getTenantId();
+        if (ObjectUtil.isEmpty(tenantId)) {
+            throw new ServiceException("租户id不能为空");
+        }
+        roleService.checkRoleAllowed(role);
+        roleService.checkRoleDataScope(role.getRoleId());
+
+        if (!roleService.checkRoleNameUnique(role)) {
+            throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
+        } else if (!roleService.checkRoleKeyUnique(role)) {
+            throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
+        }
+        role.setUpdateBy(getUsername());
+
+        int num = roleService.updateRole(role);
+        if (num == 0) {
+            throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
+        }
+
+        // 更新缓存用户权限
+        LoginUser loginUser = getLoginUser();
+        SysUser user = loginUser.getUser();
+        if (StringUtils.isNotNull(user) && !user.isAdmin()) {
+            loginUser.setPermissions(permissionService.getMenuPermission(user));
+            loginUser.setUser(userService.selectUserByUserName(user.getTenantId(), user.getUserName()));
+            tokenService.setLoginUser(loginUser);
+        }
+
+    }
+
+    /**
+     * 删除角色
+     */
+    @Log(title = "角色管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{roleIds}")
+    public void remove(@PathVariable Long[] roleIds) {
+        roleService.deleteRoleByIds(roleIds);
+    }
+
+}

+ 106 - 0
hx-tenant/src/main/java/com/fjhx/tenant/controller/tenant/UserTenantController.java

@@ -0,0 +1,106 @@
+package com.fjhx.tenant.controller.tenant;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.annotation.TenantIgnore;
+import com.ruoyi.common.constant.DatasourceConstant;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.service.ISysUserService;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@TenantIgnore
+@DS(DatasourceConstant.SLAVE_NAME)
+@RestController
+@RequestMapping("/tenantUser")
+public class UserTenantController extends BaseController {
+
+    @Autowired
+    private ISysUserService userService;
+
+    /**
+     * 获取用户列表
+     */
+    @GetMapping("/list")
+    public TableDataInfo list(SysUser user) {
+        startPage();
+        List<SysUser> list = userService.selectUserList(user);
+        return getDataTable(list);
+    }
+
+    /**
+     * 新增用户
+     */
+    @Log(title = "用户管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public void add(@Validated @RequestBody SysUser user) {
+        String tenantId = user.getTenantId();
+        if (ObjectUtil.isEmpty(tenantId)) {
+            throw new ServiceException("租户id不能为空");
+        }
+
+        if (!userService.checkUserNameUnique(user)) {
+            throw new ServiceException("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
+        }
+        user.setCreateBy(getUsername());
+        user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
+        userService.insertUser(user);
+    }
+
+    /**
+     * 修改用户
+     */
+    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public void edit(@Validated @RequestBody SysUser user) {
+        String tenantId = user.getTenantId();
+        if (ObjectUtil.isEmpty(tenantId)) {
+            throw new ServiceException("租户id不能为空");
+        }
+
+        userService.checkUserAllowed(user);
+        userService.checkUserDataScope(user.getUserId());
+        if (!userService.checkUserNameUnique(user)) {
+            throw new ServiceException("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
+        }
+        user.setUpdateBy(getUsername());
+        userService.updateUser(user);
+    }
+
+    /**
+     * 删除用户
+     */
+    @Log(title = "用户管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{userIds}")
+    public AjaxResult remove(@PathVariable Long[] userIds) {
+        if (ArrayUtils.contains(userIds, getUserId())) {
+            return error("当前用户不能删除");
+        }
+        return toAjax(userService.deleteUserByIds(userIds));
+    }
+
+    /**
+     * 重置密码
+     */
+    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
+    @PutMapping("/resetPwd")
+    public void resetPwd(@RequestBody SysUser user) {
+        userService.checkUserAllowed(user);
+        userService.checkUserDataScope(user.getUserId());
+        user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
+        user.setUpdateBy(getUsername());
+        userService.resetPwd(user);
+    }
+
+}