From 7c27a163e0de99ddab5117fab84f70c77ed9fc52 Mon Sep 17 00:00:00 2001 From: pikaqiudeshujia Date: Thu, 5 Dec 2024 10:07:02 +0800 Subject: [PATCH] =?UTF-8?q?release-=203.9=E6=96=B0=E5=A2=9E=E7=AD=9B?= =?UTF-8?q?=E9=80=89=20=E4=BB=85=E6=98=BE=E7=A4=BA=E6=9C=AC=E4=BA=BA?= =?UTF-8?q?=E5=8F=82=E4=B8=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/dto/point/LotterySearchDto.java | 3 + .../com/luoo/user/service/LotteryService.java | 116 ++++++++++++------ 2 files changed, 82 insertions(+), 37 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java index 516a0a1..6f3a46e 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java @@ -44,4 +44,7 @@ public class LotterySearchDto { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime endTime; + + @ApiModelProperty(value = "只显示我参与的 1- 只显示我参与的") + private Integer myJoin; } 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 41cb5d2..f2fe293 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 @@ -5,11 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import com.fasterxml.jackson.databind.ObjectMapper; import com.luoo.user.Scheduler.DrawLotteryScheduler; import com.luoo.user.config.EnvConfig; -import com.luoo.user.dao.LotteryDao; -import com.luoo.user.dao.LotteryRegionDao; -import com.luoo.user.dao.LotteryUserDao; -import com.luoo.user.dao.UserInfoDao; -import com.luoo.user.dao.UserPointLogDao; +import com.luoo.user.dao.*; import com.luoo.user.dto.point.DrawDTO; import com.luoo.user.dto.point.LotteryParticipatedSearchDto; import com.luoo.user.dto.point.LotterySearchDto; @@ -31,7 +27,6 @@ import enums.UserBetaEnum; import enums.UserTypeEnum; import enums.UserVipStatusEnum; import exception.BizException; -import java.util.concurrent.atomic.AtomicReference; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -55,6 +50,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; /** * @program: luoo_parent @@ -539,41 +535,86 @@ public class LotteryService { return new PageResult<>(jpaQueryFactory.select(qLottery.count()).from(qLottery).where(booleanBuilder).fetchOne(), list); } - public PageResult lotteryAPPVOPageResult(Integer page, Integer size, LotterySearchDto lotterySearchDto) { + public PageResult lotteryAPPVOPageResult(Integer page, Integer size, LotterySearchDto lotterySearchDto, UserLoginDto userLoginDto) { BooleanBuilder booleanBuilder = new BooleanBuilder(); QLottery qLottery = QLottery.lottery; checkCondition(booleanBuilder, qLottery, lotterySearchDto); booleanBuilder.and(qLottery.status.in(new Integer[]{PointEnums.LOTTERY_STATUS_LOTTERY.getCode(), PointEnums.LOTTERY_STATUS_SIGN.getCode()})); // 创建分页对象 Pageable pageable = PageRequest.of(page - 1, size); - List list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class, - qLottery.id, - qLottery.code, - qLottery.title, - qLottery.type, - qLottery.num, - qLottery.participant, - qLottery.point, - qLottery.regionCode, - qLottery.regionName, - qLottery.applyStartTime, - qLottery.applyEndTime, - qLottery.drawTime, - qLottery.way, - qLottery.image, - qLottery.description, - qLottery.status, - qLottery.createTime, - qLottery.stopReason, - qLottery.price, - qLottery.publishTime - )).from(qLottery) - .where(booleanBuilder) - .orderBy(qLottery.status.asc(), qLottery.publishTime.desc()) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetch(); - return new PageResult<>(jpaQueryFactory.select(qLottery.count()).from(qLottery).where(booleanBuilder).fetchOne(), list); + List list = new ArrayList<>(); + Long count = 0L; + if (lotterySearchDto.getMyJoin() != null && 1 == lotterySearchDto.getMyJoin()) { + if (userLoginDto != null) { + QLotteryUser qLotteryUser = QLotteryUser.lotteryUser; + booleanBuilder.and(qLotteryUser.userId.eq(userLoginDto.getUserId())); + // 只显示本人参与的 + list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class, + qLottery.id, + qLottery.code, + qLottery.title, + qLottery.type, + qLottery.num, + qLottery.participant, + qLottery.point, + qLottery.regionCode, + qLottery.regionName, + qLottery.applyStartTime, + qLottery.applyEndTime, + qLottery.drawTime, + qLottery.way, + qLottery.image, + qLottery.description, + qLottery.status, + qLottery.createTime, + qLottery.stopReason, + qLottery.price, + qLottery.publishTime + )).from(qLottery) + .innerJoin(qLotteryUser) + .on(qLotteryUser.lotteryId.eq(qLottery.id)) + .where(booleanBuilder) + .orderBy(qLottery.status.asc(), qLottery.publishTime.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + count = jpaQueryFactory.select(qLottery.count()).from(qLottery) + .innerJoin(qLotteryUser) + .on(qLotteryUser.lotteryId.eq(qLottery.id)) + .where(booleanBuilder) + .fetchOne(); + } + } else { + list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class, + qLottery.id, + qLottery.code, + qLottery.title, + qLottery.type, + qLottery.num, + qLottery.participant, + qLottery.point, + qLottery.regionCode, + qLottery.regionName, + qLottery.applyStartTime, + qLottery.applyEndTime, + qLottery.drawTime, + qLottery.way, + qLottery.image, + qLottery.description, + qLottery.status, + qLottery.createTime, + qLottery.stopReason, + qLottery.price, + qLottery.publishTime + )).from(qLottery) + .where(booleanBuilder) + .orderBy(qLottery.status.asc(), qLottery.publishTime.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + count = jpaQueryFactory.select(qLottery.count()).from(qLottery).where(booleanBuilder).fetchOne(); + } + return new PageResult<>(count, list); } private void checkCondition(BooleanBuilder booleanBuilder, QLottery qLottery, LotterySearchDto lotterySearch) { @@ -604,10 +645,11 @@ public class LotteryService { public PageResult findLotteryListForApp(Integer page, Integer size, LotterySearchDto lotterySearchDto, String token) { - PageResult lotteryPageResult = lotteryAPPVOPageResult(page, size, lotterySearchDto); + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + PageResult lotteryPageResult = lotteryAPPVOPageResult(page, size, lotterySearchDto, userLoginDto); lotteryPageResult.getRows().forEach(lottery -> { if (StringUtils.isNotBlank(token)) { - UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + LotteryUser lotteryUser = lotteryUserDao.findByLotteryIdAndUserId(lottery.getId(), userLoginDto.getUserId()); if (lotteryUser != null) { lottery.setIsParticipate(PointEnums.PARTICIPATED.getCode());