From a50ac0e73e09bb6e5325f8a027b5e1f564a3e535 Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Wed, 10 Jul 2024 13:01:34 +0800
Subject: [PATCH 1/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E4=B8=80=EF=BC=89=EF=BC=9A=E6=BD=9C=E5=9C=A8?=
=?UTF-8?q?NPE=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../austin/cron/xxl/service/impl/CronTaskServiceImpl.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
index 8c9fc6d..028fa92 100644
--- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
+++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
@@ -164,7 +164,8 @@ public class CronTaskServiceImpl implements CronTaskService {
}
} catch (Exception e) {
log.error("CronTaskService#getGroupId fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e)
- , JSON.toJSONString(params), JSON.toJSONString(response.body()));
+ , JSON.toJSONString(params),
+ response != null ? JSON.toJSONString(response.body()) : "");
}
invalidateCookie();
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(response.body()));
From 298ec9703de9b104fa41cd0137dd083a390fd42d Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Wed, 10 Jul 2024 14:31:39 +0800
Subject: [PATCH 2/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E4=BA=8C=EF=BC=89=EF=BC=9A=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E5=AD=90=E7=88=B6=E7=B1=BBequals()=E6=96=B9=E6=B3=95=E4=B8=8D?=
=?UTF-8?q?=E5=AF=B9=E7=A7=B0=E9=97=AE=E9=A2=98=EF=BC=88=E9=9C=80=E7=94=A8?=
=?UTF-8?q?getClass=E8=80=8C=E4=B8=8D=E6=98=AFinstanceof=E5=81=9A=E5=88=A4?=
=?UTF-8?q?=E6=96=AD=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../dto/account/sms/LinTongSmsAccount.java | 35 ++++++++++++++++-
.../common/dto/account/sms/SmsAccount.java | 30 ++++++++++++++
.../dto/account/sms/TencentSmsAccount.java | 39 +++++++++++++++++++
.../dto/account/sms/YunPianSmsAccount.java | 34 ++++++++++++++++
4 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/LinTongSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/LinTongSmsAccount.java
index 542288f..35f7483 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/LinTongSmsAccount.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/LinTongSmsAccount.java
@@ -2,6 +2,8 @@ package com.java3y.austin.common.dto.account.sms;
import lombok.*;
+import java.util.Objects;
+
/**
* Form File
*
Description
@@ -13,7 +15,6 @@ import lombok.*;
* @Description
* @see com.java3y.austin.common.dto.account austin
*/
-@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@@ -30,4 +31,36 @@ public class LinTongSmsAccount extends SmsAccount {
private String userName;
private String password;
+ /**
+ * 重写equals方法
+ *
+ * @param o
+ * @return
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if (!super.equals(o)) {
+ return false;
+ }
+ LinTongSmsAccount that = (LinTongSmsAccount) o;
+ return url.equals(that.url) &&
+ userName.equals(that.userName) &&
+ password.equals(that.password);
+ }
+
+ /**
+ * 重写hashCode方法
+ *
+ * @return
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(url, userName, password);
+ }
}
diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java
index d4a9410..c34b4c0 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import java.util.Objects;
+
/**
* @author 3y
*/
@@ -27,5 +29,33 @@ public class SmsAccount {
*/
protected String scriptName;
+ /**
+ * 重写equals方法
+ *
+ * @param o
+ * @return
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ SmsAccount that = (SmsAccount) o;
+ return supplierId.equals(that.supplierId) &&
+ supplierName.equals(that.supplierName) &&
+ scriptName.equals(that.scriptName);
+ }
+ /**
+ * 重写hashCode方法
+ *
+ * @return
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(supplierId, supplierName, scriptName);
+ }
}
diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java
index bd62d54..bb0717b 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import java.util.Objects;
+
/**
* 腾讯短信参数
*
@@ -42,4 +44,41 @@ public class TencentSmsAccount extends SmsAccount {
private String smsSdkAppId;
private String templateId;
private String signName;
+
+ /**
+ * 重写equals方法
+ *
+ * @param o
+ * @return
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if (!super.equals(o)) {
+ return false;
+ }
+ TencentSmsAccount that = (TencentSmsAccount) o;
+ return url.equals(that.url) &&
+ region.equals(that.region) &&
+ secretId.equals(that.secretId) &&
+ secretKey.equals(that.secretKey) &&
+ smsSdkAppId.equals(that.smsSdkAppId) &&
+ templateId.equals(that.templateId) &&
+ signName.equals(that.signName);
+ }
+
+ /**
+ * 重写hashCode方法
+ *
+ * @return
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), url, region, secretId, secretKey, smsSdkAppId, templateId, signName);
+ }
}
diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java
index f33e369..9e1e28a 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import java.util.Objects;
+
/**
* 云片账号信息
*
@@ -31,4 +33,36 @@ public class YunPianSmsAccount extends SmsAccount {
*/
private String url;
+ /**
+ * 重写equals方法
+ *
+ * @param o
+ * @return
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if (!super.equals(o)) {
+ return false;
+ }
+ YunPianSmsAccount that = (YunPianSmsAccount) o;
+ return apikey.equals(that.apikey) &&
+ tplId.equals(that.tplId) &&
+ url.equals(that.url);
+ }
+
+ /**
+ * 重写hashCode方法
+ *
+ * @return
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), apikey, tplId, url);
+ }
}
From a486063b7fadb9f9cca01e32be0cd0650a438464 Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Wed, 10 Jul 2024 17:18:34 +0800
Subject: [PATCH 3/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E4=B8=89=EF=BC=89=EF=BC=9A=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E5=8F=AF=E8=83=BD=E7=9A=84=E6=BA=A2=E5=87=BA=E4=B8=8ENPE?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../austin/cron/xxl/service/impl/CronTaskServiceImpl.java | 3 ++-
.../handler/handler/impl/DingDingWorkNoticeHandler.java | 3 +--
.../java/com/java3y/austin/support/utils/TaskInfoUtils.java | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
index 028fa92..00213fa 100644
--- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
+++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java
@@ -168,7 +168,8 @@ public class CronTaskServiceImpl implements CronTaskService {
response != null ? JSON.toJSONString(response.body()) : "");
}
invalidateCookie();
- return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(response.body()));
+ return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR,
+ response != null ? JSON.toJSONString(response.body()) : "");
}
@Override
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java
index a0e1116..75785be 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java
@@ -9,7 +9,6 @@ import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.request.OapiMessageCorpconversationGetsendresultRequest;
import com.dingtalk.api.request.OapiMessageCorpconversationRecallRequest;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
-import com.dingtalk.api.response.OapiMessageCorpconversationGetsendresultResponse;
import com.dingtalk.api.response.OapiMessageCorpconversationRecallResponse;
import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant;
@@ -179,7 +178,7 @@ public class DingDingWorkNoticeHandler extends BaseHandler{
OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest();
req.setAgentId(Long.valueOf(account.getAgentId()));
req.setTaskId(456L);
- OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken);
+ client.execute(req, accessToken);
} catch (Exception e) {
log.error("DingDingWorkNoticeHandler#pull fail:{}", Throwables.getStackTraceAsString(e));
}
diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java
index e2dfb03..f55d779 100644
--- a/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java
+++ b/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java
@@ -13,7 +13,7 @@ import java.util.Date;
* @author 3y
*/
public class TaskInfoUtils {
- private static final int TYPE_FLAG = 1000000;
+ private static final long TYPE_FLAG = 1000000L;
private static final String CODE = "track_code_bid";
private TaskInfoUtils() {
}
@@ -34,7 +34,7 @@ public class TaskInfoUtils {
*/
public static Long generateBusinessId(Long templateId, Integer templateType) {
Integer today = Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN));
- return Long.valueOf(String.format("%d%s", templateType * TYPE_FLAG + templateId, today));
+ return Long.valueOf(String.format("%d%s", templateType.longValue() * TYPE_FLAG + templateId, today));
}
/**
From b0e49b89bedb62d49cdc32706339db998f27b986 Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Thu, 11 Jul 2024 17:20:22 +0800
Subject: [PATCH 4/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E5=9B=9B=EF=BC=89=EF=BC=9A=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E6=96=87=E4=BB=B6=E6=93=8D=E4=BD=9C=E7=BB=93=E6=9E=9C=E4=B8=8D?=
=?UTF-8?q?=E5=8F=AF=E5=BF=BD=E7=95=A5=E3=80=81=E9=9A=8F=E6=9C=BA=E6=95=B0?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E4=BD=BF=E7=94=A8SecureRandom=E7=B1=BB?=
=?UTF-8?q?=E3=80=81BasicResultVO=E6=BD=9C=E5=9C=A8=E5=8F=8D=E5=BA=8F?=
=?UTF-8?q?=E5=88=97=E5=8C=96=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../austin/common/vo/BasicResultVO.java | 4 +-
.../handler/handler/impl/SmsHandler.java | 9 +++-
.../austin/support/utils/AustinFileUtils.java | 52 +++++++++++++------
.../controller/MessageTemplateController.java | 6 ++-
4 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/austin-common/src/main/java/com/java3y/austin/common/vo/BasicResultVO.java b/austin-common/src/main/java/com/java3y/austin/common/vo/BasicResultVO.java
index ab21633..7840ee9 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/vo/BasicResultVO.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/vo/BasicResultVO.java
@@ -6,6 +6,8 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
+import java.io.Serializable;
+
/**
* @author zzb
* @since 2021.11.17
@@ -15,7 +17,7 @@ import lombok.ToString;
@ToString(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
-public final class BasicResultVO {
+public final class BasicResultVO implements Serializable {
/**
* 响应状态
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java
index 00b7b2f..ee0369f 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java
@@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Random;
/**
* 短信发送处理
@@ -44,6 +44,11 @@ public class SmsHandler extends BaseHandler{
private static final Integer AUTO_FLOW_RULE = 0;
private static final String FLOW_KEY = "msgTypeSmsConfig";
private static final String FLOW_KEY_PREFIX = "message_type_";
+ /**
+ * 安全随机数,重用性能与随机数质量更高
+ */
+ private static final SecureRandom secureRandom = new SecureRandom();
+
@Autowired
private SmsRecordDao smsRecordDao;
@Autowired
@@ -99,7 +104,7 @@ public class SmsHandler extends BaseHandler{
}
// 生成一个随机数[1,total],看落到哪个区间
- int index = new Random().nextInt(total) + 1;
+ int index = secureRandom.nextInt(total) + 1;
MessageTypeSmsConfig supplier = null;
MessageTypeSmsConfig supplierBack = null;
diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java
index a366a62..1129807 100644
--- a/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java
+++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java
@@ -33,7 +33,6 @@ public class AustinFileUtils {
* @return
*/
public static File getRemoteUrl2File(String path, String remoteUrl) {
-
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
try {
@@ -41,7 +40,11 @@ public class AustinFileUtils {
File file = new File(path, url.getPath());
inputStream = url.openStream();
if (!file.exists()) {
- file.getParentFile().mkdirs();
+ boolean res = file.getParentFile().mkdirs();
+ if (!res) {
+ log.error("AustinFileUtils#getRemoteUrl2File Failed to create folder, path:{}, remoteUrl:{}", path, remoteUrl);
+ return null;
+ }
fileOutputStream = new FileOutputStream(file);
IoUtil.copy(inputStream, fileOutputStream);
}
@@ -49,20 +52,8 @@ public class AustinFileUtils {
} catch (Exception e) {
log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl);
} finally {
- if (Objects.nonNull(inputStream)) {
- try {
- inputStream.close();
- } catch (IOException e) {
- log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
- }
- }
- if (Objects.nonNull(fileOutputStream)) {
- try {
- fileOutputStream.close();
- } catch (IOException e) {
- log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
- }
- }
+ closeQuietly(inputStream);
+ closeQuietly(fileOutputStream);
}
return null;
}
@@ -85,4 +76,33 @@ public class AustinFileUtils {
return files;
}
+ /**
+ * 关闭InputStream流
+ *
+ * @param inputStream
+ */
+ private static void closeQuietly(InputStream inputStream) {
+ if (Objects.nonNull(inputStream)) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
+ }
+ }
+ }
+
+ /**
+ * 关闭FileOutputStream流
+ *
+ * @param fileOutputStream
+ */
+ private static void closeQuietly(FileOutputStream fileOutputStream) {
+ if (Objects.nonNull(fileOutputStream)) {
+ try {
+ fileOutputStream.close();
+ } catch (IOException e) {
+ log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
+ }
+ }
+ }
}
diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java
index aab3477..ea62a21 100644
--- a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java
+++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java
@@ -201,7 +201,11 @@ public class MessageTemplateController {
try {
File localFile = new File(filePath);
if (!localFile.exists()) {
- localFile.mkdirs();
+ boolean res = localFile.mkdirs();
+ if (!res) {
+ log.error("MessageTemplateController#upload fail! Failed to create folder.");
+ throw new CommonException(RespStatusEnum.SERVICE_ERROR);
+ }
}
file.transferTo(localFile);
} catch (Exception e) {
From 4be4e3c9f22004883e84f5aba7c11b71b1c3d4a0 Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Thu, 11 Jul 2024 18:56:53 +0800
Subject: [PATCH 5/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E4=BA=94=EF=BC=89=EF=BC=9A=E5=86=85=E9=83=A8?=
=?UTF-8?q?=E7=B1=BB=E6=94=B9=E4=B8=BAstatic=E7=B1=BB=E5=9E=8B=E3=80=81par?=
=?UTF-8?q?seXXX=E6=9B=BF=E6=8D=A2valueOf()(=E6=95=88=E7=8E=87=E6=9B=B4?=
=?UTF-8?q?=E9=AB=98)=E3=80=81=E9=9D=99=E6=80=81=E5=B8=B8=E9=87=8F?=
=?UTF-8?q?=E9=9B=86=E5=90=88=E6=94=B9=E4=B8=BA=E4=B8=8D=E5=8F=AF=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9=E3=80=81=E5=87=8F=E5=B0=91=E6=8B=86=E7=AE=B1=E8=A3=85?=
=?UTF-8?q?=E7=AE=B1=E6=93=8D=E4=BD=9C=E3=80=81=E4=BC=98=E9=9B=85=E5=85=B3?=
=?UTF-8?q?=E9=97=AD=E6=B5=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../austin/cron/xxl/utils/XxlJobUtils.java | 2 +-
.../handler/domain/sms/LinTongSendResult.java | 2 +-
.../impl/action/send/SendAfterCheckAction.java | 9 ++++++---
.../austin/stream/utils/LettuceRedisUtils.java | 2 +-
.../austin/web/utils/SpringFileUtils.java | 18 +++++-------------
5 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java
index f10bf8d..77d984b 100644
--- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java
+++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java
@@ -84,7 +84,7 @@ public class XxlJobUtils {
if (Objects.isNull(basicResultVO.getData())) {
XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build();
if (RespStatusEnum.SUCCESS.getCode().equals(cronTaskService.createGroup(xxlJobGroup).getStatus())) {
- return (int) cronTaskService.getGroupId(appName, jobHandlerName).getData();
+ return (Integer) cronTaskService.getGroupId(appName, jobHandlerName).getData();
}
}
return basicResultVO.getData();
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/LinTongSendResult.java b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/LinTongSendResult.java
index 8229f57..27d682d 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/LinTongSendResult.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/LinTongSendResult.java
@@ -32,7 +32,7 @@ public class LinTongSendResult {
@Data
@AllArgsConstructor
@NoArgsConstructor
- public class DataDTO {
+ public static class DataDTO {
Integer code;
String message;
Long msgId;
diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/send/SendAfterCheckAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/send/SendAfterCheckAction.java
index b6da121..9213a7c 100644
--- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/send/SendAfterCheckAction.java
+++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/send/SendAfterCheckAction.java
@@ -31,11 +31,14 @@ public class SendAfterCheckAction implements BusinessProcess {
/**
* 邮件和手机号正则
*/
- protected static final Map CHANNEL_REGEX_EXP = new HashMap<>();
+ protected static final Map CHANNEL_REGEX_EXP;
static {
- CHANNEL_REGEX_EXP.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
- CHANNEL_REGEX_EXP.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
+ Map tempMap = new HashMap<>();
+ tempMap.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
+ tempMap.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
+ // 初始化为不可变集合,避免被恶意修改
+ CHANNEL_REGEX_EXP = Collections.unmodifiableMap(tempMap);
}
diff --git a/austin-stream/src/main/java/com/java3y/austin/stream/utils/LettuceRedisUtils.java b/austin-stream/src/main/java/com/java3y/austin/stream/utils/LettuceRedisUtils.java
index 0639839..f156909 100644
--- a/austin-stream/src/main/java/com/java3y/austin/stream/utils/LettuceRedisUtils.java
+++ b/austin-stream/src/main/java/com/java3y/austin/stream/utils/LettuceRedisUtils.java
@@ -27,7 +27,7 @@ public class LettuceRedisUtils {
static {
RedisURI redisUri = RedisURI.Builder.redis(AustinFlinkConstant.REDIS_IP)
- .withPort(Integer.valueOf(AustinFlinkConstant.REDIS_PORT))
+ .withPort(Integer.parseInt(AustinFlinkConstant.REDIS_PORT))
.withPassword(AustinFlinkConstant.REDIS_PASSWORD.toCharArray())
.build();
redisClient = RedisClient.create(redisUri);
diff --git a/austin-web/src/main/java/com/java3y/austin/web/utils/SpringFileUtils.java b/austin-web/src/main/java/com/java3y/austin/web/utils/SpringFileUtils.java
index 8af9482..021845a 100644
--- a/austin-web/src/main/java/com/java3y/austin/web/utils/SpringFileUtils.java
+++ b/austin-web/src/main/java/com/java3y/austin/web/utils/SpringFileUtils.java
@@ -1,18 +1,19 @@
package com.java3y.austin.web.utils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Objects;
/**
* @author 3y
* multipartFile 转成 File 对象
*/
+@Slf4j
public class SpringFileUtils {
private SpringFileUtils() {
}
@@ -26,23 +27,14 @@ public class SpringFileUtils {
public static File getFile(MultipartFile multipartFile) {
String fileName = multipartFile.getOriginalFilename();
File file = new File(fileName);
- OutputStream out = null;
- try {
- out = new FileOutputStream(file);
+ try (OutputStream out = new FileOutputStream(file)){
byte[] ss = multipartFile.getBytes();
for (int i = 0; i < ss.length; i++) {
out.write(ss[i]);
}
} catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (Objects.nonNull(out)) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ log.error("SpringFileUtils#getFile multipartFile is converted to File error:{}", e);
+ return null;
}
return file;
}
From 5c2f39cd493d787f43722e012dd9d9cc2ae8e74f Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Fri, 12 Jul 2024 11:12:05 +0800
Subject: [PATCH 6/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E5=85=AD=EF=BC=89=EF=BC=9A=E4=BC=98=E5=8C=96?=
=?UTF-8?q?Map=E8=BF=AD=E4=BB=A3=E6=96=B9=E5=BC=8F=E6=8F=90=E9=AB=98?=
=?UTF-8?q?=E6=80=A7=E8=83=BD=E3=80=81=E6=98=BE=E7=A4=BA=E6=8C=87=E5=AE=9A?=
=?UTF-8?q?=E5=AD=97=E7=AC=A6=E7=BC=96=E7=A0=81UTF-8(=E5=87=8F=E5=B0=91?=
=?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=B7=AE=E5=BC=82)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../austin/common/constant/CommonConstant.java | 2 +-
.../java3y/austin/cron/utils/ReadFileUtils.java | 12 +++++++++---
.../handler/impl/DingDingRobotHandler.java | 2 +-
.../handler/receiver/kafka/ReceiverStart.java | 5 +++--
.../receiver/rabbit/RabbitMqReceiver.java | 3 ++-
.../java3y/austin/stream/sink/AustinSink.java | 15 ++++++++-------
.../java3y/austin/support/utils/OkHttpUtils.java | 10 +++++-----
.../java3y/austin/support/utils/RedisUtils.java | 16 ++++++++++------
8 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java
index 4f8aac9..3f8c366 100644
--- a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java
+++ b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java
@@ -35,7 +35,7 @@ public class CommonConstant {
/**
* 编码格式
*/
- public static final String CHARSET_NAME = "UTF-8";
+ public static final String CHARSET_UTF_8 = "UTF-8";
/**
* HTTP请求内容格式
*/
diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java b/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java
index ce05f04..653da76 100644
--- a/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java
+++ b/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java
@@ -4,12 +4,16 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.csv.*;
+import cn.hutool.core.util.CharsetUtil;
import com.google.common.base.Throwables;
import com.java3y.austin.cron.csv.CountFileRowHandler;
import com.java3y.austin.cron.vo.CrowdInfoVo;
import lombok.extern.slf4j.Slf4j;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.*;
/**
@@ -37,7 +41,8 @@ public class ReadFileUtils {
public static void getCsvRow(String path, CsvRowHandler csvRowHandler) {
// 把首行当做是标题,获取reader
- try (CsvReader reader = CsvUtil.getReader(new FileReader(path),
+ try (CsvReader reader = CsvUtil.getReader(
+ new InputStreamReader(Files.newInputStream(Paths.get(path)), CharsetUtil.CHARSET_UTF_8),
new CsvReadConfig().setContainsHeader(true))) {
reader.read(csvRowHandler);
} catch (Exception e) {
@@ -54,7 +59,8 @@ public class ReadFileUtils {
public static long countCsvRow(String path, CountFileRowHandler countFileRowHandler) {
// 把首行当做是标题,获取reader
- try (CsvReader reader = CsvUtil.getReader(new FileReader(path),
+ try (CsvReader reader = CsvUtil.getReader(
+ new InputStreamReader(new FileInputStream(path), CharsetUtil.CHARSET_UTF_8),
new CsvReadConfig().setContainsHeader(true))) {
reader.read(countFileRowHandler);
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java
index 1474d8b..0c0d885 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java
@@ -128,7 +128,7 @@ public class DingDingRobotHandler extends BaseHandler{
Mac mac = Mac.getInstance(CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO);
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
- sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), CommonConstant.CHARSET_NAME);
+ sign = URLEncoder.encode(new String(Base64.encodeBase64(signData), CommonConstant.CHARSET_UTF_8));
} catch (Exception e) {
log.error("DingDingHandler#assembleSign fail!:{}", Throwables.getStackTraceAsString(e));
}
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java
index 4ba8cc0..dcebc20 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java
@@ -84,14 +84,15 @@ public class ReceiverStart {
@Bean
public ConcurrentKafkaListenerContainerFactory filterContainerFactory(@Value("${austin.business.tagId.key}") String tagIdKey,
@Value("${austin.business.tagId.value}") String tagIdValue) {
- ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
+ ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.setAckDiscarded(true);
factory.setRecordFilterStrategy(consumerRecord -> {
if (Optional.ofNullable(consumerRecord.value()).isPresent()) {
for (Header header : consumerRecord.headers()) {
- if (header.key().equals(tagIdKey) && new String(header.value()).equals(new String(tagIdValue.getBytes(StandardCharsets.UTF_8)))) {
+ if (header.key().equals(tagIdKey) &&
+ new String(header.value(), StandardCharsets.UTF_8).equals(tagIdValue)) {
return false;
}
}
diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java
index edbadff..ab56379 100644
--- a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java
+++ b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
+import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -42,7 +43,7 @@ public class RabbitMqReceiver implements MessageReceiver {
public void onMessage(Message message) {
String messageType = message.getMessageProperties().getHeader("messageType");
byte[] body = message.getBody();
- String messageContent = new String(body);
+ String messageContent = new String(body, StandardCharsets.UTF_8);
if (StringUtils.isBlank(messageContent)) {
return;
}
diff --git a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java
index ef4a145..dca72f7 100644
--- a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java
+++ b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java
@@ -13,6 +13,7 @@ import io.lettuce.core.RedisFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
@@ -50,8 +51,8 @@ public class AustinSink implements SinkFunction {
*/
String redisMessageKey = CharSequenceUtil.join(StrPool.COLON, AustinConstant.CACHE_KEY_PREFIX, AustinConstant.MESSAGE_ID, info.getMessageId());
SimpleAnchorInfo messageAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
- redisFutures.add(redisAsyncCommands.lpush(redisMessageKey.getBytes(), JSON.toJSONString(messageAnchorInfo).getBytes()));
- redisFutures.add(redisAsyncCommands.expire(redisMessageKey.getBytes(), Duration.ofDays(3).toMillis() / 1000));
+ redisFutures.add(redisAsyncCommands.lpush(redisMessageKey.getBytes(StandardCharsets.UTF_8), JSON.toJSONString(messageAnchorInfo).getBytes(StandardCharsets.UTF_8)));
+ redisFutures.add(redisAsyncCommands.expire(redisMessageKey.getBytes(StandardCharsets.UTF_8), Duration.ofDays(3).toMillis() / 1000));
/**
* 1.构建userId维度的链路信息 数据结构list:{key,list}
@@ -59,17 +60,17 @@ public class AustinSink implements SinkFunction {
*/
SimpleAnchorInfo userAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
for (String id : info.getIds()) {
- redisFutures.add(redisAsyncCommands.lpush(id.getBytes(), JSON.toJSONString(userAnchorInfo).getBytes()));
- redisFutures.add(redisAsyncCommands.expire(id.getBytes(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
+ redisFutures.add(redisAsyncCommands.lpush(id.getBytes(StandardCharsets.UTF_8), JSON.toJSONString(userAnchorInfo).getBytes(StandardCharsets.UTF_8)));
+ redisFutures.add(redisAsyncCommands.expire(id.getBytes(StandardCharsets.UTF_8), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
}
/**
* 2.构建消息模板维度的链路信息 数据结构hash:{key,hash}
* key:businessId,hashValue:{state,stateCount}
*/
- redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(),
- String.valueOf(info.getState()).getBytes(), info.getIds().size()));
- redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(),
+ redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(StandardCharsets.UTF_8),
+ String.valueOf(info.getState()).getBytes(StandardCharsets.UTF_8), info.getIds().size()));
+ redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(StandardCharsets.UTF_8),
((DateUtil.offsetDay(new Date(), 30).getTime()) / 1000) - DateUtil.currentSeconds()));
return redisFutures;
diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java
index e4c4f2a..2da5a1f 100644
--- a/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java
+++ b/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java
@@ -70,12 +70,12 @@ public class OkHttpUtils {
StringBuilder sb = new StringBuilder(url);
if (Objects.nonNull(params) && params.keySet().size() > 0) {
boolean firstFlag = true;
- for (String key : params.keySet()) {
+ for (Map.Entry entry : params.entrySet()) {
if (firstFlag) {
- sb.append("?").append(key).append("=").append(params.get(key));
+ sb.append("?").append(entry.getKey()).append("=").append(entry.getValue());
firstFlag = false;
} else {
- sb.append("&").append(key).append("=").append(params.get(key));
+ sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
}
}
@@ -98,8 +98,8 @@ public class OkHttpUtils {
FormBody.Builder formBuilder = new FormBody.Builder();
if (Objects.nonNull(params) && params.keySet().size() > 0) {
- for (String key : params.keySet()) {
- formBuilder.add(key, params.get(key));
+ for (Map.Entry entry : params.entrySet()) {
+ formBuilder.add(entry.getKey(), entry.getValue());
}
}
Request.Builder builder = getBuilderWithHeaders(headers);
diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java
index 71f672f..788c8cc 100644
--- a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java
+++ b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java
@@ -10,6 +10,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Component;
+import java.nio.charset.StandardCharsets;
import java.util.*;
/**
@@ -82,8 +83,8 @@ public class RedisUtils {
try {
redisTemplate.executePipelined((RedisCallback) connection -> {
for (Map.Entry entry : keyValues.entrySet()) {
- connection.setEx(entry.getKey().getBytes(), seconds,
- entry.getValue().getBytes());
+ connection.setEx(entry.getKey().getBytes(StandardCharsets.UTF_8), seconds,
+ entry.getValue().getBytes(StandardCharsets.UTF_8));
}
return null;
});
@@ -99,8 +100,8 @@ public class RedisUtils {
public void lPush(String key, String value, Long seconds) {
try {
redisTemplate.executePipelined((RedisCallback) connection -> {
- connection.lPush(key.getBytes(), value.getBytes());
- connection.expire(key.getBytes(), seconds);
+ connection.lPush(key.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8));
+ connection.expire(key.getBytes(StandardCharsets.UTF_8), seconds);
return null;
});
} catch (Exception e) {
@@ -142,8 +143,11 @@ public class RedisUtils {
try {
redisTemplate.executePipelined((RedisCallback) connection -> {
for (Map.Entry entry : keyValues.entrySet()) {
- connection.hIncrBy(entry.getKey().getBytes(), entry.getValue().getBytes(), delta);
- connection.expire(entry.getKey().getBytes(), seconds);
+ connection.hIncrBy(entry.getKey().getBytes(StandardCharsets.UTF_8),
+ entry.getValue().getBytes(StandardCharsets.UTF_8),
+ delta);
+ connection.expire(entry.getKey().getBytes(StandardCharsets.UTF_8),
+ seconds);
}
return null;
});
From 9da756ee7c3d7caa49ca28a366ac76edbd3dcd1b Mon Sep 17 00:00:00 2001
From: xiaoxiamo <82970607@qq.com>
Date: Fri, 12 Jul 2024 14:18:10 +0800
Subject: [PATCH 7/7] =?UTF-8?q?fix:=20SpotBugs=E6=89=AB=E6=8F=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=88=E4=B8=83=EF=BC=89=EF=BC=9A=E6=9B=B4=E6=94=B9?=
=?UTF-8?q?=E6=B8=85=E9=99=A4StringBuilder=E6=96=B9=E5=BC=8F(=E6=9B=B4?=
=?UTF-8?q?=E6=94=B9getPlaceholderList()=E6=96=B9=E6=B3=95)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java3y/austin/web/utils/Convert4Amis.java | 66 +++++++++----------
1 file changed, 30 insertions(+), 36 deletions(-)
diff --git a/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java b/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java
index 729ae87..9b7fe52 100644
--- a/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java
+++ b/austin-web/src/main/java/com/java3y/austin/web/utils/Convert4Amis.java
@@ -26,7 +26,6 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import java.lang.reflect.Field;
import java.util.*;
-import java.util.stream.Collectors;
/**
* 【该类的逻辑不用看,没有什么意义】
@@ -231,62 +230,57 @@ public class Convert4Amis {
* @return
*/
public static Set getPlaceholderList(String content) {
- char[] textChars = content.toCharArray();
- StringBuilder textSofar = new StringBuilder();
+
+ // 内容为空,直接返回
+ if (content == null || content.isEmpty()) {
+ return Collections.emptySet();
+ }
+
StringBuilder sb = new StringBuilder();
- // 存储占位符 位置信息集合
- List placeholderList = new ArrayList<>();
- // 当前标识
+ Set placeholderSet = new HashSet<>();
int modeTg = IGNORE_TG;
- for (int m = 0; m < textChars.length; m++) {
- char c = textChars[m];
- textSofar.append(c);
+
+ for (char c : content.toCharArray()) {
switch (c) {
- case '{': {
- modeTg = START_TG;
- sb.append(c);
- }
- break;
- case '$': {
+ case '{':
+ if (modeTg == IGNORE_TG) {
+ sb.append(c);
+ modeTg = START_TG;
+ }
+ break;
+ case '$':
if (modeTg == START_TG) {
sb.append(c);
modeTg = READ_TG;
} else {
- if (modeTg == READ_TG) {
- sb = new StringBuilder();
- modeTg = IGNORE_TG;
- }
+ sb.setLength(0);
+ modeTg = IGNORE_TG;
}
- }
- break;
- case '}': {
+ break;
+ case '}':
if (modeTg == READ_TG) {
- modeTg = IGNORE_TG;
sb.append(c);
- String str = sb.toString();
- if (StrUtil.isNotEmpty(str)) {
- placeholderList.add(str);
- textSofar = new StringBuilder();
- }
- sb = new StringBuilder();
+ String placeholder = sb.toString();
+ placeholderSet.add(placeholder.replaceAll("[\\{\\$\\}]", ""));
+ sb.setLength(0);
+ modeTg = IGNORE_TG;
} else if (modeTg == START_TG) {
+ sb.setLength(0);
modeTg = IGNORE_TG;
- sb = new StringBuilder();
}
break;
- }
- default: {
+ default:
if (modeTg == READ_TG) {
sb.append(c);
} else if (modeTg == START_TG) {
+ sb.setLength(0);
modeTg = IGNORE_TG;
- sb = new StringBuilder();
}
- }
+ break;
}
}
- Set result = placeholderList.stream().map(s -> s.replaceAll("\\{", "").replaceAll("\\$", "").replaceAll("\\}", "")).collect(Collectors.toSet());
- return result;
+
+ return placeholderSet;
}
/**