From d06ef3f44d6dc19dae223ab420165369ea13cc16 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 20 五月 2026 16:29:35 +0800
Subject: [PATCH] Merge branch 'dev_New_pro' of http://114.132.189.42:9002/r/product-inventory-management-after into dev_New_pro
---
src/main/java/com/ruoyi/project/system/controller/SysRoleController.java | 503 +++++++++++++++++++++++++++++--------------------------
1 files changed, 264 insertions(+), 239 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/controller/SysRoleController.java b/src/main/java/com/ruoyi/project/system/controller/SysRoleController.java
index a934bf6..650a3e3 100644
--- a/src/main/java/com/ruoyi/project/system/controller/SysRoleController.java
+++ b/src/main/java/com/ruoyi/project/system/controller/SysRoleController.java
@@ -1,240 +1,265 @@
-package com.ruoyi.project.system.controller;
-
-import java.util.List;
-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.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import com.ruoyi.common.constant.UserConstants;
-import com.ruoyi.common.utils.ServletUtils;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.framework.aspectj.lang.annotation.Log;
-import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.framework.security.LoginUser;
-import com.ruoyi.framework.security.service.SysPermissionService;
-import com.ruoyi.framework.security.service.TokenService;
-import com.ruoyi.framework.web.controller.BaseController;
-import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.framework.web.page.TableDataInfo;
-import com.ruoyi.project.system.domain.SysRole;
-import com.ruoyi.project.system.domain.SysUser;
-import com.ruoyi.project.system.domain.SysUserRole;
-import com.ruoyi.project.system.service.ISysRoleService;
-import com.ruoyi.project.system.service.ISysUserService;
-
-/**
- * 瑙掕壊淇℃伅
- *
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/system/role")
-public class SysRoleController extends BaseController
-{
- @Autowired
- private ISysRoleService roleService;
-
- @Autowired
- private TokenService tokenService;
-
- @Autowired
- private SysPermissionService permissionService;
-
- @Autowired
- private ISysUserService userService;
-
- @PreAuthorize("@ss.hasPermi('system:role:list')")
- @GetMapping("/list")
- public TableDataInfo list(SysRole role)
- {
- startPage();
- List<SysRole> list = roleService.selectRoleList(role);
- return getDataTable(list);
- }
-
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT)
- @PreAuthorize("@ss.hasPermi('system:role:export')")
- @GetMapping("/export")
- public AjaxResult export(SysRole role)
- {
- List<SysRole> list = roleService.selectRoleList(role);
- ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
- return util.exportExcel(list, "瑙掕壊鏁版嵁");
- }
-
- /**
- * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅
- */
- @PreAuthorize("@ss.hasPermi('system:role:query')")
- @GetMapping(value = "/{roleId}")
- public AjaxResult getInfo(@PathVariable Long roleId)
- {
- return AjaxResult.success(roleService.selectRoleById(roleId));
- }
-
- /**
- * 鏂板瑙掕壊
- */
- @PreAuthorize("@ss.hasPermi('system:role:add')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@Validated @RequestBody SysRole role)
- {
- if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
- {
- return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪");
- }
- else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
- {
- return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
- }
- role.setCreateBy(getUsername());
- return toAjax(roleService.insertRole(role));
-
- }
-
- /**
- * 淇敼淇濆瓨瑙掕壊
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@Validated @RequestBody SysRole role)
- {
- roleService.checkRoleAllowed(role);
- if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
- {
- return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪");
- }
- else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
- {
- return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
- }
- role.setUpdateBy(getUsername());
-
- if (roleService.updateRole(role) > 0)
- {
- // 鏇存柊缂撳瓨鐢ㄦ埛鏉冮檺
- LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
- if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
- {
- loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
- loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
- tokenService.setLoginUser(loginUser);
- }
- return AjaxResult.success();
- }
- return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛�");
- }
-
- /**
- * 淇敼淇濆瓨鏁版嵁鏉冮檺
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
- @PutMapping("/dataScope")
- public AjaxResult dataScope(@RequestBody SysRole role)
- {
- roleService.checkRoleAllowed(role);
- return toAjax(roleService.authDataScope(role));
- }
-
- /**
- * 鐘舵�佷慨鏀�
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
- @PutMapping("/changeStatus")
- public AjaxResult changeStatus(@RequestBody SysRole role)
- {
- roleService.checkRoleAllowed(role);
- role.setUpdateBy(getUsername());
- return toAjax(roleService.updateRoleStatus(role));
- }
-
- /**
- * 鍒犻櫎瑙掕壊
- */
- @PreAuthorize("@ss.hasPermi('system:role:remove')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE)
- @DeleteMapping("/{roleIds}")
- public AjaxResult remove(@PathVariable Long[] roleIds)
- {
- return toAjax(roleService.deleteRoleByIds(roleIds));
- }
-
- /**
- * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛�
- */
- @PreAuthorize("@ss.hasPermi('system:role:query')")
- @GetMapping("/optionselect")
- public AjaxResult optionselect()
- {
- return AjaxResult.success(roleService.selectRoleAll());
- }
-
- /**
- * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛�
- */
- @PreAuthorize("@ss.hasPermi('system:role:list')")
- @GetMapping("/authUser/allocatedList")
- public TableDataInfo allocatedList(SysUser user)
- {
- startPage();
- List<SysUser> list = userService.selectAllocatedList(user);
- return getDataTable(list);
- }
-
- /**
- * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛�
- */
- @PreAuthorize("@ss.hasPermi('system:role:list')")
- @GetMapping("/authUser/unallocatedList")
- public TableDataInfo unallocatedList(SysUser user)
- {
- startPage();
- List<SysUser> list = userService.selectUnallocatedList(user);
- return getDataTable(list);
- }
-
- /**
- * 鍙栨秷鎺堟潈鐢ㄦ埛
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
- @PutMapping("/authUser/cancel")
- public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
- {
- return toAjax(roleService.deleteAuthUser(userRole));
- }
-
- /**
- * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
- @PutMapping("/authUser/cancelAll")
- public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
- {
- return toAjax(roleService.deleteAuthUsers(roleId, userIds));
- }
-
- /**
- * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈
- */
- @PreAuthorize("@ss.hasPermi('system:role:edit')")
- @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
- @PutMapping("/authUser/selectAll")
- public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
- {
- return toAjax(roleService.insertAuthUsers(roleId, userIds));
- }
+package com.ruoyi.project.system.controller;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import jakarta.servlet.http.HttpServletResponse;
+
+import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.project.system.domain.vo.SysUserDeptVo;
+import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.project.system.service.*;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
+import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.framework.security.service.SysPermissionService;
+import com.ruoyi.framework.security.service.TokenService;
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.framework.web.page.TableDataInfo;
+import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysRole;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.domain.SysUserRole;
+
+/**
+ * 瑙掕壊淇℃伅
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/system/role")
+@AllArgsConstructor
+public class SysRoleController extends BaseController
+{
+ private ISysRoleService roleService;
+ private TokenService tokenService;
+ private SysPermissionService permissionService;
+ private ISysUserService userService;
+ private ISysDeptService deptService;
+
+ @PreAuthorize("@ss.hasPermi('system:role:list')")
+ @GetMapping("/list")
+ public TableDataInfo list(SysRole role)
+ {
+ startPage();
+ List<SysRole> list = roleService.selectRoleList(role);
+ return getDataTable(list);
+ }
+
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT)
+ @PreAuthorize("@ss.hasPermi('system:role:export')")
+ @PostMapping("/export")
+ 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, "瑙掕壊鏁版嵁");
+ }
+
+ /**
+ * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:query')")
+ @GetMapping(value = "/{roleId}")
+ public R<?> getInfo(@PathVariable Long roleId)
+ {
+ roleService.checkRoleDataScope(roleId);
+ return R.ok(roleService.selectRoleById(roleId));
+ }
+
+ /**
+ * 鏂板瑙掕壊
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:add')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT)
+ @PostMapping
+ public R<?> add(@Validated @RequestBody SysRole role)
+ {
+ if (!roleService.checkRoleNameUnique(role))
+ {
+ return R.fail("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪");
+ }
+ else if (!roleService.checkRoleKeyUnique(role))
+ {
+ return R.fail("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
+ }
+ role.setCreateBy(getUsername());
+ roleService.insertRole(role);
+ return R.ok();
+
+ }
+
+ /**
+ * 淇敼淇濆瓨瑙掕壊
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping
+ public R<?> edit(@Validated @RequestBody SysRole role)
+ {
+ roleService.checkRoleAllowed(role);
+ roleService.checkRoleDataScope(role.getRoleId());
+ if (!roleService.checkRoleNameUnique(role))
+ {
+ return R.fail("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪");
+ }
+ else if (!roleService.checkRoleKeyUnique(role))
+ {
+ return R.fail("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
+ }
+ role.setUpdateBy(getUsername());
+
+ if (roleService.updateRole(role) > 0)
+ {
+ // 鏇存柊缂撳瓨鐢ㄦ埛鏉冮檺
+ LoginUser loginUser = getLoginUser();
+ if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
+ {
+ loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
+ loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
+ tokenService.setLoginUser(loginUser);
+ }
+ return R.ok();
+ }
+ return R.fail("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛�");
+ }
+
+ /**
+ * 淇敼淇濆瓨鏁版嵁鏉冮檺
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping("/dataScope")
+ public R<?> dataScope(@RequestBody SysRole role)
+ {
+ roleService.checkRoleAllowed(role);
+ roleService.checkRoleDataScope(role.getRoleId());
+ roleService.authDataScope(role);
+ return R.ok();
+ }
+
+ /**
+ * 鐘舵�佷慨鏀�
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping("/changeStatus")
+ public R<?> changeStatus(@RequestBody SysRole role)
+ {
+ roleService.checkRoleAllowed(role);
+ roleService.checkRoleDataScope(role.getRoleId());
+ role.setUpdateBy(getUsername());
+ roleService.updateRoleStatus(role);
+ return R.ok();
+ }
+
+ /**
+ * 鍒犻櫎瑙掕壊
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:remove')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE)
+ @DeleteMapping("/{roleIds}")
+ public R<?> remove(@PathVariable Long[] roleIds)
+ {
+ roleService.deleteRoleByIds(roleIds);
+ return R.ok();
+ }
+
+ /**
+ * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:query')")
+ @GetMapping("/optionselect")
+ public R<?> optionselect()
+ {
+ return R.ok(roleService.selectRoleAll());
+ }
+
+ /**
+ * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:list')")
+ @GetMapping("/authUser/allocatedList")
+ public TableDataInfo allocatedList(SysUser user)
+ {
+ startPage();
+ List<SysUser> list = userService.selectAllocatedList(user);
+ return getDataTable(list);
+ }
+
+ /**
+ * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:list')")
+ @GetMapping("/authUser/unallocatedList")
+ public TableDataInfo unallocatedList(SysUser user)
+ {
+ startPage();
+ List<SysUser> list = userService.selectUnallocatedList(user);
+ return getDataTable(list);
+ }
+
+ /**
+ * 鍙栨秷鎺堟潈鐢ㄦ埛
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+ @PutMapping("/authUser/cancel")
+ public R<?> cancelAuthUser(@RequestBody SysUserRole userRole)
+ {
+ roleService.deleteAuthUser(userRole);
+ return R.ok();
+ }
+
+ /**
+ * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+ @PutMapping("/authUser/cancelAll")
+ public R<?> cancelAuthUserAll(Long roleId, Long[] userIds)
+ {
+ roleService.deleteAuthUsers(roleId, userIds);
+ return R.ok();
+ }
+
+ /**
+ * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:edit')")
+ @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+ @PutMapping("/authUser/selectAll")
+ public R<?> selectAuthUserAll(Long roleId, Long[] userIds)
+ {
+ roleService.checkRoleDataScope(roleId);
+ roleService.insertAuthUsers(roleId, userIds);
+ return R.ok();
+ }
+
+ /**
+ * 鑾峰彇瀵瑰簲瑙掕壊閮ㄩ棬鏍戝垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('system:role:query')")
+ @GetMapping(value = "/deptTree/{roleId}")
+ public R<?> deptTree(@PathVariable("roleId") Long roleId)
+ {
+ Map<String, Object> map = new HashMap<>();
+ map.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
+ map.put("depts", deptService.selectDeptTreeList(new SysDept()));
+ return R.ok(map);
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3