|
|
@@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -174,50 +176,75 @@ public class ScreenUtil {
|
|
|
*/
|
|
|
private String TimeFormat(String value){
|
|
|
String formatValue = "";
|
|
|
- LocalDate localDate = LocalDate.now();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
switch (value) {
|
|
|
case "today" :
|
|
|
- formatValue = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "yesterday" :
|
|
|
- formatValue = localDate.plusDays(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "week" :
|
|
|
- formatValue = localDate.plusWeeks(0).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusWeeks(0).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
|
|
+ formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "lastweek" :
|
|
|
- formatValue = localDate.plusWeeks(-1).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusWeeks(-1).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.add(Calendar.WEEK_OF_YEAR, -1);
|
|
|
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
|
|
+ formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "month" :
|
|
|
- formatValue = localDate.plusMonths(0).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusWeeks(0).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
+ formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "lastmonth" :
|
|
|
- formatValue = localDate.plusMonths(-1).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusMonths(-1).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.add(Calendar.MONTH, -1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
+ formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "quarter" :
|
|
|
- formatValue = quarterStart(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + quarterStart(0).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ formatValue = simpleDateFormat.format(quarterStart(0).getTime()) + ",";
|
|
|
+ Calendar c1 = quarterStart(0);
|
|
|
+ c1.add(Calendar.MONTH, 2);
|
|
|
+ formatValue += simpleDateFormat.format(c1.getTime());
|
|
|
break;
|
|
|
case "lastquarter" :
|
|
|
- formatValue = quarterStart(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + quarterStart(-1).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
- formatValue = "";
|
|
|
+ formatValue = simpleDateFormat.format(quarterStart(-2).getTime()) + ",";
|
|
|
+ Calendar c2 = quarterStart(0);
|
|
|
+ c2.add(Calendar.MONTH, 2);
|
|
|
+ formatValue += simpleDateFormat.format(c2.getTime());
|
|
|
break;
|
|
|
case "halfyear" :
|
|
|
- formatValue = localDate.plusMonths(-6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.add(Calendar.MONTH, -6);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar = Calendar.getInstance();
|
|
|
+ formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
break;
|
|
|
case "year" :
|
|
|
- formatValue = localDate.plusYears(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusWeeks(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.roll(Calendar.DAY_OF_YEAR, -1);
|
|
|
+ formatValue += calendar.getTime();
|
|
|
break;
|
|
|
case "lastyear" :
|
|
|
- formatValue = localDate.plusYears(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
- + localDate.plusWeeks(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
+ formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
+ calendar.roll(Calendar.DAY_OF_YEAR, -1);
|
|
|
+ formatValue += calendar.getTime();
|
|
|
break;
|
|
|
default:
|
|
|
formatValue = value;
|
|
|
@@ -226,9 +253,9 @@ public class ScreenUtil {
|
|
|
return formatValue;
|
|
|
}
|
|
|
|
|
|
- private static LocalDate quarterStart(int offset) {
|
|
|
- final LocalDate date = LocalDate.now().plusMonths(offset * 3);
|
|
|
- int month = date.getMonth().getValue();//当月
|
|
|
+ private static Calendar quarterStart(int offset) {
|
|
|
+ final Calendar calendar = Calendar.getInstance();
|
|
|
+ int month = calendar.get(Calendar.MONTH);//当月
|
|
|
int start = 0;
|
|
|
if (month >= 1 && month <= 3) {//第一季度
|
|
|
start = 1;
|
|
|
@@ -242,6 +269,8 @@ public class ScreenUtil {
|
|
|
start = 12;
|
|
|
month = 14;
|
|
|
}
|
|
|
- return date.plusMonths(start - month).with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ calendar.add(Calendar.MONTH,start - month);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ return calendar;
|
|
|
}
|
|
|
}
|