From c0fbb9d7a57fa6ce1b93b2a3d51cd0fde0c60369 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Mon, 5 Aug 2024 15:31:45 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E5=B7=B2=E5=8F=82=E4=B8=8E=E6=8A=BD?= =?UTF-8?q?=E5=A5=96=E7=9A=84=E4=BA=BA(APP)=20=E5=92=8C=20=E6=8A=BD?= =?UTF-8?q?=E5=A5=96=E7=BB=93=E6=9E=9C(APP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/PointController.java | 24 ++++++++-- .../com/luoo/user/dao/LotteryUserDao.java | 4 +- .../com/luoo/user/service/LotteryService.java | 44 +++++++++++++++---- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java index 5754315..d190982 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java @@ -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> 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 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)); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java b/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java index 7691f6d..cde78fe 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java @@ -10,10 +10,10 @@ public interface LotteryUserDao extends JpaRepository, public List findByLotteryId(String lotteryId); - public List findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId, + public LotteryUser findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId, Integer regionId); - public List findByLotteryIdAndUserId(String lotteryId, String userId); + public LotteryUser findByLotteryIdAndUserId(String lotteryId, String userId); public List findByLotteryIdAndRegionId(String lotteryId, Integer regionId); diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index ff478fc..0729901 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -309,10 +309,6 @@ public class LotteryService { // 校验用户是否可参与 UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); - List 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 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 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 findPageByLotteryId(Integer page, Integer size, String lotteryId) { + Sort sort = new Sort(Direction.DESC, "createTime"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + + Specification specification = getLotteryUserSpecification(lotteryId); + Page lotteryUserPage = lotteryUserDao.findAll(specification, pageRequest); + + long totalElements = lotteryUserPage.getTotalElements(); + return new PageResult<>(totalElements, lotteryUserPage.getContent()); + } + + private Specification getLotteryUserSpecification(String lotteryId) { + return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { + List 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(); + } }