From c9f9bb85ed2e0e68274083a0d2aa7f953db2d4ac Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 27 Mar 2023 13:04:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=80=92=E5=BD=92=E5=A4=84=E7=90=86?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/common/util/TreeUtil.java | 38 ++++++++++++---------- .../pmapi/sys/model/dto/MenuUpdateDTO.java | 3 +- .../pmapi/sys/service/impl/MenuServiceImpl.java | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java index 64436ad..0bd168c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java @@ -10,10 +10,7 @@ import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; import com.ningdatech.pmapi.sys.model.vo.MenuRoleVO; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -125,32 +122,37 @@ public final class TreeUtil { } Map> menuGroup = CollUtils.group(treeList, MenuTreeEntity::getPid); Map menuMap = CollUtils.listToMap(treeList, MenuTreeEntity::getId); - return buildUserMenuTree(menuGroup, menuMap, StrPool.DEF_PARENT_ID); + return buildUserMenuTree(menuGroup, menuMap, StrPool.DEF_PARENT_ID, null); } - private static List buildUserMenuTree(Map> menuGroup, Map menuMap, Long parentId) { + private static List buildUserMenuTree(Map> menuGroup, + Map menuMap, + Long parentId, + ListIterator parentIter) { List currMenus = menuGroup.get(parentId); if (currMenus == null) { return Collections.emptyList(); } - List menus = new ArrayList<>(currMenus); - for (MenuRoleVO curr : currMenus) { + List menus; + if (!parentId.equals(StrPool.DEF_PARENT_ID)) { + Map> group = CollUtils.group(currMenus, MenuRoleVO::getMenuType); + for (MenuRoleVO vo : group.getOrDefault(MenuTypeEnum.BUTTON, Collections.emptyList())) { + parentIter.add(vo); + } + menus = group.getOrDefault(MenuTypeEnum.MENU, Collections.emptyList()); + } else { + menus = new ArrayList<>(currMenus); + } + ListIterator currIter = menus.listIterator(); + while (currIter.hasNext()) { + MenuRoleVO curr = currIter.next(); if (curr.getPid().equals(StrPool.DEF_PARENT_ID)) { curr.setPid(null); curr.setTopMenu(curr.getName()); } else { curr.setTopMenu(menuMap.get(curr.getPid()).getTopMenu()); } - List childMenus = menuGroup.get(curr.getId()); - if (childMenus != null) { - Map> groupByType = CollUtils.group(childMenus, MenuRoleVO::getMenuType); - menus.addAll(groupByType.getOrDefault(MenuTypeEnum.BUTTON, Collections.emptyList())); - curr.setChildren(groupByType.get(MenuTypeEnum.MENU)); - for (MenuRoleVO child : curr.getChildren()) { - child.setTopMenu(curr.getTopMenu()); - child.setChildren(buildUserMenuTree(menuGroup, menuMap, child.getId())); - } - } + curr.setChildren(buildUserMenuTree(menuGroup, menuMap, curr.getId(), currIter)); } return menus; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java index ee76257..49be37e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java @@ -1,5 +1,6 @@ package com.ningdatech.pmapi.sys.model.dto; +import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.*; @@ -48,7 +49,7 @@ public class MenuUpdateDTO implements Serializable { * 类型 */ @ApiModelProperty(value = "类型") - private Integer type; + private MenuTypeEnum menuType; /** * 页面路径 diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java index 33f7709..2894537 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java @@ -79,7 +79,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM @Override @Transactional(rollbackFor = Exception.class) public boolean update(MenuUpdateDTO data, Long userId) { - if (MenuTypeEnum.MENU.getCode().equals(data.getType())) { + if (MenuTypeEnum.MENU.equals(data.getMenuType())) { if (StrUtil.isBlank(data.getPath())) { throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】不能为空"); } From 3bbb61c77c55ea93e16c7fdb4a0766fa4093cd0d Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 27 Mar 2023 15:35:55 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/basic/AbstractRegionCacheHelper.java | 7 +- .../pmapi/datascope/aop/LambdaDataScope.java | 22 +++++ .../pmapi/datascope/aop/LambdaDataScopeAspect.java | 81 ++++++++++++++++++ .../pmapi/datascope/aop/XmlDataScope.java | 24 ++++++ .../pmapi/datascope/aop/XmlDataScopeAspect.java | 97 ++++++++++++++++++++++ .../datascope/contants/DataScopeColumnConst.java | 19 +++++ .../contants/LambdaDataScopeTypeEnum.java | 32 +++++++ .../pmapi/datascope/model/DataScopeDTO.java | 31 +++++++ .../pmapi/datascope/model/DataScopeEntity.java | 27 ++++++ .../pmapi/datascope/provider/DataScopeContext.java | 38 +++++++++ .../datascope/provider/DataScopeProvider.java | 25 ++++++ .../impl/OrdinaryUserDataScopeProviderImpl.java | 41 +++++++++ .../impl/OrgAdminDataScopeProviderImpl.java | 40 +++++++++ .../impl/RegionAdminDataScopeProviderImpl.java | 54 ++++++++++++ .../impl/SuperAdminDataScopeProviderImpl.java | 51 ++++++++++++ .../impl/VisitoyDataScopeProviderImpl.java | 37 +++++++++ .../service/IDingOrganizationService.java | 2 +- .../service/impl/DingOrganizationServiceImpl.java | 16 ++-- .../pmapi/todocenter/mapper/StatisticsMapper.java | 6 ++ .../pmapi/todocenter/mapper/StatisticsMapper.xml | 34 ++++++++ .../service/impl/StatisticsServiceImpl.java | 10 ++- .../pmapi/user/entity/enumeration/RoleEnum.java | 49 +++++++++-- .../pmapi/user/manage/UserInfoManage.java | 16 +++- .../pmapi/user/model/vo/ResUserInfoListVO.java | 3 + .../user/security/auth/model/UserInfoDetails.java | 15 ++++ 25 files changed, 759 insertions(+), 18 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java index 4b0caa5..92f2e63 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java @@ -14,6 +14,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; /** @@ -59,7 +60,11 @@ public abstract class AbstractRegionCacheHelper implements InitializingBean { .maximumSize(512) .build(key -> { Region region = regionService.getOne(key.getRegionCode(), key.getRegionLevel()); - Assert.notNull(region, "区域不存在:%s", key); +// Assert.notNull(region, "区域不存在:%s", key); + if(Objects.isNull(region)){ + //查不到直接返回null + return null; + } return RegionConverter.toRegionDTO(region); }); // 初始化所有区域数据到缓存 diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java new file mode 100644 index 0000000..766c2f0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java @@ -0,0 +1,22 @@ +package com.ningdatech.pmapi.datascope.aop; + +import com.ningdatech.pmapi.datascope.contants.LambdaDataScopeTypeEnum; + +import java.lang.annotation.*; + +/** + * @Classname LambdaDataScope + * @Description + * @Date 2022/11/11 15:34 + * @Created by PoffyZhang + */ + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface LambdaDataScope { + LambdaDataScopeTypeEnum type() default LambdaDataScopeTypeEnum.ORG; + + //wrapper的下标位置 如果是分页的话 可能是第二个 + int wrapperIndex() default 0; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java new file mode 100644 index 0000000..4079892 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java @@ -0,0 +1,81 @@ +package com.ningdatech.pmapi.datascope.aop; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.model.DataScopeEntity; +import com.ningdatech.pmapi.datascope.provider.DataScopeContext; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.util.Objects; +import java.util.Optional; + +/** + * @program: + * @description: 数据权限切面 + * LambdaDataScopeAspect + * @author: PoffyZhang + * @created: 2023/3/11 09:12 + */ +@Aspect +@Component +@Slf4j +@AllArgsConstructor +@Order(10) +public class LambdaDataScopeAspect { + + @Pointcut("@annotation(com.ningdatech.pmapi.datascope.aop.LambdaDataScope)") + public void lambdaDataScopeAspect() { + + } + + @Before("lambdaDataScopeAspect() && @annotation(lambdaDataScope)") + public void before(JoinPoint joinPoint, LambdaDataScope lambdaDataScope) throws Throwable { + Optional currentUserDataScoper = getCurrentUserDataScoper(); + if (!currentUserDataScoper.isPresent()) { + return; + } + DataScopeDTO dataScopeDto = currentUserDataScoper.get(); + LambdaQueryWrapper wrapper = + (LambdaQueryWrapper) joinPoint.getArgs()[lambdaDataScope.wrapperIndex()]; + + if (Objects.isNull(wrapper)) { + return; + } + + switch (lambdaDataScope.type()) { + case REGION: + wrapper.in(CollUtil.isNotEmpty(dataScopeDto.getRegionCodes()), DataScopeEntity::getRegionCode, dataScopeDto.getRegionCodes()); + break; + case ORG: + wrapper.in(StringUtils.isNotBlank(dataScopeDto.getOrgCode()), DataScopeEntity::getOrgCode, dataScopeDto.getOrgCode()); + break; + case EMPLOYEE: + wrapper.in(StringUtils.isNotBlank(dataScopeDto.getEmployeeCode()), DataScopeEntity::getEmployeeCode, dataScopeDto.getEmployeeCode()); + break; + case NONE: + break; + default: + break; + } + + } + + public Optional getCurrentUserDataScoper() { + UserInfoDetails loginUser = LoginUserUtil.loginUserDetail(); + if (Objects.isNull(loginUser) || Objects.isNull(loginUser.getRoleCode())) { + return Optional.empty(); + } + return DataScopeContext.getDataScope(loginUser.getRoleCode().name()); + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java new file mode 100644 index 0000000..5c84e89 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java @@ -0,0 +1,24 @@ +package com.ningdatech.pmapi.datascope.aop; + +import java.lang.annotation.*; + +/** + * @Classname XmlDataScope + * xml 可以join 所以要设置 别名 + * @Description + * @Date 2022/11/11 15:34 + * @Created by PoffyZhang + */ + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface XmlDataScope { + + String regionAlias() default "r"; + + String orgAlias() default "o"; + + //实体的位置 默认0 如果有分页 那么可能是第二个 + int entityIndex() default 0; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java new file mode 100644 index 0000000..a62efe0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java @@ -0,0 +1,97 @@ +package com.ningdatech.pmapi.datascope.aop; + +import cn.hutool.core.collection.CollUtil; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +; + +/** + * @program: + * @description: xml sql方式 + * 数据权限切面 + * @author: PoffyZhang + * @created: 2022/11/11 09:12 + */ +@Aspect +@Component +@Slf4j +@AllArgsConstructor +@Order(10) +public class XmlDataScopeAspect { + +// @Pointcut("@annotation(com.ningdatech.carapi.datascope.aop.XmlDataScope)") +// public void xmlDataScopeAspect() { +// +// } +// +// @Before("xmlDataScopeAspect() && @annotation(xmlDataScope)") +// public void before(JoinPoint joinPoint, XmlDataScope xmlDataScope) throws Throwable { +// Optional currentUserDataScoper = getCurrentUserDataScoper(); +// if(!currentUserDataScoper.isPresent()){ +// return; +// } +// DataScopeDto dataScopeDto = currentUserDataScoper.get(); +// Object entity = joinPoint.getArgs()[xmlDataScope.entityIndex()]; +// +// if(Objects.isNull(entity)){ +// return; +// } +// +// StringBuilder sql = new StringBuilder(); +// if(CollUtil.isEmpty(dataScopeDto.getCompanyIds()) +// && CollUtil.isEmpty(dataScopeDto.getRegionIds())){ +// return; +// } +// +// if(CollUtil.isNotEmpty(dataScopeDto.getCompanyIds())){ +// sql.append(" AND " + xmlDataScope.companyAlias() + ".id in (" +// + convertForStr(dataScopeDto.getCompanyIds()) + ")"); +// } +// +// +// if(CollUtil.isNotEmpty(dataScopeDto.getRegionIds())){ +// sql.append(" AND " + xmlDataScope.regionAlias() + ".id in (" +// + convertForStr(dataScopeDto.getRegionIds()) + ")"); +// } +// +// if(sql.length() > 0){ +// Class clazz = entity.getClass(); +// Field dataScopeSql = clazz.getDeclaredField("dataScopeSql"); +// dataScopeSql.setAccessible(true); +// dataScopeSql.set(entity, sql.toString()); +// } +// } +// +// private String convertForStr(List companyIds) { +// if(CollUtil.isEmpty(companyIds)){ +// return StringUtils.EMPTY; +// } +// StringBuilder sql = new StringBuilder(); +// for(Long companyId : companyIds){ +// sql.append(companyId + ","); +// } +// sql.delete(sql.length()-1,sql.length()); +// return sql.toString(); +// } +// +// public Optional getCurrentUserDataScoper(){ +// UserInfoDetails loginUser = LoginUserUtil.loginUserDetail(); +// if(Objects.isNull(loginUser) || Objects.isNull(loginUser.getDataScope())){ +// return Optional.empty(); +// } +// return DataScopeContext.getDataScope(loginUser.getDataScope()); +// } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java new file mode 100644 index 0000000..edb745d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java @@ -0,0 +1,19 @@ +package com.ningdatech.pmapi.datascope.contants; + +/** + *

+ * DataScopeColumnConst + *

+ * + * @author WendyYang + * @since 16:24 2022/11/3 + */ +public interface DataScopeColumnConst { + + String REGION_ID = "region_id"; + + String REGION_CODE = "region_code"; + + String ORG_CODE = "org_code"; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java new file mode 100644 index 0000000..526e8a4 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java @@ -0,0 +1,32 @@ +package com.ningdatech.pmapi.datascope.contants; + +import io.swagger.annotations.ApiModel; + +/** + * @Classname DataScopeTypeEnum + * @Description + * @Date 2022/11/18 11:15 + * @Created by PoffyZhang + */ +@ApiModel(value = "DataScopeTypeEnum", description = "数据范围类型-枚举") +public enum LambdaDataScopeTypeEnum { + /** + * 地区 + */ + REGION, + + /** + * 公司 + */ + ORG, + + /** + * 员工 + */ + EMPLOYEE, + + /** + * 都没有 + */ + NONE; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java new file mode 100644 index 0000000..2c16506 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java @@ -0,0 +1,31 @@ +package com.ningdatech.pmapi.datascope.model; + +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import lombok.Data; + +import java.util.List; + +/** + *

+ * DataScopeDto + *

+ * + * @author WendyYang + * @since 13:42 2022/11/4 + */ +@Data +public class DataScopeDTO { + + private RoleEnum role; + + private List regionIds; + + private List regionCodes; + + private String orgCode; + + private String employeeCode; + + private Long userId; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java new file mode 100644 index 0000000..d7a6c0f --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java @@ -0,0 +1,27 @@ +package com.ningdatech.pmapi.datascope.model; + +import lombok.Data; + +/** + * @Classname DataScopEntity + * @Description + * @Date 2022/11/11 16:25 + * @Created by PoffyZhang + */ +@Data +public class DataScopeEntity { + + protected Long id; + + protected Long regionId; + + protected String regionCode; + + protected Long orgCode; + + protected Long userId; + + protected String employeeCode; + + protected String dataScopeSql; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java new file mode 100644 index 0000000..7d55cae --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java @@ -0,0 +1,38 @@ +package com.ningdatech.pmapi.datascope.provider; + +import com.ningdatech.basic.util.SpringUtils; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.Optional; + +/** + *

+ * 数据权限获取 + *

+ * + * @author WendyYang + * @since 2022/1/9 23:28 + */ +@RequiredArgsConstructor +public class DataScopeContext { + + private static final String WARN_MSG = "请先创建数据权限[%s]的实现类,使其实现 DataScopeProvider"; + + private static final Map DSP_MAP; + + static { + DSP_MAP = SpringUtils.getBeansOfType(DataScopeProvider.class); + } + + public static Optional getDataScope(String roleCode) { + String key = roleCode; + DataScopeProvider dataScopeProvider = DSP_MAP.get(key); + if (dataScopeProvider == null) { + throw new IllegalArgumentException(String.format(WARN_MSG, key)); + } + return dataScopeProvider.findDataFieldProperty(); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java new file mode 100644 index 0000000..def8e0e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java @@ -0,0 +1,25 @@ +package com.ningdatech.pmapi.datascope.provider; + + +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; + +import java.util.Optional; + +/** + *

+ * 数据权限获取接口 + *

+ * + * @author zpf + * @since 2023/3/27 23:28 + */ +public interface DataScopeProvider { + + /** + * 获取登录人的数据权限 + * + * @return 数据权限 + **/ + Optional findDataFieldProperty(); + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java new file mode 100644 index 0000000..055f7d8 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java @@ -0,0 +1,41 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import com.google.common.collect.Lists; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import java.util.Optional; + +/** + *

+ * 数据权限 普通用户 + *

+ * + * @author ZPF + * @since 2023/3/27 23:29 + */ +@Slf4j +@RequiredArgsConstructor +@Component("ORDINARY_USER") +public class OrdinaryUserDataScopeProviderImpl implements DataScopeProvider { + + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + DataScopeDTO ds = new DataScopeDTO(); + ds.setEmployeeCode(userFullInfo.getOrganizationCode()); + ds.setRegionCodes(Lists.newArrayList(userFullInfo.getRegionCode())); + ds.setUserId(userFullInfo.getUserId()); + ds.setRole(RoleEnum.ORDINARY_USER); + return Optional.ofNullable(ds); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java new file mode 100644 index 0000000..a903b60 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java @@ -0,0 +1,40 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import java.util.Optional; + +/** + *

+ * 数据权限 单位管理员 + *

+ * + * @author ZPF + * @since 2023/3/27 23:29 + */ +@Slf4j +@RequiredArgsConstructor +@Component("ORG_ADMIN") +public class OrgAdminDataScopeProviderImpl implements DataScopeProvider { + + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + DataScopeDTO ds = new DataScopeDTO(); + ds.setOrgCode(userFullInfo.getOrganizationCode()); + ds.setUserId(userFullInfo.getUserId()); + ds.setEmployeeCode(userFullInfo.getEmployeeCode()); + ds.setRole(RoleEnum.ORG_ADMIN); + return Optional.ofNullable(ds); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java new file mode 100644 index 0000000..d4b06cc --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java @@ -0,0 +1,54 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import cn.hutool.core.collection.CollUtil; +import com.ningdatech.pmapi.common.constant.RegionConst; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + *

+ * 数据权限 + *

+ * + * @author ZPF + * @since 2023/3/27 23:29 + */ +@Slf4j +@RequiredArgsConstructor +@Component("REGION_ADMIN") +public class RegionAdminDataScopeProviderImpl implements DataScopeProvider { + + private final RegionCacheHelper regionCacheHelper; + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + //借由 丽水市的code 来映射市本级的regionCode + Collection regionCodes = regionCacheHelper.listChildRegionCodeList(userFullInfo.getRegionCode(), + RegionConst.RL_CITY); + //如果不是市本级的话 就直接放入本区域的县就好了 + if(CollUtil.isEmpty(regionCodes)){ + regionCodes.add(userFullInfo.getRegionCode()); + } + + DataScopeDTO ds = new DataScopeDTO(); + ds.setRegionCodes(regionCodes.stream().collect(Collectors.toList())); + ds.setUserId(userFullInfo.getUserId()); + ds.setEmployeeCode(userFullInfo.getEmployeeCode()); + ds.setRole(RoleEnum.REGION_ADMIN); + return Optional.ofNullable(ds); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java new file mode 100644 index 0000000..3bd3efc --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java @@ -0,0 +1,51 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import com.ningdatech.pmapi.common.constant.RegionConst; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + *

+ * 数据权限 + *

+ * + * @author ZPF + * @since 2023/3/27 23:29 + */ +@Slf4j +@RequiredArgsConstructor +@Component("SUPER_ADMIN") +public class SuperAdminDataScopeProviderImpl implements DataScopeProvider { + + private final RegionCacheHelper regionCacheHelper; + + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + //所有 丽水市的code + Collection regionCodes = regionCacheHelper.listChildRegionCodeList(RegionConst.RC_LS, + RegionConst.RL_CITY); + + DataScopeDTO ds = new DataScopeDTO(); + ds.setRegionCodes(regionCodes.stream().collect(Collectors.toList())); + ds.setUserId(userFullInfo.getUserId()); + ds.setEmployeeCode(userFullInfo.getEmployeeCode()); + ds.setRole(RoleEnum.SUPER_ADMIN); + return Optional.ofNullable(ds); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java new file mode 100644 index 0000000..04202b2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java @@ -0,0 +1,37 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import java.util.Optional; + +/** + *

+ * 数据权限 访客 + *

+ * + * @author ZPF + * @since 2023/3/27 23:29 + */ +@Slf4j +@RequiredArgsConstructor +@Component("VISITOR") +public class VisitoyDataScopeProviderImpl implements DataScopeProvider { + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); + DataScopeDTO ds = new DataScopeDTO(); + ds.setEmployeeCode(userFullInfo.getEmployeeCode()); + ds.setRole(RoleEnum.SUPER_ADMIN); + return Optional.ofNullable(ds); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java index b445093..f84c074 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java @@ -58,6 +58,6 @@ public interface IDingOrganizationService extends IService { * @return */ Map getOrgCodeAndNameMap(List orgCodeList); - + Map getOrgMap(List orgCodeList); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java index a0b9459..53bf625 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java @@ -11,10 +11,7 @@ import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -53,7 +50,7 @@ public class DingOrganizationServiceImpl extends ServiceImpl(); } LambdaQueryWrapper query = Wrappers.lambdaQuery(DingOrganization.class) - .eq(DingOrganization::getOrganizationCode, codes); + .in(DingOrganization::getOrganizationCode, codes); return list(query); } @@ -73,4 +70,13 @@ public class DingOrganizationServiceImpl extends ServiceImpl StringUtils.isNotBlank(r.getOrganizationCode()) && StringUtils.isNotBlank(r.getOrganizationName())) .collect(Collectors.toMap(DingOrganization::getOrganizationCode, DingOrganization::getOrganizationName)); } + + @Override + public Map getOrgMap(List orgCodeList) { + orgCodeList = orgCodeList.stream().distinct().collect(Collectors.toList()); + List dingOrganizationList = listByCodes(orgCodeList); + return dingOrganizationList.stream() + .filter(r -> StringUtils.isNotBlank(r.getOrganizationCode()) && Objects.nonNull(r)) + .collect(Collectors.toMap(DingOrganization::getOrganizationCode, r->r)); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java index 0336c63..fe78d59 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java @@ -8,4 +8,10 @@ public interface StatisticsMapper extends BaseMapper { TodoCenterStatisticsPO getStatistics(@Param("userId") Long userId); + + TodoCenterStatisticsPO getTodoOrIdo(@Param("userId") Long userId); + + TodoCenterStatisticsPO mysubmitNum(@Param("userId") Long userId); + + TodoCenterStatisticsPO ccNums(@Param("userId") Long userId); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml index e22baae..f8033c3 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml @@ -23,4 +23,38 @@ GROUP BY hp.id_ ) tol + + + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java index 3c77943..832f192 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java @@ -20,6 +20,14 @@ public class StatisticsServiceImpl implements StatisticsService { @Override public TodoCenterStatisticsPO getStatistics(Long userId) { - return mapper.getStatistics(userId); + TodoCenterStatisticsPO res = new TodoCenterStatisticsPO(); + TodoCenterStatisticsPO todoOrIdo = mapper.getTodoOrIdo(userId); + res.setTodoNum(todoOrIdo.getTodoNum()); + res.setIdoNum(todoOrIdo.getIdoNum()); + TodoCenterStatisticsPO submit = mapper.mysubmitNum(userId); + res.setMysubmitNum(submit.getMysubmitNum()); + TodoCenterStatisticsPO ccMe = mapper.ccNums(userId); + res.setCcmeNum(ccMe.getCcmeNum()); + return res; } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java index 00353a4..54737c2 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java @@ -1,6 +1,10 @@ package com.ningdatech.pmapi.user.entity.enumeration; import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Objects; /** *

@@ -16,26 +20,57 @@ public enum RoleEnum { /** * 系统角色枚举 */ - ORDINARY_USER("普通用户"), + ORDINARY_USER("普通用户",6), + + EXPERT("专家",5), - EXPERT("专家"), + ORG_ADMIN("单位管理员",4), - ORG_ADMIN("单位管理员"), + EXPERT_ADMIN("专家管理员",2), - EXPERT_ADMIN("专家管理员"), + REGION_ADMIN("区域管理员",3), - REGION_ADMIN("区域管理员"), + SUPER_ADMIN("超级管理员",1), - SUPER_ADMIN("超级管理员"); + VISITOR("访客",7); private final String desc; - RoleEnum(String desc) { + /** + * 角色优先级 + */ + private final Integer level; + + RoleEnum(String desc,Integer level) { this.desc = desc; + this.level = level; } public boolean eq(String name) { return this.name().equals(name); } + public static RoleEnum mathByName(String name){ + if(StringUtils.isBlank(name)){ + return null; + } + for(RoleEnum roleEnum : RoleEnum.values()){ + if(roleEnum.name().equals(name)){ + return roleEnum; + } + } + return null; + } + + public static RoleEnum checkHigherRole(List roleCodes){ + RoleEnum res = null; + for(String roleCode : roleCodes){ + RoleEnum roleEnum = mathByName(roleCode); + if(Objects.isNull(res) || + (Objects.nonNull(roleEnum) && roleEnum.getLevel() < res.getLevel())){ + res = roleEnum; + } + } + return res; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index e2d42cf..335f33a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -7,11 +7,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.model.PageVo; +import com.ningdatech.pmapi.common.constant.RegionConst; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.helper.UserInfoHelper; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.pmapi.sys.model.dto.RegionDTO; import com.ningdatech.pmapi.sys.model.entity.Role; import com.ningdatech.pmapi.sys.model.entity.UserRole; import com.ningdatech.pmapi.sys.service.IRoleService; @@ -52,6 +55,8 @@ public class UserInfoManage { private final IRoleService iRoleService; private final UserInfoHelper userInfoHelper; + private final RegionCacheHelper regionCacheHelper; + public PageVo list(ReqUserInfoListPO reqUserInfoListPO) { PageVo pageVo = new PageVo<>(); @@ -94,7 +99,7 @@ public class UserInfoManage { .filter(r -> StringUtils.isNotBlank(r.getOrganizationCode())) .map(DingEmployeeInfo::getOrganizationCode).distinct() .collect(Collectors.toList()); - Map orgCodeAndNameMap = iDingOrganizationService.getOrgCodeAndNameMap(orgCodeList); + Map orgMap = iDingOrganizationService.getOrgMap(orgCodeList); Map finalEmployeeCodeAvailableMap = employeeCodeAvailableMap; resUserInfoListVOList = records.stream() @@ -102,9 +107,14 @@ public class UserInfoManage { ResUserInfoListVO resListVO = new ResUserInfoListVO(); resListVO.setName(r.getEmployeeName()); String organizationCode = r.getOrganizationCode(); - if (StringUtils.isNotBlank(organizationCode)) { - resListVO.setOrgName(orgCodeAndNameMap.get(organizationCode)); + if (StringUtils.isNotBlank(organizationCode) && orgMap.containsKey(organizationCode)) { + resListVO.setOrgName(orgMap.get(organizationCode).getOrganizationName()); resListVO.setOrgCode(organizationCode); + String regionCode = orgMap.get(organizationCode).getDivisionCode(); + resListVO.setRegionCode(regionCode); + if(Objects.nonNull(regionCode)){ + resListVO.setRegionName(regionCacheHelper.getDisplayName(regionCode,RegionConst.RL_COUNTY)); + } } // TODO 从用户信息中获取 // 从所属组织中获取 diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java index f552f0a..9bf6341 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java @@ -35,6 +35,9 @@ public class ResUserInfoListVO { @ApiModelProperty("所属区域") private Long regionId; + private Integer regionLevel; + private String regionCode; + private String regionName; @ApiModelProperty("用户角色") private List userRoleList; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java index 2dcabca..9b8527b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java @@ -1,8 +1,10 @@ package com.ningdatech.pmapi.user.security.auth.model; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import com.ningdatech.basic.auth.AbstractLoginUser; import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.security.core.GrantedAuthority; @@ -12,6 +14,7 @@ import org.springframework.security.core.userdetails.UserDetails; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; /** * @author LiuXinXin @@ -98,4 +101,16 @@ public class UserInfoDetails extends AbstractLoginUser implements UserDetails { return true; } + /** + * 取最高的权限 + * @return + */ + public RoleEnum getRoleCode(){ + if(CollUtil.isNotEmpty(this.userRoleList)){ + return RoleEnum.checkHigherRole(this.userRoleList.stream() + .map(Role::getCode).collect(Collectors.toList())); + } + return null; + } + } From 163e563e265bca17af68cf568c589d993b9edf4f Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 27 Mar 2023 15:37:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=9A=84topMenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java index 0bd168c..01eb535 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java @@ -129,6 +129,7 @@ public final class TreeUtil { Map menuMap, Long parentId, ListIterator parentIter) { + MenuRoleVO parentMenu = menuMap.get(parentId); List currMenus = menuGroup.get(parentId); if (currMenus == null) { return Collections.emptyList(); @@ -137,6 +138,7 @@ public final class TreeUtil { if (!parentId.equals(StrPool.DEF_PARENT_ID)) { Map> group = CollUtils.group(currMenus, MenuRoleVO::getMenuType); for (MenuRoleVO vo : group.getOrDefault(MenuTypeEnum.BUTTON, Collections.emptyList())) { + vo.setTopMenu(parentMenu.getTopMenu()); parentIter.add(vo); } menus = group.getOrDefault(MenuTypeEnum.MENU, Collections.emptyList()); @@ -150,7 +152,7 @@ public final class TreeUtil { curr.setPid(null); curr.setTopMenu(curr.getName()); } else { - curr.setTopMenu(menuMap.get(curr.getPid()).getTopMenu()); + curr.setTopMenu(parentMenu.getTopMenu()); } curr.setChildren(buildUserMenuTree(menuGroup, menuMap, curr.getId(), currIter)); } From 981ec97b70f3b1749eedfeb331065777cb009e2d Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 27 Mar 2023 15:51:16 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todocenter/model/po/TodoCenterStatisticsPO.java | 8 ++++---- .../service/impl/StatisticsServiceImpl.java | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java index ab9bfdf..682caa6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java @@ -16,12 +16,12 @@ import java.util.List; public class TodoCenterStatisticsPO { @ApiModelProperty("待处理数") - private Integer todoNum; + private Integer todoNum = 0; @ApiModelProperty("已处理数") - private Integer idoNum; + private Integer idoNum = 0; @ApiModelProperty("我发起数") - private Integer mysubmitNum; + private Integer mysubmitNum = 0; @ApiModelProperty("抄送我数") - private Integer ccmeNum; + private Integer ccmeNum = 0; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java index 832f192..0cc04fc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java @@ -6,6 +6,8 @@ import com.ningdatech.pmapi.todocenter.service.StatisticsService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Objects; + /** * @Classname StatisticsService * @Description @@ -21,13 +23,23 @@ public class StatisticsServiceImpl implements StatisticsService { @Override public TodoCenterStatisticsPO getStatistics(Long userId) { TodoCenterStatisticsPO res = new TodoCenterStatisticsPO(); + TodoCenterStatisticsPO todoOrIdo = mapper.getTodoOrIdo(userId); - res.setTodoNum(todoOrIdo.getTodoNum()); - res.setIdoNum(todoOrIdo.getIdoNum()); + if(Objects.nonNull(todoOrIdo)){ + res.setTodoNum(todoOrIdo.getTodoNum()); + res.setIdoNum(todoOrIdo.getIdoNum()); + } + TodoCenterStatisticsPO submit = mapper.mysubmitNum(userId); - res.setMysubmitNum(submit.getMysubmitNum()); + if(Objects.nonNull(submit)){ + res.setMysubmitNum(submit.getMysubmitNum()); + } + TodoCenterStatisticsPO ccMe = mapper.ccNums(userId); - res.setCcmeNum(ccMe.getCcmeNum()); + if(Objects.nonNull(ccMe)){ + res.setCcmeNum(ccMe.getCcmeNum()); + } + return res; } }