Commit 2acf27d508e2c1060f8b70d9a325d27f495040f9

Authored by 张志伟
1 parent 67926cfa

:boom: feat(*): 优化代码

- 优化代码
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/DateUtil.java
... ... @@ -17,7 +17,7 @@ import java.util.Objects;
17 17 */
18 18 public final class DateUtil {
19 19  
20   - static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  20 + private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
21 21  
22 22 /**
23 23 * 默认构造器
... ...
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/MessageFormatUtil.kt
1   -package cn.fw.hestia.common.utils;
  1 +package cn.fw.hestia.common.utils
2 2  
3   -import java.text.MessageFormat;
4   -import java.util.ArrayList;
5   -import java.util.Date;
6   -import java.util.List;
  3 +import java.text.MessageFormat
7 4  
8 5 /**
9 6 * @author kurisu
10 7 * @description 占位符转换工具
11 8 * @date 2019/5/30.
12 9 */
13   -public class MessageFormatUtil {
14   -
15   - public static String MessageFormatTransfer(String pattern, Object... arguments) {
16   - List<Object> param = new ArrayList<>();
17   - for (int i = 0; i < arguments.length; i++) {
18   - if (arguments[i] instanceof Number) {
19   - param.add(String.valueOf(arguments[i]));
20   - }else {
21   - param.add(arguments[i]);
  10 +object MessageFormatUtil {
  11 + fun messageFormatTransfer(pattern: String?, vararg arguments: Any): String {
  12 + val param: MutableList<Any> = ArrayList()
  13 + for (i in arguments.indices) {
  14 + if (arguments[i] is Number) {
  15 + param.add(arguments[i].toString())
  16 + } else {
  17 + param.add(arguments[i])
22 18 }
23 19 }
24   - return MessageFormat.format(pattern, param.toArray());
25   - }
26   -
27   - public static void main(String[] args) {
28   - System.out.println("示例:" + MessageFormatTransfer("crm:valhalla:save:lock:key:{0}:{1}", 11111L, new Date()));
  20 + return MessageFormat.format(pattern, *param.toTypedArray())
29 21 }
30   -
31   -}
  22 +}
32 23 \ No newline at end of file
... ...
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/StringUtils.java
... ... @@ -27,7 +27,7 @@ public final class StringUtils {
27 27 */
28 28 public static final String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
29 29  
30   - public static final String regNo = "^[-\\+]?[\\d]*$";
  30 + public static final String regNo = "^[-+]?\\d*$";
31 31  
32 32 private StringUtils() {
33 33 }
... ...
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/ThreadPoolUtil.kt
1   -package cn.fw.hestia.common.utils;
  1 +package cn.fw.hestia.common.utils
2 2  
3   -import cn.hutool.core.thread.ExecutorBuilder;
4   -import cn.hutool.core.thread.NamedThreadFactory;
5   -
6   -import java.util.concurrent.ExecutorService;
7   -import java.util.concurrent.LinkedBlockingQueue;
  3 +import cn.hutool.core.thread.ExecutorBuilder
  4 +import cn.hutool.core.thread.NamedThreadFactory
  5 +import java.util.concurrent.ExecutorService
8 6  
9 7 /**
10 8 * ThreadPoolUtil
... ... @@ -15,32 +13,13 @@ import java.util.concurrent.LinkedBlockingQueue;
15 13 * @description : ThreadPoolUtil
16 14 * @date : 2023-04-19 17:31
17 15 */
18   -public class ThreadPoolUtil {
19   - private static volatile ThreadPoolUtil INSTANCE;
20   - private final ExecutorService executor;
21   -
22   - private ThreadPoolUtil() {
23   - this.executor = ExecutorBuilder.create()
24   - .setCorePoolSize(30)
25   - .setMaxPoolSize(100)
26   - .setThreadFactory(new NamedThreadFactory("hestia-custom-", false))
27   - .setAllowCoreThreadTimeOut(true)
28   - .useArrayBlockingQueue(512)
29   - .build();
30   - }
31   -
32   - public static ThreadPoolUtil getInstance() {
33   - if (INSTANCE == null) {
34   - synchronized (ThreadPoolUtil.class) {
35   - if (INSTANCE == null) {
36   - INSTANCE = new ThreadPoolUtil();
37   - }
38   - }
39   - }
40   - return INSTANCE;
41   - }
42 16  
43   - public ExecutorService getExecutor() {
44   - return executor;
45   - }
46   -}
  17 +object ThreadPoolUtil {
  18 + val executor: ExecutorService = ExecutorBuilder.create()
  19 + .setCorePoolSize(30)
  20 + .setMaxPoolSize(100)
  21 + .setThreadFactory(NamedThreadFactory("hestia-custom-", false))
  22 + .setAllowCoreThreadTimeOut(true)
  23 + .useArrayBlockingQueue(512)
  24 + .build()
  25 +}
47 26 \ No newline at end of file
... ...
fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/api/MessageCenterServiceImpl.kt
... ... @@ -44,7 +44,7 @@ class MessageCenterServiceImpl(private val messageCenterBizService: MessageCente
44 44 BV.isNotEmpty(paramList) { "消息列表不能为空" }
45 45 BV.isTrue(
46 46 paramList!!.size <= maxSize
47   - ) { MessageFormatUtil.MessageFormatTransfer("最多支持一次性发送{0}条", maxSize) }
  47 + ) { MessageFormatUtil.messageFormatTransfer("最多支持一次性发送{0}条", maxSize) }
48 48 return success(
49 49 messageCenterBizService.saveBatchMessage(
50 50 paramList
... ...
fw-hestia-server/src/main/java/cn/fw/hestia/server/task/SendMessageTask.kt
... ... @@ -84,7 +84,7 @@ class SendMessageTask(
84 84 id?.let {
85 85 CompletableFuture.runAsync(
86 86 { messageCenterBizService.clearHistory(it) },
87   - ThreadPoolUtil.getInstance().executor
  87 + ThreadPoolUtil.executor
88 88 )
89 89 }
90 90 }
... ...