| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.ruoyi.account.api.model.TAppUserSign; |
| | | import com.ruoyi.account.service.TAppUserSignService; |
| | | import org.springframework.cglib.core.Local; |
| | | import org.springframework.stereotype.Component; |
| | | import sun.rmi.server.LoaderHandler; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | |
| | | return calculateMaxContinuousSignDays(signDays); |
| | | } |
| | | |
| | | public int calculateContinuousSignDays1(Long userId, LocalDate date) { |
| | | DateTime startOfMonth = DateUtil.beginOfMonth(new Date()); |
| | | // DateTime endOfMonth = DateUtil.endOfMonth(new Date()); |
| | | // 获取用户的所有签到记录 |
| | | List<TAppUserSign> signRecords = signService.lambdaQuery() |
| | | .between(TAppUserSign::getSignDay, startOfMonth, date) |
| | | .eq(TAppUserSign::getAppUserId, userId) |
| | | .orderByDesc(TAppUserSign::getSignDay) |
| | | .list(); |
| | | |
| | | // 如果没有签到记录,则返回0 |
| | | if (signRecords.isEmpty()) { |
| | | return 0; |
| | | } |
| | | |
| | | // 将签到日期转换为 LocalDate 列表,并按照日期排序 |
| | | List<LocalDate> signDays = signRecords.stream() |
| | | .map(TAppUserSign::getSignDay) |
| | | .sorted() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算连续签到的最大天数 |
| | | return calculateMaxContinuousSignDays(signDays); |
| | | } |
| | | |
| | | /** |
| | | * 根据签到日期列表计算连续签到的最大天数 |
| | | * @param signDays 签到日期列表 |