车车 10 kuukautta sitten
vanhempi
sitoutus
52a362a758
22 muutettua tiedostoa jossa 384 lisäystä ja 201 poistoa
  1. 22 46
      ktg-admin/src/main/java/com/ktg/web/controller/system/SysRoleController.java
  2. 20 0
      ktg-common/src/main/java/com/ktg/common/core/domain/entity/SysRole.java
  3. 22 0
      ktg-common/src/main/java/com/ktg/common/core/domain/model/BaseBean.java
  4. 0 1
      ktg-framework/src/main/java/com/ktg/framework/aspectj/DataScopeAspect.java
  5. 49 30
      ktg-framework/src/main/java/com/ktg/framework/aspectj/MarsDataScopeAspect.java
  6. 10 0
      ktg-framework/src/main/java/com/ktg/framework/web/service/UserDetailsServiceImpl.java
  7. 1 1
      ktg-iscs/src/main/java/com/ktg/iscs/controller/IsLotoStationController.java
  8. 4 5
      ktg-iscs/src/main/java/com/ktg/iscs/domain/IsLotoStation.java
  9. 1 1
      ktg-iscs/src/main/java/com/ktg/iscs/service/IIsLotoStationService.java
  10. 3 1
      ktg-iscs/src/main/java/com/ktg/iscs/service/impl/IsLotoStationServiceImpl.java
  11. 3 2
      ktg-iscs/src/main/resources/mapper/IsLotoStationMapper.xml
  12. 29 0
      ktg-system/src/main/java/com/ktg/system/domain/SysRoleWorkstation.java
  13. 16 0
      ktg-system/src/main/java/com/ktg/system/mapper/SysRoleWorkstationMapper.java
  14. 5 0
      ktg-system/src/main/java/com/ktg/system/mapper/SysUserMapper.java
  15. 17 0
      ktg-system/src/main/java/com/ktg/system/service/ISysRoleWorkstationService.java
  16. 4 0
      ktg-system/src/main/java/com/ktg/system/service/ISysUserService.java
  17. 75 91
      ktg-system/src/main/java/com/ktg/system/service/impl/SysRoleServiceImpl.java
  18. 40 0
      ktg-system/src/main/java/com/ktg/system/service/impl/SysRoleWorkstationServiceImpl.java
  19. 26 4
      ktg-system/src/main/java/com/ktg/system/service/impl/SysUserServiceImpl.java
  20. 22 18
      ktg-system/src/main/resources/mapper/system/SysRoleMapper.xml
  21. 7 0
      ktg-system/src/main/resources/mapper/system/SysRoleWorkstationMapper.xml
  22. 8 1
      ktg-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 22 - 46
ktg-admin/src/main/java/com/ktg/web/controller/system/SysRoleController.java

@@ -33,8 +33,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping("/system/role")
-public class SysRoleController extends BaseController
-{
+public class SysRoleController extends BaseController {
     @Autowired
     private ISysRoleService roleService;
 
@@ -49,8 +48,7 @@ public class SysRoleController extends BaseController
 
     @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);
@@ -59,8 +57,7 @@ public class SysRoleController extends BaseController
     @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, "角色数据");
@@ -71,8 +68,7 @@ public class SysRoleController extends BaseController
      */
     @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 AjaxResult.success(roleService.selectRoleById(roleId));
     }
@@ -83,14 +79,10 @@ public class SysRoleController extends BaseController
     @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)))
-        {
+    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)))
-        {
+        } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
             return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
         }
         role.setCreateBy(getUsername());
@@ -104,26 +96,20 @@ public class SysRoleController extends BaseController
     @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 (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
-        {
+        if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
             return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
-        }
-        else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
-        {
+        } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
             return AjaxResult.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);
@@ -139,8 +125,7 @@ public class SysRoleController extends BaseController
     @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));
@@ -152,8 +137,7 @@ public class SysRoleController extends BaseController
     @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());
@@ -166,8 +150,7 @@ public class SysRoleController extends BaseController
     @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));
     }
 
@@ -176,8 +159,7 @@ public class SysRoleController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping("/optionselect")
-    public AjaxResult optionselect()
-    {
+    public AjaxResult optionselect() {
         return AjaxResult.success(roleService.selectRoleAll());
     }
 
@@ -186,8 +168,7 @@ public class SysRoleController extends BaseController
      */
     @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);
@@ -195,8 +176,7 @@ public class SysRoleController extends BaseController
 
     @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/allocatedListByRoleKey")
-    public TableDataInfo allocatedListByRoleKey(SysUser user)
-    {
+    public TableDataInfo allocatedListByRoleKey(SysUser user) {
         Assert.notBlank(user.getRoleKey(), "字符权限不可为空!");
         SysRole sysRole = roleService.getOne(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getRoleKey, user.getRoleKey()));
         user.setRoleId(sysRole.getRoleId());
@@ -210,8 +190,7 @@ public class SysRoleController extends BaseController
      */
     @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);
@@ -223,8 +202,7 @@ public class SysRoleController extends BaseController
     @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));
     }
 
@@ -234,8 +212,7 @@ public class SysRoleController extends BaseController
     @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));
     }
 
@@ -245,8 +222,7 @@ public class SysRoleController extends BaseController
     @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));
     }

+ 20 - 0
ktg-common/src/main/java/com/ktg/common/core/domain/entity/SysRole.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.ktg.common.annotation.Excel;
 import com.ktg.common.annotation.Excel.ColumnType;
 import com.ktg.common.core.domain.BaseEntity;
+import lombok.Data;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
@@ -15,6 +16,7 @@ import javax.validation.constraints.Size;
  *
  * @author ruoyi
  */
+@Data
 public class SysRole extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
@@ -39,6 +41,9 @@ public class SysRole extends BaseEntity
     @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限")
     private String dataScope;
 
+    @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本岗位数据权限,4=本岗位及以下数据权限,5=仅本人数据权限")
+    private String marsDataScope;
+
     /** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */
     private boolean menuCheckStrictly;
 
@@ -64,6 +69,10 @@ public class SysRole extends BaseEntity
     @TableField(exist = false)
     private Long[] deptIds;
 
+    /** 岗位组(mars数据权限) */
+    @TableField(exist = false)
+    private Long[] workstationIds;
+
     public SysRole()
     {
 
@@ -139,6 +148,16 @@ public class SysRole extends BaseEntity
         this.dataScope = dataScope;
     }
 
+    public String getMarsDataScope()
+    {
+        return marsDataScope;
+    }
+
+    public void setMarsDataScope(String marsDataScope)
+    {
+        this.marsDataScope = marsDataScope;
+    }
+
     public boolean isMenuCheckStrictly()
     {
         return menuCheckStrictly;
@@ -217,6 +236,7 @@ public class SysRole extends BaseEntity
             .append("roleKey", getRoleKey())
             .append("roleSort", getRoleSort())
             .append("dataScope", getDataScope())
+            .append("marsDataScope", getMarsDataScope())
             .append("menuCheckStrictly", isMenuCheckStrictly())
             .append("deptCheckStrictly", isDeptCheckStrictly())
             .append("status", getStatus())

+ 22 - 0
ktg-common/src/main/java/com/ktg/common/core/domain/model/BaseBean.java

@@ -1,11 +1,15 @@
 package com.ktg.common.core.domain.model;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Bean基类
@@ -37,4 +41,22 @@ public class BaseBean implements Serializable
     @Schema(description = "备注")
     private String remark;
 
+    @ApiModelProperty(value = "权限数据")
+    @TableField(exist = false)
+    private Map<String, Object> paramMap;
+
+    public Map<String, Object> getParamMap()
+    {
+        if (paramMap == null)
+        {
+            paramMap = new HashMap<>();
+        }
+        return paramMap;
+    }
+
+    public void setParamMap(Map<String, Object> paramMap)
+    {
+        this.paramMap = paramMap;
+    }
+
 }

+ 0 - 1
ktg-framework/src/main/java/com/ktg/framework/aspectj/DataScopeAspect.java

@@ -90,7 +90,6 @@ public class DataScopeAspect {
                         role.getRoleId()));
             } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
                 sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
-                System.out.println("1----" + sqlString);
             } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
                 sqlString.append(StringUtils.format(
                         " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",

+ 49 - 30
ktg-framework/src/main/java/com/ktg/framework/aspectj/MarsDataScopeAspect.java

@@ -1,17 +1,23 @@
 package com.ktg.framework.aspectj;
 
+import cn.hutool.core.lang.Assert;
 import com.ktg.common.annotation.MarsDataScope;
-import com.ktg.common.core.domain.BaseEntity;
 import com.ktg.common.core.domain.entity.SysRole;
 import com.ktg.common.core.domain.entity.SysUser;
+import com.ktg.common.core.domain.model.BaseBean;
 import com.ktg.common.core.domain.model.LoginUser;
 import com.ktg.common.utils.SecurityUtils;
 import com.ktg.common.utils.StringUtils;
+import com.ktg.system.service.ISysUserService;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * 数据过滤处理
  *
@@ -23,32 +29,36 @@ public class MarsDataScopeAspect {
     /**
      * 全部数据权限
      */
-    public static final String DATA_SCOPE_ALL = "1";
+    public static final String MARS_DATA_SCOPE_ALL = "1";
 
     /**
      * 自定数据权限
      */
-    public static final String DATA_SCOPE_CUSTOM = "2";
+    public static final String MARS_DATA_SCOPE_CUSTOM = "2";
 
     /**
-     * 部门数据权限
+     * 岗位数据权限
      */
-    public static final String DATA_SCOPE_DEPT = "3";
+    public static final String MARS_DATA_SCOPE_WORKSTATION = "3";
 
     /**
-     * 部门及以下数据权限
+     * 岗位及以下数据权限
      */
-    public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
+    public static final String MARS_DATA_SCOPE_WORKSTATION_AND_CHILD = "4";
 
     /**
      * 仅本人数据权限
      */
-    public static final String DATA_SCOPE_SELF = "5";
+    public static final String MARS_DATA_SCOPE_SELF = "5";
 
     /**
      * 数据权限过滤关键字
      */
-    public static final String DATA_SCOPE = "workstationScope";
+    public static final String MARS_DATA_SCOPE = "workstationScope";
+
+
+    @Autowired
+    private ISysUserService iSysUserService;
 
     @Before("@annotation(controllerDataScope)")
     public void doBefore(JoinPoint point, MarsDataScope controllerDataScope) {
@@ -59,11 +69,12 @@ public class MarsDataScopeAspect {
     protected void handleDataScope(final JoinPoint joinPoint, MarsDataScope controllerDataScope) {
         // 获取当前的用户
         LoginUser loginUser = SecurityUtils.getLoginUser();
+        List<Long> allChildWorkstationByUserIds = iSysUserService.getAllChildWorkstationByUserId(loginUser.getUser().getUserId());
         if (StringUtils.isNotNull(loginUser)) {
             SysUser currentUser = loginUser.getUser();
             // 如果是超级管理员,则不过滤数据
             if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) {
-                dataScopeFilter(joinPoint, currentUser, controllerDataScope.workstationAlias());
+                dataScopeFilter(joinPoint, currentUser, controllerDataScope.workstationAlias(), allChildWorkstationByUserIds);
             }
         }
     }
@@ -75,27 +86,35 @@ public class MarsDataScopeAspect {
      * @param user      用户
      * @param workstationAlias 别名
      */
-    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String workstationAlias) {
+    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String workstationAlias, List<Long> allChildWorkstationByUserIds) {
         StringBuilder sqlString = new StringBuilder();
 
         for (SysRole role : user.getRoles()) {
-            String dataScope = role.getDataScope();
-            if (DATA_SCOPE_ALL.equals(dataScope)) {
+            String marsDataScope = role.getMarsDataScope();
+            if (MARS_DATA_SCOPE_ALL.equals(marsDataScope)) {
+                // 1.全部数据权限
                 sqlString = new StringBuilder();
                 break;
-            } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
+            } else if (MARS_DATA_SCOPE_CUSTOM.equals(marsDataScope)) {
+                // 2.自定义数据权限
                 sqlString.append(StringUtils.format(
-                        " OR {}.workstation IN ( SELECT workstation_id FROM sys_role_dept WHERE role_id = {} ) ", workstationAlias,
+                        " OR {}.workstation_id IN ( SELECT workstation_id FROM sys_role_workstation WHERE role_id = {} ) ", workstationAlias,
                         role.getRoleId()));
-            } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
-                sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", workstationAlias, user.getDeptId()));
-            } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
-                sqlString.append(StringUtils.format(
-                        " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
-                        workstationAlias, user.getDeptId(), user.getDeptId()));
-            } else if (DATA_SCOPE_SELF.equals(dataScope)) {
+            } else if (MARS_DATA_SCOPE_WORKSTATION.equals(marsDataScope)) {
+                // 3.自身岗位权限
+                sqlString.append(StringUtils.format(" OR {}.workstation_id IN ( SELECT workstation_id FROM is_user_workstation WHERE user_id = {} )", workstationAlias, user.getUserId()));
+            } else if (MARS_DATA_SCOPE_WORKSTATION_AND_CHILD.equals(marsDataScope)) {
+               // 4.自身部门及以下数据权限
+                Assert.isFalse(allChildWorkstationByUserIds.isEmpty(), "请先给该人员配置岗位信息!");
+                String result = allChildWorkstationByUserIds.stream()
+                        .map(String::valueOf)
+                        .collect(Collectors.joining(","));
+                sqlString.append(StringUtils.format(" OR {}.workstation_id IN ({})",
+                        workstationAlias, result));
+            } else if (MARS_DATA_SCOPE_SELF.equals(marsDataScope)) {
+                // 5.自身权限
                 if (StringUtils.isNotBlank(workstationAlias)) {
-                    sqlString.append(StringUtils.format(" OR {}.user_id = {} ", workstationAlias, user.getUserId()));
+                    sqlString.append(StringUtils.format(" OR {}.create_by = {} ", workstationAlias, user.getUserId()));
                 } else {
                     // 数据权限为仅本人且没有userAlias别名不查询任何数据
                     sqlString.append(" OR 1=0 ");
@@ -105,9 +124,9 @@ public class MarsDataScopeAspect {
 
         if (StringUtils.isNotBlank(sqlString.toString())) {
             Object params = joinPoint.getArgs()[0];
-            if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
-                BaseEntity baseEntity = (BaseEntity) params;
-                baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
+            if (StringUtils.isNotNull(params) && params instanceof BaseBean) {
+                BaseBean baseBean = (BaseBean) params;
+                baseBean.getParamMap().put(MARS_DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
             }
         }
     }
@@ -116,10 +135,10 @@ public class MarsDataScopeAspect {
      * 拼接权限sql前先清空params.dataScope参数防止注入
      */
     private void clearDataScope(final JoinPoint joinPoint) {
-        Object params = joinPoint.getArgs()[0];
-        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
-            BaseEntity baseEntity = (BaseEntity) params;
-            baseEntity.getParams().put(DATA_SCOPE, "");
+        Object paramMap = joinPoint.getArgs()[0];
+        if (StringUtils.isNotNull(paramMap) && paramMap instanceof BaseBean) {
+            BaseBean baseBean = (BaseBean) paramMap;
+            baseBean.getParamMap().put(MARS_DATA_SCOPE, "");
         }
     }
 }

+ 10 - 0
ktg-framework/src/main/java/com/ktg/framework/web/service/UserDetailsServiceImpl.java

@@ -15,6 +15,8 @@ import com.ktg.common.exception.ServiceException;
 import com.ktg.common.utils.StringUtils;
 import com.ktg.system.service.ISysUserService;
 
+import java.util.List;
+
 /**
  * 用户验证处理
  *
@@ -41,6 +43,14 @@ public class UserDetailsServiceImpl implements UserDetailsService
 
         if(!StringUtils.isNotNull(user)){
             user = userService.selectUserByUserName(username);
+            // 开始放入岗位的权限数据
+            List<Long> userWorkstationIds = userService.getUserWorkstationIds(user.getUserId());
+            if (!userWorkstationIds.isEmpty()) {
+                // 将List<Long>转换为Long[]
+                Long[] array = new Long[userWorkstationIds.size()];
+                Long[] workstationIdsArray = userWorkstationIds.toArray(array);
+                user.setWorkstationIds(workstationIdsArray);
+            }
         }
 
         if (StringUtils.isNull(user))

+ 1 - 1
ktg-iscs/src/main/java/com/ktg/iscs/controller/IsLotoStationController.java

@@ -51,7 +51,7 @@ public class IsLotoStationController extends BaseController
     @GetMapping("/getIsLotoStationPage")
     public CommonResult<Page<IsLotoStationVO>> getIsLotoStationPage(Page<IsLotoStation> page, IsLotoStation isLotoStation)
     {
-        Page<IsLotoStationVO> result = isLotoStationService.getIsLotoStationPage(page, isLotoStation);
+        Page<IsLotoStationVO> result = isLotoStationService.getIsLotoStationPage(isLotoStation, page);
         return CommonResult.success(result);
     }
 

+ 4 - 5
ktg-iscs/src/main/java/com/ktg/iscs/domain/IsLotoStation.java

@@ -1,12 +1,12 @@
 package com.ktg.iscs.domain;
 
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import io.swagger.annotations.ApiModelProperty;
-import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.ktg.common.annotation.Excel;
 import com.ktg.common.core.domain.model.BaseBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 /**
  * 电柜对象 is_loto_station
@@ -47,5 +47,4 @@ public class IsLotoStation extends BaseBean
     @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)")
     private String delFlag;
 
-
 }

+ 1 - 1
ktg-iscs/src/main/java/com/ktg/iscs/service/IIsLotoStationService.java

@@ -16,7 +16,7 @@ import java.util.List;
  */
 public interface IIsLotoStationService extends IService<IsLotoStation> {
 
-    Page<IsLotoStationVO> getIsLotoStationPage(Page<IsLotoStation> page, IsLotoStation isLotoStation);
+    Page<IsLotoStationVO> getIsLotoStationPage(IsLotoStation isLotoStation, Page<IsLotoStation> page);
 
     List<PointsMapVO> selectLotoMapById(Long lotoId, Long sopId, Long ticketId);
 

+ 3 - 1
ktg-iscs/src/main/java/com/ktg/iscs/service/impl/IsLotoStationServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ktg.common.annotation.MarsDataScope;
 import com.ktg.common.utils.StringUtils;
 import com.ktg.iscs.domain.IsJobTicketPoints;
 import com.ktg.iscs.domain.IsLotoStation;
@@ -45,7 +46,8 @@ public class IsLotoStationServiceImpl extends ServiceImpl<IsLotoStationMapper, I
     private IIsJobTicketPointsService iIsJobTicketPointsService;
 
     @Override
-    public Page<IsLotoStationVO> getIsLotoStationPage(Page<IsLotoStation> page, IsLotoStation isLotoStation) {
+    @MarsDataScope(workstationAlias = "w")
+    public Page<IsLotoStationVO> getIsLotoStationPage(IsLotoStation isLotoStation, Page<IsLotoStation> page) {
         return isLotoStationMapper.getIsLotoStationPage(page, isLotoStation);
     }
 

+ 3 - 2
ktg-iscs/src/main/resources/mapper/IsLotoStationMapper.xml

@@ -11,7 +11,8 @@
         FROM
         is_loto_station l
         LEFT JOIN is_workstation w ON w.workstation_id = l.workstation_id
-        <where>
+        where
+            l.del_flag = '0'
             <if test="isLotoStation.lotoName != null and isLotoStation.lotoName.trim != ''">
                 and l.loto_name like concat('%',#{isLotoStation.lotoName},'%')
             </if>
@@ -21,7 +22,7 @@
             <if test="isLotoStation.workstationId != null">
                 and l.workstation_id = #{isLotoStation.workstationId}
             </if>
-        </where>
+            ${isLotoStation.paramMap.workstationScope}
         ORDER BY
         l.loto_id DESC
     </select>

+ 29 - 0
ktg-system/src/main/java/com/ktg/system/domain/SysRoleWorkstation.java

@@ -0,0 +1,29 @@
+package com.ktg.system.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 角色和岗位关联对象 sys_role_workstation
+ *
+ * @author cgj
+ * @date 2024-12-31
+ */
+@EqualsAndHashCode(callSuper = false)
+@Data
+public class SysRoleWorkstation
+{
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "角色ID")
+    @TableId(type = IdType.AUTO)
+    private Long roleId;
+
+    @ApiModelProperty(value = "部门ID")
+    private Long workstationId;
+
+
+}

+ 16 - 0
ktg-system/src/main/java/com/ktg/system/mapper/SysRoleWorkstationMapper.java

@@ -0,0 +1,16 @@
+package com.ktg.system.mapper;
+
+import com.ktg.common.mapper.BaseMapperX;
+import com.ktg.system.domain.SysRoleWorkstation;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 角色和岗位关联Mapper接口
+ *
+ * @author cgj
+ * @date 2024-12-31
+ */
+@Mapper
+public interface SysRoleWorkstationMapper extends BaseMapperX<SysRoleWorkstation> {
+
+}

+ 5 - 0
ktg-system/src/main/java/com/ktg/system/mapper/SysUserMapper.java

@@ -137,4 +137,9 @@ public interface SysUserMapper extends BaseMapperX<SysUser>
     public SysUser checkEmailUnique(String email);
 
     List<Long> getWorkstationUserIds(@Param(value = "workstationId") Long workstationId);
+
+    List<Long> getUserWorkstationIds(@Param(value = "userId") Long userId);
+
+    List<Long> getChildWorkstations(@Param(value = "userWorkstationId") Long userWorkstationId);
+
 }

+ 17 - 0
ktg-system/src/main/java/com/ktg/system/service/ISysRoleWorkstationService.java

@@ -0,0 +1,17 @@
+package com.ktg.system.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ktg.common.core.domain.entity.SysRole;
+import com.ktg.system.domain.SysRoleWorkstation;
+
+/**
+ * 角色和岗位关联Service接口
+ *
+ * @author cgj
+ * @date 2024-12-31
+ */
+public interface ISysRoleWorkstationService extends IService<SysRoleWorkstation> {
+
+    Boolean insertRoleWorkstation(SysRole role);
+
+}

+ 4 - 0
ktg-system/src/main/java/com/ktg/system/service/ISysUserService.java

@@ -212,4 +212,8 @@ public interface ISysUserService extends IService<SysUser>
      * @return 结果
      */
     public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
+
+    List<Long> getUserWorkstationIds(Long userId);
+
+    List<Long> getAllChildWorkstationByUserId(Long userId);
 }

+ 75 - 91
ktg-system/src/main/java/com/ktg/system/service/impl/SysRoleServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ktg.system.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ktg.common.annotation.DataScope;
 import com.ktg.common.constant.UserConstants;
@@ -11,17 +12,20 @@ import com.ktg.common.utils.StringUtils;
 import com.ktg.common.utils.spring.SpringUtils;
 import com.ktg.system.domain.SysRoleDept;
 import com.ktg.system.domain.SysRoleMenu;
+import com.ktg.system.domain.SysRoleWorkstation;
 import com.ktg.system.domain.SysUserRole;
 import com.ktg.system.mapper.SysRoleDeptMapper;
 import com.ktg.system.mapper.SysRoleMapper;
 import com.ktg.system.mapper.SysRoleMenuMapper;
 import com.ktg.system.mapper.SysUserRoleMapper;
 import com.ktg.system.service.ISysRoleService;
+import com.ktg.system.service.ISysRoleWorkstationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 角色 业务层处理
@@ -29,8 +33,7 @@ import java.util.*;
  * @author guoruan
  */
 @Service
-public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService
-{
+public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
     @Autowired
     private SysRoleMapper roleMapper;
 
@@ -42,6 +45,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
 
     @Autowired
     private SysRoleDeptMapper roleDeptMapper;
+    @Autowired
+    private ISysRoleWorkstationService iSysRoleWorkstationService;
 
     /**
      * 根据条件分页查询角色数据
@@ -51,8 +56,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @DataScope(deptAlias = "d")
-    public List<SysRole> selectRoleList(SysRole role)
-    {
+    public List<SysRole> selectRoleList(SysRole role) {
         return roleMapper.selectRoleList(role);
     }
 
@@ -63,16 +67,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 角色列表
      */
     @Override
-    public List<SysRole> selectRolesByUserId(Long userId)
-    {
+    public List<SysRole> selectRolesByUserId(Long userId) {
         List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
         List<SysRole> roles = selectRoleAll();
-        for (SysRole role : roles)
-        {
-            for (SysRole userRole : userRoles)
-            {
-                if (role.getRoleId().longValue() == userRole.getRoleId().longValue())
-                {
+        for (SysRole role : roles) {
+            for (SysRole userRole : userRoles) {
+                if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
                     role.setFlag(true);
                     break;
                 }
@@ -88,14 +88,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 权限列表
      */
     @Override
-    public Set<String> selectRolePermissionByUserId(Long userId)
-    {
+    public Set<String> selectRolePermissionByUserId(Long userId) {
         List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
         Set<String> permsSet = new HashSet<>();
-        for (SysRole perm : perms)
-        {
-            if (StringUtils.isNotNull(perm))
-            {
+        for (SysRole perm : perms) {
+            if (StringUtils.isNotNull(perm)) {
                 permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
             }
         }
@@ -108,8 +105,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 角色列表
      */
     @Override
-    public List<SysRole> selectRoleAll()
-    {
+    public List<SysRole> selectRoleAll() {
         return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
     }
 
@@ -120,8 +116,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 选中角色ID列表
      */
     @Override
-    public List<Long> selectRoleListByUserId(Long userId)
-    {
+    public List<Long> selectRoleListByUserId(Long userId) {
         return roleMapper.selectRoleListByUserId(userId);
     }
 
@@ -132,9 +127,19 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 角色对象信息
      */
     @Override
-    public SysRole selectRoleById(Long roleId)
-    {
-        return roleMapper.selectRoleById(roleId);
+    public SysRole selectRoleById(Long roleId) {
+        SysRole sysRole = roleMapper.selectRoleById(roleId);
+        // 查询岗位信息进行回显
+        List<SysRoleWorkstation> list = iSysRoleWorkstationService
+                .list(Wrappers.<SysRoleWorkstation>lambdaQuery().eq(SysRoleWorkstation::getRoleId, roleId));
+        if (!list.isEmpty()) {
+            List<Long> workstationIdList = list.stream().map(SysRoleWorkstation::getWorkstationId).collect(Collectors.toList());
+            // 将List<Long>转换为Long[]
+            Long[] size = new Long[workstationIdList.size()];
+            Long[] workstationIds = workstationIdList.toArray(size);
+            sysRole.setWorkstationIds(workstationIds);
+        }
+        return sysRole;
     }
 
     /**
@@ -144,12 +149,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 结果
      */
     @Override
-    public String checkRoleNameUnique(SysRole role)
-    {
+    public String checkRoleNameUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
-        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
-        {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -162,12 +165,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 结果
      */
     @Override
-    public String checkRoleKeyUnique(SysRole role)
-    {
+    public String checkRoleKeyUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
-        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
-        {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -179,10 +180,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @param role 角色信息
      */
     @Override
-    public void checkRoleAllowed(SysRole role)
-    {
-        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
-        {
+    public void checkRoleAllowed(SysRole role) {
+        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) {
             throw new ServiceException("不允许操作超级管理员角色");
         }
     }
@@ -193,15 +192,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @param roleId 角色id
      */
     @Override
-    public void checkRoleDataScope(Long roleId)
-    {
-        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
-        {
+    public void checkRoleDataScope(Long roleId) {
+        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
             SysRole role = new SysRole();
             role.setRoleId(roleId);
             List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
-            if (StringUtils.isEmpty(roles))
-            {
+            if (StringUtils.isEmpty(roles)) {
                 throw new ServiceException("没有权限访问角色数据!");
             }
         }
@@ -214,8 +210,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 结果
      */
     @Override
-    public int countUserRoleByRoleId(Long roleId)
-    {
+    public int countUserRoleByRoleId(Long roleId) {
         return userRoleMapper.countUserRoleByRoleId(roleId);
     }
 
@@ -227,8 +222,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @Transactional
-    public int insertRole(SysRole role)
-    {
+    public int insertRole(SysRole role) {
         // 新增角色信息
         roleMapper.insertRole(role);
         return insertRoleMenu(role);
@@ -242,8 +236,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @Transactional
-    public int updateRole(SysRole role)
-    {
+    public int updateRole(SysRole role) {
         // 修改角色信息
         roleMapper.updateRole(role);
         // 删除角色与菜单关联
@@ -258,8 +251,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 结果
      */
     @Override
-    public int updateRoleStatus(SysRole role)
-    {
+    public int updateRoleStatus(SysRole role) {
         return roleMapper.updateRole(role);
     }
 
@@ -271,14 +263,18 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @Transactional
-    public int authDataScope(SysRole role)
-    {
+    public int authDataScope(SysRole role) {
         // 修改角色信息
         roleMapper.updateRole(role);
         // 删除角色与部门关联
         roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
         // 新增角色和部门信息(数据权限)
-        return insertRoleDept(role);
+        insertRoleDept(role);
+        // 删除角色和岗位关联
+        iSysRoleWorkstationService.remove(Wrappers.<SysRoleWorkstation>lambdaQuery().eq(SysRoleWorkstation::getRoleId, role.getRoleId()));
+        // 新增角色和岗位信息(mars数据权限)
+        iSysRoleWorkstationService.insertRoleWorkstation(role);
+        return 1;
     }
 
     /**
@@ -286,20 +282,17 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      *
      * @param role 角色对象
      */
-    public int insertRoleMenu(SysRole role)
-    {
+    public int insertRoleMenu(SysRole role) {
         int rows = 1;
         // 新增用户与角色管理
         List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
-        for (Long menuId : role.getMenuIds())
-        {
+        for (Long menuId : role.getMenuIds()) {
             SysRoleMenu rm = new SysRoleMenu();
             rm.setRoleId(role.getRoleId());
             rm.setMenuId(menuId);
             list.add(rm);
         }
-        if (list.size() > 0)
-        {
+        if (list.size() > 0) {
             rows = roleMenuMapper.batchRoleMenu(list);
         }
         return rows;
@@ -310,21 +303,20 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      *
      * @param role 角色对象
      */
-    public int insertRoleDept(SysRole role)
-    {
+    public int insertRoleDept(SysRole role) {
         int rows = 1;
         // 新增角色与部门(数据权限)管理
-        List<SysRoleDept> list = new ArrayList<SysRoleDept>();
-        for (Long deptId : role.getDeptIds())
-        {
-            SysRoleDept rd = new SysRoleDept();
-            rd.setRoleId(role.getRoleId());
-            rd.setDeptId(deptId);
-            list.add(rd);
-        }
-        if (list.size() > 0)
-        {
-            rows = roleDeptMapper.batchRoleDept(list);
+        if (role.getDeptIds() != null) {
+            List<SysRoleDept> list = new ArrayList<SysRoleDept>();
+            for (Long deptId : role.getDeptIds()) {
+                SysRoleDept rd = new SysRoleDept();
+                rd.setRoleId(role.getRoleId());
+                rd.setDeptId(deptId);
+                list.add(rd);
+            }
+            if (!list.isEmpty()) {
+                rows = roleDeptMapper.batchRoleDept(list);
+            }
         }
         return rows;
     }
@@ -337,8 +329,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @Transactional
-    public int deleteRoleById(Long roleId)
-    {
+    public int deleteRoleById(Long roleId) {
         // 删除角色与菜单关联
         roleMenuMapper.deleteRoleMenuByRoleId(roleId);
         // 删除角色与部门关联
@@ -354,15 +345,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      */
     @Override
     @Transactional
-    public int deleteRoleByIds(Long[] roleIds)
-    {
-        for (Long roleId : roleIds)
-        {
+    public int deleteRoleByIds(Long[] roleIds) {
+        for (Long roleId : roleIds) {
             checkRoleAllowed(new SysRole(roleId));
             checkRoleDataScope(roleId);
             SysRole role = selectRoleById(roleId);
-            if (countUserRoleByRoleId(roleId) > 0)
-            {
+            if (countUserRoleByRoleId(roleId) > 0) {
                 throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
             }
         }
@@ -380,38 +368,34 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
      * @return 结果
      */
     @Override
-    public int deleteAuthUser(SysUserRole userRole)
-    {
+    public int deleteAuthUser(SysUserRole userRole) {
         return userRoleMapper.deleteUserRoleInfo(userRole);
     }
 
     /**
      * 批量取消授权用户角色
      *
-     * @param roleId 角色ID
+     * @param roleId  角色ID
      * @param userIds 需要取消授权的用户数据ID
      * @return 结果
      */
     @Override
-    public int deleteAuthUsers(Long roleId, Long[] userIds)
-    {
+    public int deleteAuthUsers(Long roleId, Long[] userIds) {
         return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
     }
 
     /**
      * 批量选择授权用户角色
      *
-     * @param roleId 角色ID
+     * @param roleId  角色ID
      * @param userIds 需要授权的用户数据ID
      * @return 结果
      */
     @Override
-    public int insertAuthUsers(Long roleId, Long[] userIds)
-    {
+    public int insertAuthUsers(Long roleId, Long[] userIds) {
         // 新增用户与角色管理
         List<SysUserRole> list = new ArrayList<SysUserRole>();
-        for (Long userId : userIds)
-        {
+        for (Long userId : userIds) {
             SysUserRole ur = new SysUserRole();
             ur.setUserId(userId);
             ur.setRoleId(roleId);

+ 40 - 0
ktg-system/src/main/java/com/ktg/system/service/impl/SysRoleWorkstationServiceImpl.java

@@ -0,0 +1,40 @@
+package com.ktg.system.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ktg.common.core.domain.entity.SysRole;
+import com.ktg.system.domain.SysRoleWorkstation;
+import com.ktg.system.mapper.SysRoleWorkstationMapper;
+import com.ktg.system.service.ISysRoleWorkstationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 角色和岗位关联Service业务层处理
+ *
+ * @author cgj
+ * @date 2024-12-31
+ */
+@Service
+public class SysRoleWorkstationServiceImpl extends ServiceImpl<SysRoleWorkstationMapper, SysRoleWorkstation> implements ISysRoleWorkstationService {
+
+    @Autowired
+    private SysRoleWorkstationMapper sysRoleWorkstationMapper;
+
+    @Override
+    public Boolean insertRoleWorkstation(SysRole role) {
+        if ("2".equals(role.getMarsDataScope()) && role.getWorkstationIds() != null && role.getWorkstationIds().length > 0) {
+            List<SysRoleWorkstation> sysRoleWorkstations = new ArrayList<>();
+            for (Long workstationId : role.getWorkstationIds()) {
+                SysRoleWorkstation sysRoleWorkstation = new SysRoleWorkstation();
+                sysRoleWorkstation.setRoleId(role.getRoleId());
+                sysRoleWorkstation.setWorkstationId(workstationId);
+                sysRoleWorkstations.add(sysRoleWorkstation);
+            }
+            sysRoleWorkstationMapper.insertBatch(sysRoleWorkstations);
+        }
+        return true;
+    }
+}

+ 26 - 4
ktg-system/src/main/java/com/ktg/system/service/impl/SysUserServiceImpl.java

@@ -25,10 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.validation.Validator;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -608,4 +605,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         }
         return successMsg.toString();
     }
+
+    @Override
+    public List<Long> getUserWorkstationIds(Long userId) {
+        return userMapper.getUserWorkstationIds(userId);
+    }
+
+    @Override
+    public List<Long> getAllChildWorkstationByUserId(Long userId) {
+        // 定义一个list返回值
+        List<Long> longs = new ArrayList<>();
+        // 查询当前人的所属岗位
+        List<Long> userWorkstationIds = userMapper.getUserWorkstationIds(userId);
+        // 查询所有的子岗位
+        if (!userWorkstationIds.isEmpty()) {
+            for (Long userWorkstationId : userWorkstationIds) {
+                List<Long> childWorkstations = userMapper.getChildWorkstations(userWorkstationId);
+                // 返回的值包含自身,如果自身没值则不会进来,所以直接存入返回值就行了
+                longs.addAll(childWorkstations);
+            }
+        }
+        // 使用LinkedHashSet去除重复元素并保持插入顺序
+        Set<Long> set = new LinkedHashSet<>(longs);
+        // 将Set转换回List
+        return new ArrayList<>(set);
+    }
 }

+ 22 - 18
ktg-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -19,17 +19,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="updateBy"           column="update_by"             />
 		<result property="updateTime"         column="update_time"           />
 		<result property="remark"             column="remark"                />
+		<result property="marsDataScope"          column="mars_data_scope"            />
 	</resultMap>
-	
+
 	<sql id="selectRoleVo">
-	    select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
-            r.status, r.del_flag, r.create_time, r.remark 
+	    select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.mars_data_scope, r.menu_check_strictly, r.dept_check_strictly,
+            r.status, r.del_flag, r.create_time, r.remark
         from sys_role r
 	        left join sys_user_role ur on ur.role_id = r.role_id
 	        left join sys_user u on u.user_id = ur.user_id
 	        left join sys_dept d on u.dept_id = d.dept_id
     </sql>
-    
+
     <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		where r.del_flag = '0'
@@ -55,16 +56,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		${params.dataScope}
 		order by r.role_sort
 	</select>
-    
+
 	<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		WHERE r.del_flag = '0' and ur.user_id = #{userId}
 	</select>
-	
+
 	<select id="selectRoleAll" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 	</select>
-	
+
 	<select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
 		select r.role_id
         from sys_role r
@@ -72,27 +73,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	        left join sys_user u on u.user_id = ur.user_id
 	    where u.user_id = #{userId}
 	</select>
-	
+
 	<select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		where r.role_id = #{roleId}
 	</select>
-	
+
 	<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		WHERE r.del_flag = '0' and u.user_name = #{userName}
 	</select>
-	
+
 	<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		 where r.role_name=#{roleName} limit 1
 	</select>
-	
+
 	<select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		 where r.role_key=#{roleKey} limit 1
 	</select>
-	
+
  	<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
  		insert into sys_role(
  			<if test="roleId != null and roleId != 0">role_id,</if>
@@ -100,6 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="roleKey != null and roleKey != ''">role_key,</if>
  			<if test="roleSort != null and roleSort != ''">role_sort,</if>
  			<if test="dataScope != null and dataScope != ''">data_scope,</if>
+			<if test="marsDataScope != null and marsDataScope != ''">mars_data_scope,</if>
  			<if test="menuCheckStrictly != null">menu_check_strictly,</if>
  			<if test="deptCheckStrictly != null">dept_check_strictly,</if>
  			<if test="status != null and status != ''">status,</if>
@@ -112,6 +114,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  			<if test="roleSort != null and roleSort != ''">#{roleSort},</if>
  			<if test="dataScope != null and dataScope != ''">#{dataScope},</if>
+			<if test="marsDataScope != null and marsDataScope != ''">#{marsDataScope},</if>
  			<if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
  			<if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
  			<if test="status != null and status != ''">#{status},</if>
@@ -120,7 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			sysdate()
  		)
 	</insert>
-	
+
 	<update id="updateRole" parameterType="SysRole">
  		update sys_role
  		<set>
@@ -128,6 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  			<if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
  			<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
+			<if test="marsDataScope != null and marsDataScope != ''">mars_data_scope = #{marsDataScope},</if>
  			<if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  			<if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  			<if test="status != null and status != ''">status = #{status},</if>
@@ -137,16 +141,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  		</set>
  		where role_id = #{roleId}
 	</update>
-	
+
 	<delete id="deleteRoleById" parameterType="Long">
 		update sys_role set del_flag = '2' where role_id = #{roleId}
  	</delete>
- 	
+
  	<delete id="deleteRoleByIds" parameterType="Long">
  	    update sys_role set del_flag = '2' where role_id in
  		<foreach collection="array" item="roleId" open="(" separator="," close=")">
  			#{roleId}
-        </foreach> 
+        </foreach>
  	</delete>
- 	
-</mapper> 
+
+</mapper>

+ 7 - 0
ktg-system/src/main/resources/mapper/system/SysRoleWorkstationMapper.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ktg.system.mapper.SysRoleWorkstationMapper">
+
+</mapper>

+ 8 - 1
ktg-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -42,13 +42,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="roleKey"      column="role_key"       />
 		<result property="roleSort"     column="role_sort"      />
 		<result property="dataScope"     column="data_scope"    />
+		<result property="marsDataScope"     column="mars_data_scope"    />
 		<result property="status"       column="role_status"    />
 	</resultMap>
 
 	<sql id="selectUserVo">
         select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
         d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
-        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
+        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.mars_data_scope, r.status as role_status
         from sys_user u
 		    left join sys_dept d on u.dept_id = d.dept_id
 		    left join sys_user_role ur on u.user_id = ur.user_id
@@ -239,5 +240,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<select id="getWorkstationUserIds" resultType="java.lang.Long">
 		select u.user_id from is_user_workstation u where u.workstation_id = #{workstationId}
 	</select>
+	<select id="getUserWorkstationIds" resultType="java.lang.Long">
+		select u.workstation_id from is_user_workstation u where u.user_id = #{userId}
+	</select>
+	<select id="getChildWorkstations" resultType="java.lang.Long">
+		SELECT workstation_id FROM is_workstation WHERE workstation_id = #{userWorkstationId} or find_in_set( #{userWorkstationId} , ancestors )
+	</select>
 
 </mapper>