release: 已参与抽奖的人(APP) 和 抽奖结果(APP)

release-2024-08-08
huangyw 4 months ago
parent 24467b787f
commit c0fbb9d7a5

@ -4,10 +4,7 @@ import annotation.GlobalInterceptor;
import api.PageResult;
import api.Result;
import com.luoo.user.dto.point.*;
import com.luoo.user.pojo.Lottery;
import com.luoo.user.pojo.LotteryRegion;
import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.pojo.*;
import com.luoo.user.service.DrawLotteryService;
import com.luoo.user.service.LotteryService;
import com.luoo.user.service.TaskPointService;
@ -330,5 +327,24 @@ public class PointController {
return Result.success(lotteryService.findLotteryListForApp(page, size, lotterySearchDto, token));
}
@ApiOperation(value = "3.10.已参与抽奖的人(APP)", notes = "APP")
@PostMapping("/lottery/participated/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<LotteryUser>> findParticipatedLotteryUserList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "抽奖id") String lotteryId,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(lotteryService.findPageByLotteryId(page, size, lotteryId));
}
@ApiOperation(value = "3.11.抽奖结果(APP)", notes = "APP")
@PostMapping("/lottery/result/{id}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Integer> findLotteryResult(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "抽奖id", required = true) @PathVariable String id) {
return Result.success(lotteryService.getLotteryUserResult(id, token));
}
}

@ -10,10 +10,10 @@ public interface LotteryUserDao extends JpaRepository<LotteryUser, String>,
public List<LotteryUser> findByLotteryId(String lotteryId);
public List<LotteryUser> findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId,
public LotteryUser findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId,
Integer regionId);
public List<LotteryUser> findByLotteryIdAndUserId(String lotteryId, String userId);
public LotteryUser findByLotteryIdAndUserId(String lotteryId, String userId);
public List<LotteryUser> findByLotteryIdAndRegionId(String lotteryId, Integer regionId);

@ -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();
}
}

Loading…
Cancel
Save