|
|
|
@ -309,10 +309,6 @@ public class LotteryService {
|
|
|
|
|
|
|
|
|
|
// 校验用户是否可参与
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
List<LotteryUser> list = lotteryUserDao.findByLotteryIdAndUserId(id, userLoginDto.getUserId());
|
|
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
|
|
throw new BizException(ErrorConstants.ALREADY_PARTICIPATED_CANNOT_PARTICIPATE_AGAIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer participant = lottery.getParticipant();
|
|
|
|
|
if (Objects.equals(participant, PointEnums.LOTTERY_ALL_MEMBER.getCode())) {
|
|
|
|
@ -340,9 +336,9 @@ public class LotteryService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<LotteryUser> checkUserList = lotteryUserDao.findByLotteryIdAndUserIdAndRegionId(
|
|
|
|
|
id, userLoginDto.getUserId(), regionId);
|
|
|
|
|
if (!checkUserList.isEmpty()) {
|
|
|
|
|
LotteryUser checkLotteryUser = lotteryUserDao.findByLotteryIdAndUserId(
|
|
|
|
|
id, userLoginDto.getUserId());
|
|
|
|
|
if (checkLotteryUser != null) {
|
|
|
|
|
throw new BizException(ErrorConstants.ALREADY_PARTICIPATED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -398,8 +394,8 @@ public class LotteryService {
|
|
|
|
|
lotteryPageResult.getRows().forEach(lottery -> {
|
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
List<LotteryUser> list = lotteryUserDao.findByLotteryIdAndUserId(lottery.getId(), userLoginDto.getUserId());
|
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
|
LotteryUser lotteryUser = lotteryUserDao.findByLotteryIdAndUserId(lottery.getId(), userLoginDto.getUserId());
|
|
|
|
|
if (lotteryUser != null) {
|
|
|
|
|
lottery.setIsParticipate(PointEnums.PARTICIPATED.getCode());
|
|
|
|
|
} else {
|
|
|
|
|
lottery.setIsParticipate(PointEnums.NOT_PARTICIPATED.getCode());
|
|
|
|
@ -449,5 +445,35 @@ public class LotteryService {
|
|
|
|
|
return lotteryRegionList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PageResult<LotteryUser> findPageByLotteryId(Integer page, Integer size, String lotteryId) {
|
|
|
|
|
Sort sort = new Sort(Direction.DESC, "createTime");
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
|
|
|
|
|
|
Specification<LotteryUser> specification = getLotteryUserSpecification(lotteryId);
|
|
|
|
|
Page<LotteryUser> lotteryUserPage = lotteryUserDao.findAll(specification, pageRequest);
|
|
|
|
|
|
|
|
|
|
long totalElements = lotteryUserPage.getTotalElements();
|
|
|
|
|
return new PageResult<>(totalElements, lotteryUserPage.getContent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<LotteryUser> getLotteryUserSpecification(String lotteryId) {
|
|
|
|
|
return (Root<LotteryUser> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(lotteryId)) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.equal(root.get("lotteryId"), lotteryId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getLotteryUserResult(String lotteryId, String token) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
LotteryUser lotteryUser = lotteryUserDao.findByLotteryIdAndUserId(lotteryId, userLoginDto.getUserId());
|
|
|
|
|
|
|
|
|
|
return lotteryUser.getResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|