mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
[improvement][project]Optimize certain code structures.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tencent.supersonic.auth.authentication.interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.tencent.supersonic.common.pojo.enums;
|
||||
|
||||
public enum ErrorCode {
|
||||
MULTIPLE_ERRORS_PLACEHOLDER,
|
||||
MULTIPLE_ERRORS,
|
||||
NULL_POINTER,
|
||||
ILLEGAL_ARGUMENT,
|
||||
ILLEGAL_STATE,
|
||||
NO_PERMISSION,
|
||||
INDEX_OUT_OF_BOUND,
|
||||
DUPLICATED_THEME,
|
||||
UNKNOWN;
|
||||
|
||||
private ErrorCode() {}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.tencent.supersonic.common.pojo.enums;
|
||||
|
||||
public enum SinkDbEnum {
|
||||
TDW("TDW"),
|
||||
|
||||
DORIS("DORIS"),
|
||||
|
||||
ICEBERY("ICEBERY"),
|
||||
|
||||
NOT_SUPPORT("NOT_SUPPORT");
|
||||
|
||||
private String db;
|
||||
|
||||
SinkDbEnum(String db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public String getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public static SinkDbEnum of(String name) {
|
||||
for (SinkDbEnum item : SinkDbEnum.values()) {
|
||||
if (item.db.equalsIgnoreCase(name)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return SinkDbEnum.NOT_SUPPORT;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.tencent.supersonic.common.pojo.enums;
|
||||
|
||||
public enum TimeMode {
|
||||
|
||||
// a specific date at N days ago
|
||||
// a single date at N days ago
|
||||
LAST,
|
||||
// a period of time from N days ago to today
|
||||
// a period of date from N days ago to today
|
||||
RECENT,
|
||||
// a period of time from the first day of current month/year to today
|
||||
// a period of date from the first day of current month/year to today
|
||||
CURRENT
|
||||
}
|
||||
|
||||
@@ -24,11 +24,14 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
public class DateUtils {
|
||||
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String FORMAT = "yyyyMMddHHmmss";
|
||||
private static final DateTimeFormatter dateTimeFormatter =
|
||||
DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String DEFAULT_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
private static final DateTimeFormatter DEFAULT_DATE_FORMATTER2 =
|
||||
DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
|
||||
private static final SimpleDateFormat DEFAULT_DATE_FORMATTER =
|
||||
new SimpleDateFormat(DEFAULT_DATE_FORMAT);
|
||||
private static final SimpleDateFormat DEFAULT_TIME_FORMATTER =
|
||||
new SimpleDateFormat(DEFAULT_DATE_FORMAT);
|
||||
|
||||
public static DateTimeFormatter getDateFormatter(String date, String[] formats) {
|
||||
for (int i = 0; i < formats.length; i++) {
|
||||
@@ -66,13 +69,13 @@ public class DateUtils {
|
||||
if (Objects.isNull(datePeriodEnum)) {
|
||||
datePeriodEnum = DatePeriodEnum.DAY;
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
|
||||
String currentDate = dateFormat.format(new Date());
|
||||
return getBeforeDate(currentDate, intervalDay, datePeriodEnum);
|
||||
}
|
||||
|
||||
public static String getBeforeDate(String currentDate, DatePeriodEnum datePeriodEnum) {
|
||||
LocalDate specifiedDate = LocalDate.parse(currentDate, dateTimeFormatter);
|
||||
LocalDate specifiedDate = LocalDate.parse(currentDate, DEFAULT_DATE_FORMATTER2);
|
||||
LocalDate startDate;
|
||||
switch (datePeriodEnum) {
|
||||
case MONTH:
|
||||
@@ -85,12 +88,12 @@ public class DateUtils {
|
||||
startDate = specifiedDate;
|
||||
}
|
||||
|
||||
return startDate.format(dateTimeFormatter);
|
||||
return startDate.format(DEFAULT_DATE_FORMATTER2);
|
||||
}
|
||||
|
||||
public static String getBeforeDate(
|
||||
String currentDate, int intervalDay, DatePeriodEnum datePeriodEnum) {
|
||||
LocalDate specifiedDate = LocalDate.parse(currentDate, dateTimeFormatter);
|
||||
LocalDate specifiedDate = LocalDate.parse(currentDate, DEFAULT_DATE_FORMATTER2);
|
||||
LocalDate result = null;
|
||||
switch (datePeriodEnum) {
|
||||
case DAY:
|
||||
@@ -133,7 +136,7 @@ public class DateUtils {
|
||||
default:
|
||||
}
|
||||
if (Objects.nonNull(result)) {
|
||||
return result.format(DateTimeFormatter.ofPattern(DATE_FORMAT));
|
||||
return result.format(DEFAULT_DATE_FORMATTER2);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -142,9 +145,9 @@ public class DateUtils {
|
||||
public static String format(Date date) {
|
||||
DateFormat dateFormat;
|
||||
if (containsTime(date)) {
|
||||
dateFormat = new SimpleDateFormat(DateUtils.TIME_FORMAT);
|
||||
dateFormat = DEFAULT_TIME_FORMATTER;
|
||||
} else {
|
||||
dateFormat = new SimpleDateFormat(DateUtils.DATE_FORMAT);
|
||||
dateFormat = DEFAULT_DATE_FORMATTER;
|
||||
}
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class S2SqlDateHelper {
|
||||
private static String reformatDate(String dateStr, String format) {
|
||||
try {
|
||||
// Assuming the input date format is "yyyy-MM-dd"
|
||||
SimpleDateFormat inputFormat = new SimpleDateFormat(DateUtils.DATE_FORMAT);
|
||||
SimpleDateFormat inputFormat = new SimpleDateFormat(DateUtils.DEFAULT_DATE_FORMAT);
|
||||
Date date = inputFormat.parse(dateStr);
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat(format);
|
||||
return outputFormat.format(date);
|
||||
|
||||
@@ -155,10 +155,10 @@ public class SqlUtils {
|
||||
private Object getValue(Object value) {
|
||||
if (value instanceof LocalDate) {
|
||||
LocalDate localDate = (LocalDate) value;
|
||||
return localDate.format(DateTimeFormatter.ofPattern(DateUtils.DATE_FORMAT));
|
||||
return localDate.format(DateTimeFormatter.ofPattern(DateUtils.DEFAULT_DATE_FORMAT));
|
||||
} else if (value instanceof LocalDateTime) {
|
||||
LocalDateTime localDateTime = (LocalDateTime) value;
|
||||
return localDateTime.format(DateTimeFormatter.ofPattern(DateUtils.TIME_FORMAT));
|
||||
return localDateTime.format(DateTimeFormatter.ofPattern(DateUtils.DEFAULT_TIME_FORMAT));
|
||||
} else if (value instanceof Date) {
|
||||
Date date = (Date) value;
|
||||
return DateUtils.format(date);
|
||||
|
||||
@@ -60,6 +60,8 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
|
||||
private static final long downloadSize = 10000;
|
||||
|
||||
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||
|
||||
private MetricService metricService;
|
||||
|
||||
private DimensionService dimensionService;
|
||||
@@ -80,8 +82,7 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
DownloadMetricReq downloadMetricReq, User user, HttpServletResponse response)
|
||||
throws Exception {
|
||||
String fileName =
|
||||
String.format(
|
||||
"%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), DateUtils.FORMAT));
|
||||
String.format("%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), dateFormat));
|
||||
File file = FileUtils.createTmpFile(fileName);
|
||||
try {
|
||||
QueryStructReq queryStructReq = metricService.convert(downloadMetricReq);
|
||||
@@ -108,8 +109,7 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
BatchDownloadReq batchDownloadReq, User user, HttpServletResponse response)
|
||||
throws Exception {
|
||||
String fileName =
|
||||
String.format(
|
||||
"%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), DateUtils.FORMAT));
|
||||
String.format("%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), dateFormat));
|
||||
File file = FileUtils.createTmpFile(fileName);
|
||||
List<Long> metricIds = batchDownloadReq.getMetricIds();
|
||||
if (CollectionUtils.isEmpty(metricIds)) {
|
||||
|
||||
Reference in New Issue
Block a user