Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

master
CMM 1 anno fa
parent
commit
5d62469d71
29 ha cambiato i file con 801 aggiunte e 43 eliminazioni
  1. +6
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java
  2. +23
    -19
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java
  3. +22
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java
  4. +81
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java
  5. +24
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java
  6. +97
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java
  7. +19
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java
  8. +32
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java
  9. +31
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java
  10. +27
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java
  11. +38
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java
  12. +25
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java
  13. +41
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java
  14. +40
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java
  15. +54
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java
  16. +51
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java
  17. +37
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java
  18. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java
  19. +11
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java
  20. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java
  21. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java
  22. +6
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java
  23. +34
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml
  24. +4
    -4
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java
  25. +21
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java
  26. +42
    -7
      pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java
  27. +13
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java
  28. +3
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java
  29. +15
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java

+ 6
- 1
pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java Vedi File

@@ -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);
});
// 初始化所有区域数据到缓存


+ 23
- 19
pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java Vedi File

@@ -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,39 @@ public final class TreeUtil {
}
Map<Long, List<MenuRoleVO>> menuGroup = CollUtils.group(treeList, MenuTreeEntity::getPid);
Map<Long, MenuRoleVO> 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<MenuRoleVO> buildUserMenuTree(Map<Long, List<MenuRoleVO>> menuGroup, Map<Long, MenuRoleVO> menuMap, Long parentId) {
private static List<MenuRoleVO> buildUserMenuTree(Map<Long, List<MenuRoleVO>> menuGroup,
Map<Long, MenuRoleVO> menuMap,
Long parentId,
ListIterator<MenuRoleVO> parentIter) {
MenuRoleVO parentMenu = menuMap.get(parentId);
List<MenuRoleVO> currMenus = menuGroup.get(parentId);
if (currMenus == null) {
return Collections.emptyList();
}
List<MenuRoleVO> menus = new ArrayList<>(currMenus);
for (MenuRoleVO curr : currMenus) {
List<MenuRoleVO> menus;
if (!parentId.equals(StrPool.DEF_PARENT_ID)) {
Map<MenuTypeEnum, List<MenuRoleVO>> 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());
} else {
menus = new ArrayList<>(currMenus);
}
ListIterator<MenuRoleVO> 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<MenuRoleVO> childMenus = menuGroup.get(curr.getId());
if (childMenus != null) {
Map<MenuTypeEnum, List<MenuRoleVO>> 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.setTopMenu(parentMenu.getTopMenu());
}
curr.setChildren(buildUserMenuTree(menuGroup, menuMap, curr.getId(), currIter));
}
return menus;
}


+ 22
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java Vedi File

@@ -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;
}

+ 81
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java Vedi File

@@ -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<DataScopeDTO> currentUserDataScoper = getCurrentUserDataScoper();
if (!currentUserDataScoper.isPresent()) {
return;
}
DataScopeDTO dataScopeDto = currentUserDataScoper.get();
LambdaQueryWrapper<DataScopeEntity> 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<DataScopeDTO> getCurrentUserDataScoper() {
UserInfoDetails loginUser = LoginUserUtil.loginUserDetail();
if (Objects.isNull(loginUser) || Objects.isNull(loginUser.getRoleCode())) {
return Optional.empty();
}
return DataScopeContext.getDataScope(loginUser.getRoleCode().name());
}
}

+ 24
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java Vedi File

@@ -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;
}

+ 97
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java Vedi File

@@ -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<DataScopeDto> 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<Long> 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<DataScopeDto> getCurrentUserDataScoper(){
// UserInfoDetails loginUser = LoginUserUtil.loginUserDetail();
// if(Objects.isNull(loginUser) || Objects.isNull(loginUser.getDataScope())){
// return Optional.empty();
// }
// return DataScopeContext.getDataScope(loginUser.getDataScope());
// }
}

+ 19
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java Vedi File

@@ -0,0 +1,19 @@
package com.ningdatech.pmapi.datascope.contants;

/**
* <p>
* DataScopeColumnConst
* </p>
*
* @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";

}

+ 32
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java Vedi File

@@ -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;
}

+ 31
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java Vedi File

@@ -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;

/**
* <p>
* DataScopeDto
* </p>
*
* @author WendyYang
* @since 13:42 2022/11/4
*/
@Data
public class DataScopeDTO {

private RoleEnum role;

private List<Long> regionIds;

private List<String> regionCodes;

private String orgCode;

private String employeeCode;

private Long userId;

}

+ 27
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java Vedi File

@@ -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;
}

+ 38
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java Vedi File

@@ -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;

/**
* <p>
* 数据权限获取
* </p>
*
* @author WendyYang
* @since 2022/1/9 23:28
*/
@RequiredArgsConstructor
public class DataScopeContext {

private static final String WARN_MSG = "请先创建数据权限[%s]的实现类,使其实现 DataScopeProvider";

private static final Map<String, DataScopeProvider> DSP_MAP;

static {
DSP_MAP = SpringUtils.getBeansOfType(DataScopeProvider.class);
}

public static Optional<DataScopeDTO> 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();
}

}

+ 25
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java Vedi File

@@ -0,0 +1,25 @@
package com.ningdatech.pmapi.datascope.provider;


import com.ningdatech.pmapi.datascope.model.DataScopeDTO;

import java.util.Optional;

/**
* <p>
* 数据权限获取接口
* </p>
*
* @author zpf
* @since 2023/3/27 23:28
*/
public interface DataScopeProvider {

/**
* 获取登录人的数据权限
*
* @return 数据权限
**/
Optional<DataScopeDTO> findDataFieldProperty();

}

+ 41
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java Vedi File

@@ -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;

/**
* <p>
* 数据权限 普通用户
* </p>
*
* @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<DataScopeDTO> 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);
}

}

+ 40
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java Vedi File

@@ -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;

/**
* <p>
* 数据权限 单位管理员
* </p>
*
* @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<DataScopeDTO> 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);
}

}

+ 54
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java Vedi File

@@ -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;

/**
* <p>
* 数据权限
* </p>
*
* @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<DataScopeDTO> findDataFieldProperty() {
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
//借由 丽水市的code 来映射市本级的regionCode
Collection<String> 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);
}

}

+ 51
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java Vedi File

@@ -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;

/**
* <p>
* 数据权限
* </p>
*
* @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<DataScopeDTO> findDataFieldProperty() {
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
//所有 丽水市的code
Collection<String> 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);
}

}

+ 37
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java Vedi File

@@ -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;

/**
* <p>
* 数据权限 访客
* </p>
*
* @author ZPF
* @since 2023/3/27 23:29
*/
@Slf4j
@RequiredArgsConstructor
@Component("VISITOR")
public class VisitoyDataScopeProviderImpl implements DataScopeProvider {
private final UserInfoHelper userInfoHelper;

@Override
public Optional<DataScopeDTO> findDataFieldProperty() {
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
DataScopeDTO ds = new DataScopeDTO();
ds.setEmployeeCode(userFullInfo.getEmployeeCode());
ds.setRole(RoleEnum.SUPER_ADMIN);
return Optional.ofNullable(ds);
}

}

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java Vedi File

@@ -58,6 +58,6 @@ public interface IDingOrganizationService extends IService<DingOrganization> {
* @return
*/
Map<String, String> getOrgCodeAndNameMap(List<String> orgCodeList);
Map<String, DingOrganization> getOrgMap(List<String> orgCodeList);

}

+ 11
- 5
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java Vedi File

@@ -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<DingOrganizationMap
return new ArrayList<>();
}
LambdaQueryWrapper<DingOrganization> 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<DingOrganizationMap
.filter(r -> StringUtils.isNotBlank(r.getOrganizationCode()) && StringUtils.isNotBlank(r.getOrganizationName()))
.collect(Collectors.toMap(DingOrganization::getOrganizationCode, DingOrganization::getOrganizationName));
}

@Override
public Map<String, DingOrganization> getOrgMap(List<String> orgCodeList) {
orgCodeList = orgCodeList.stream().distinct().collect(Collectors.toList());
List<DingOrganization> dingOrganizationList = listByCodes(orgCodeList);
return dingOrganizationList.stream()
.filter(r -> StringUtils.isNotBlank(r.getOrganizationCode()) && Objects.nonNull(r))
.collect(Collectors.toMap(DingOrganization::getOrganizationCode, r->r));
}
}

+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java Vedi File

@@ -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;

/**
* 页面路径


+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java Vedi File

@@ -79,7 +79,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> 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, "【地址栏路径】不能为空");
}


+ 6
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java Vedi File

@@ -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);
}

+ 34
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml Vedi File

@@ -23,4 +23,38 @@
GROUP BY hp.id_
) tol
</select>

<select id="getTodoOrIdo" parameterType="java.lang.Long"
resultType="com.ningdatech.pmapi.todocenter.model.po.TodoCenterStatisticsPO">
SELECT
sum(CASE WHEN ht.assignee_ = #{userId} AND ht.end_time_ is NULL THEN 1 end) todoNum,
sum(CASE WHEN ht.assignee_ = #{userId} AND ht.end_time_ IS not NULL THEN 1 end) idoNum
FROM
act_hi_taskinst ht
</select>

<select id="mysubmitNum" parameterType="java.lang.Long"
resultType="com.ningdatech.pmapi.todocenter.model.po.TodoCenterStatisticsPO">
SELECT
sum(CASE WHEN tol.mysubmitNum IS NOT NULL AND tol.mysubmitNum > 0 THEN 1 ELSE 0 end) mysubmitNum
from
(SELECT
count(0) mysubmitNum
FROM
act_hi_procinst hp
LEFT JOIN
act_hi_taskinst ht ON hp.proc_inst_id_ = ht.proc_inst_id_
where start_user_id_ = #{userId}
GROUP BY hp.id_) tol
</select>


<select id="ccNums" parameterType="java.lang.Long"
resultType="com.ningdatech.pmapi.todocenter.model.po.TodoCenterStatisticsPO">
SELECT
count(0) ccmeNum
FROM
wflow_cc_tasks cc
where cc.user_id = #{userId}
</select>
</mapper>

+ 4
- 4
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/po/TodoCenterStatisticsPO.java Vedi File

@@ -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;

}

+ 21
- 1
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java Vedi File

@@ -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
@@ -20,6 +22,24 @@ public class StatisticsServiceImpl implements StatisticsService {

@Override
public TodoCenterStatisticsPO getStatistics(Long userId) {
return mapper.getStatistics(userId);
TodoCenterStatisticsPO res = new TodoCenterStatisticsPO();

TodoCenterStatisticsPO todoOrIdo = mapper.getTodoOrIdo(userId);
if(Objects.nonNull(todoOrIdo)){
res.setTodoNum(todoOrIdo.getTodoNum());
res.setIdoNum(todoOrIdo.getIdoNum());
}

TodoCenterStatisticsPO submit = mapper.mysubmitNum(userId);
if(Objects.nonNull(submit)){
res.setMysubmitNum(submit.getMysubmitNum());
}

TodoCenterStatisticsPO ccMe = mapper.ccNums(userId);
if(Objects.nonNull(ccMe)){
res.setCcmeNum(ccMe.getCcmeNum());
}

return res;
}
}

+ 42
- 7
pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java Vedi File

@@ -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;

/**
* <p>
@@ -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<String> 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;
}
}

+ 13
- 3
pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java Vedi File

@@ -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<ResUserInfoListVO> list(ReqUserInfoListPO reqUserInfoListPO) {
PageVo<ResUserInfoListVO> pageVo = new PageVo<>();

@@ -94,7 +99,7 @@ public class UserInfoManage {
.filter(r -> StringUtils.isNotBlank(r.getOrganizationCode()))
.map(DingEmployeeInfo::getOrganizationCode).distinct()
.collect(Collectors.toList());
Map<String, String> orgCodeAndNameMap = iDingOrganizationService.getOrgCodeAndNameMap(orgCodeList);
Map<String, DingOrganization> orgMap = iDingOrganizationService.getOrgMap(orgCodeList);

Map<String, UserInfo> 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 从用户信息中获取
// 从所属组织中获取


+ 3
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java Vedi File

@@ -35,6 +35,9 @@ public class ResUserInfoListVO {

@ApiModelProperty("所属区域")
private Long regionId;
private Integer regionLevel;
private String regionCode;
private String regionName;

@ApiModelProperty("用户角色")
private List<UserRoleVO> userRoleList;


+ 15
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java Vedi File

@@ -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;
}

}

Loading…
Annulla
Salva