diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java index eb95136..3667f04 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java @@ -5,6 +5,7 @@ import com.ningdatech.basic.enumeration.Status; import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.basic.util.CollUtils; +import com.wflow.exception.BusinessException; import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.HttpStatus; @@ -84,4 +85,10 @@ public class GlobalExceptionHandler { return ApiResponse.of(ERROR_CODE, e.getMessage()); } + @ResponseBody + @ExceptionHandler(value = BusinessException.class) + public ApiResponse catchException(BusinessException e) { + return ApiResponse.of(ERROR_CODE, e.getMessage()); + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java index 23eab78..9295885 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java @@ -1,5 +1,6 @@ package com.hz.pm.api.common.helper.basic; +import cn.hutool.core.date.StopWatch; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.collect.Lists; @@ -68,7 +69,11 @@ public abstract class AbstractRegionCacheHelper implements InitializingBean { return RegionConverter.toRegionDTO(region); }); // 初始化所有区域数据到缓存 + StopWatch watch = new StopWatch(); + watch.start(); initRegionCache(); + watch.stop(); + log.info("初始化区域缓存耗时:{} ms", watch.getTotalTimeMillis()); } public String getParentCodeRoot() { diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java b/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java index b982854..2b90196 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java @@ -2,6 +2,7 @@ package com.hz.pm.api.meta.helper.basic; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.IterUtil; +import cn.hutool.core.date.StopWatch; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; @@ -66,10 +67,14 @@ public abstract class AbstractDictionaryCache implements InitializingBean, Dicti } private void initAllDicts() { + StopWatch watch = new StopWatch(); + watch.start(); List dictTypes = Arrays.stream(DictTypeEnum.values()) .map(DictTypeEnum::getKey) .collect(Collectors.toList()); dictCache.getAll(dictTypes); + watch.stop(); + log.info("初始化字典数据耗时:{} ms", watch.getTotalTimeMillis()); } } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java b/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java index c137d4c..27aece1 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java @@ -2,6 +2,7 @@ package com.hz.pm.api.meta.helper.basic; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.IterUtil; +import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.NumberUtil; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; @@ -102,10 +103,14 @@ public abstract class AbstractTagsCache implements InitializingBean, TagCache { } public void initAllTags() { + StopWatch watch = new StopWatch(); + watch.start(); List allLevels = Arrays.stream(NumberUtil.range(1, MAX_LEVEL)) .mapToObj(String::valueOf) .collect(Collectors.toList()); tagsCache.getAll(allLevels); + watch.stop(); + log.info("初始化标签树耗时:{} ms", watch.getTotalTimeMillis()); } protected List getChildren(String tagCode, List list) { diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java index 393edf8..ed43252 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java @@ -1,5 +1,6 @@ package com.hz.pm.api.projectdeclared.utils; +import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -45,12 +46,16 @@ public class ProjectIdCodeCacheUtil { @PostConstruct public void initProjectIdCodeCache() { + StopWatch watch = new StopWatch(); + watch.start(); Wrapper query = Wrappers.lambdaQuery(Project.class) .select(Project::getProjectCode, Project::getId, Project::getCreateOn, Project::getNewest); for (Project project : projectService.list(query)) { put(project.getId(), project, false); } - log.info("初始化项目ID编码缓存:{}", CACHE.size()); + watch.stop(); + log.info("初始化项目ID编码缓存耗时:{} ms", watch.getTotalTimeMillis()); + log.info("初始化项目ID编码缓存:{} 个", CACHE.size()); } //================================================================================================================== diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java index c23620c..37f7dfa 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java @@ -3,6 +3,7 @@ package com.hz.pm.api.user.helper.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.IterUtil; +import cn.hutool.core.date.StopWatch; import cn.hutool.core.lang.Assert; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; @@ -96,7 +97,11 @@ public class MhUnitCacheImpl implements MhUnitCache, InitializingBean { } }); // 初始化所有单位 + StopWatch watch = new StopWatch(); + watch.start(); cache.getAll(Collections.singletonList(ALL)); + watch.stop(); + log.info("初始化单位缓存耗时:{} ms", watch.getTotalTimeMillis()); } @Override diff --git a/hz-pm-api/src/main/resources/application-prod.yml b/hz-pm-api/src/main/resources/application-prod.yml index 7da5099..3b7d6e2 100644 --- a/hz-pm-api/src/main/resources/application-prod.yml +++ b/hz-pm-api/src/main/resources/application-prod.yml @@ -96,6 +96,7 @@ nd: log: enabled: true type: DB + keep-days: 365 # 文件存储 file: storage-type: ALI_OSS @@ -235,20 +236,20 @@ thread-pool-util: keep-alive-seconds: 120 thread-name-prefix: request-executor- scheduler: - core-pool-size: 4 + core-pool-size: 3 thread-name-prefix: scheduler-executor- # 工作流线程池配置 wflow-thread-pool-util: scheduler: - core-pool-size: 4 + core-pool-size: 3 thread-name-prefix: wflow-thread-scheduler- executor: - core-pool-size: 4 + core-pool-size: 3 thread-name-prefix: wflow-thread-executor- queue-capacity: 300 keep-alive-seconds: 120 - max-pool-size: 8 + max-pool-size: 6 random-invite: thread-pool-properties: core-pool-size: 3