diff --git a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 6bebb97f96..37312c17f6 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -3,6 +3,7 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.GovStaffRoleDTO; import com.epmet.dto.UserDTO; import com.epmet.dto.UserWechatDTO; import com.epmet.dto.form.*; @@ -107,4 +108,11 @@ public interface EpmetUserFeignClient { **/ @PostMapping(value = "epmetuser/staffagencyvisited/saveStaffLoginRecord", consumes = MediaType.APPLICATION_JSON_VALUE) Result saveStaffLoginRecord(StaffLoginAgencyRecordFormDTO staffLoginHistoryFormDTO); + + /** + * 查询工作人员的角色 + * @return + */ + @PostMapping("/epmetuser/staffrole/staffroles") + Result> getRolesOfStaff(StaffRoleFormDTO staffRoleFormDTO); } diff --git a/epmet-auth/src/main/java/com/epmet/feign/GovOrgFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/GovOrgFeignClient.java index 27c596f0de..de717a944e 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/GovOrgFeignClient.java +++ b/epmet-auth/src/main/java/com/epmet/feign/GovOrgFeignClient.java @@ -2,8 +2,10 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.StaffOrgFormDTO; import com.epmet.dto.result.DepartmentListResultDTO; +import com.epmet.dto.result.GridByStaffResultDTO; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.feign.fallback.GovOrgFeignClientFallback; import org.springframework.cloud.openfeign.FeignClient; @@ -37,4 +39,20 @@ public interface GovOrgFeignClient { */ @PostMapping("/gov/org/department/staff/{staffId}/departmentlist") Result> getDepartmentListByStaffId(@PathVariable("staffId") String staffId); + + /** + * 查询工作人员所有的网格 + * @param staffId + * @return + */ + @PostMapping("/gov/org/grid/gridsbystaffid/{staffId}") + Result> listGridsbystaffid(@PathVariable("staffId") String staffId); + + /** + * 根据staffId查询所属的组织机构 + * @param staffId + * @return + */ + @PostMapping("/gov/org/agency/agencybystaff/{staffId}") + Result getAgencyByStaff(@PathVariable("staffId") String staffId); } diff --git a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java index b08fcbca1a..88ed4e42de 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java +++ b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java @@ -4,6 +4,7 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.GovStaffRoleDTO; import com.epmet.dto.UserDTO; import com.epmet.dto.UserWechatDTO; import com.epmet.dto.form.*; @@ -62,4 +63,9 @@ public class EpmetUserFeignClientFallback implements EpmetUserFeignClient { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveStaffLoginRecord", staffLoginHistoryFormDTO); } + @Override + public Result> getRolesOfStaff(StaffRoleFormDTO staffRoleFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getRolesOfStaff", staffRoleFormDTO); + } + } diff --git a/epmet-auth/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallback.java b/epmet-auth/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallback.java index 0e42e2436f..9e5d0d05ee 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallback.java +++ b/epmet-auth/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallback.java @@ -3,8 +3,10 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.StaffOrgFormDTO; import com.epmet.dto.result.DepartmentListResultDTO; +import com.epmet.dto.result.GridByStaffResultDTO; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.feign.GovOrgFeignClient; import org.springframework.stereotype.Component; @@ -28,5 +30,15 @@ public class GovOrgFeignClientFallback implements GovOrgFeignClient { public Result> getDepartmentListByStaffId(String staffId) { return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getDepartmentListByStaffId", staffId); } + + @Override + public Result> listGridsbystaffid(String staffId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "listGridsbystaffid", staffId); + } + + @Override + public Result getAgencyByStaff(String staffId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getAgencyByStaff", staffId); + } } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index 6b5fc2914d..7ad0fae480 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -11,12 +11,11 @@ import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.PhoneValidatorUtils; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.GovStaffRoleDTO; import com.epmet.dto.form.*; -import com.epmet.dto.result.DepartmentListResultDTO; -import com.epmet.dto.result.StaffLatestAgencyResultDTO; -import com.epmet.dto.result.StaffOrgsResultDTO; -import com.epmet.dto.result.UserTokenResultDTO; +import com.epmet.dto.result.*; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.GovOrgFeignClient; import com.epmet.feign.MessageFeignClient; @@ -168,12 +167,59 @@ public class GovLoginServiceImpl implements GovLoginService { govTokenDto.setAgencyId(staffLatestAgency.getAgencyId()); govTokenDto.setCustomerId(staffLatestAgency.getCustomerId()); + //设置部门,网格,角色列表 + govTokenDto.setDeptIdList(getDeptartmentIdList(staffLatestAgency.getStaffId())); + govTokenDto.setGridIdList(getGridIdList(staffLatestAgency.getStaffId())); + CustomerAgencyDTO agency = getAgencyByStaffId(staffLatestAgency.getStaffId()); + if (agency != null) { + govTokenDto.setRoleIdList(queryGovStaffRoleIds(staffLatestAgency.getStaffId(), agency.getId())); + } + govTokenDto.setOrgIdPath(getOrgIdPath(staffLatestAgency.getStaffId())); + + cpUserDetailRedis.set(govTokenDto, expire); + logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); + } + + /** + * 查询人员在某机关单位下的角色列表 + * @param staffId + * @param orgId + * @return + */ + public Set queryGovStaffRoleIds(String staffId, String orgId) { + StaffRoleFormDTO formDTO = new StaffRoleFormDTO(); + formDTO.setStaffId(staffId); + formDTO.setOrgId(orgId); + Result> gridResult = epmetUserFeignClient.getRolesOfStaff(formDTO); + if (!CollectionUtils.isEmpty(gridResult.getData())) { + return gridResult.getData().stream().map(role -> role.getId()).collect(Collectors.toSet()); + } + return null; + } + + /** + * 根据工作人员ID查询网格ID列表 + * @param staffId + * @return + */ + public Set getGridIdList(String staffId) { + Result> result = govOrgFeignClient.listGridsbystaffid(staffId); + if (!result.success()) { + logger.error("登录:查询网格列表,远程调用返回错误:{}", result.getMsg()); + return null; + } else { + List grids = result.getData(); + return grids.stream().map(grid -> grid.getGridId()).collect(Collectors.toSet()); + } + } + + public Set getDeptartmentIdList(String staffId) { try { - Result> deptListResult = govOrgFeignClient.getDepartmentListByStaffId(staffLatestAgency.getStaffId()); + Result> deptListResult = govOrgFeignClient.getDepartmentListByStaffId(staffId); if (deptListResult.success()) { if (!CollectionUtils.isEmpty(deptListResult.getData())) { Set deptIdLists = deptListResult.getData().stream().map(dept -> dept.getDepartmentId()).collect(Collectors.toSet()); - govTokenDto.setDeptIdList(deptIdLists); + return deptIdLists; } } else { logger.error("登录:查询部门列表,远程调用返回错误:{}", deptListResult.getMsg()); @@ -182,9 +228,7 @@ public class GovLoginServiceImpl implements GovLoginService { String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); logger.error("登录:查询部门列表异常:{}", errorStackTrace); } - - cpUserDetailRedis.set(govTokenDto, expire); - logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); + return null; } //保存登录日志 @@ -300,8 +344,50 @@ public class GovLoginServiceImpl implements GovLoginService { govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); govTokenDto.setAgencyId(orgId); govTokenDto.setCustomerId(customerId); + + //设置部门,网格,角色列表 + govTokenDto.setDeptIdList(getDeptartmentIdList(staffId)); + govTokenDto.setGridIdList(getGridIdList(staffId)); + CustomerAgencyDTO agency = getAgencyByStaffId(staffId); + if (agency != null) { + govTokenDto.setRoleIdList(queryGovStaffRoleIds(staffId, agency.getId())); + } + govTokenDto.setOrgIdPath(getOrgIdPath(staffId)); + cpUserDetailRedis.set(govTokenDto, expire); logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); } + + /** + * 查询工作人员的OrgIdPath + * @param staffId + * @return + */ + public String getOrgIdPath(String staffId) { + Result result = govOrgFeignClient.getAgencyByStaff(staffId); + if (!result.success()) { + logger.error("登录:查询登录人所属的机关OrgIdPath失败:{}", result.getMsg()); + return null; + } + CustomerAgencyDTO agency = result.getData(); + if (agency != null) { + if ("0".equals(agency.getPid())) { + // 顶级 + return agency.getId(); + } else { + return agency.getPids().concat(":").concat(agency.getId()); + } + } + return null; + } + + public CustomerAgencyDTO getAgencyByStaffId(String staffId) { + Result result = govOrgFeignClient.getAgencyByStaff(staffId); + if (!result.success()) { + logger.error("登录:查询登录人所属的机关OrgIdPath失败:{}", result.getMsg()); + return null; + } + return result.getData(); + } } diff --git a/epmet-auth/src/test/java/com/epmet/TokenGenTest.java b/epmet-auth/src/test/java/com/epmet/TokenGenTest.java index 60f7654b22..e337632663 100644 --- a/epmet-auth/src/test/java/com/epmet/TokenGenTest.java +++ b/epmet-auth/src/test/java/com/epmet/TokenGenTest.java @@ -1,10 +1,15 @@ package com.epmet; +import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import com.epmet.common.token.constant.LoginConstant; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.dto.CustomerAgencyDTO; +import com.epmet.dto.result.StaffLatestAgencyResultDTO; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; +import com.epmet.service.impl.GovLoginServiceImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +34,9 @@ public class TokenGenTest { @Autowired private CpUserDetailRedis cpUserDetailRedis; + @Autowired + private GovLoginServiceImpl govLoginService; + @Test public void genToken() { String staffId = "wxz"; @@ -50,6 +58,33 @@ public class TokenGenTest { cpUserDetailRedis.set(govTokenDto, expire); } + @Test + public void saveLatestGovTokenDto() { + String staffId = "wxz"; + String token = generateGovWxmpToken(staffId); + int expire = jwtTokenProperties.getExpire(); + GovTokenDto govTokenDto = new GovTokenDto(); + govTokenDto.setApp(LoginConstant.APP_GOV); + govTokenDto.setClient(LoginConstant.CLIENT_WXMP); + govTokenDto.setToken(token); + govTokenDto.setUserId(staffId); + govTokenDto.setUpdateTime(System.currentTimeMillis()); + govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); + //govTokenDto.setAgencyId(staffLatestAgency.getAgencyId()); + //govTokenDto.setCustomerId(staffLatestAgency.getCustomerId()); + + //设置部门,网格,角色列表 + govTokenDto.setDeptIdList(govLoginService.getDeptartmentIdList(staffId)); + govTokenDto.setGridIdList(govLoginService.getGridIdList(staffId)); + CustomerAgencyDTO agency = govLoginService.getAgencyByStaffId(staffId); + if (agency != null) { + govTokenDto.setRoleIdList(govLoginService.queryGovStaffRoleIds(staffId, agency.getId())); + } + govTokenDto.setOrgIdPath(govLoginService.getOrgIdPath(staffId)); + + cpUserDetailRedis.set(govTokenDto, expire); + } + /** * @Description 生成token * @Date 2020/4/18 23:04 diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java index a7c5fc1683..78b2ba49e0 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java @@ -10,9 +10,8 @@ package com.epmet.commons.mybatis.aspect; import com.epmet.commons.mybatis.annotation.DataFilter; import com.epmet.commons.mybatis.constant.AccessSettingConstant; -import com.epmet.commons.mybatis.constant.OpeScopeConstant; +import com.epmet.commons.tools.constant.OpeScopeConstant; import com.epmet.commons.mybatis.dto.form.*; -import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.feign.GovAccessFeignClient; import com.epmet.commons.mybatis.feign.GovOrgFeignClient; import com.epmet.commons.tools.aspect.AccessOpeAspect; @@ -32,6 +31,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.stream.Collectors; /** * 数据过滤,切面处理类 @@ -86,11 +86,11 @@ public class DataFilterAspect { String client = loginUserUtil.getLoginUserClient(); String userId = loginUserUtil.getLoginUserId(); - StaffPermissionFormDTO staffPermissionFormDTO = new StaffPermissionFormDTO(); + StaffPermCacheFormDTO staffPermissionFormDTO = new StaffPermCacheFormDTO(); staffPermissionFormDTO.setApp(app); staffPermissionFormDTO.setClient(client); staffPermissionFormDTO.setStaffId(userId); - Result result = govAccessFeignClient.getStaffCurrPermissions(staffPermissionFormDTO); + Result result = govAccessFeignClient.getLoginUserInfo(staffPermissionFormDTO); if (result.getCode() != 0) { // 查询不到权限,记录日志,抛出8000异常 @@ -98,21 +98,23 @@ public class DataFilterAspect { throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); } - StaffPermCacheResultDTO permCacheResultDTO = result.getData(); + LoginUserInfoResultDTO userDetail = result.getData(); - if (permCacheResultDTO == null || CollectionUtils.isEmpty(permCacheResultDTO.getPermissions())) { - log.error("操作权限不足,查询不到权限"); + if (userDetail == null) { + log.error("操作权限不足,查询不到登录用户信息"); throw new RenException(EpmetErrorCode.REQUIRE_PERMISSION.getCode()); } + Set currPermissions = getPermissions(userDetail.getRoleIdList()); + // 校验操作权限 - validateOpePermission(permCacheResultDTO.getPermissions(), requirePermission); + validateOpePermission(currPermissions, requirePermission); hasConditions.set(false); // 生成过滤sql - String sqlFilterSegment = getSqlFilterSegment(userId, permCacheResultDTO.getRoleIdList(), requirePermission, - permCacheResultDTO.getOrgIdPath(), permCacheResultDTO.getGridId(), tableAlias, permCacheResultDTO.getDeptIdList()); + String sqlFilterSegment = getSqlFilterSegment(userId, userDetail.getRoleIdList(), requirePermission, + userDetail.getOrgIdPath(), userDetail.getDeptIdList(), tableAlias, userDetail.getDeptIdList()); // 方式1.填充到Service方法列表中的DataScope对象中。如果dao入参是用DTO的话,那么再加一个DataScope入参,sql中会报错提示#{}参数找不到,因此改用方法2 //Object[] methodArgs = point.getArgs(); @@ -129,6 +131,22 @@ public class DataFilterAspect { } } + private Set getPermissions(Set roleIdList) { + Set permissions = new HashSet<>(); + roleIdList.forEach(role -> { + // 找出该角色的所有功能操作列表 + Result> result = govAccessFeignClient.listRoleAllOperationScopesByRoleId(role); + if (!result.success()) { + // 获取operation异常 + log.error("调用GovAccess,根据RoleId查询Operation列表失败:{}", result.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + Set roleOperations = result.getData(); + permissions.addAll(roleOperations.stream().map(ope -> ope.getOperationKey()).collect(Collectors.toSet())); + }); + return permissions; + } + /** * 校验操作权限 */ @@ -146,7 +164,7 @@ public class DataFilterAspect { * @return */ private String getSqlFilterSegment(String userId, Set roleIds, String reqiurePermission, String orgIdPath, - String gridId, String tableAlias, Set deptIds) { + Set gridIdList, String tableAlias, Set deptIds) { StringBuilder sb = new StringBuilder(); @@ -164,7 +182,7 @@ public class DataFilterAspect { // 3.生成sql:本网格的 String inGrid = accessSettings.get(AccessSettingConstant.IN_GRID_KEY); if (StringUtils.isNotBlank(inGrid) && AccessSettingConstant.IN_GRID_YES.equals(inGrid)) { - genInGrid(sb, gridId, tableAlias); + genInGrid(sb, gridIdList, tableAlias); } // 4.生成sql:根据部门列表 @@ -218,15 +236,28 @@ public class DataFilterAspect { * 网格sql * * @param sb - * @param gridId * @param tableAlias */ - private void genInGrid(StringBuilder sb, String gridId, String tableAlias) { - if (StringUtils.isBlank(tableAlias)) { - sb.append(hasConditions.get() ? " OR " : "").append(" GRID_ID ='").append(gridId).append("' "); - } else { - sb.append(hasConditions.get() ? " OR " : "").append(tableAlias).append(".GRID_ID ='").append(gridId).append("' "); + private void genInGrid(StringBuilder sb, Set gridIdList, String tableAlias) { + //if (StringUtils.isBlank(tableAlias)) { + // sb.append(hasConditions.get() ? " OR " : "").append(" GRID_ID ='").append(gridId).append("' "); + //} else { + // sb.append(hasConditions.get() ? " OR " : "").append(tableAlias).append(".GRID_ID ='").append(gridId).append("' "); + //} + + if (hasConditions.get()) { + // 之前没有条件 + sb.append(" OR "); } + // OR GRID_ID = 'XXX' OR GRID_ID = 'QQQ' + for (String gridId : gridIdList) { + if (StringUtils.isBlank(tableAlias)) { + sb.append(" GRID_ID = '").append(gridId).append("' OR"); + } else { + sb.append(" ").append(tableAlias).append(".GRID_ID ='").append(gridId).append("' OR "); + } + } + sb.replace(sb.lastIndexOf("OR"), sb.lastIndexOf("OR") + 3, ""); hasConditions.set(true); } @@ -253,19 +284,31 @@ public class DataFilterAspect { public void genOrgScopeSql(StringBuilder sb, String orgIdPath, Set roleIds, String reqiurePermission, String tableAlias) { // 根据角色列表查询操作范围列表 - Set scopeDTOS = new HashSet<>(); + Set opeAndScopes = new HashSet<>(); + //roleIds.forEach(roleId -> { + // OperationScopeFormDTO osformDto = new OperationScopeFormDTO(); + // osformDto.setRoleId(roleId); + // osformDto.setOperationKey(reqiurePermission); + // Result> result = govAccessFeignClient.getOperationScopesByRoleId(osformDto); + // if (result.success()) { + // scopeDTOS.addAll(result.getData()); + // } + //}); + roleIds.forEach(roleId -> { - OperationScopeFormDTO osformDto = new OperationScopeFormDTO(); - osformDto.setRoleId(roleId); - osformDto.setOperationKey(reqiurePermission); - Result> result = govAccessFeignClient.getOperationScopesByRoleId(osformDto); - if (result.success()) { - scopeDTOS.addAll(result.getData()); + Result> opeResult = govAccessFeignClient.listRoleAllOperationScopesByRoleId(roleId); + if (!opeResult.success()) { + log.error("DataFilter:根据角色查询角色所有的操作列表出错:{}", opeResult.getMsg()); + } else { + Set opes = opeResult.getData(); + if (!CollectionUtils.isEmpty(opes)) { + opeAndScopes.addAll(opes); + } } }); // 过滤范围 - HashSet scopes = filteScopes(scopeDTOS); + HashSet scopes = filteScopes(opeAndScopes); if (CollectionUtils.isEmpty(scopes)) { // 没有范围限制 return; @@ -333,10 +376,10 @@ public class DataFilterAspect { * @param scopeDTOS * @return */ - private HashSet filteScopes(Set scopeDTOS) { - HashMap filtedScopes = new HashMap<>(); + private HashSet filteScopes(Set scopeDTOS) { + HashMap filtedScopes = new HashMap<>(); - for (OperationScopeDTO scope : scopeDTOS) { + for (RoleOpeScopeResultDTO scope : scopeDTOS) { String scopeIndex = scope.getScopeIndex(); if (StringUtils.isBlank(scopeIndex)) { continue; @@ -348,7 +391,7 @@ public class DataFilterAspect { continue; } - OperationScopeDTO tempScope = filtedScopes.get(currArr[0]); + RoleOpeScopeResultDTO tempScope = filtedScopes.get(currArr[0]); if (tempScope != null) { // 已经有ac开头的了 String tempScopeIndex = tempScope.getScopeIndex(); @@ -360,8 +403,8 @@ public class DataFilterAspect { } } HashSet scopeStrs = new HashSet<>(); - Set> entries = filtedScopes.entrySet(); - for (Map.Entry entry : entries) { + Set> entries = filtedScopes.entrySet(); + for (Map.Entry entry : entries) { scopeStrs.add(entry.getValue().getScopeKey()); } return scopeStrs; diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/LoginUserInfoResultDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/LoginUserInfoResultDTO.java new file mode 100644 index 0000000000..dc7cf8e657 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/LoginUserInfoResultDTO.java @@ -0,0 +1,40 @@ +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +import java.util.Set; + +@Data +public class LoginUserInfoResultDTO { + + /** + * 权限列表 + */ + private Set permissions; + + /** + * 角色列表 + */ + private Set roleIdList; + + /** + * 部门id列表 + */ + private Set deptIdList; + + /** + * 组织ID + */ + private String orgIdPath; + + /** + * 网格ID + */ + private String gridId; + + /** + * 网格ID列表 + */ + private Set gridIdList; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/RoleOpeScopeResultDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/RoleOpeScopeResultDTO.java new file mode 100644 index 0000000000..f255b6d546 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/RoleOpeScopeResultDTO.java @@ -0,0 +1,33 @@ +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +@Data +public class RoleOpeScopeResultDTO { + + /** + * 角色ID + */ + private String roleId; + + /** + * 操作key + */ + private String operationKey; + + /** + * 范围key + */ + private String scopeKey; + + /** + * 范围名称 + */ + private String scopeName; + + /** + * 范围序号 + */ + private String scopeIndex; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheFormDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheFormDTO.java new file mode 100644 index 0000000000..19bb386e00 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheFormDTO.java @@ -0,0 +1,59 @@ +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.Set; + +@Data +public class StaffPermCacheFormDTO { + + /** + * 更新权限缓存分组 + */ + public interface UpdatePermissionCache {} + + /** + * 查询当前权限列表 + */ + public interface GetStaffCurrPermissions {} + + /** + * 工作人员 id + */ + @NotBlank(message = "工作人员ID不能为空", groups = {UpdatePermissionCache.class, GetStaffCurrPermissions.class}) + private String staffId; + + /** + * 登录头信息app + */ + @NotBlank(message = "登录头信息app不能为空", groups = {UpdatePermissionCache.class, GetStaffCurrPermissions.class}) + private String app; + + /** + * 登录头信息client + */ + @NotBlank(message = "登录头信息client不能为空", groups = {UpdatePermissionCache.class, GetStaffCurrPermissions.class}) + private String client; + + /** + * 组织ID路径 + */ + private String orgIdPath; + + /** + * 权限列表 + */ + private Set permissions; + + /** + * 角色列表 + */ + private Set roleIdList; + + /** + * 当前所在网格id + */ + private String gridId; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java index ec090d7aee..e00dce2b3a 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java @@ -32,4 +32,6 @@ public class StaffPermCacheResultDTO { */ private String gridId; + private String gridIdList; + } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java index 354df4950f..9eb4c00377 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java @@ -25,8 +25,8 @@ public interface GovAccessFeignClient { * 查询用户当前权限列表 * @return */ - @PostMapping("/gov/access/access/getcurrpermissions") - Result getStaffCurrPermissions(StaffPermissionFormDTO dto); + @PostMapping("/gov/access/access/loginuserinfo") + Result getLoginUserInfo(@RequestBody StaffPermCacheFormDTO dto); /** * 查询角色的操作key对应操作范围列表 @@ -43,4 +43,11 @@ public interface GovAccessFeignClient { */ @PostMapping("/gov/access/access/role/{roleId}/accesssettings") Result> listAccessSettings(@PathVariable("roleId") String roleId); + + /** + * 查询角色所有operation及其范围(缓存) + * @return + */ + @PostMapping("/gov/access/access/roleallopesandscopes/{roleId}") + Result> listRoleAllOperationScopesByRoleId(@PathVariable("roleId") String roleId); } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java index ae74de9483..197ddbfc7a 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java @@ -6,8 +6,8 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PathVariable; -import java.util.List; import java.util.Map; import java.util.Set; @@ -21,8 +21,8 @@ import java.util.Set; public class GovAccessFeignClientFallback implements GovAccessFeignClient { @Override - public Result getStaffCurrPermissions(StaffPermissionFormDTO dto) { - return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getStaffCurrPermissions", dto); + public Result getLoginUserInfo(StaffPermCacheFormDTO dto) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getLoginUserInfo", dto); } @Override @@ -34,4 +34,9 @@ public class GovAccessFeignClientFallback implements GovAccessFeignClient { public Result> listAccessSettings(String roleId) { return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "listAccessSettings", roleId); } + + @Override + public Result> listRoleAllOperationScopesByRoleId(@PathVariable("roleId") String roleId){ + return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "listRoleAllOperationScopesByRoleId", roleId); + } } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/OpeScopeConstant.java similarity index 71% rename from epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java rename to epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/OpeScopeConstant.java index 3d415ffb30..9d11c7d3b3 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/OpeScopeConstant.java @@ -1,4 +1,4 @@ -package com.epmet.commons.mybatis.constant; +package com.epmet.commons.tools.constant; public class OpeScopeConstant { //"同级组织的下级" @@ -7,6 +7,7 @@ public class OpeScopeConstant { public static final String ORG_EQUAL_AND_SUB = "org_equal_and_sub"; //"同级组织" public static final String ORG_EQUAL = "org_equal"; + //"本组织的下级" public static final String ORG_CURR_SUB = "org_curr_sub"; //"本组织及下级" @@ -14,4 +15,9 @@ public class OpeScopeConstant { //"本组织" public static final String ORG_CURR = "org_curr"; + //"本组织的上级" + public static final String ORG_CURR_SUP = "org_curr_sup"; + //"本组织及上级" + public static final String ORG_CURR_AND_SUP = "org_curr_and_sup"; + } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 0b6c64d6ef..f4f6be0539 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -218,6 +218,15 @@ public class RedisKeys { return rootPrefix.concat("gov:access:role:opescopes:").concat(roleId).concat(":").concat(opeKey); } + /** + * 角色所有操作权限对应的可操作范围 + * @param roleId 角色ID + * @return + */ + public static String getRoleAllOpeScopesKey(String roleId) { + return rootPrefix.concat("gov:access:role:allopescopes:").concat(roleId); + } + /** * 角色ID对应的权限配置 * @param roleId diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java index de94567fb6..5362a740ca 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java @@ -59,6 +59,11 @@ public class GovTokenDto extends BaseTokenDto implements Serializable { */ private String gridId; + /*** + * 所在网格列表 + */ + private Set gridIdList; + /** * 部门id列表 */ diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java index 19e1111e96..35885d7f8c 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java @@ -48,6 +48,11 @@ public class OperationScopeDTO implements Serializable { */ private String scopeName; + /** + * 范围序号 + */ + private String scopeIndex; + /** * 是否删除,0:未删除,1:已删除 */ diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/LoginUserInfoResultDTO.java similarity index 79% rename from epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java rename to epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/LoginUserInfoResultDTO.java index d19ed3ff27..ee62b2d80e 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/LoginUserInfoResultDTO.java @@ -2,11 +2,10 @@ package com.epmet.dto.result; import lombok.Data; -import javax.validation.constraints.NotBlank; import java.util.Set; @Data -public class StaffPermCacheResultDTO { +public class LoginUserInfoResultDTO { /** * 权限列表 @@ -33,4 +32,9 @@ public class StaffPermCacheResultDTO { */ private String gridId; + /** + * 网格ID列表 + */ + private Set gridIdList; + } diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java index fbafb374e7..db971dcbb2 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java @@ -10,6 +10,11 @@ public class RoleOpeScopeResultDTO { */ private String roleId; + /** + * 操作key + */ + private String operationKey; + /** * 范围key */ diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java index 2f9bdcb567..e017c63cf1 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java @@ -6,9 +6,9 @@ import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.OperationScopeDTO; import com.epmet.dto.form.OperationScopeFormDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.result.LoginUserInfoResultDTO; import com.epmet.dto.result.RoleAccessSettingResultDTO; import com.epmet.dto.result.RoleOpeScopeResultDTO; -import com.epmet.dto.result.StaffPermCacheResultDTO; import com.epmet.entity.OperationScopeEntity; import com.epmet.service.AccessService; import org.springframework.beans.BeanUtils; @@ -53,23 +53,23 @@ public class AccessController { } /** - * 从缓存中查询用户当前权限列表(DataFilterAspect中用到) + * 从缓存中查询用户信息(DataFilterAspect中用到) * @return */ - @PostMapping("getcurrpermissions") - public Result getStaffCurrPermissions(@RequestBody StaffPermCacheFormDTO dto) { + @PostMapping("loginuserinfo") + public Result getLoginUserInfo(@RequestBody StaffPermCacheFormDTO dto) { ValidatorUtils.validateEntity(dto, StaffPermCacheFormDTO.GetStaffCurrPermissions.class); - GovTokenDto govTokenDto = accessService.listStaffCurrPermissions(dto.getApp(), dto.getClient(), dto.getStaffId()); - StaffPermCacheResultDTO resultDTO = null; + GovTokenDto govTokenDto = accessService.getUserDetails(dto.getApp(), dto.getClient(), dto.getStaffId()); + LoginUserInfoResultDTO resultDTO = null; if (govTokenDto != null) { - resultDTO = new StaffPermCacheResultDTO(); - resultDTO.setPermissions(govTokenDto.getPermissions()); + resultDTO = new LoginUserInfoResultDTO(); resultDTO.setRoleIdList(govTokenDto.getRoleIdList()); + //resultDTO.setGridId(govTokenDto.getGridId()); resultDTO.setOrgIdPath(govTokenDto.getOrgIdPath()); - resultDTO.setGridId(govTokenDto.getGridId()); + resultDTO.setGridIdList(govTokenDto.getGridIdList()); resultDTO.setDeptIdList(govTokenDto.getDeptIdList()); } - return new Result().ok(resultDTO); + return new Result().ok(resultDTO); } /** @@ -83,6 +83,16 @@ public class AccessController { return new Result>().ok(scopes); } + /** + * 查询角色所有operation及其范围(缓存) + * @return + */ + @PostMapping("roleallopesandscopes/{roleId}") + public Result> listRoleAllOperationScopesByRoleId(@PathVariable("roleId") String roleId) { + Set scopes = accessService.listAllRoleOperationScopesByRoleId(roleId); + return new Result>().ok(scopes); + } + /** * 查询角色的权限相关配置 * @param roleId diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java index 4ac02b7f91..1a3504ad7e 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java @@ -44,4 +44,14 @@ public interface OperationScopeDao extends BaseDao { */ Set listOperationScopesByRoleId(@Param("roleId") String roleId, @Param("operationKey") String operationKey); + + /** + * 查询角色所有operation及其范围 + * @param roleId + */ + Set listAllRoleOperationScopesByRoleId(String roleId); + + String getDefaultScopeKeyForOperation(@Param("operationKey") String operationKey); + + String getScopeIndexByScopeKey(@Param("scopeKey") String scopeKey); } \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java index cd929c692d..6bcc3ed5ed 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java @@ -29,6 +29,16 @@ public class RoleOpeScopeRedis { redisUtils.set(roleOpeScopesKey, scopes); } + /** + * 缓存角色所有的操作范围 + * @param roleId + * @param scopes + */ + public void setRoleAllOpeScopes(String roleId, Set scopes) { + String roleAllOpeScopesKey = RedisKeys.getRoleAllOpeScopesKey(roleId); + redisUtils.set(roleAllOpeScopesKey, scopes); + } + /** * 查询角色操作范围 * @param roleId @@ -40,4 +50,14 @@ public class RoleOpeScopeRedis { return (Set)redisUtils.get(roleOpeScopesKey); } + /** + * 查询角色所有操作范围 + * @param roleId + * @return + */ + public Set getRoleAllOpeScopes(String roleId) { + String roleOpeScopesKey = RedisKeys.getRoleAllOpeScopesKey(roleId); + return (Set)redisUtils.get(roleOpeScopesKey); + } + } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java index dcda2ebe7e..24fc47532c 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java @@ -21,7 +21,7 @@ public interface AccessService { * 查询用户当前权限列表 * @return */ - GovTokenDto listStaffCurrPermissions(String app, String client, String staffId); + GovTokenDto getUserDetails(String app, String client, String staffId); /** * 查询角色的操作key对应操作范围列表 @@ -37,4 +37,11 @@ public interface AccessService { * @return */ Map listAccessSettings(String roleId); + + /** + * 查询角色所有operation及其范围(缓存) + * @param roleId + * @return + */ + Set listAllRoleOperationScopesByRoleId(String roleId); } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java index 0249885536..19a0cc4616 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -10,6 +10,7 @@ import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.redis.RoleAccessSettingRedis; import com.epmet.redis.RoleOpeScopeRedis; import com.epmet.service.AccessService; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -65,7 +66,7 @@ public class AccessServiceImpl implements AccessService { } @Override - public GovTokenDto listStaffCurrPermissions(String app, String client, String staffId) { + public GovTokenDto getUserDetails(String app, String client, String staffId) { return cpUserDetailRedis.get(app, client, staffId, GovTokenDto.class); } @@ -111,4 +112,30 @@ public class AccessServiceImpl implements AccessService { } return settings; } + + @Override + public Set listAllRoleOperationScopesByRoleId(String roleId) { + Set roleAllOpeScopes = roleOpeScopeRedis.getRoleAllOpeScopes(roleId); + if (roleAllOpeScopes == null) { + roleAllOpeScopes = new HashSet<>(); + Set roleAllOpeScopesResult = operationScopeDao.listAllRoleOperationScopesByRoleId(roleId); + for (RoleOpeScopeResultDTO opeAndScope : roleAllOpeScopesResult) { + if (StringUtils.isBlank(opeAndScope.getScopeKey())) { + // 没有人为配置scope,则使用角色默认配置 + String scopeKey = operationScopeDao.getDefaultScopeKeyForOperation(opeAndScope.getOperationKey()); + if (StringUtils.isNotBlank(scopeKey)) { + String scopeIndex = operationScopeDao.getScopeIndexByScopeKey(scopeKey); + opeAndScope.setScopeKey(scopeKey); + opeAndScope.setScopeIndex(scopeIndex); + roleAllOpeScopes.add(opeAndScope); + // 有默认scope配置的才返回 + } + } else { + roleAllOpeScopes.add(opeAndScope); + } + } + roleOpeScopeRedis.setRoleAllOpeScopes(roleId, roleAllOpeScopes); + } + return roleAllOpeScopes; + } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml index 8b07df685d..032ebac635 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml @@ -27,5 +27,32 @@ and os.DEL_FLAG = '0' + + + + + + + \ No newline at end of file diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java index 8cb514ad3f..5d6b6e81ca 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java @@ -2,7 +2,10 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.OperationScopeDTO; +import com.epmet.dto.form.OperationScopeFormDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.dto.result.RoleOperationResultDTO; import com.epmet.feign.fallback.GovAccessFeignClientFallback; import org.springframework.cloud.openfeign.FeignClient; @@ -11,11 +14,13 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import java.util.List; +import java.util.Set; /** * @Description * @Author sun */ +//url = "localhost:8099" @FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallback.class) public interface GovAccessFeignClient { @@ -34,4 +39,20 @@ public interface GovAccessFeignClient { */ @PostMapping("/gov/access/access/updatepermissioncache") Result updatePermissionCache(@RequestBody StaffPermCacheFormDTO staffPermCacheFormDTO); + + /** + * 查询角色的操作key对应操作范围列表 + * @param operationScopeFormDTO + * @return + */ + @PostMapping("/gov/access/access/operationscopes") + Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO); + + /** + * 查询角色所有operation及其范围(缓存) + * @return + */ + @PostMapping("/gov/access/access/roleallopesandscopes/{roleId}") + Result> listRoleAllOperationScopesByRoleId(@PathVariable("roleId") String roleId); + } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java index 45f0647c4b..f5ba8752e5 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java @@ -56,6 +56,14 @@ public interface GovOrgFeignClient { * @param agencyId * @return */ - @PostMapping("/gov/org/agency/{agencyId}") + @PostMapping("/gov/org/agency/agencybyid/{agencyId}") Result getAgencyById(@PathVariable("agencyId") String agencyId); + + /** + * 根据staffId查询所属的组织机构 + * @param staffId + * @return + */ + @PostMapping("/gov/org/agency/agencybystaff/{staffId}") + Result getAgencyByStaff(@PathVariable("staffId") String staffId); } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallback.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallback.java index 3e9fc8e415..867f6cbf5c 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallback.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovAccessFeignClientFallback.java @@ -3,13 +3,17 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.OperationScopeDTO; +import com.epmet.dto.form.OperationScopeFormDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.dto.result.RoleOperationResultDTO; import com.epmet.feign.GovAccessFeignClient; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; import java.util.List; +import java.util.Set; /** * @Description @@ -32,4 +36,14 @@ public class GovAccessFeignClientFallback implements GovAccessFeignClient { public Result updatePermissionCache(@RequestBody StaffPermCacheFormDTO staffPermCacheFormDTO) { return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "updatePermissionCache"); } + + @Override + public Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getOperationScopesByRoleId", operationScopeFormDTO); + } + + @Override + public Result> listRoleAllOperationScopesByRoleId(String roleId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "listRoleAllOperationScopesByRoleId", roleId); + } } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java index 128f81bd50..c81a8c0451 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java @@ -34,6 +34,11 @@ public class GovOrgFeignClientFallBack implements GovOrgFeignClient { return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getAgencyById", agencyId); } + @Override + public Result getAgencyByStaff(String staffId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getAgencyByStaff", staffId); + } + @Override public Result getLatestCustomer(String userId) { return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getLatestCustomer", userId); diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/AccessService.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/AccessService.java index 9866ea9ffd..ef088f44dc 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/AccessService.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/AccessService.java @@ -1,6 +1,5 @@ package com.epmet.service; -import java.util.List; import java.util.Set; /** @@ -15,4 +14,5 @@ public interface AccessService { * @return */ Set listOpeKeysByStaffId(String app, String client, String staffId, String agencyId, String gridId); + //Set listOpeKeysByStaffIdBak(String app, String client, String staffId, String agencyId, String gridId); } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java index 13340d53e1..1142b84700 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -1,28 +1,26 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.constant.OpeScopeConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; -import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.GovStaffRoleDTO; -import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.OperationScopeDTO; import com.epmet.dto.form.StaffRoleFormDTO; -import com.epmet.dto.result.RoleOperationResultDTO; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.GovAccessFeignClient; import com.epmet.feign.GovOrgFeignClient; import com.epmet.service.AccessService; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; @Service public class AccessServiceImpl implements AccessService { @@ -38,6 +36,10 @@ public class AccessServiceImpl implements AccessService { @Autowired private GovOrgFeignClient govOrgFeignClient; + public static final String ORG_RELATION_SAME = "same"; + public static final String ORG_RELATION_SUB = "sub"; + public static final String ORG_RELATION_SUP = "sup"; + public List queryGovStaffRoles(String staffId, String orgId) { List roleDTOS = new ArrayList<>(); StaffRoleFormDTO formDTO = new StaffRoleFormDTO(); @@ -51,55 +53,222 @@ public class AccessServiceImpl implements AccessService { } @Override - public Set listOpeKeysByStaffId(String app, String client, String staffId, String agencyId, String gridId) { - List roleDTOS = new ArrayList<>(); + public Set listOpeKeysByStaffId(String app, String client, String staffId, String currAgencyId, String currGridId) { + + // 1.拿到所属组织机构信息 + Result agencyByStaffRst = govOrgFeignClient.getAgencyByStaff(staffId); + if (!agencyByStaffRst.success()) { + logger.error("根据StaffId查询所属单位出错,StaffId:{}, 错误信息:{}", staffId, agencyByStaffRst.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + CustomerAgencyDTO belongAgency = agencyByStaffRst.getData(); + if (belongAgency == null) { + logger.error("根据StaffId查询所属单位结果为空,StaffId:{}", staffId); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + + // 2.拿到当前所处机关单位信息 + Result currAgencyRst = govOrgFeignClient.getAgencyById(currAgencyId); + CustomerAgencyDTO currAgencyDto = currAgencyRst.getData(); + if (!currAgencyRst.success() || currAgencyDto == null) { + logger.error("根据当前机构id[{}]查询pids失败:{}", currAgencyId, currAgencyRst.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + + // 拿到该用户所属的组织机构的orgIdPath,拿到当前组织机构的orgIdPath,看当前组织机构的orgIdPath是否在用户所属的组织机构的orgIdPath下 + // 查询机关单位中的角色 - roleDTOS.addAll(queryGovStaffRoles(staffId, agencyId)); - // 查询网格中的角色 - roleDTOS.addAll(queryGovStaffRoles(staffId, gridId)); + List roleDTOS = queryGovStaffRoles(staffId, belongAgency.getId()); // 拼装操作key列表 - Set opeKeys = new HashSet<>(); + //Set opeKeys = new HashSet<>(); // 角色ID列表 - Set roleIds = new HashSet<>(); + //Set roleIds = new HashSet<>(); + + // 当前组织和所属组织的orgId路径,以及他们的上下级关系 + String belongOrgIdPath = getOrgIdPath(belongAgency); + String currOrgIdPath = getOrgIdPath(currAgencyDto); + String currOrgRelation = getCurrOrgRelation(belongOrgIdPath, currOrgIdPath); + + HashSet filtedOps = new HashSet<>(); roleDTOS.forEach(roleDto -> { String roleId = roleDto.getId(); - Result> result = govAccessFeignClient.listOperationsByRoleId(roleId); - if (result.getCode() != 0) { + // 找出该角色的所有功能操作列表 + Result> result = govAccessFeignClient.listRoleAllOperationScopesByRoleId(roleId); + if (!result.success()) { // 获取operation异常 logger.error("调用GovAccess,根据RoleId查询Operation列表失败:{}", result.getMsg()); throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); } - List roleOperations = result.getData(); - // 角色id - roleIds.add(roleDto.getId()); - if (!CollectionUtils.isEmpty(roleOperations)) { - roleOperations.forEach(roleOpe -> { - if (roleOpe != null) { - opeKeys.add(roleOpe.getOperationKey()); + Set roleOperations = result.getData(); + filtedOps.addAll(filterOpesByScope(currOrgRelation, roleOperations)); + }); + return filtedOps; + } + + /** + * 根据上下级关系过滤出要返回的权限列表 + * + * @param currOrgRelation + * @param roleOperations + * @return + */ + private HashSet filterOpesByScope(String currOrgRelation, Set roleOperations) { + HashSet opeKeys = new HashSet<>(); + roleOperations.stream().forEach(opeScope -> { + String scopeKey = opeScope.getScopeKey(); + switch (currOrgRelation) { + case ORG_RELATION_SAME:// 就在所在机构下 + if (OpeScopeConstant.ORG_CURR.equals(scopeKey) + || OpeScopeConstant.ORG_CURR_AND_SUB.equals(scopeKey) + || OpeScopeConstant.ORG_CURR_AND_SUP.equals(scopeKey)) { + opeKeys.add(opeScope.getOperationKey()); + } + break; + case ORG_RELATION_SUB:// 所在机构的子级 + if (OpeScopeConstant.ORG_CURR_SUB.equals(scopeKey) + || OpeScopeConstant.ORG_CURR_AND_SUB.equals(scopeKey)) { + opeKeys.add(opeScope.getOperationKey()); + } + break; + case ORG_RELATION_SUP:// 所在机构的上级 + if (OpeScopeConstant.ORG_CURR_SUP.equals(scopeKey) + || OpeScopeConstant.ORG_CURR_AND_SUP.equals(scopeKey)) { + opeKeys.add(opeScope.getOperationKey()); } - }); + break; } }); + return opeKeys; + } - // 查询该直属机关的orgIdPath - Result agencyById = govOrgFeignClient.getAgencyById(agencyId); - if (!agencyById.success() || agencyById.getData() == null) { - logger.error("根据当前机构id[{}]查询pids失败:{}", agencyId, agencyById.getMsg()); - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + /** + * 获取当前所处机关与所属机关的关系 + */ + private String getCurrOrgRelation(String belongOrgPath, String currAgencyPath) { + if (belongOrgPath.equals(currAgencyPath)) { + // 当前机关即该人员所属机关 + return ORG_RELATION_SAME; + } else if (currAgencyPath.indexOf(belongOrgPath.concat(":")) > -1) { + // 说明当前所在机关是人员所属机关子级,只取出scope为sub的 + return ORG_RELATION_SUB; + } else if (belongOrgPath.indexOf(currAgencyPath.concat(":")) > -1) { + // 说明当前所在机关是人员所属机关的上级 + return ORG_RELATION_SUP; } + return belongOrgPath; + } - // 将最新权限缓存到redis,为了尽量统一操作入口,调用gov-access接口实现 - StaffPermCacheFormDTO staffPermCacheFormDTO = new StaffPermCacheFormDTO(); - staffPermCacheFormDTO.setApp(app); - staffPermCacheFormDTO.setClient(client); - staffPermCacheFormDTO.setStaffId(staffId); - staffPermCacheFormDTO.setPermissions(opeKeys); - staffPermCacheFormDTO.setRoleIdList(roleIds); - staffPermCacheFormDTO.setGridId(gridId); - // 拼接orgIdPath - staffPermCacheFormDTO.setOrgIdPath(String.format("%s:%s", agencyById.getData().getPids(), agencyId)); - govAccessFeignClient.updatePermissionCache(staffPermCacheFormDTO); - return opeKeys; + /** + * 获取组织的orgId路径 + */ + public String getOrgIdPath(CustomerAgencyDTO agency) { + // 拼接单位ID全路径 + if ("0".equals(agency.getPid())) { + // 顶级组织 + return agency.getId(); + } else { + return agency.getPids().concat(":").concat(agency.getId()); + } + } + + //private boolean filterCurrOrgKeysByScope(Set roleIds, String opeKey) { + // for (String roleId : roleIds) { + // Result> result = govAccessFeignClient.listRoleAllOperationScopesByRoleId(roleId); + // if (!result.success()) { + // continue; + // } + // Set scopeDTOS = result.getData(); + // Set scopeKeys = scopeDTOS.stream() + // .filter(scope -> scope.getScopeKey().equals(opeKey)) + // .map(scope -> scope.getScopeKey()) + // .collect(Collectors.toSet()); + // if (scopeKeys.contains(OpeScopeConstant.ORG_CURR) + // || scopeKeys.contains(OpeScopeConstant.ORG_CURR_AND_SUB) + // || scopeKeys.contains(OpeScopeConstant.ORG_CURR_AND_SUP)) { + // return true; + // } + // } + // return false; + //} + + //private boolean filterSubOrgKeysByScope(Set roleIds, String opeKey) { + // for (String roleId : roleIds) { + // OperationScopeFormDTO opeScopeFormDTO = new OperationScopeFormDTO(); + // opeScopeFormDTO.setRoleId(roleId); + // opeScopeFormDTO.setOperationKey(opeKey); + // Result> result = govAccessFeignClient.getOperationScopesByRoleId(opeScopeFormDTO); + // if (!result.success()) { + // continue; + // } + // + // Set scopeDTOS = result.getData(); + // Set scopeKeys = scopeDTOS.stream().map(scope -> scope.getScopeKey()).collect(Collectors.toSet()); + // if (scopeKeys.contains(OpeScopeConstant.ORG_CURR_SUB) + // || scopeKeys.contains(OpeScopeConstant.ORG_CURR_AND_SUB)) { + // return true; + // } + // } + // return false; + //} + + //private boolean filterSupOrgKeysByScope(Set roleIds, String opeKey) { + // for (String roleId : roleIds) { + // OperationScopeFormDTO opeScopeFormDTO = new OperationScopeFormDTO(); + // opeScopeFormDTO.setRoleId(roleId); + // opeScopeFormDTO.setOperationKey(opeKey); + // Result> result = govAccessFeignClient.getOperationScopesByRoleId(opeScopeFormDTO); + // if (!result.success()) { + // continue; + // } + // + // Set scopeDTOS = result.getData(); + // Set scopeKeys = scopeDTOS.stream().map(scope -> scope.getScopeKey()).collect(Collectors.toSet()); + // if (scopeKeys.contains(OpeScopeConstant.ORG_CURR_SUP) + // || scopeKeys.contains(OpeScopeConstant.ORG_CURR_AND_SUP)) { + // return true; + // } + // } + // return false; + //} + + /** + * 过滤有效范围 + * + * @param scopeDTOS + * @return + */ + private HashSet filteScopes(Set scopeDTOS) { + HashMap filtedScopes = new HashMap<>(); + + for (OperationScopeDTO scope : scopeDTOS) { + String scopeIndex = scope.getScopeIndex(); + if (StringUtils.isBlank(scopeIndex)) { + continue; + } + String[] currArr = scopeIndex.split("_"); + if ("0".equals(currArr[1])) { + // 为0,说明没有包含关系,直接放入 + filtedScopes.put(scopeIndex, scope); + continue; + } + + OperationScopeDTO tempScope = filtedScopes.get(currArr[0]); + if (tempScope != null) { + // 已经有ac开头的了 + String tempScopeIndex = tempScope.getScopeIndex(); + if (Integer.valueOf(currArr[1]) < Integer.valueOf(tempScopeIndex.split("_")[1])) { + filtedScopes.put(currArr[0], scope); + } + } else { + filtedScopes.put(currArr[0], scope); + } + } + HashSet scopeStrs = new HashSet<>(); + Set> entries = filtedScopes.entrySet(); + for (Map.Entry entry : entries) { + scopeStrs.add(entry.getValue().getScopeKey()); + } + return scopeStrs; } } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridByStaffResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridByStaffResultDTO.java new file mode 100644 index 0000000000..5c4eab1c1b --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridByStaffResultDTO.java @@ -0,0 +1,11 @@ +package com.epmet.dto.result; + +import lombok.Data; + +@Data +public class GridByStaffResultDTO { + + private String gridId; + private String gridName; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index 6f554aa48c..184dfc1a87 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -126,7 +126,7 @@ public class AgencyController { * @param agencyId * @return */ - @PostMapping("{agencyId}") + @PostMapping("agencybyid/{agencyId}") public Result getAgencyById(@PathVariable("agencyId") String agencyId) { CustomerAgencyEntity agency = agencyService.getAgencyById(agencyId); CustomerAgencyDTO customerAgencyDTO = new CustomerAgencyDTO(); @@ -134,6 +134,22 @@ public class AgencyController { BeanUtils.copyProperties(agency, customerAgencyDTO); return new Result().ok(customerAgencyDTO); } + return new Result<>(); + } + + /** + * 根据staffId查询 + * @param staffId + * @return + */ + @PostMapping("agencybystaff/{staffId}") + public Result getAgencyByStaff(@PathVariable("staffId") String staffId) { + CustomerAgencyEntity agencyEntity = agencyService.getAgencyByStaff(staffId); + CustomerAgencyDTO customerAgencyDTO = new CustomerAgencyDTO(); + if (agencyEntity != null) { + BeanUtils.copyProperties(agencyEntity, customerAgencyDTO); + return new Result().ok(customerAgencyDTO); + } return new Result(); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/GridController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/GridController.java index 553644d00a..c1d0b48b40 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/GridController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/GridController.java @@ -5,18 +5,11 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.*; import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.dto.result.AddGridResultDTO; -import com.epmet.dto.result.CommonStaffInfoResultDTO; -import com.epmet.dto.result.GridBaseInfoResultDTO; -import com.epmet.dto.result.GridDetailResultDTO; -import com.epmet.dto.result.GridListInfoResultDTO; +import com.epmet.dto.result.*; import com.epmet.service.CustomerGridService; import com.epmet.service.CustomerStaffAgencyService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -141,4 +134,15 @@ public class GridController { ValidatorUtils.validateEntity(tokenDto); return customerGridService.removeGridStaff(commonGridStaffInfoFormDTO); } + + /** + * 查询工作人员所有的网格 + * @param staffId + * @return + */ + @PostMapping("gridsbystaffid/{staffId}") + public Result> listGridsbystaffid(@PathVariable("staffId") String staffId) { + List grids = customerGridService.listGridsbystaffid(staffId); + return new Result>().ok(grids); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java index ba4bde9b07..0f438fbdca 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java @@ -77,4 +77,6 @@ public interface CustomerAgencyDao extends BaseDao { * @Description 查询当前组织的所有下级组织列表 **/ List selectFindList(CustomerAgencyDTO customerAgencyDTO); + + CustomerAgencyEntity getAgencyByStaffId(@Param("staffId") String staffId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java index 7e4219012e..fb184b7027 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java @@ -20,20 +20,15 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.form.ListCustomerGridFormDTO; import com.epmet.dto.form.SelectGridNameByGridIdFormDTO; -import com.epmet.dto.result.CustomerGridForStrangerResultDTO; +import com.epmet.dto.result.*; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerGridDTO; import com.epmet.dto.CustomerStaffGridDTO; import com.epmet.dto.UserIdDTO; import com.epmet.dto.form.CustomerGridFormDTO; -import com.epmet.dto.result.SelectGridNameByGridIdResultDTO; import com.epmet.dto.form.DeleteGridFormDTO; import com.epmet.dto.form.ListCustomerGridFormDTO; -import com.epmet.dto.result.AddGridResultDTO; -import com.epmet.dto.result.CustomerGridByUserIdResultDTO; import com.epmet.dto.result.CustomerGridForStrangerResultDTO; -import com.epmet.dto.result.GridDetailResultDTO; -import com.epmet.dto.result.GridBaseInfoResultDTO; import com.epmet.entity.CustomerGridEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -164,4 +159,6 @@ public interface CustomerGridDao extends BaseDao { * @Date 2020.04.23 15:30 **/ List selectGridListByAgencyId(@Param("agencyId")String agencyId,@Param("pageSize")Integer pageSize); + + List listGridsbystaffid(@Param("staffId") String staffId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java index d09e56ba05..0f19dac336 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java @@ -88,4 +88,6 @@ public interface AgencyService { * @return */ CustomerAgencyEntity getAgencyById(String agencyId); + + CustomerAgencyEntity getAgencyByStaff(String staffId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerGridService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerGridService.java index 76459d1de6..477780c4bd 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerGridService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerGridService.java @@ -31,10 +31,8 @@ import com.epmet.dto.form.SelectGridNameByGridIdFormDTO; import com.epmet.dto.result.CustomerGridForStrangerResultDTO; import com.epmet.dto.result.SelectGridNameByGridIdResultDTO; import com.epmet.dto.result.GridInfoResultDTO; -import com.epmet.dto.result.GridInfoResultDTO; import com.epmet.dto.result.*; import com.epmet.entity.CustomerGridEntity; -import org.springframework.web.bind.annotation.RequestBody; import java.util.List; import java.util.Map; @@ -219,4 +217,6 @@ public interface CustomerGridService extends BaseService { * @Description 根据网格id查询所属组织信息、根据网格Id查询网格下所有工作人员列表 **/ Result getAgencyAndStaffsBygridId(String gridId); + + List listGridsbystaffid(String staffId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index ea5cee6df4..72b95f4181 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -244,4 +244,9 @@ public class AgencyServiceImpl implements AgencyService { public CustomerAgencyEntity getAgencyById(String agencyId) { return customerAgencyDao.selectById(agencyId); } + + @Override + public CustomerAgencyEntity getAgencyByStaff(String staffId) { + return customerAgencyDao.getAgencyByStaffId(staffId); + } } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java index 3271e2b6f9..4429146e93 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java @@ -36,7 +36,6 @@ import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.entity.CustomerGridEntity; import com.epmet.feign.EpmetUserFeignClient; -import com.epmet.resi.partymember.dto.warmhearted.form.ResiWarmheartedFormDTO; import com.epmet.service.CustomerAgencyService; import com.epmet.service.CustomerGridService; import com.epmet.service.CustomerStaffGridService; @@ -498,4 +497,9 @@ public class CustomerGridServiceImpl extends BaseServiceImpl listGridsbystaffid(String staffId) { + return baseDao.listGridsbystaffid(staffId); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml index 017ae50451..d709ad78e5 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml @@ -84,4 +84,11 @@ AND ca.pids LIKE concat('%', #{pids}, '%') + + \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml index fc801f289a..dc096e5a73 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml @@ -251,4 +251,13 @@ + + \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java index b943b44be7..8196b45787 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java @@ -45,7 +45,7 @@ public interface StaffRoleDao extends BaseDao { * @param orgId * @return */ - //@DataFilter(tableAliases = { "sr" }) + @DataFilter(tableAliases = { "sr" }) List listStaffIdsByRoleKeyAndOrgId(@Param("roleKey") String roleKey, @Param("orgId") String orgId, @Param("dataScope") DataScope dataScope);