From f98edf511964e126806e7945fdc25bb69c56953c Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Thu, 8 Aug 2024 11:46:41 +0800 Subject: [PATCH] =?UTF-8?q?release:=203.9.=E6=8A=BD=E5=A5=96=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B5,=E4=BB=A5=E5=8F=8A=E6=9C=AC=E4=BA=BA?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B7=B2=E5=8F=82=E5=8A=A0(APP)=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E4=B8=8E=E7=94=A8=E6=88=B7=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/PointController.java | 3 +- .../com/luoo/user/service/LotteryService.java | 89 +++++++++-- .../com/luoo/user/vo/point/LotteryAPPVO.java | 141 ++++++++++++++++++ .../luoo/user/vo/point/UserPointLogVO.java | 7 + 4 files changed, 228 insertions(+), 12 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/vo/point/LotteryAPPVO.java 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 6c319c5..e86b122 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 @@ -9,6 +9,7 @@ import com.luoo.user.service.DrawLotteryService; import com.luoo.user.service.LotteryService; import com.luoo.user.service.TaskPointService; import com.luoo.user.service.UserPointLogService; +import com.luoo.user.vo.point.LotteryAPPVO; import com.luoo.user.vo.point.UserPointLogVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -351,7 +352,7 @@ public class PointController { @ApiOperation(value = "3.9.抽奖列表页,以及本人是否已参加(APP)", notes = "APP") @PostMapping("/lottery/list/user/{page}/{size}") @GlobalInterceptor(checkAppUserLogin = true) - public Result> findLotteryListForApp( + public Result> findLotteryListForApp( @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto, @ApiParam(value = "页码", required = true) @PathVariable Integer page, 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 cf40619..cdb7dda 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 @@ -7,12 +7,11 @@ import com.luoo.user.dao.LotteryRegionDao; import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dto.point.LotterySearchDto; -import com.luoo.user.pojo.Lottery; -import com.luoo.user.pojo.LotteryRegion; -import com.luoo.user.pojo.LotteryUser; -import com.luoo.user.pojo.Region; -import com.luoo.user.pojo.UserInfo; -import com.luoo.user.pojo.UserPointLog; +import com.luoo.user.pojo.*; +import com.luoo.user.vo.point.LotteryAPPVO; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; import constants.ErrorConstants; import dto.UserLoginDto; import enums.PointEnums; @@ -31,8 +30,11 @@ import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; @@ -76,7 +78,9 @@ public class LotteryService { private final DrawLotteryScheduler drawLotteryScheduler; - public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler) { + private final JPAQueryFactory jpaQueryFactory; + + public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory) { this.lotteryDao = lotteryDao; this.jwtUtil = jwtUtil; this.idWorker = idWorker; @@ -87,6 +91,7 @@ public class LotteryService { this.rabbitTemplate = rabbitTemplate; this.lotteryUserDao = lotteryUserDao; this.drawLotteryScheduler = drawLotteryScheduler; + this.jpaQueryFactory = jpaQueryFactory; } @@ -387,10 +392,63 @@ public class LotteryService { } - public PageResult findLotteryListForApp(Integer page, Integer size, - LotterySearchDto lotterySearchDto, - String token) { - PageResult lotteryPageResult = lotteryPageResult(page, size, lotterySearchDto); + public PageResult lotteryAPPVOPageResult(Integer page, Integer size, LotterySearchDto lotterySearchDto) { + BooleanBuilder booleanBuilder = new BooleanBuilder(); + QLottery qLottery = QLottery.lottery; + checkCondition(booleanBuilder, qLottery, lotterySearchDto); + // 创建分页对象 + 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 + + )).from(qLottery) + .where(booleanBuilder) + .orderBy(qLottery.createTime.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + return new PageResult<>(jpaQueryFactory.select(qLottery.count()).from(qLottery).where(booleanBuilder).fetchOne(), list); + } + + private void checkCondition(BooleanBuilder booleanBuilder, QLottery qLottery, LotterySearchDto lotterySearch) { + if (StringUtils.isNotBlank(lotterySearch.getSearchStr())) { + booleanBuilder.and(qLottery.title.like(lotterySearch.getSearchStr()).or(qLottery.code.like("%" + lotterySearch.getSearchStr() + "%"))); + } + if (Objects.nonNull(lotterySearch.getStatus())) { + booleanBuilder.and(qLottery.status.eq(lotterySearch.getStatus())); + } + if (Objects.nonNull(lotterySearch.getType())) { + booleanBuilder.and(qLottery.type.eq(lotterySearch.getType())); + } + if (StringUtils.isNotBlank(lotterySearch.getCreateUser())) { + booleanBuilder.and(qLottery.createUser.eq(lotterySearch.getCreateUser())); + } + if (StringUtils.isNotBlank(lotterySearch.getCityName())) { + booleanBuilder.and(qLottery.regionName.like("%" + lotterySearch.getCityName() + "%")); + } + } + + public PageResult findLotteryListForApp(Integer page, Integer size, + LotterySearchDto lotterySearchDto, + String token) { + PageResult lotteryPageResult = lotteryAPPVOPageResult(page, size, lotterySearchDto); lotteryPageResult.getRows().forEach(lottery -> { if (StringUtils.isNotBlank(token)) { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); @@ -400,6 +458,15 @@ public class LotteryService { } else { lottery.setIsParticipate(PointEnums.NOT_PARTICIPATED.getCode()); } + + QLotteryUser qLotteryUser = QLotteryUser.lotteryUser; + long participateNum = jpaQueryFactory + .select(qLotteryUser.count()) + .from(qLotteryUser) + .where(qLotteryUser.lotteryId.eq(lottery.getId())) + .fetchCount(); +// 设置抽奖人数 + lottery.setParticipateNum(participateNum); } }); return lotteryPageResult; diff --git a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryAPPVO.java b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryAPPVO.java new file mode 100644 index 0000000..256368f --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryAPPVO.java @@ -0,0 +1,141 @@ +package com.luoo.user.vo.point; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.luoo.user.pojo.LotteryRegion; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.Transient; +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; + +/** + * DTO for {@link com.luoo.user.pojo.Lottery} + */ +@Data +public class LotteryAPPVO implements Serializable { + + private static final long serialVersionUID = -3199469715292060249L; + + @ApiModelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "抽奖编码") + private String code; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖") + private Integer type; + + @ApiModelProperty(value = "奖品总数量") + private Integer num; + + @ApiModelProperty(value = "可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者") + private Integer participant; + + @ApiModelProperty(value = "积分") + private Integer point; + + @ApiModelProperty(value = "地区编码") + private String regionCode; + + @ApiModelProperty(value = "地区名称") + private String regionName; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "报名开始时间") + private LocalDateTime applyStartTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "报名结束时间") + private LocalDateTime applyEndTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "抽奖时间") + private LocalDateTime drawTime; + + @ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖") + private Integer way; + + @ApiModelProperty(value = "抽奖封面url") + private String image; + + @ApiModelProperty(value = "抽奖描述") + private String description; + + @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") + private Integer status; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("创建时间") + @CreatedDate + private LocalDateTime createTime; + + @ApiModelProperty(value = "停止原因") + private String stopReason; + + @Transient + @ApiModelProperty(value = "本人是否参与抽奖 1-已参加 2-未参加") + private Integer isParticipate; + + @Transient + @ApiModelProperty(value = "参与人数") + private Long participateNum; + + + public LotteryAPPVO() { + + } + + public LotteryAPPVO(String id, String code, String title, Integer type, Integer num, Integer participant, Integer point, String regionCode, String regionName, LocalDateTime applyStartTime, LocalDateTime applyEndTime, LocalDateTime drawTime, Integer way, String image, String description, Integer status, LocalDateTime createTime, String stopReason) { + this.id = id; + this.code = code; + this.title = title; + this.type = type; + this.num = num; + this.participant = participant; + this.point = point; + this.regionCode = regionCode; + this.regionName = regionName; + this.applyStartTime = applyStartTime; + this.applyEndTime = applyEndTime; + this.drawTime = drawTime; + this.way = way; + this.image = image; + this.description = description; + this.status = status; + this.createTime = createTime; + this.stopReason = stopReason; + } + + public LotteryAPPVO(String id, String code, String title, Integer type, Integer num, Integer participant, Integer point, String regionCode, String regionName, LocalDateTime applyStartTime, LocalDateTime applyEndTime, LocalDateTime drawTime, Integer way, String image, String description, Integer status, LocalDateTime createTime, String stopReason, Integer isParticipate) { + this.id = id; + this.code = code; + this.title = title; + this.type = type; + this.num = num; + this.participant = participant; + this.point = point; + this.regionCode = regionCode; + this.regionName = regionName; + this.applyStartTime = applyStartTime; + this.applyEndTime = applyEndTime; + this.drawTime = drawTime; + this.way = way; + this.image = image; + this.description = description; + this.status = status; + this.createTime = createTime; + this.stopReason = stopReason; + this.isParticipate = isParticipate; + } +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/vo/point/UserPointLogVO.java b/luoo_user/src/main/java/com/luoo/user/vo/point/UserPointLogVO.java index a43b8c1..73237a0 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/point/UserPointLogVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/point/UserPointLogVO.java @@ -21,11 +21,17 @@ import java.time.LocalDateTime; @AllArgsConstructor public class UserPointLogVO implements Serializable { + @ApiModelProperty(value = "主键") String id; + @ApiModelProperty(value = "积分") Integer score; + @ApiModelProperty(value = "类型 1-增加 2-减少") Integer type; + @ApiModelProperty(value = "用户id") String userId; + @ApiModelProperty(value = "任务id") String taskPointId; + @ApiModelProperty(value = "任务描述") String description; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @@ -33,5 +39,6 @@ public class UserPointLogVO implements Serializable { LocalDateTime createTime; @Transient + @ApiModelProperty(value = "所属月份") String createMonth; } \ No newline at end of file