[CMLR-060] 修复跨表归属并新增 SignInRecordDao
This commit is contained in:
32
src/main/java/vvpkassistant/User/mapper/SignInRecordDao.java
Normal file
32
src/main/java/vvpkassistant/User/mapper/SignInRecordDao.java
Normal file
@@ -0,0 +1,32 @@
|
||||
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.SignInRecord;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Mapper
|
||||
public interface SignInRecordDao extends BaseMapper<SignInRecord> {
|
||||
|
||||
default int signIn(int userId) {
|
||||
SignInRecord record = new SignInRecord();
|
||||
record.setUserId(userId);
|
||||
record.setTime(todayInShanghai());
|
||||
return insert(record);
|
||||
}
|
||||
|
||||
default int checkSignStatus(int userId) {
|
||||
return Math.toIntExact(selectCount(Wrappers.<SignInRecord>lambdaQuery()
|
||||
.eq(SignInRecord::getUserId, userId)
|
||||
.eq(SignInRecord::getTime, todayInShanghai())));
|
||||
}
|
||||
|
||||
static int todayInShanghai() {
|
||||
return Integer.parseInt(LocalDate.now(ZoneId.of("Asia/Shanghai"))
|
||||
.format(DateTimeFormatter.BASIC_ISO_DATE));
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,8 @@ package vvpkassistant.User.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import vvpkassistant.User.model.UserModel;
|
||||
import vvpkassistant.pk.model.PkRecord;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserDao extends BaseMapper<UserModel> {
|
||||
@@ -19,20 +14,4 @@ public interface UserDao extends BaseMapper<UserModel> {
|
||||
.eq(UserModel::getMobile, phoneNumber));
|
||||
}
|
||||
|
||||
// 我邀请的pk数据
|
||||
@Select("SELECT * FROM pk_record WHERE user_id_b = #{userId} ORDER BY id DESC LIMIT #{page}, #{size};")
|
||||
List<PkRecord> getMyGuestPkList(@Param("userId") Integer userId , @Param("page") Integer page, @Param("size") Integer size);
|
||||
|
||||
// 我发起的pk数据
|
||||
@Select("SELECT * FROM pk_record WHERE user_id_a = #{userId} ORDER BY id DESC LIMIT #{page}, #{size};")
|
||||
List<PkRecord> findCreatedPk(@Param("userId") Integer userId , @Param("page") Integer page, @Param("size") Integer size);
|
||||
|
||||
// 签到
|
||||
@Insert("insert into `sign_in_records` set user_id = #{userId} , time = replace(current_date, '-', '')")
|
||||
int signIn(@Param("userId") int userId);
|
||||
|
||||
// 查询当天签到状态
|
||||
@Select("SELECT COUNT(*) FROM `sign_in_records` WHERE user_id = #{userId} AND time = REPLACE(CURDATE(), '-', '')")
|
||||
int checkSignStatus(@Param("userId") int userId);
|
||||
|
||||
}
|
||||
|
||||
15
src/main/java/vvpkassistant/User/model/SignInRecord.java
Normal file
15
src/main/java/vvpkassistant/User/model/SignInRecord.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package vvpkassistant.User.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("sign_in_records")
|
||||
public class SignInRecord {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer time;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class PkController {
|
||||
@PostMapping("fetchDetailPkDataWithId")
|
||||
public ResponseData<Object> fetchDetailPkDataWithId(@RequestBody PkFetchDetailDTO request) {
|
||||
Integer id = request.getId();
|
||||
List<PkRecordDetail> pkRecordDetails = recordDao.fetchDetailPkDataWithId(id);
|
||||
List<PkRecordDetail> pkRecordDetails = detailDao.queryDetail(id);
|
||||
return ResponseData.success(pkRecordDetails);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import vvpkassistant.Data.ResponseData;
|
||||
import vvpkassistant.Data.ResponseInfo;
|
||||
import vvpkassistant.Data.WxChatParam;
|
||||
import vvpkassistant.User.mapper.UserDao;
|
||||
import vvpkassistant.User.mapper.SignInRecordDao;
|
||||
import vvpkassistant.User.model.DTO.ScanInfoDTO;
|
||||
import vvpkassistant.User.model.DTO.UserCancelPinDTO;
|
||||
import vvpkassistant.User.model.DTO.UserHandlePkInfoDTO;
|
||||
@@ -30,6 +31,7 @@ import vvpkassistant.exception.BusinessException;
|
||||
import vvpkassistant.mail.model.MailModel;
|
||||
import vvpkassistant.mail.service.MailService;
|
||||
import vvpkassistant.pk.mapper.PkInfoDao;
|
||||
import vvpkassistant.pk.mapper.PkRecordDao;
|
||||
import vvpkassistant.pk.model.PkInfoModel;
|
||||
import vvpkassistant.pk.model.PkRecordDetail;
|
||||
import vvpkassistant.pk.mapper.PkRecordDetailDao;
|
||||
@@ -52,9 +54,15 @@ public class UserController {
|
||||
@Autowired
|
||||
private PkRecordDetailDao detailDao;
|
||||
|
||||
@Autowired
|
||||
private PkRecordDao recordDao;
|
||||
|
||||
@Autowired
|
||||
private CoinRecordsDao coinRecordsDao;
|
||||
|
||||
@Autowired
|
||||
private SignInRecordDao signInRecordDao;
|
||||
|
||||
@Autowired
|
||||
private WxChatParam wxChatParam;
|
||||
|
||||
@@ -241,10 +249,10 @@ public class UserController {
|
||||
|
||||
// 我发起的pk数据
|
||||
if (type == 1) {
|
||||
return ResponseData.success(userDao.findCreatedPk(id, page * size, size));
|
||||
return ResponseData.success(recordDao.findCreatedPk(id, page * size, size));
|
||||
}else if (type == 2){
|
||||
// 别人邀请我的pk数据
|
||||
return ResponseData.success(userDao.getMyGuestPkList(id, page * size, size));
|
||||
return ResponseData.success(recordDao.getMyGuestPkList(id, page * size, size));
|
||||
}
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||
}
|
||||
@@ -262,12 +270,12 @@ public class UserController {
|
||||
@PostMapping("signIn")
|
||||
public ResponseData<Object> signIn() {
|
||||
int userId = Integer.parseInt(StpUtil.getLoginId().toString());
|
||||
int i = userDao.checkSignStatus(userId);
|
||||
int i = signInRecordDao.checkSignStatus(userId);
|
||||
if (i != 0) {
|
||||
throw new BusinessException(ErrorCode.SIGN_IN_FAIL);
|
||||
}
|
||||
|
||||
int result = userDao.signIn(userId);
|
||||
int result = signInRecordDao.signIn(userId);
|
||||
UserModel userModel = userDao.selectById(userId);
|
||||
int count = Integer.parseInt(FunctionConfigHolder.getValue("签到增加积分"));
|
||||
|
||||
@@ -290,7 +298,7 @@ public class UserController {
|
||||
// 查询用户当天签到状态
|
||||
@GetMapping("checkSignStatus")
|
||||
public ResponseData<Object> checkSignStatus(Integer userId) {
|
||||
int i = userDao.checkSignStatus(userId);
|
||||
int i = signInRecordDao.checkSignStatus(userId);
|
||||
return i == 0 ? ResponseData.success(true) : ResponseData.success(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,13 +88,4 @@ public interface PkInfoDao extends BaseMapper<PkInfoModel> {
|
||||
.gt(PkInfoModel::getPkTime, currentTime));
|
||||
}
|
||||
|
||||
// 查询当前用户与该主播是否存在未完成的pk记录
|
||||
@Select("SELECT COUNT(*) FROM `pk_record`\n" +
|
||||
"WHERE (user_id_a = #{userId} OR user_id_b = #{userId})\n" +
|
||||
"AND (anchor_id_a = #{anchorId} OR anchor_id_b = #{anchorId})\n" +
|
||||
"AND pk_status = 1\n" +
|
||||
"AND pk_time > UNIX_TIMESTAMP()")
|
||||
Integer checkIfUnfinishedPKExistsWithAnchor(@Param("userId") Integer userId, @Param("anchorId") String anchorId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ package vvpkassistant.pk.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import vvpkassistant.pk.model.PkRecordDetail;
|
||||
import vvpkassistant.pk.model.PkRecord;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,10 +40,35 @@ public interface PkRecordDao extends BaseMapper<PkRecord> {
|
||||
return selectById(id);
|
||||
}
|
||||
|
||||
// 我邀请的pk数据
|
||||
default List<PkRecord> getMyGuestPkList(Integer userId, Integer page, Integer size) {
|
||||
return selectList(Wrappers.<PkRecord>lambdaQuery()
|
||||
.eq(PkRecord::getUserIdB, userId)
|
||||
.orderByDesc(PkRecord::getId)
|
||||
.last(String.format("limit %d, %d", page, size)));
|
||||
}
|
||||
|
||||
// 查询每场pk的详细数据
|
||||
@Select("select * from pk_record_detail where pk_record_id = #{id}")
|
||||
List<PkRecordDetail> fetchDetailPkDataWithId(@Param("id") Integer id);
|
||||
// 我发起的pk数据
|
||||
default List<PkRecord> findCreatedPk(Integer userId, Integer page, Integer size) {
|
||||
return selectList(Wrappers.<PkRecord>lambdaQuery()
|
||||
.eq(PkRecord::getUserIdA, userId)
|
||||
.orderByDesc(PkRecord::getId)
|
||||
.last(String.format("limit %d, %d", page, size)));
|
||||
}
|
||||
|
||||
// 查询当前用户与该主播是否存在未完成的pk记录
|
||||
default int checkIfUnfinishedPKExistsWithAnchor(Integer userId, String anchorId) {
|
||||
long currentTime = System.currentTimeMillis() / 1000;
|
||||
return Math.toIntExact(selectCount(Wrappers.<PkRecord>lambdaQuery()
|
||||
.and(wrapper -> wrapper.eq(PkRecord::getUserIdA, userId)
|
||||
.or()
|
||||
.eq(PkRecord::getUserIdB, userId))
|
||||
.and(wrapper -> wrapper.eq(PkRecord::getAnchorIdA, anchorId)
|
||||
.or()
|
||||
.eq(PkRecord::getAnchorIdB, anchorId))
|
||||
.eq(PkRecord::getPkStatus, 1)
|
||||
.gt(PkRecord::getPkTime, String.valueOf(currentTime))));
|
||||
}
|
||||
|
||||
// 查询主播是否存在pk记录
|
||||
default int existsPkRecordByAnchor(String id) {
|
||||
|
||||
@@ -221,7 +221,7 @@ public class PKServiceImpl extends ServiceImpl<PkInfoDao, PkInfoModel> implement
|
||||
pkInfoModel.setDisPlayId(pkInfoModel.getAnchorId());
|
||||
} else {
|
||||
// 查询是否存在未完成的pk记录
|
||||
Integer isHave = pkInfoDao.checkIfUnfinishedPKExistsWithAnchor(userId, pkInfoModel.getAnchorId());
|
||||
Integer isHave = pkRecordDao.checkIfUnfinishedPKExistsWithAnchor(userId, pkInfoModel.getAnchorId());
|
||||
if (isHave > 0) {
|
||||
pkInfoModel.setDisPlayId(pkInfoModel.getAnchorId());
|
||||
} else {
|
||||
@@ -233,7 +233,7 @@ public class PKServiceImpl extends ServiceImpl<PkInfoDao, PkInfoModel> implement
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"当前信息已无效");
|
||||
}
|
||||
} else {
|
||||
Integer isHave = pkInfoDao.checkIfUnfinishedPKExistsWithAnchor(userId, pkInfoModel.getAnchorId());
|
||||
Integer isHave = pkRecordDao.checkIfUnfinishedPKExistsWithAnchor(userId, pkInfoModel.getAnchorId());
|
||||
if (isHave > 0) {
|
||||
pkInfoModel.setDisPlayId(pkInfoModel.getAnchorId());
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user