mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
code review:签到逻辑
This commit is contained in:
parent
3e570b8b89
commit
0db4581030
@ -93,6 +93,7 @@ public class ProductSpuController {
|
|||||||
// 查询商品 SKU
|
// 查询商品 SKU
|
||||||
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
|
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
|
||||||
// 查询优惠卷
|
// 查询优惠卷
|
||||||
|
// TODO @puhui999:优惠劵的信息,要不交给前端读取?主要是为了避免商品依赖 promotion 模块哈;
|
||||||
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
|
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
|
||||||
spu.getGiveCouponTemplateIds());
|
spu.getGiveCouponTemplateIds());
|
||||||
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList));
|
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList));
|
||||||
|
@ -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;
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author xia
|
|
||||||
*/
|
|
||||||
@Schema(description = "管理后台 - Banner 分页 Request VO")
|
@Schema(description = "管理后台 - Banner 分页 Request VO")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class BannerPageReqVO extends PageParam {
|
public class BannerPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
// TODO @puhui999:example
|
||||||
@Schema(description = "标题")
|
@Schema(description = "标题")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync
|
|||||||
@Validated
|
@Validated
|
||||||
public class AppBannerController {
|
public class AppBannerController {
|
||||||
|
|
||||||
@Resource
|
// TODO @puhui999:这个目前不缓存,也没问题,因为首页没用到。
|
||||||
private BannerService bannerService;
|
|
||||||
/**
|
/**
|
||||||
* {@link AppBannerRespVO} 缓存,通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据
|
* {@link AppBannerRespVO} 缓存,通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据
|
||||||
*/
|
*/
|
||||||
@ -41,6 +40,9 @@ public class AppBannerController {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BannerService bannerService;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "获得 banner 列表")
|
@Operation(summary = "获得 banner 列表")
|
||||||
@Parameter(name = "position", description = "Banner position", example = "1")
|
@Parameter(name = "position", description = "Banner position", example = "1")
|
||||||
|
@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
// TODO @puhui999:表名改成 promotion_banner,然后有序加下;另外,sql 给我下哈;还有那个 position 字典,嘿嘿。
|
||||||
/**
|
/**
|
||||||
* banner DO
|
* banner DO
|
||||||
*
|
*
|
||||||
@ -61,6 +62,4 @@ public class BannerDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer browseCount;
|
private Integer browseCount;
|
||||||
|
|
||||||
// TODO 芋艿 其他数据相关
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,19 +48,20 @@ public interface MemberSignInRecordConvert {
|
|||||||
// 1. 计算今天是第几天签到
|
// 1. 计算今天是第几天签到
|
||||||
long day = ChronoUnit.DAYS.between(firstRecord.getCreateTime(), LocalDateTime.now());
|
long day = ChronoUnit.DAYS.between(firstRecord.getCreateTime(), LocalDateTime.now());
|
||||||
// 2. 初始化签到信息
|
// 2. 初始化签到信息
|
||||||
|
// TODO @puhui999:signInRecord=》record
|
||||||
MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId)
|
MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId)
|
||||||
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数
|
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数 TODO @puhui999:day 应该跟着第几天签到走;不是累加哈;另外 long 转 int,应该 (int) day 就可以了。。。
|
||||||
.setPoint(0) // 设置签到积分默认为 0
|
.setPoint(0) // 设置签到积分默认为
|
||||||
.setExperience(0); // 设置签到经验默认为 0
|
.setExperience(0); // 设置签到经验默认为 0
|
||||||
|
|
||||||
|
|
||||||
// 3. 获取签到对应的积分数
|
// 3. 获取签到对应的积分数
|
||||||
MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数
|
MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数
|
||||||
if (day > lastConfig.getDay()) { // 超出范围按第一天的经验计算
|
if (day > lastConfig.getDay()) { // 超出范围按第一天的经验计算
|
||||||
|
// TODO @puhui999:不能直接取 0,万一它 day 不匹配哈。就是第一天没奖励。。。
|
||||||
signInRecord.setPoint(signInConfigs.get(0).getPoint());
|
signInRecord.setPoint(signInConfigs.get(0).getPoint());
|
||||||
signInRecord.setExperience(signInConfigs.get(0).getExperience());
|
signInRecord.setExperience(signInConfigs.get(0).getExperience());
|
||||||
return signInRecord;
|
return signInRecord;
|
||||||
}
|
}
|
||||||
|
// TODO @puhui999:signInConfig 可以改成 config;
|
||||||
MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day));
|
MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day));
|
||||||
if (signInConfig == null) {
|
if (signInConfig == null) {
|
||||||
return signInRecord;
|
return signInRecord;
|
||||||
|
@ -35,9 +35,9 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
|
|||||||
.orderByDesc(MemberSignInRecordDO::getId));
|
.orderByDesc(MemberSignInRecordDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:这 2 个方法,是不是一个 first;一个 last 就可以了。。
|
||||||
/**
|
/**
|
||||||
* 获取用户最近的签到记录信息,根据签到时间倒序
|
* 获取用户最近的签到记录信息,根据签到时间倒序
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @return 签到记录列表
|
* @return 签到记录列表
|
||||||
@ -63,6 +63,7 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
default Long selectCountByUserId(Long userId) {
|
default Long selectCountByUserId(Long userId) {
|
||||||
|
// TODO @puhui999:可以使用 selectCount 里面允许传递字段的方法
|
||||||
return selectCount(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
return selectCount(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
||||||
.eq(MemberSignInRecordDO::getUserId, userId));
|
.eq(MemberSignInRecordDO::getUserId, userId));
|
||||||
}
|
}
|
||||||
@ -73,6 +74,7 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
|
|||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @return 签到记录信息
|
* @return 签到记录信息
|
||||||
*/
|
*/
|
||||||
|
// TODO @puhui999:这个排序,可以交给 service 哈;
|
||||||
default List<MemberSignInRecordDO> selectListByUserId(Long userId) {
|
default List<MemberSignInRecordDO> selectListByUserId(Long userId) {
|
||||||
return selectList(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
return selectList(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
||||||
.eq(MemberSignInRecordDO::getUserId, userId)
|
.eq(MemberSignInRecordDO::getUserId, userId)
|
||||||
|
@ -58,6 +58,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
@Override
|
@Override
|
||||||
public AppMemberSignInRecordSummaryRespVO getSignInRecordSummary(Long userId) {
|
public AppMemberSignInRecordSummaryRespVO getSignInRecordSummary(Long userId) {
|
||||||
// 1. 初始化默认返回信息
|
// 1. 初始化默认返回信息
|
||||||
|
// TODO @puhui999:这里 vo 改成 summary 会更好理解;
|
||||||
AppMemberSignInRecordSummaryRespVO vo = new AppMemberSignInRecordSummaryRespVO();
|
AppMemberSignInRecordSummaryRespVO vo = new AppMemberSignInRecordSummaryRespVO();
|
||||||
vo.setTotalDay(0);
|
vo.setTotalDay(0);
|
||||||
vo.setContinuousDay(0);
|
vo.setContinuousDay(0);
|
||||||
@ -71,6 +72,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
vo.setTotalDay(signCount.intValue()); // 设置总签到天数
|
vo.setTotalDay(signCount.intValue()); // 设置总签到天数
|
||||||
|
|
||||||
// 3. 校验当天是否有签到
|
// 3. 校验当天是否有签到
|
||||||
|
// TODO @puhui999:是不是 signInRecord 可以精简成 record 哈;另外,Desc 貌似可以去掉哈;最后一条了;
|
||||||
MemberSignInRecordDO signInRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId);
|
MemberSignInRecordDO signInRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId);
|
||||||
if (signInRecord == null) {
|
if (signInRecord == null) {
|
||||||
return vo;
|
return vo;
|
||||||
@ -82,6 +84,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
// 4.1. 判断连续签到天数
|
// 4.1. 判断连续签到天数
|
||||||
|
// TODO @puhui999:连续签到,可以基于 signInRecord 的 day 和当前时间判断呀?
|
||||||
List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId);
|
List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId);
|
||||||
vo.setContinuousDay(calculateConsecutiveDays(signInRecords));
|
vo.setContinuousDay(calculateConsecutiveDays(signInRecords));
|
||||||
return vo;
|
return vo;
|
||||||
@ -164,7 +167,6 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
if (!ObjectUtils.equalsAny(record.getExperience(), null, 0)) {
|
if (!ObjectUtils.equalsAny(record.getExperience(), null, 0)) {
|
||||||
memberLevelService.addExperience(userId, record.getExperience(), MemberExperienceBizTypeEnum.SIGN_IN, String.valueOf(record.getId()));
|
memberLevelService.addExperience(userId, record.getExperience(), MemberExperienceBizTypeEnum.SIGN_IN, String.valueOf(record.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user