Skip to content

Commit 9a4bed0

Browse files
committed
fix: 修复类或方法不存在问题
1 parent 7402e97 commit 9a4bed0

File tree

3 files changed

+151
-26
lines changed

3 files changed

+151
-26
lines changed

spring-boot-base-core/src/main/java/com/starimmortal/core/advice/GlobalExceptionAdvice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ResponseVO<String> handleException(Exception exception) {
5757
*/
5858
@ExceptionHandler(value = HttpException.class)
5959
public ResponseEntity<ResponseVO> handleHttpException(HttpException exception) {
60-
String errorMessage = exception.getIfDefaultMessage() ? codeMessageConfiguration.getMessage(exception.getCode()) : exception.getMessage();
60+
String errorMessage = exception.isDefaultMessage() ? codeMessageConfiguration.getMessage(exception.getCode()) : exception.getMessage();
6161
ResponseVO response = new ResponseVO<>(exception.getCode(), errorMessage);
6262
HttpHeaders httpHeaders = new HttpHeaders();
6363
httpHeaders.setContentType(MediaType.APPLICATION_JSON);

spring-boot-base-core/src/main/java/com/starimmortal/core/util/DateUtil.java

Lines changed: 149 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import java.time.*;
66
import java.time.format.DateTimeFormatter;
77
import java.time.temporal.ChronoField;
8+
import java.time.temporal.ChronoUnit;
89
import java.time.temporal.TemporalAdjusters;
10+
import java.util.Calendar;
911
import java.util.Date;
1012

1113
/**
@@ -15,27 +17,54 @@
1517
*/
1618
public class DateUtil {
1719
/**
18-
* 例如:2018-12-28
20+
* 例如2018-12-28
1921
*/
2022
public static final String DATE = "yyyy-MM-dd";
23+
2124
/**
22-
* 例如:2018-12-28 10:00:00
25+
* 例如2018-12-28 10:00:00
2326
*/
2427
public static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";
28+
29+
/**
30+
* 例如:10:00:00
31+
*/
32+
public static final String TIME = "HH:mm:ss";
33+
2534
/**
26-
* 例如:10:00:00
35+
* 例如:10_00_00
2736
*/
28-
public static final String TIME = "HHmmss";
37+
public static final String TIME_WITH_UNDERLINE = "HH_mm_ss";
38+
2939
/**
30-
* 例如:10:00
40+
* 例如10:00
3141
*/
3242
public static final String TIME_WITHOUT_SECOND = "HH:mm";
3343

3444
/**
35-
* 例如:2018-12-28 10:00
45+
* 例如2018-12-28 10:00
3646
*/
3747
public static final String DATE_TIME_WITHOUT_SECONDS = "yyyy-MM-dd HH:mm";
3848

49+
/**
50+
* 例如:2018-06-08T10:34:56+08:00
51+
*/
52+
public static final String RFC3339 = "yyyy-MM-dd'T'HH:mm:ssXXX";
53+
54+
/**
55+
* 生肖
56+
*/
57+
public static final String[] ZODIAC_ARRAY = {"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"};
58+
59+
/**
60+
* 星座
61+
*/
62+
public static final String[] CONSTELLATION_ARRAY = {"水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座"};
63+
64+
/**
65+
* 月份-天
66+
*/
67+
public static final int[] CONSTELLATION_EDGE_DAY = {20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22};
3968

4069
/**
4170
* 获取年
@@ -94,14 +123,16 @@ public static Date parse(String dateStr, String pattern) {
94123
}
95124

96125
/**
97-
* 解析字符串日期为LocalDateTime
126+
* 为Date增加秒数,减传负数
98127
*
99-
* @param dateStr 日期字符串
100-
* @param pattern 格式
101-
* @return LocalDateTime
128+
* @param date 日期
129+
* @param plusSeconds 要增加的秒数
130+
* @return 新的日期
102131
*/
103-
public static LocalDateTime parseLocalDateTime(String dateStr, String pattern) {
104-
return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(pattern));
132+
public static Date addSeconds(Date date, Long plusSeconds) {
133+
LocalDateTime dateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
134+
LocalDateTime newDateTime = dateTime.plusSeconds(plusSeconds);
135+
return Date.from(newDateTime.atZone(ZoneId.systemDefault()).toInstant());
105136
}
106137

107138
/**
@@ -146,26 +177,26 @@ public static Instant addSeconds(long duration) {
146177
*/
147178
public static Date getStartTime() {
148179
LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
149-
return localDateTime2Date(now);
180+
return localDateTimeToDate(now);
150181
}
151182

152183
/**
153184
* @return 返回当天的结束时间
154185
*/
155186
public static Date getEndTime() {
156187
LocalDateTime now = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).withNano(999);
157-
return localDateTime2Date(now);
188+
return localDateTimeToDate(now);
158189
}
159190

160191
/**
161192
* 减月份
162193
*
163-
* @param months 月份
194+
* @param monthsToSubtract 月份
164195
* @return Date
165196
*/
166-
public static Date minusMonths(long months) {
167-
LocalDate localDate = LocalDate.now().minusMonths(months);
168-
return localDate2Date(localDate);
197+
public static Date minusMonths(long monthsToSubtract) {
198+
LocalDate localDate = LocalDate.now().minusMonths(monthsToSubtract);
199+
return localDateToDate(localDate);
169200
}
170201

171202
/**
@@ -187,7 +218,7 @@ public static long minusSeconds(long seconds) {
187218
* @param localDate LocalDate object
188219
* @return Date object
189220
*/
190-
public static Date localDate2Date(LocalDate localDate) {
221+
public static Date localDateToDate(LocalDate localDate) {
191222
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
192223
return Date.from(zonedDateTime.toInstant());
193224
}
@@ -198,7 +229,7 @@ public static Date localDate2Date(LocalDate localDate) {
198229
* @param localDateTime LocalDateTime object
199230
* @return Date object
200231
*/
201-
public static Date localDateTime2Date(LocalDateTime localDateTime) {
232+
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
202233
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
203234
}
204235

@@ -214,7 +245,7 @@ public static String getFirstDayOfCurrentYear(String pattern) {
214245
pattern = "yyyyMMdd";
215246
}
216247

217-
return format(localDateTime2Date(localDateTime), pattern);
248+
return format(localDateTimeToDate(localDateTime), pattern);
218249
}
219250

220251
/**
@@ -228,7 +259,7 @@ public static String getLastMonthFirstDayOfPreviousYear(String pattern) {
228259
if (!StringUtils.hasText(pattern)) {
229260
pattern = "yyyyMMdd";
230261
}
231-
return format(localDateTime2Date(localDateTime), pattern);
262+
return format(localDateTimeToDate(localDateTime), pattern);
232263
}
233264

234265
/**
@@ -242,7 +273,7 @@ public static String getLastMonthLastDayOfPreviousYear(String pattern) {
242273
if (!StringUtils.hasText(pattern)) {
243274
pattern = "yyyyMMdd";
244275
}
245-
return format(localDateTime2Date(localDateTime), pattern);
276+
return format(localDateTimeToDate(localDateTime), pattern);
246277
}
247278

248279
/**
@@ -256,6 +287,100 @@ public static String getCurrentDay(String pattern) {
256287
if (!StringUtils.hasText(pattern)) {
257288
pattern = "yyyyMMdd";
258289
}
259-
return format(localDateTime2Date(localDateTime), pattern);
290+
return format(localDateTimeToDate(localDateTime), pattern);
291+
}
292+
293+
/**
294+
* 获取本月所对应的月初时间
295+
*
296+
* @return 月初时间
297+
*/
298+
public static Date getFirstDate() {
299+
LocalDateTime now = LocalDateTime.now();
300+
LocalDateTime firstDate = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
301+
return localDateTimeToDate(firstDate);
302+
}
303+
304+
/**
305+
* 获取本月所对应的月末时间
306+
*
307+
* @return 月末时间
308+
*/
309+
public static Date getLastDate() {
310+
LocalDateTime now = LocalDateTime.now();
311+
LocalDateTime endDate = now.plusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS).plus(-1L, ChronoUnit.MILLIS);
312+
return localDateTimeToDate(endDate);
313+
}
314+
315+
/**
316+
* 根据日期获取生肖
317+
*
318+
* @param date 日期
319+
* @return 生肖
320+
*/
321+
public static String getZodiac(Date date) {
322+
Calendar calendar = Calendar.getInstance();
323+
calendar.setTime(date);
324+
return ZODIAC_ARRAY[calendar.get(Calendar.YEAR) % 12];
325+
}
326+
327+
/**
328+
* 根据日期获取星座
329+
*
330+
* @param date 日期
331+
* @return 星座
332+
*/
333+
public static String getConstellation(Date date) {
334+
Calendar calendar = Calendar.getInstance();
335+
calendar.setTime(date);
336+
int month = calendar.get(Calendar.MONTH);
337+
int day = calendar.get(Calendar.DAY_OF_MONTH);
338+
if (day < CONSTELLATION_EDGE_DAY[month]) {
339+
month = month - 1;
340+
}
341+
if (month >= 0) {
342+
return CONSTELLATION_ARRAY[month];
343+
}
344+
return CONSTELLATION_ARRAY[11];
345+
}
346+
347+
/**
348+
* 判断当前时间是否位于开始时间与结束时间之间
349+
*
350+
* @param date 当前时间
351+
* @param start 开始时间
352+
* @param end 结束时间
353+
* @return true || false
354+
*/
355+
public static Boolean isInTimeLine(Date date, Date start, Date end) {
356+
long time = date.getTime();
357+
long startTime = start.getTime();
358+
long endTime = end.getTime();
359+
return time > startTime && time < endTime;
360+
}
361+
362+
/**
363+
* 判断某个时间是否超过当前时间
364+
*
365+
* @param date 开始时间
366+
* @param period 秒数
367+
* @return true || false
368+
*/
369+
public static Boolean isOutOfDate(Date date, Long period) {
370+
long time = addSeconds(date, period).getTime();
371+
long now = Calendar.getInstance().getTimeInMillis();
372+
return now >= time;
373+
}
374+
375+
/**
376+
* 判断过期时间是否超过当前时间
377+
*
378+
* @param expiredTime 过期时间
379+
* @return true || false
380+
*/
381+
public static Boolean isOutOfDate(Date expiredTime) {
382+
long time = expiredTime.getTime();
383+
long now = Calendar.getInstance().getTimeInMillis();
384+
return now >= time;
260385
}
261386
}

spring-boot-jwt/src/main/java/com/starimmortal/jwt/controller/TokenController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.auth0.jwt.exceptions.JWTVerificationException;
77
import com.auth0.jwt.interfaces.Claim;
88
import com.auth0.jwt.interfaces.DecodedJWT;
9+
import com.starimmortal.core.enumeration.Code;
910
import com.starimmortal.core.vo.ResponseVO;
10-
import com.starimmortal.jwt.enumeration.Code;
1111
import com.starimmortal.jwt.vo.TokenVO;
1212
import io.swagger.annotations.Api;
1313
import io.swagger.annotations.ApiOperation;

0 commit comments

Comments
 (0)