Browse Source

设置登录用户信息线程共享

tags/24080901
WendyYang 8 months ago
parent
commit
c0938c28e5
4 changed files with 88 additions and 6 deletions
  1. +2
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/App.java
  2. +83
    -5
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/DeclaredRecordManage.java
  3. +3
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/model/vo/MhUnitListVO.java
  4. +0
    -1
      hz-pm-api/src/main/resources/application-dev.yml

+ 2
- 0
hz-pm-api/src/main/java/com/hz/pm/api/App.java View File

@@ -11,6 +11,7 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;


/** /**
@@ -28,6 +29,7 @@ public class App {
protected static final String MAPPER_PACKAGES = "com.hz.pm.api.**.mapper"; protected static final String MAPPER_PACKAGES = "com.hz.pm.api.**.mapper";


public static void main(String[] args) { public static void main(String[] args) {
System.setProperty(SecurityContextHolder.SYSTEM_PROPERTY, SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
ApplicationContext context = SpringApplication.run(App.class, args); ApplicationContext context = SpringApplication.run(App.class, args);
// 设置applicationContext // 设置applicationContext
SpringUtils.setApplicationContext(context); SpringUtils.setApplicationContext(context);


+ 83
- 5
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/DeclaredRecordManage.java View File

@@ -6,7 +6,6 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -14,9 +13,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hz.pm.api.common.enumeration.CommonEnum; import com.hz.pm.api.common.enumeration.CommonEnum;
import com.hz.pm.api.common.enumeration.ProjectProcessStageEnum; import com.hz.pm.api.common.enumeration.ProjectProcessStageEnum;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.common.model.constant.TypeReferenceConst; import com.hz.pm.api.common.model.constant.TypeReferenceConst;
import com.hz.pm.api.common.statemachine.event.ProjectStatusChangeEvent; import com.hz.pm.api.common.statemachine.event.ProjectStatusChangeEvent;
import com.hz.pm.api.common.util.BizUtils; import com.hz.pm.api.common.util.BizUtils;
import com.hz.pm.api.datascope.model.DataScopeDTO;
import com.hz.pm.api.datascope.utils.DataScopeUtil;
import com.hz.pm.api.external.model.enumeration.MhUnitStripEnum; import com.hz.pm.api.external.model.enumeration.MhUnitStripEnum;
import com.hz.pm.api.external.model.enumeration.MhUnitTypeEnum; import com.hz.pm.api.external.model.enumeration.MhUnitTypeEnum;
import com.hz.pm.api.projectdeclared.manage.DefaultDeclaredProjectManage; import com.hz.pm.api.projectdeclared.manage.DefaultDeclaredProjectManage;
@@ -45,6 +47,7 @@ import com.hz.pm.api.todocenter.constant.WorkNoticeConst;
import com.hz.pm.api.user.helper.MhUnitCache; import com.hz.pm.api.user.helper.MhUnitCache;
import com.hz.pm.api.user.model.dto.UnitDTO; import com.hz.pm.api.user.model.dto.UnitDTO;
import com.hz.pm.api.user.model.entity.MhUnit; import com.hz.pm.api.user.model.entity.MhUnit;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.user.security.model.UserInfoDetails; import com.hz.pm.api.user.security.model.UserInfoDetails;
import com.hz.pm.api.user.service.IMhUnitService; import com.hz.pm.api.user.service.IMhUnitService;
import com.hz.pm.api.user.util.LoginUserUtil; import com.hz.pm.api.user.util.LoginUserUtil;
@@ -83,6 +86,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class DeclaredRecordManage { public class DeclaredRecordManage {


private final UserInfoHelper userInfoHelper;
private final ProjectCodeGenUtil projectCodeGenUtil; private final ProjectCodeGenUtil projectCodeGenUtil;
private final IMhProjectService mhProjectService; private final IMhProjectService mhProjectService;
private final IMhProjectSchemaTargetDataService schemaTargetDataService; private final IMhProjectSchemaTargetDataService schemaTargetDataService;
@@ -108,24 +112,98 @@ public class DeclaredRecordManage {
if (req.getCreateDateMax() != null) { if (req.getCreateDateMax() != null) {
query.lt(MhProject::getCreateTime, req.getCreateDateMax().minusDays(1)); query.lt(MhProject::getCreateTime, req.getCreateDateMax().minusDays(1));
} }
UserInfoDetails user = LoginUserUtil.loginUserDetail();
if (!user.getSuperAdmin() && !user.getRegionAdmin()) {
query.eq(MhProject::getUnitId, user.getMhUnitId());
}
if (req.getUnitStrip() != null) { if (req.getUnitStrip() != null) {
query.eq(MhProject::getUnitStrip, req.getUnitStrip()); query.eq(MhProject::getUnitStrip, req.getUnitStrip());
} }
return query; return query;
} }


private boolean buildMhProjectLibPermission(LambdaQueryWrapper<MhProject> query, UserFullInfoDTO user) {
boolean queryState = true;
Optional<DataScopeDTO> currentUserDataScope = DataScopeUtil.getCurrentUserDataScopeHasUserId(user);
if (!currentUserDataScope.isPresent()) {
log.warn("没有取到权限信息 当前查询 没有权限条件");
queryState = false;
} else {
switch (currentUserDataScope.get().getRole()) {
case NORMAL_MEMBER:
//普通用户 只能看到自己单位去申报的
query.eq(MhProject::getUnitId, user.getMhUnitId());
break;
case COMPANY_MANAGER:
List<Long> childUnitIds = mhUnitCache.getChildrenIdsRecursion(user.getMhUnitId());
childUnitIds.add(user.getMhUnitId());
//单位管理员 看到自己单位去申报的 + 待预审的主管单位是自己单位的项目
query.in(MhProject::getUnitId, childUnitIds);
break;
case SUPER_ADMIN:
//超级管理员 看到丽水全市的 并且也要判断他 同时是不是单位管理员
break;
case VISITOR:
//访客可以看全市的
break;
case DASHBOARD:
break;
default:
//没有权限的话 就让它查不到
queryState = false;
break;
}
}
return queryState;
}

private boolean buildProjectLibPermission(LambdaQueryWrapper<Project> query, UserFullInfoDTO user) {
boolean queryState = true;
Optional<DataScopeDTO> currentUserDataScope = DataScopeUtil.getCurrentUserDataScopeHasUserId(user);
if (!currentUserDataScope.isPresent()) {
log.warn("没有取到权限信息 当前查询 没有权限条件");
queryState = false;
} else {
switch (currentUserDataScope.get().getRole()) {
case NORMAL_MEMBER:
//普通用户 只能看到自己单位去申报的
query.eq(Project::getBuildOrgCode, user.getMhUnitIdStr());
break;
case COMPANY_MANAGER:
List<Long> childUnitIds = mhUnitCache.getChildrenIdsRecursion(user.getMhUnitId());
childUnitIds.add(user.getMhUnitId());
List<String> viewUnitIdList = CollUtils.convert(childUnitIds, String::valueOf);
//单位管理员 看到自己单位去申报的 + 待预审的主管单位是自己单位的项目
query.in(Project::getBuildOrgCode, viewUnitIdList);
break;
case SUPER_ADMIN:
//超级管理员 看到丽水全市的 并且也要判断他 同时是不是单位管理员
break;
case VISITOR:
//访客可以看全市的
break;
case DASHBOARD:
break;
default:
//没有权限的话 就让它查不到
queryState = false;
break;
}
}
return queryState;
}

public PageVo<DeclaredProjectListVO> pageDeclaredProject(DeclaredProjectListReq req) { public PageVo<DeclaredProjectListVO> pageDeclaredProject(DeclaredProjectListReq req) {
LambdaQueryWrapper<MhProject> query = buildQuery(req); LambdaQueryWrapper<MhProject> query = buildQuery(req);
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
// 查询审核中、失败、待立项备案的项目信息 // 查询审核中、失败、待立项备案的项目信息
LambdaQueryWrapper<Project> pQuery = Wrappers.lambdaQuery(Project.class) LambdaQueryWrapper<Project> pQuery = Wrappers.lambdaQuery(Project.class)
.in(Project::getStatus, ProjectStatusEnum.DECLARED_APPROVED_RECORD_FAILED.getCode(), .in(Project::getStatus, ProjectStatusEnum.DECLARED_APPROVED_RECORD_FAILED.getCode(),
ProjectStatusEnum.DECLARED_APPROVED_TO_BE_RECORD.getCode(), ProjectStatusEnum.DECLARED_APPROVED_TO_BE_RECORD.getCode(),
ProjectStatusEnum.DECLARED_APPROVED_RECORD_AUDITING.getCode()) ProjectStatusEnum.DECLARED_APPROVED_RECORD_AUDITING.getCode())
.select(Project::getId, Project::getProjectCode, Project::getStage, Project::getStatus, Project::getCreateOn); .select(Project::getId, Project::getProjectCode, Project::getStage, Project::getStatus, Project::getCreateOn);
if (!buildProjectLibPermission(pQuery, user)) {
return PageVo.empty();
}
if (!buildMhProjectLibPermission(query, user)) {
return PageVo.empty();
}
List<Project> projects = projectService.list(pQuery); List<Project> projects = projectService.list(pQuery);
Map<String, Project> projectMap = BizUtils.groupFirstMap(projects, Project::getProjectCode, Map<String, Project> projectMap = BizUtils.groupFirstMap(projects, Project::getProjectCode,
Comparator.comparing(Project::getCreateOn).reversed()); Comparator.comparing(Project::getCreateOn).reversed());


+ 3
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/model/vo/MhUnitListVO.java View File

@@ -22,6 +22,9 @@ public class MhUnitListVO {
@ApiModelProperty("单位名称") @ApiModelProperty("单位名称")
private String name; private String name;


@ApiModelProperty("单位简称")
private String shortName;

@ApiModelProperty("上级单位ID") @ApiModelProperty("上级单位ID")
private Long parentId; private Long parentId;




+ 0
- 1
hz-pm-api/src/main/resources/application-dev.yml View File

@@ -118,7 +118,6 @@ log:


swagger: swagger:
enabled: true enabled: true

flowable: flowable:
async-executor-activate: true async-executor-activate: true
#关闭一些不需要的功能服务 #关闭一些不需要的功能服务


Loading…
Cancel
Save