签到记录
This commit is contained in:
parent
16b158e5e1
commit
5b632f80d8
|
|
@ -12,7 +12,6 @@ import com.sqx.modules.app.dao.UserDao;
|
|||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.common.dao.CommonInfoDao;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||
import com.sqx.modules.userSign.dao.UserSignRecordDao;
|
||||
import com.sqx.modules.userSign.dto.UserSignDTO;
|
||||
import com.sqx.modules.userSign.dto.UserSignRecordDTO;
|
||||
|
|
@ -24,10 +23,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -62,7 +58,7 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
// 连续签到日期
|
||||
List<String> flowDays = buildFlowDays(beginDay, activeDays);
|
||||
// 实际签到记录
|
||||
List<UserSignRecord> list = baseMapper.selectList(Wrappers.<UserSignRecord>lambdaQuery().eq(UserSignRecord::getUserId, currentUser.getUserId()).orderByAsc(UserSignRecord::getCreateTime));
|
||||
List<UserSignRecord> list = baseMapper.selectList(Wrappers.<UserSignRecord>lambdaQuery().eq(UserSignRecord::getUserId, currentUser.getUserId()).orderByAsc(UserSignRecord::getSignDay).orderByAsc(UserSignRecord::getCreateTime).orderByAsc(UserSignRecord::getId));
|
||||
// 第x天
|
||||
int index = 1;
|
||||
// 连续签到天数
|
||||
|
|
@ -81,8 +77,10 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
dto.setSignDays(signDays);
|
||||
return dto;
|
||||
}
|
||||
flowDays = buildFlowDays(beginDay.plusDays(-6), activeDays);
|
||||
index = 1;
|
||||
LocalDate beginSignDay = LocalDate.parse(list.get(0).getSignDay(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
//LocalDate endDay = LocalDate.parse(list.get(list.size() - 1).getSignDay(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusDays(activeDays);
|
||||
LocalDate endDay = LocalDate.now().plusDays(activeDays - 1);
|
||||
flowDays = buildFlowDays(beginSignDay, endDay);
|
||||
Map<String, Date> signMap = list.stream().collect(Collectors.toMap(UserSignRecord::getSignDay, UserSignRecord::getCreateTime));
|
||||
for (String day : flowDays) {
|
||||
Date date = signMap.get(day);
|
||||
|
|
@ -107,16 +105,29 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
} else if (daysBetween == 0) {
|
||||
record.setShowText("待签到");
|
||||
} else {
|
||||
record.setShowText(StrUtil.format("第{}天", index));
|
||||
record.setShowText("第{}天");
|
||||
}
|
||||
}
|
||||
recordList.add(record);
|
||||
if (signDays == activeDays) {
|
||||
break;
|
||||
}
|
||||
if (LocalDate.parse(record.getSignDay(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).isEqual(endDay.plusDays(0 - signDays))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Collections.reverse(recordList);
|
||||
recordList = recordList.stream().limit(activeDays).collect(Collectors.toList());
|
||||
Collections.reverse(recordList);
|
||||
index = 1;
|
||||
for (UserSignRecordDTO record : recordList) {
|
||||
record.setShowText(StrUtil.format(record.getShowText(), index));
|
||||
index++;
|
||||
}
|
||||
dto.setRecordList(recordList);
|
||||
dto.setSignDays(signDays);
|
||||
// 该用户是否可以继续签到
|
||||
if (signDays >= 7) {
|
||||
if (signDays >= activeDays) {
|
||||
dto.setEnable(0);
|
||||
}
|
||||
return dto;
|
||||
|
|
@ -133,7 +144,7 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Long,Integer> getTaskWCount(long userId,int wCount) {
|
||||
public Map<Long, Integer> getTaskWCount(long userId, int wCount) {
|
||||
Date thirtyDaysAgo = DateUtil.offsetDay(new Date(), -30);
|
||||
List<Long> noRecordTasks = baseMapper.getNoRecordTask(userId, DateUtil.format(thirtyDaysAgo, "yyyy-MM-dd") + " 00:00:00");
|
||||
List<UserSignRecord> taskWCount = baseMapper.getTaskWCount(userId, wCount, DateUtil.format(thirtyDaysAgo, "yyyy-MM-dd") + " 00:00:00", noRecordTasks);
|
||||
|
|
@ -166,5 +177,19 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
}
|
||||
return flowDays;
|
||||
}
|
||||
|
||||
private List<String> buildFlowDays(LocalDate beginDay, LocalDate endDay) {
|
||||
List<String> flowDays = new ArrayList<>();
|
||||
LocalDate tempDay = beginDay;
|
||||
flowDays.add(tempDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
while (true) {
|
||||
if (tempDay.isEqual(endDay)) {
|
||||
break;
|
||||
}
|
||||
tempDay = tempDay.plusDays(1);
|
||||
flowDays.add(tempDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
}
|
||||
return flowDays;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue