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