|
@@ -8,7 +8,10 @@ import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
import cn.newfeifan.mall.framework.common.util.date.DateUtils;
|
|
|
import cn.newfeifan.mall.framework.common.util.object.ObjectUtils;
|
|
|
import cn.newfeifan.mall.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO;
|
|
|
+import cn.newfeifan.mall.module.member.controller.app.signin.vo.record.AppMemberSignInConfigMoonRespVO;
|
|
|
import cn.newfeifan.mall.module.member.controller.app.signin.vo.record.AppMemberSignInRecordSummaryRespVO;
|
|
|
+import cn.newfeifan.mall.module.member.controller.app.signin.vo.record.Days;
|
|
|
+import cn.newfeifan.mall.module.member.controller.app.signin.vo.record.Rules;
|
|
|
import cn.newfeifan.mall.module.member.convert.signin.MemberSignInRecordConvert;
|
|
|
import cn.newfeifan.mall.module.member.dal.dataobject.signin.MemberSignInConfigDO;
|
|
|
import cn.newfeifan.mall.module.member.dal.dataobject.signin.MemberSignInRecordDO;
|
|
@@ -25,6 +28,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
@@ -84,6 +91,70 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|
|
return summary;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AppMemberSignInConfigMoonRespVO getOwnSignInMoon(Long loginUserId) {
|
|
|
+
|
|
|
+ // 获取当前月份, 天数 , 星期数
|
|
|
+ List<Days> days = generateDaysForCurrentMonth();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
+ LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth());
|
|
|
+
|
|
|
+ // 获取签到的天数
|
|
|
+ // 查询用户当月的签到情况
|
|
|
+ List<MemberSignInRecordDO> lastRecordInMoon = signInRecordMapper.selectListByUserIdInCurrentMoon(loginUserId,
|
|
|
+ Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()),
|
|
|
+ Date.from(lastDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant())
|
|
|
+ );
|
|
|
+ for (MemberSignInRecordDO memberSignInRecordDO : lastRecordInMoon) {
|
|
|
+ updateDayByNumber(days,memberSignInRecordDO.getDay());
|
|
|
+ }
|
|
|
+
|
|
|
+ MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(loginUserId);
|
|
|
+ return AppMemberSignInConfigMoonRespVO.builder()
|
|
|
+ .days(days)
|
|
|
+ .continueDays(lastRecord.getDay())
|
|
|
+ .rules(Rules.builder().build())
|
|
|
+ .continueDays(0).build();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void updateDayByNumber(List<Days> daysList, int day) {
|
|
|
+ for (Days dayObj : daysList) {
|
|
|
+ if (dayObj.getDay() == day) {
|
|
|
+ dayObj.setIsSign(1);
|
|
|
+ dayObj.setIsReplenish(0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static List<Days> generateDaysForCurrentMonth() {
|
|
|
+ List<Days> daysList = new ArrayList<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
+ LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth());
|
|
|
+
|
|
|
+ for (LocalDate date = firstDayOfMonth; date.isBefore(lastDayOfMonth.plusDays(1)); date = date.plusDays(1)) {
|
|
|
+ Days day = new Days();
|
|
|
+ day.setDate(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ day.setTime(day.getDate().getTime());
|
|
|
+ day.setDay(date.getDayOfMonth());
|
|
|
+ day.setWeek(date.getDayOfWeek().toString());
|
|
|
+
|
|
|
+ if (date.isBefore(today)) {
|
|
|
+ day.setCurrent("before");
|
|
|
+ } else if (date.equals(today)) {
|
|
|
+ day.setCurrent("today");
|
|
|
+ } else {
|
|
|
+ day.setCurrent("after");
|
|
|
+ }
|
|
|
+ daysList.add(day);
|
|
|
+ }
|
|
|
+ return daysList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult<MemberSignInRecordDO> getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) {
|
|
|
// 根据用户昵称查询出用户ids
|