Explorar el Código

工作台数据 debug

tags/24080901
PoffyZhang hace 1 año
padre
commit
3bbb61c77c
Se han modificado 25 ficheros con 759 adiciones y 18 borrados
  1. +6
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java
  2. +22
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java
  3. +81
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScopeAspect.java
  4. +24
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScope.java
  5. +97
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/XmlDataScopeAspect.java
  6. +19
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/DataScopeColumnConst.java
  7. +32
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/contants/LambdaDataScopeTypeEnum.java
  8. +31
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeDTO.java
  9. +27
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/model/DataScopeEntity.java
  10. +38
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeContext.java
  11. +25
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/DataScopeProvider.java
  12. +41
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java
  13. +40
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java
  14. +54
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java
  15. +51
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java
  16. +37
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/VisitoyDataScopeProviderImpl.java
  17. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java
  18. +11
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java
  19. +6
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java
  20. +34
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.xml
  21. +9
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java
  22. +42
    -7
      pmapi/src/main/java/com/ningdatech/pmapi/user/entity/enumeration/RoleEnum.java
  23. +13
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java
  24. +3
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserInfoListVO.java
  25. +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 Ver fichero

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


+ 22
- 0
pmapi/src/main/java/com/ningdatech/pmapi/datascope/aop/LambdaDataScope.java Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

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

+ 6
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/mapper/StatisticsMapper.java Ver fichero

@@ -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 Ver fichero

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

+ 9
- 1
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/service/impl/StatisticsServiceImpl.java Ver fichero

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

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

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

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

}

Cargando…
Cancelar
Guardar