release: LotterySearchDto新增开始结束时间查询

release-2024-08-08
huangyw 4 months ago
parent ae6c5a1b56
commit 84fb28c187

@ -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<PageResult<Lottery>> lotteryList(
public Result<PageResult<LotteryPCVO>> lotteryList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,

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

@ -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;
@ -379,19 +380,54 @@ public class LotteryService {
* @param lotterySearchDto
* @return
*/
public PageResult<Lottery> lotteryPageResult(Integer page, Integer size,
public PageResult<LotteryPCVO> lotteryPageResult(Integer page, Integer size,
LotterySearchDto lotterySearchDto) {
Sort sort = new Sort(Direction.DESC, "createTime");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
PageResult<LotteryPCVO> lotteryPageResult = lotteryPCVOPageResult(page, size, lotterySearchDto);
lotteryPageResult.getRows().forEach(lottery -> {
long participateNum = getParticipateNumByLotteryId(lottery.getId());
// 设置抽奖人数
lottery.setParticipateNum(participateNum);
});
return lotteryPageResult;
}
Specification<Lottery> specification = getSpecification(lotterySearchDto);
Page<Lottery> lotteryPage = lotteryDao.findAll(specification, pageRequest);
long totalElements = lotteryPage.getTotalElements();
return new PageResult<>(totalElements, lotteryPage.getContent());
public PageResult<LotteryPCVO> 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<LotteryPCVO> 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<LotteryAPPVO> lotteryAPPVOPageResult(Integer page, Integer size, LotterySearchDto lotterySearchDto) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
QLottery qLottery = QLottery.lottery;
@ -417,7 +453,6 @@ public class LotteryService {
qLottery.status,
qLottery.createTime,
qLottery.stopReason
)).from(qLottery)
.where(booleanBuilder)
.orderBy(qLottery.createTime.desc())
@ -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<LotteryAPPVO> 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<Lottery> getSpecification(LotterySearchDto lotterySearchDto) {
return (Root<Lottery> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> 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();
}
/**

@ -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;
}
}
Loading…
Cancel
Save