Browse Source

增加异步线程执行器

tags/24080901
WendyYang 8 months ago
parent
commit
1f021217d4
8 changed files with 234 additions and 29 deletions
  1. +34
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/util/MDCThreadPoolTaskExecutor.java
  2. +50
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/util/MDCThreadUtil.java
  3. +33
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/util/ThreadPoolUtil.java
  4. +28
    -22
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java
  5. +67
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ConstructionDetailVO.java
  6. +4
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java
  7. +8
    -7
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IMhProjectSchemaTargetDataService.java
  8. +10
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IMhProjectService.java

+ 34
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/util/MDCThreadPoolTaskExecutor.java View File

@@ -0,0 +1,34 @@
package com.hz.pm.api.common.util;

import org.springframework.lang.NonNull;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

/**
* <p>
* MDCThreadPoolTaskExecutor
* </p>
*
* @author WendyYang
* @since 2023/10/27
**/
public class MDCThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {

@Override
public @NonNull Future<?> submit(@NonNull Runnable task) {
return super.submit(MDCThreadUtil.wrap(task));
}

@Override
public void execute(@NonNull Runnable task) {
super.execute(MDCThreadUtil.wrap(task));
}

@Override
public <T> @NonNull Future<T> submit(@NonNull Callable<T> task) {
return super.submit(MDCThreadUtil.wrap(task));
}

}

+ 50
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/util/MDCThreadUtil.java View File

@@ -0,0 +1,50 @@
package com.hz.pm.api.common.util;

import cn.hutool.core.map.MapUtil;
import org.slf4j.MDC;

import java.util.Map;
import java.util.concurrent.Callable;

/**
* <p>
* MDCThreadPoolUtil
* </p>
*
* @author WendyYang
* @since 2023/10/27
**/
public class MDCThreadUtil {

private MDCThreadUtil() {
}

public static <T> Callable<T> wrap(final Callable<T> callable) {
Map<String, String> context = MDC.getCopyOfContextMap();
return () -> {
if (MapUtil.isNotEmpty(context)) {
MDC.setContextMap(context);
}
try {
return callable.call();
} finally {
MDC.clear();
}
};
}

public static Runnable wrap(final Runnable runnable) {
Map<String, String> context = MDC.getCopyOfContextMap();
return () -> {
if (MapUtil.isNotEmpty(context)) {
MDC.setContextMap(context);
}
try {
runnable.run();
} finally {
MDC.clear();
}
};
}

}

+ 33
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/util/ThreadPoolUtil.java View File

@@ -0,0 +1,33 @@
package com.hz.pm.api.common.util;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
* <p>
* ThreadPoolUtil
* </p>
*
* @author WendyYang
* @since 2023/10/27
**/
public class ThreadPoolUtil {

private ThreadPoolUtil() {
}

public static final ThreadPoolTaskExecutor REQUEST;

static {
REQUEST = new MDCThreadPoolTaskExecutor();
REQUEST.setCorePoolSize(5);
REQUEST.setMaxPoolSize(15);
REQUEST.setQueueCapacity(300);
REQUEST.setKeepAliveSeconds(120);
REQUEST.setThreadNamePrefix("requestAsyncExecutor-");
REQUEST.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
REQUEST.initialize();
}

}

+ 28
- 22
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java View File

@@ -66,10 +66,7 @@ import com.hz.pm.api.projectlib.model.enumeration.TenderStatusEnum;
import com.hz.pm.api.projectlib.model.po.ProjectPO;
import com.hz.pm.api.projectlib.model.req.ProjectApplicationListReq;
import com.hz.pm.api.projectlib.model.req.ProjectListReq;
import com.hz.pm.api.projectlib.model.vo.AnnualAmountVO;
import com.hz.pm.api.projectlib.model.vo.ProjectApplicationVO;
import com.hz.pm.api.projectlib.model.vo.ProjectDetailVO;
import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO;
import com.hz.pm.api.projectlib.model.vo.*;
import com.hz.pm.api.projectlib.service.*;
import com.hz.pm.api.safety.model.entity.PersonSafetyInfo;
import com.hz.pm.api.safety.model.entity.SupplierSafetyQualification;
@@ -149,6 +146,8 @@ public class ProjectLibManage {
private final ConstructionManage constructionManage;
private final IProjectGovSystemReplaceInfosService projectGovSystemReplaceInfosService;
private final MhUnitCache mhUnitCache;
private final IMhProjectSchemaTargetDataService projectSchemaTargetDataService;
private final IMhProjectService mhProjectService;

public PageVo<ProjectLibListItemVO> projectLibList(ProjectListReq req) {
LambdaQueryWrapper<Project> query = ProjectHelper.projectQuery(req);
@@ -699,9 +698,9 @@ public class ProjectLibManage {
}

private ProjectDetailVO getProjectDetailLogic(Project project) {
ProjectDetailVO vo = new ProjectDetailVO();
BeanUtils.copyProperties(project, vo);
vo.buildDynamicForm(project.getDynamicForm());
ProjectDetailVO retProjectDetail = new ProjectDetailVO();
BeanUtils.copyProperties(project, retProjectDetail);
retProjectDetail.buildDynamicForm(project.getDynamicForm());
String projectCode = project.getProjectCode();
// 查询应用
List<ProjectApplication> applications = applicationService.list(projectCode, project.getVersion(), project.getIsConstruct());
@@ -712,20 +711,20 @@ public class ProjectLibManage {
if (CollUtil.isNotEmpty(applicationIds)) {
List<ProjectCoreBusinessIndicators> coreBizs = projectCoreBusinessIndicatorsService.listByApplicationIds(applicationIds);
Map<Long, List<ProjectCoreBusinessIndicators>> coreBizMap = CollUtils.group(coreBizs, ProjectCoreBusinessIndicators::getApplicationId);
vo.setProjectApplications(CollUtils.convert(applications, app -> ProjectHelper.convertVOWithMap(app, coreBizMap)));
retProjectDetail.setProjectApplications(CollUtils.convert(applications, app -> ProjectHelper.convertVOWithMap(app, coreBizMap)));
}
vo.setSystemReplaceInfos(getGovSystemReplaceInfos(project.getId()));
retProjectDetail.setSystemReplaceInfos(getGovSystemReplaceInfos(project.getId()));
//审批信息
if (StrUtils.isNotBlank(project.getInstCode())) {
ProcessDetailReq req = new ProcessDetailReq();
req.setInstanceId(project.getInstCode());
req.setProjectId(project.getId());
vo.setProcess(todoService.getProcessDetail(req));
retProjectDetail.setProcess(todoService.getProcessDetail(req));
}

List<Long> allVersionProjectIds = projectService.allVersionProjectIds(projectCode);
// 查询采购备案
vo.setPurchaseDetails(new ArrayList<>());
retProjectDetail.setPurchaseDetails(new ArrayList<>());
List<Purchase> purchases = purchaseService.listByProjectIds(allVersionProjectIds);
if (!purchases.isEmpty()) {
Map<Long, PurchaseVO> purchaseMap = CollUtils.listToMap(purchases, Purchase::getId, w -> {
@@ -754,13 +753,20 @@ public class ProjectLibManage {
if (tmpPersons != null) {
purchaseFullInfo.setFirstInspectedPersons(convertPersons(tmpPersons));
}
vo.getPurchaseDetails().add(purchaseFullInfo);
retProjectDetail.getPurchaseDetails().add(purchaseFullInfo);
});
// 建设方案
mhProjectService.getIdByProjectCode(projectCode).ifPresent(w -> {
MhProjectSchemaTargetData schemaTargetData = projectSchemaTargetDataService.getByMhProjectId(w);
ConstructionDetailVO construction = new ConstructionDetailVO();
BeanUtil.copyProperties(schemaTargetData, construction);
retProjectDetail.setConstruction(construction);
});
}


List<ProjectAnnualPaymentPlan> annualPaymentPlans = projectAnnualPaymentPlanService.listByProjectId(project.getId());
vo.setAnnualPaymentPlans(BeanUtil.copyToList(annualPaymentPlans, ProjectPaymentPlanDTO.class));
retProjectDetail.setAnnualPaymentPlans(BeanUtil.copyToList(annualPaymentPlans, ProjectPaymentPlanDTO.class));


SafetyMonitorVO safetyVo = new SafetyMonitorVO();
@@ -769,7 +775,7 @@ public class ProjectLibManage {
if (CollUtil.isNotEmpty(safetyQualifications)) {
safetyVo.setSupplierSafetyQualification(BeanUtil.copyToList(safetyQualifications, SupplierSafetyQualificationVO.class));
}
vo.setSafetyInfo(safetyVo);
retProjectDetail.setSafetyInfo(safetyVo);

List<PersonSafetyInfo> personSafetyInfos = personSafetyInfoService.listByProjectCode(projectCode);
if (CollUtil.isNotEmpty(personSafetyInfos)) {
@@ -777,27 +783,27 @@ public class ProjectLibManage {
}

// 查询终验信息
vo.setFinalIrsApps(applicationHandler.generateIrsApp(projectCode));
retProjectDetail.setFinalIrsApps(applicationHandler.generateIrsApp(projectCode));

// 处理文件名
List<Long> fileIdList = new ArrayList<>();
BizUtils.notBlank(vo.getApprovedFile(), w -> fileIdList.add(Long.parseLong(w)));
BizUtils.notBlank(vo.getApprovedConstructionPlanFile(), w -> fileIdList.add(Long.parseLong(w)));
BizUtils.notBlank(retProjectDetail.getApprovedFile(), w -> fileIdList.add(Long.parseLong(w)));
BizUtils.notBlank(retProjectDetail.getApprovedConstructionPlanFile(), w -> fileIdList.add(Long.parseLong(w)));
if (!fileIdList.isEmpty()) {
List<File> files = fileService.listByIds(fileIdList);
Map<String, String> fileMap = CollUtils.listToMap(files, w -> w.getId().toString(), File::getOriginalFileName);
vo.setApprovedFileName(fileMap.get(vo.getApprovedFile()));
vo.setApprovedConstructionPlanFileName(fileMap.get(vo.getApprovedConstructionPlanFile()));
retProjectDetail.setApprovedFileName(fileMap.get(retProjectDetail.getApprovedFile()));
retProjectDetail.setApprovedConstructionPlanFileName(fileMap.get(retProjectDetail.getApprovedConstructionPlanFile()));
}
//专家评审 其它建议 -> 建设方案的会议
ExpertReview finalReview = expertReviewService.getFinalReview(projectCode,
ReviewTemplateTypeEnum.CONSTRUCTION_SCHEME_REVIEW.getCode());

if (Objects.nonNull(finalReview)) {
vo.setProposeAttach(finalReview.getOtherAdvice());
vo.setBaseReviewResults(finalReview.getReviewResult());
retProjectDetail.setProposeAttach(finalReview.getOtherAdvice());
retProjectDetail.setBaseReviewResults(finalReview.getReviewResult());
}
return vo;
return retProjectDetail;
}




+ 67
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ConstructionDetailVO.java View File

@@ -0,0 +1,67 @@
package com.hz.pm.api.projectlib.model.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

/**
* <p>
* ConstructionDetailVO
* </p>
*
* @author WendyYang
* @since 10:22 2024/3/8
*/
@Data
public class ConstructionDetailVO {

@ApiModelProperty(value = "迁移上云信息系统数量")
private int cloudSystemNum;

@ApiModelProperty(value = "本地部署非涉密信息系统数量")
private Integer fsmLocalSystemNum;

@ApiModelProperty(value = "更新购置非涉密服务器数量")
private Integer fsmServerNum;

@ApiModelProperty(value = "更新购置非涉密数据库数量")
private Integer fsmUpdateDbNum;

@ApiModelProperty(value = "更新购置非涉密中间件数量")
private Integer fsmUpdateMiddleNum;

@ApiModelProperty(value = "vCPU(核数)")
private Integer hostCpuNum;

@ApiModelProperty(value = "内存(GB)")
private Integer hostMemoryNum;

@ApiModelProperty(value = "信创云虚拟主机数量")
private Integer hostNum;

@ApiModelProperty(value = "存储(GB)")
private Integer hostStoreNum;

@ApiModelProperty(value = "总投资预算金额(万元)")
private BigDecimal money;

@ApiModelProperty(value = "本地部署涉密信息系统数量")
private Integer smLocalSystemNum;

@ApiModelProperty(value = "更新购置涉密服务器数量")
private Integer smServerNum;

@ApiModelProperty(value = "更新购置涉密数据库数量")
private Integer smUpdateDbNum;

@ApiModelProperty(value = "更新购置涉密中间件数量")
private Integer smUpdateMiddleNum;

@ApiModelProperty(value = "信创云数据库数量")
private Integer xcDbNum;

@ApiModelProperty(value = "信创云中间件数量")
private Integer xcMiddleNum;

}

+ 4
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java View File

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.hz.pm.api.common.compare.Compare;
import com.hz.pm.api.dashboard.model.vo.ProtraitProjectOutputVO;
import com.hz.pm.api.external.model.dto.MhProjectSchemeTargetDTO;
import com.hz.pm.api.portrait.model.vo.TagVO;
import com.hz.pm.api.projectdeclared.model.vo.PurchaseFullInfoVO;
import com.hz.pm.api.projectlib.model.dto.GovSystemReplaceInfoDTO;
@@ -573,4 +574,7 @@ public class ProjectDetailVO {
@Compare("批复-政府投资-上级补助资金")
private BigDecimal approvalGovSuperiorFinanceAmount;

@ApiModelProperty("建设方案详情")
private ConstructionDetailVO construction;

}

+ 8
- 7
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IMhProjectSchemaTargetDataService.java View File

@@ -6,10 +6,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.projectlib.model.entity.MhProjectSchemaTargetData;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.projectlib.model.vo.ConstructionDetailVO;

/**
* <p>
* 服务类
* 服务类
* </p>
*
* @author WendyYang
@@ -17,11 +18,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IMhProjectSchemaTargetDataService extends IService<MhProjectSchemaTargetData> {

default MhProjectSchemaTargetData getByMhProjectId(Long mhProjectId){
Wrapper<MhProjectSchemaTargetData> query = Wrappers.lambdaQuery(MhProjectSchemaTargetData.class)
.eq(MhProjectSchemaTargetData::getMhProjectId,mhProjectId)
.last(BizConst.LIMIT_1);
return getOne(query);
}
default MhProjectSchemaTargetData getByMhProjectId(Long mhProjectId) {
Wrapper<MhProjectSchemaTargetData> query = Wrappers.lambdaQuery(MhProjectSchemaTargetData.class)
.eq(MhProjectSchemaTargetData::getMhProjectId, mhProjectId)
.last(BizConst.LIMIT_1);
return getOne(query);
}

}

+ 10
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IMhProjectService.java View File

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.projectlib.model.entity.MhProject;

import java.util.Optional;

/**
* <p>
* 服务类
@@ -22,6 +24,14 @@ public interface IMhProjectService extends IService<MhProject> {
return getOne(query);
}

default Optional<Long> getIdByProjectCode(String projectCode) {
LambdaQueryWrapper<MhProject> query = Wrappers.lambdaQuery(MhProject.class)
.select(MhProject::getId)
.eq(MhProject::getProjectCode, projectCode);
return Optional.ofNullable(getOne(query))
.flatMap(w -> Optional.of(w.getId()));
}

default boolean existsByProjectCode(String projectCode) {
LambdaQueryWrapper<MhProject> query = Wrappers.lambdaQuery(MhProject.class)
.eq(MhProject::getProjectCode, projectCode)


Loading…
Cancel
Save