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 5706711..0665ee8 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-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);
+ }
}
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-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-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..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
@@ -164,10 +164,12 @@ 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()));
+ return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR,
+ response != null ? JSON.toJSONString(response.body()) : "");
}
@Override
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-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/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-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-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-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/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-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-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 7439ef4..9f42452 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
@@ -34,7 +34,6 @@ public class AustinFileUtils {
* @return
*/
public static File getRemoteUrl2File(String path, String remoteUrl) {
-
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
try {
@@ -51,7 +50,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);
}
@@ -59,20 +62,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;
}
@@ -95,4 +86,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-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;
});
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));
}
/**
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) {
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;
}
/**
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;
}