code review:签到逻辑

This commit is contained in:
YunaiV 2023-10-21 19:56:53 +08:00
parent 3e570b8b89
commit 0db4581030
7 changed files with 19 additions and 14 deletions

View File

@ -93,6 +93,7 @@ public class ProductSpuController {
// 查询商品 SKU
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
// 查询优惠卷
// TODO @puhui999优惠劵的信息要不交给前端读取主要是为了避免商品依赖 promotion 模块哈
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
spu.getGiveCouponTemplateIds());
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList));

View File

@ -13,15 +13,13 @@ import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* @author xia
*/
@Schema(description = "管理后台 - Banner 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BannerPageReqVO extends PageParam {
// TODO @puhui999example
@Schema(description = "标题")
private String title;

View File

@ -26,8 +26,7 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync
@Validated
public class AppBannerController {
@Resource
private BannerService bannerService;
// TODO @puhui999这个目前不缓存也没问题因为首页没用到
/**
* {@link AppBannerRespVO} 缓存通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据
*/
@ -41,6 +40,9 @@ public class AppBannerController {
});
@Resource
private BannerService bannerService;
@GetMapping("/list")
@Operation(summary = "获得 banner 列表")
@Parameter(name = "position", description = "Banner position", example = "1")

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
// TODO @puhui999表名改成 promotion_banner然后有序加下另外sql 给我下哈还有那个 position 字典嘿嘿
/**
* banner DO
*
@ -61,6 +62,4 @@ public class BannerDO extends BaseDO {
*/
private Integer browseCount;
// TODO 芋艿 其他数据相关
}

View File

@ -48,19 +48,20 @@ public interface MemberSignInRecordConvert {
// 1. 计算今天是第几天签到
long day = ChronoUnit.DAYS.between(firstRecord.getCreateTime(), LocalDateTime.now());
// 2. 初始化签到信息
// TODO @puhui999signInRecord=record
MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId)
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数
.setPoint(0) // 设置签到积分默认为 0
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数 TODO @puhui999day 应该跟着第几天签到走不是累加哈另外 long int应该 (int) day 就可以了
.setPoint(0) // 设置签到积分默认为
.setExperience(0); // 设置签到经验默认为 0
// 3. 获取签到对应的积分数
MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数
if (day > lastConfig.getDay()) { // 超出范围按第一天的经验计算
// TODO @puhui999不能直接取 0万一它 day 不匹配哈就是第一天没奖励
signInRecord.setPoint(signInConfigs.get(0).getPoint());
signInRecord.setExperience(signInConfigs.get(0).getExperience());
return signInRecord;
}
// TODO @puhui999signInConfig 可以改成 config
MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day));
if (signInConfig == null) {
return signInRecord;

View File

@ -35,9 +35,9 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
.orderByDesc(MemberSignInRecordDO::getId));
}
// TODO @puhui999 2 个方法是不是一个 first一个 last 就可以了
/**
* 获取用户最近的签到记录信息,根据签到时间倒序
* 获取用户最近的签到记录信息根据签到时间倒序
*
* @param userId 用户编号
* @return 签到记录列表
@ -63,6 +63,7 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
}
default Long selectCountByUserId(Long userId) {
// TODO @puhui999可以使用 selectCount 里面允许传递字段的方法
return selectCount(new LambdaQueryWrapperX<MemberSignInRecordDO>()
.eq(MemberSignInRecordDO::getUserId, userId));
}
@ -73,6 +74,7 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
* @param userId 用户编号
* @return 签到记录信息
*/
// TODO @puhui999这个排序可以交给 service
default List<MemberSignInRecordDO> selectListByUserId(Long userId) {
return selectList(new LambdaQueryWrapperX<MemberSignInRecordDO>()
.eq(MemberSignInRecordDO::getUserId, userId)

View File

@ -58,6 +58,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
@Override
public AppMemberSignInRecordSummaryRespVO getSignInRecordSummary(Long userId) {
// 1. 初始化默认返回信息
// TODO @puhui999这里 vo 改成 summary 会更好理解
AppMemberSignInRecordSummaryRespVO vo = new AppMemberSignInRecordSummaryRespVO();
vo.setTotalDay(0);
vo.setContinuousDay(0);
@ -71,6 +72,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
vo.setTotalDay(signCount.intValue()); // 设置总签到天数
// 3. 校验当天是否有签到
// TODO @puhui999是不是 signInRecord 可以精简成 record 另外Desc 貌似可以去掉哈最后一条了
MemberSignInRecordDO signInRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId);
if (signInRecord == null) {
return vo;
@ -82,6 +84,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
return vo;
}
// 4.1. 判断连续签到天数
// TODO @puhui999连续签到可以基于 signInRecord day 和当前时间判断呀
List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId);
vo.setContinuousDay(calculateConsecutiveDays(signInRecords));
return vo;
@ -164,7 +167,6 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
if (!ObjectUtils.equalsAny(record.getExperience(), null, 0)) {
memberLevelService.addExperience(userId, record.getExperience(), MemberExperienceBizTypeEnum.SIGN_IN, String.valueOf(record.getId()));
}
return record;
}