@@ -47,6 +47,11 @@
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.10</version>
+ </dependency>
</dependencies>
<build>
@@ -7,6 +7,7 @@ import com.jkcredit.record.storage.model.MonthResult;
import com.jkcredit.record.storage.service.RecordStorageService;
import com.jkcredit.record.storage.util.MD5Util;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
@@ -43,6 +44,9 @@ public class RecordStorageServiceImpl implements RecordStorageService {
//保存的数据 这里指定json类型
for (MonthResult monthResult : monthResultList) {
String id = MD5Util.MD5(monthResult.getMonth() + "_" + monthResult.getVehicleid());
+ if (StringUtils.isBlank(id)) {
+ id = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + UUID.randomUUID().toString();
+ }
//设置保存的索引和id
String indexName = "index-record-" + monthResult.getMonth();
IndexRequest indexRequest = new IndexRequest(indexName).id(id);
@@ -1,10 +1,13 @@
package com.jkcredit.record.storage.util;
+import lombok.extern.slf4j.Slf4j;
+
import java.security.MessageDigest;
+@Slf4j
public class MD5Util {
- public final static String MD5(String s) {
+ public static String MD5(String s) {
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
try {
byte[] btInput = s.getBytes();
@@ -21,8 +24,8 @@ public class MD5Util {
}
return new String(str);
} catch (Exception e) {
- e.printStackTrace();
- return null;
+ log.error("MD5EncryptException:", e);
+ return "";