From 84fb28c18720a3f70b64cd4b0e1150b4942ade27 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Fri, 9 Aug 2024 08:53:02 +0800 Subject: [PATCH] =?UTF-8?q?release:=20LotterySearchDto=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/PointController.java | 3 +- .../luoo/user/dto/point/LotterySearchDto.java | 14 ++ .../com/luoo/user/service/LotteryService.java | 145 ++++++++++-------- .../com/luoo/user/vo/point/LotteryPCVO.java | 121 +++++++++++++++ 4 files changed, 221 insertions(+), 62 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.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 e86b122..f34b4ef 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 @@ -10,6 +10,7 @@ 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.LotteryPCVO; import com.luoo.user.vo.point.UserPointLogVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -261,7 +262,7 @@ public class PointController { @ApiOperation(value = "3.2.抽奖列表页(PC)", notes = "admin") @PostMapping("/lottery/list/{page}/{size}") @GlobalInterceptor(checkAdminLogin = true) - public Result> lotteryList( + public Result> lotteryList( @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/dto/point/LotterySearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java index 2e078b7..516a0a1 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 @@ -1,9 +1,13 @@ package com.luoo.user.dto.point; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; /** * @program: luoo_parent @@ -30,4 +34,14 @@ public class LotterySearchDto { @ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖") private Integer type; + + @ApiModelProperty(value = "开始时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime startTime; + + @ApiModelProperty(value = "结束时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime endTime; } 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 cdb7dda..f9a40a3 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 @@ -9,6 +9,7 @@ import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dto.point.LotterySearchDto; import com.luoo.user.pojo.*; import com.luoo.user.vo.point.LotteryAPPVO; +import com.luoo.user.vo.point.LotteryPCVO; import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -166,7 +167,7 @@ public class LotteryService { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - if(lottery.getStatus() != null && !Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_EDITING.getCode())) { + if (lottery.getStatus() != null && !Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_EDITING.getCode())) { throw new BizException(ErrorConstants.CAN_NOT_EDIT); } @@ -379,19 +380,54 @@ public class LotteryService { * @param lotterySearchDto 查询参数 * @return 列表页 */ - public PageResult lotteryPageResult(Integer page, Integer size, - LotterySearchDto lotterySearchDto) { - Sort sort = new Sort(Direction.DESC, "createTime"); - PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + public PageResult lotteryPageResult(Integer page, Integer size, + LotterySearchDto lotterySearchDto) { + PageResult lotteryPageResult = lotteryPCVOPageResult(page, size, lotterySearchDto); + lotteryPageResult.getRows().forEach(lottery -> { + long participateNum = getParticipateNumByLotteryId(lottery.getId()); + // 设置抽奖人数 + lottery.setParticipateNum(participateNum); + }); + return lotteryPageResult; + } - Specification specification = getSpecification(lotterySearchDto); - Page lotteryPage = lotteryDao.findAll(specification, pageRequest); - long totalElements = lotteryPage.getTotalElements(); - return new PageResult<>(totalElements, lotteryPage.getContent()); + public PageResult lotteryPCVOPageResult(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(LotteryPCVO.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.createUser, + qLottery.createUserName, + 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); } - public PageResult lotteryAPPVOPageResult(Integer page, Integer size, LotterySearchDto lotterySearchDto) { BooleanBuilder booleanBuilder = new BooleanBuilder(); QLottery qLottery = QLottery.lottery; @@ -399,26 +435,25 @@ public class LotteryService { // 创建分页对象 Pageable pageable = PageRequest.of(page - 1, size); List list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class, - qLottery.id, + 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) + 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()) @@ -443,6 +478,13 @@ public class LotteryService { if (StringUtils.isNotBlank(lotterySearch.getCityName())) { booleanBuilder.and(qLottery.regionName.like("%" + lotterySearch.getCityName() + "%")); } + // 开始时间和结束时间 + if (Objects.nonNull(lotterySearch.getStartTime())) { + booleanBuilder.and(qLottery.applyStartTime.goe(lotterySearch.getStartTime())); + } + if (Objects.nonNull(lotterySearch.getEndTime())) { + booleanBuilder.and(qLottery.applyEndTime.loe(lotterySearch.getEndTime())); + } } public PageResult findLotteryListForApp(Integer page, Integer size, @@ -459,12 +501,7 @@ public class LotteryService { 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(); + long participateNum = getParticipateNumByLotteryId(lottery.getId()); // 设置抽奖人数 lottery.setParticipateNum(participateNum); } @@ -472,33 +509,19 @@ public class LotteryService { return lotteryPageResult; } - private Specification getSpecification(LotterySearchDto lotterySearchDto) { - return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { - List predicateList = new ArrayList<>(); - - if (StringUtils.isNotBlank(lotterySearchDto.getSearchStr())) { - predicateList.add( - criteriaBuilder.or( - criteriaBuilder.like(root.get("title"), - "%" + lotterySearchDto.getSearchStr() + "%"), - criteriaBuilder.like(root.get("code"), "%" + lotterySearchDto.getSearchStr() + "%") - ) - ); - } - if (lotterySearchDto.getStatus() != null) { - predicateList.add(criteriaBuilder.equal(root.get("status"), lotterySearchDto.getStatus())); - } - if (StringUtils.isNotBlank(lotterySearchDto.getCreateUser())) { - predicateList.add( - criteriaBuilder.equal(root.get("createUser"), lotterySearchDto.getCreateUser())); - } - - if (lotterySearchDto.getType() != null) { - predicateList.add(criteriaBuilder.equal(root.get("type"), lotterySearchDto.getType())); - } - - return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); - }; + /** + * 根据抽奖id获取抽奖人数 + * + * @param lotteryId 抽奖id + * @return 抽奖人数 + */ + private long getParticipateNumByLotteryId(String lotteryId) { + QLotteryUser qLotteryUser = QLotteryUser.lotteryUser; + return jpaQueryFactory + .select(qLotteryUser.count()) + .from(qLotteryUser) + .where(qLotteryUser.lotteryId.eq(lotteryId)) + .fetchCount(); } /** diff --git a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java new file mode 100644 index 0000000..9685fd0 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java @@ -0,0 +1,121 @@ +package com.luoo.user.vo.point; + +import com.fasterxml.jackson.annotation.JsonFormat; +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; + +/** + * DTO for {@link com.luoo.user.pojo.Lottery} + */ +@Data +public class LotteryPCVO 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 createUser; + + @ApiModelProperty(value = "创建人姓名") + private String createUserName; + + @ApiModelProperty(value = "停止原因") + private String stopReason; + + @Transient + @ApiModelProperty(value = "参与人数") + private Long participateNum; + + + public LotteryPCVO() { + + } + + public LotteryPCVO(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 createUser, String createUserName, 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.createUser = createUser; + this.createUserName = createUserName; + this.stopReason = stopReason; + } +} \ No newline at end of file