修正连续天数的判断问题
This commit is contained in:
parent
28bb3fd5d5
commit
24cbd183de
@ -7,10 +7,13 @@ import me.xiaoyan.point.api.service.SignRecordService;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("sign")
|
@RequestMapping("sign")
|
||||||
public class SignController {
|
public class SignController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
private SignRecordService signRecordService;
|
private SignRecordService signRecordService;
|
||||||
|
|
||||||
@ApiOperation("今日签到")
|
@ApiOperation("今日签到")
|
||||||
|
@ -51,6 +51,14 @@ public class SignRecordServiceImpl extends ServiceImpl<SignRecordMapper, SignRec
|
|||||||
List<Date> dates = new ArrayList<>();
|
List<Date> dates = new ArrayList<>();
|
||||||
if (isSign) {
|
if (isSign) {
|
||||||
dates.add(new Date());
|
dates.add(new Date());
|
||||||
|
}else{
|
||||||
|
// 没有记录直接返回0
|
||||||
|
if(signRecords.size() == 0) return 0;
|
||||||
|
Date firstDate = signRecords.get(0).getCreateTime();
|
||||||
|
// 第一个记录是否是今天
|
||||||
|
if(!DateUtils.isToday(firstDate) && !DateUtils.isYesterday(firstDate)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
signRecords.forEach(it -> dates.add(it.getCreateTime()));
|
signRecords.forEach(it -> dates.add(it.getCreateTime()));
|
||||||
Date[] dateArr = new Date[dates.size()];
|
Date[] dateArr = new Date[dates.size()];
|
||||||
|
@ -2,6 +2,7 @@ package me.xiaoyan.point.api.util;
|
|||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ public class DateUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int continuousDays(Date[] dates) {
|
public static int continuousDays(Date[] dates) {
|
||||||
|
if(dates.length == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int totalDays = 1;
|
int totalDays = 1;
|
||||||
for (int i = 1;i < dates.length; i ++){
|
for (int i = 1;i < dates.length; i ++){
|
||||||
Date d1 = dates[i-1];
|
Date d1 = dates[i-1];
|
||||||
@ -43,6 +47,25 @@ public class DateUtils {
|
|||||||
return totalDays;
|
return totalDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isToday(String d){
|
||||||
|
try {
|
||||||
|
return isToday(full.parse(d));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static boolean isToday(Date d){
|
||||||
|
if(d == null) return false;
|
||||||
|
return today().equalsIgnoreCase(formatDate(d));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isYesterday(Date d){
|
||||||
|
if(d == null) return false;
|
||||||
|
Date today = new Date(); // 今天
|
||||||
|
if(today.getTime() < d.getTime()) return false;
|
||||||
|
return isBetween(today,d);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isBetween(Date d1,Date d2){
|
public static boolean isBetween(Date d1,Date d2){
|
||||||
// 直接获取两个日期之间的毫秒,计算
|
// 直接获取两个日期之间的毫秒,计算
|
||||||
Date date1 = parse(formatDate(d1) + " 00:00:00");
|
Date date1 = parse(formatDate(d1) + " 00:00:00");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user