[improvement][project]Optimize certain code structures.

This commit is contained in:
jerryjzhang
2024-09-21 18:13:31 +08:00
parent 4193b84e83
commit ae889bb0ae
8 changed files with 26 additions and 68 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)) {