release: 3.9.抽奖列表页,以及本人是否已参加(APP) 增加参与用户数量字段

release-2024-08-08
huangyw 4 months ago
parent 2ffef0516f
commit f98edf5119

@ -9,6 +9,7 @@ import com.luoo.user.service.DrawLotteryService;
import com.luoo.user.service.LotteryService; import com.luoo.user.service.LotteryService;
import com.luoo.user.service.TaskPointService; import com.luoo.user.service.TaskPointService;
import com.luoo.user.service.UserPointLogService; import com.luoo.user.service.UserPointLogService;
import com.luoo.user.vo.point.LotteryAPPVO;
import com.luoo.user.vo.point.UserPointLogVO; import com.luoo.user.vo.point.UserPointLogVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -351,7 +352,7 @@ public class PointController {
@ApiOperation(value = "3.9.抽奖列表页,以及本人是否已参加(APP)", notes = "APP") @ApiOperation(value = "3.9.抽奖列表页,以及本人是否已参加(APP)", notes = "APP")
@PostMapping("/lottery/list/user/{page}/{size}") @PostMapping("/lottery/list/user/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<Lottery>> findLotteryListForApp( public Result<PageResult<LotteryAPPVO>> findLotteryListForApp(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto, @ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "页码", required = true) @PathVariable Integer page,

@ -7,12 +7,11 @@ import com.luoo.user.dao.LotteryRegionDao;
import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.LotteryUserDao;
import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dto.point.LotterySearchDto; import com.luoo.user.dto.point.LotterySearchDto;
import com.luoo.user.pojo.Lottery; import com.luoo.user.pojo.*;
import com.luoo.user.pojo.LotteryRegion; import com.luoo.user.vo.point.LotteryAPPVO;
import com.luoo.user.pojo.LotteryUser; import com.querydsl.core.BooleanBuilder;
import com.luoo.user.pojo.Region; import com.querydsl.core.types.Projections;
import com.luoo.user.pojo.UserInfo; import com.querydsl.jpa.impl.JPAQueryFactory;
import com.luoo.user.pojo.UserPointLog;
import constants.ErrorConstants; import constants.ErrorConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.PointEnums;
@ -31,8 +30,11 @@ import javax.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; 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.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -76,7 +78,9 @@ public class LotteryService {
private final DrawLotteryScheduler drawLotteryScheduler; 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.lotteryDao = lotteryDao;
this.jwtUtil = jwtUtil; this.jwtUtil = jwtUtil;
this.idWorker = idWorker; this.idWorker = idWorker;
@ -87,6 +91,7 @@ public class LotteryService {
this.rabbitTemplate = rabbitTemplate; this.rabbitTemplate = rabbitTemplate;
this.lotteryUserDao = lotteryUserDao; this.lotteryUserDao = lotteryUserDao;
this.drawLotteryScheduler = drawLotteryScheduler; this.drawLotteryScheduler = drawLotteryScheduler;
this.jpaQueryFactory = jpaQueryFactory;
} }
@ -387,10 +392,63 @@ public class LotteryService {
} }
public PageResult<Lottery> findLotteryListForApp(Integer page, Integer size, public PageResult<LotteryAPPVO> 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<LotteryAPPVO> 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<LotteryAPPVO> findLotteryListForApp(Integer page, Integer size,
LotterySearchDto lotterySearchDto, LotterySearchDto lotterySearchDto,
String token) { String token) {
PageResult<Lottery> lotteryPageResult = lotteryPageResult(page, size, lotterySearchDto); PageResult<LotteryAPPVO> lotteryPageResult = lotteryAPPVOPageResult(page, size, lotterySearchDto);
lotteryPageResult.getRows().forEach(lottery -> { lotteryPageResult.getRows().forEach(lottery -> {
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
@ -400,6 +458,15 @@ public class LotteryService {
} else { } else {
lottery.setIsParticipate(PointEnums.NOT_PARTICIPATED.getCode()); 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; return lotteryPageResult;

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

@ -21,11 +21,17 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
public class UserPointLogVO implements Serializable { public class UserPointLogVO implements Serializable {
@ApiModelProperty(value = "主键")
String id; String id;
@ApiModelProperty(value = "积分")
Integer score; Integer score;
@ApiModelProperty(value = "类型 1-增加 2-减少")
Integer type; Integer type;
@ApiModelProperty(value = "用户id")
String userId; String userId;
@ApiModelProperty(value = "任务id")
String taskPointId; String taskPointId;
@ApiModelProperty(value = "任务描述")
String description; String description;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ -33,5 +39,6 @@ public class UserPointLogVO implements Serializable {
LocalDateTime createTime; LocalDateTime createTime;
@Transient @Transient
@ApiModelProperty(value = "所属月份")
String createMonth; String createMonth;
} }
Loading…
Cancel
Save