Explorar el Código

modify:

1. 项目ID编码缓存修复;
tags/24080901
WendyYang hace 3 meses
padre
commit
022e483ba3
Se han modificado 2 ficheros con 20 adiciones y 11 borrados
  1. +17
    -9
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java
  2. +3
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectStoppedManage.java

+ 17
- 9
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java Ver fichero

@@ -11,7 +11,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -38,9 +37,7 @@ public class ProjectIdCodeCacheUtil {

private String projectCode;

private LocalDateTime createOn;

private Boolean newest;
private volatile Boolean newest;

}

@@ -51,7 +48,7 @@ public class ProjectIdCodeCacheUtil {
Wrapper<Project> query = Wrappers.lambdaQuery(Project.class)
.select(Project::getProjectCode, Project::getId, Project::getCreateOn, Project::getNewest);
for (Project project : projectService.list(query)) {
put(project.getId(), project);
put(project.getId(), project, false);
}
log.info("初始化项目ID编码缓存:{}", CACHE.size());
}
@@ -75,22 +72,33 @@ public class ProjectIdCodeCacheUtil {
}

public static void put(Long projectId, Project project) {
put(projectId, project, true);
}

private static void put(Long projectId, Project project, boolean refresh) {
IdCodeCacheDTO idCodeCache = new IdCodeCacheDTO();
idCodeCache.setProjectId(project.getId());
idCodeCache.setProjectCode(project.getProjectCode());
idCodeCache.setCreateOn(project.getCreateOn());
idCodeCache.setNewest(project.getNewest());
if (refresh && Boolean.TRUE.equals(project.getNewest())) {
Optional<IdCodeCacheDTO> preCache = newestCache(project.getProjectCode());
preCache.ifPresent(w -> w.setNewest(Boolean.FALSE));
}
CACHE.put(projectId, idCodeCache);
}

public static Long newest(String projectCode) {
return get(projectCode).stream().map(CACHE::get)
.filter(IdCodeCacheDTO::getNewest)
.findFirst()
return newestCache(projectCode)
.flatMap(w -> Optional.of(w.getProjectId()))
.orElse(null);
}

private static Optional<IdCodeCacheDTO> newestCache(String projectCode) {
return get(projectCode).stream().map(CACHE::get)
.filter(IdCodeCacheDTO::getNewest)
.findFirst();
}

public static Long newest(Long projectId) {
String projectCode = get(projectId);
if (StrUtil.isBlank(projectCode)) {


+ 3
- 2
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectStoppedManage.java Ver fichero

@@ -1,6 +1,7 @@
package com.hz.pm.api.projectlib.manage;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -114,10 +115,10 @@ public class ProjectStoppedManage {
.isNotNull(Project::getStoppedStatus);
Page<Project> page = req.page();
projectService.page(page, query);
if (page.getTotal() == 0) {
List<Project> records = page.getRecords();
if (CollUtil.isEmpty(records)) {
return PageVo.empty();
}
List<Project> records = page.getRecords();
Wrapper<ProjectInst> projectInstQuery = Wrappers.lambdaQuery(ProjectInst.class)
.eq(ProjectInst::getInstType, ProjectProcessType.PROJECT_STOPPED.getCode())
.in(ProjectInst::getProjectId, CollUtils.fieldList(records, Project::getId));


Cargando…
Cancelar
Guardar