Files
pkAssistant/src/main/java/vvpkassistant/User/mapper/UserDao.java
ziin 994d71a10c feat(pin): 重构置顶逻辑并抽离PkPinService
- 将UserController中置顶/取消置顶逻辑下沉到PkPinService,统一事务与异常处理
- UserDao新增原子增减积分方法,避免并发扣减问题
- VVTools抽取SECONDS_PER_HOUR常量并修复向上取整计算
- 新增EpochSecondProvider等接口与实现,为后续测试提供时钟桩
- 补充PkPinServiceImplTests单元测试,覆盖置顶成功、积分不足、重复取消等场景
2026-02-26 21:53:06 +08:00

33 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package vvpkassistant.User.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;
import vvpkassistant.User.model.UserModel;
@Mapper
public interface UserDao extends BaseMapper<UserModel> {
// 原子扣减积分:当 points >= cost 时扣减,返回受影响行数(1=成功0=积分不足/用户不存在)
default int decreasePointsIfEnough(Integer userId, int cost) {
return update(null, Wrappers.<UserModel>lambdaUpdate()
.eq(UserModel::getId, userId)
.ge(UserModel::getPoints, cost)
.setSql("points = points - " + cost));
}
// 原子增加积分:返回受影响行数(1=成功0=用户不存在)
default int increasePoints(Integer userId, int amount) {
return update(null, Wrappers.<UserModel>lambdaUpdate()
.eq(UserModel::getId, userId)
.setSql("points = points + " + amount));
}
// 根据用户的手机号查询用户
default UserModel queryWithPhoneNumber(String phoneNumber) {
return selectOne(Wrappers.<UserModel>lambdaQuery()
.eq(UserModel::getMobile, phoneNumber));
}
}