|
|
@ -19,6 +19,7 @@ import com.querydsl.core.types.dsl.StringExpression;
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
|
|
|
|
import constants.TaskPointIdConstants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.PointEnums;
|
|
|
|
import enums.PointEnums;
|
|
|
|
import enums.UserTypeEnum;
|
|
|
|
import enums.UserTypeEnum;
|
|
|
@ -26,6 +27,7 @@ import enums.UserVipStatusEnum;
|
|
|
|
import exception.BizException;
|
|
|
|
import exception.BizException;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
@ -266,6 +268,8 @@ public class LotteryService {
|
|
|
|
if (lottery.getDrawTime() == null) {
|
|
|
|
if (lottery.getDrawTime() == null) {
|
|
|
|
throw new BizException(ErrorConstants.DRAW_TIME_IS_REQUIRED);
|
|
|
|
throw new BizException(ErrorConstants.DRAW_TIME_IS_REQUIRED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 发布时间
|
|
|
|
|
|
|
|
lottery.setPublishTime(LocalDateTime.now());
|
|
|
|
lottery.setUpdateUser(userLoginDto.getUserId());
|
|
|
|
lottery.setUpdateUser(userLoginDto.getUserId());
|
|
|
|
lottery.setUpdateUserName(userLoginDto.getNickName());
|
|
|
|
lottery.setUpdateUserName(userLoginDto.getNickName());
|
|
|
|
|
|
|
|
|
|
|
@ -306,7 +310,7 @@ public class LotteryService {
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
|
|
|
|
.createUser(lotteryUser.getUserId())
|
|
|
|
.createUser(lotteryUser.getUserId())
|
|
|
|
.taskPointId(null)
|
|
|
|
.taskPointId(TaskPointIdConstants.LOTTERY_RETURNS)
|
|
|
|
.description(POINTS_WILL_BE_RETURNED)
|
|
|
|
.description(POINTS_WILL_BE_RETURNED)
|
|
|
|
.userId(lotteryUser.getUserId())
|
|
|
|
.userId(lotteryUser.getUserId())
|
|
|
|
.score(lottery.getPoint())
|
|
|
|
.score(lottery.getPoint())
|
|
|
@ -352,7 +356,7 @@ public class LotteryService {
|
|
|
|
|
|
|
|
|
|
|
|
// 已参与抽奖,不能再次参与
|
|
|
|
// 已参与抽奖,不能再次参与
|
|
|
|
LotteryUser byLotteryIdAndUserId = lotteryUserDao.findByLotteryIdAndUserId(id, userLoginDto.getUserId());
|
|
|
|
LotteryUser byLotteryIdAndUserId = lotteryUserDao.findByLotteryIdAndUserId(id, userLoginDto.getUserId());
|
|
|
|
if(byLotteryIdAndUserId != null) {
|
|
|
|
if (byLotteryIdAndUserId != null) {
|
|
|
|
throw new BizException(ErrorConstants.ALREADY_PARTICIPATED);
|
|
|
|
throw new BizException(ErrorConstants.ALREADY_PARTICIPATED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -399,6 +403,7 @@ public class LotteryService {
|
|
|
|
.score(point)
|
|
|
|
.score(point)
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_REDUCE.getCode())
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_REDUCE.getCode())
|
|
|
|
.userId(userLoginDto.getUserId())
|
|
|
|
.userId(userLoginDto.getUserId())
|
|
|
|
|
|
|
|
.taskPointId(TaskPointIdConstants.LOTTERY)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
rabbitTemplate.convertAndSend("draw", drawDTO);
|
|
|
|
rabbitTemplate.convertAndSend("draw", drawDTO);
|
|
|
|
|
|
|
|
|
|
|
@ -450,7 +455,9 @@ public class LotteryService {
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.createUser,
|
|
|
|
qLottery.createUser,
|
|
|
|
qLottery.createUserName,
|
|
|
|
qLottery.createUserName,
|
|
|
|
qLottery.stopReason
|
|
|
|
qLottery.stopReason,
|
|
|
|
|
|
|
|
qLottery.price,
|
|
|
|
|
|
|
|
qLottery.publishTime
|
|
|
|
)).from(qLottery)
|
|
|
|
)).from(qLottery)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.orderBy(qLottery.createTime.desc())
|
|
|
|
.orderBy(qLottery.createTime.desc())
|
|
|
@ -464,6 +471,7 @@ public class LotteryService {
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
QLottery qLottery = QLottery.lottery;
|
|
|
|
QLottery qLottery = QLottery.lottery;
|
|
|
|
checkCondition(booleanBuilder, qLottery, lotterySearchDto);
|
|
|
|
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);
|
|
|
|
Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
|
List<LotteryAPPVO> list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class,
|
|
|
|
List<LotteryAPPVO> list = jpaQueryFactory.select(Projections.constructor(LotteryAPPVO.class,
|
|
|
@ -484,10 +492,12 @@ public class LotteryService {
|
|
|
|
qLottery.description,
|
|
|
|
qLottery.description,
|
|
|
|
qLottery.status,
|
|
|
|
qLottery.status,
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.stopReason
|
|
|
|
qLottery.stopReason,
|
|
|
|
|
|
|
|
qLottery.price,
|
|
|
|
|
|
|
|
qLottery.publishTime
|
|
|
|
)).from(qLottery)
|
|
|
|
)).from(qLottery)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.orderBy(qLottery.createTime.desc())
|
|
|
|
.orderBy(qLottery.status.asc(), qLottery.publishTime.desc())
|
|
|
|
.offset(pageable.getOffset())
|
|
|
|
.offset(pageable.getOffset())
|
|
|
|
.limit(pageable.getPageSize())
|
|
|
|
.limit(pageable.getPageSize())
|
|
|
|
.fetch();
|
|
|
|
.fetch();
|
|
|
@ -572,14 +582,6 @@ public class LotteryService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PageResult<LotteryUserAPPVO> findPageByLotteryId(Integer page, Integer size, String lotteryId) {
|
|
|
|
public PageResult<LotteryUserAPPVO> findPageByLotteryId(Integer page, Integer size, String lotteryId) {
|
|
|
|
// Sort sort = new Sort(Direction.DESC, "createTime");
|
|
|
|
|
|
|
|
// PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Specification<LotteryUser> specification = getLotteryUserSpecification(lotteryId);
|
|
|
|
|
|
|
|
// Page<LotteryUser> lotteryUserPage = lotteryUserDao.findAll(specification, pageRequest);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// long totalElements = lotteryUserPage.getTotalElements();
|
|
|
|
|
|
|
|
// return new PageResult<>(totalElements, lotteryUserPage.getContent());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QLotteryUser qLotteryUser = QLotteryUser.lotteryUser;
|
|
|
|
QLotteryUser qLotteryUser = QLotteryUser.lotteryUser;
|
|
|
|
QUserInfo qUserInfo = QUserInfo.userInfo;
|
|
|
|
QUserInfo qUserInfo = QUserInfo.userInfo;
|
|
|
@ -636,11 +638,44 @@ public class LotteryService {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Integer getLotteryUserResult(String lotteryId, String token) {
|
|
|
|
public LotteryUserAPPVO getLotteryUserResult(String lotteryId, String token) {
|
|
|
|
|
|
|
|
QLotteryUser qLotteryUser = QLotteryUser.lotteryUser;
|
|
|
|
|
|
|
|
QUserInfo qUserInfo = QUserInfo.userInfo;
|
|
|
|
|
|
|
|
QRegion qRegion = QRegion.region;
|
|
|
|
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
LotteryUser lotteryUser = lotteryUserDao.findByLotteryIdAndUserId(lotteryId, userLoginDto.getUserId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return lotteryUser.getResult();
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
|
|
|
|
booleanBuilder.and(qLotteryUser.lotteryId.eq(lotteryId));
|
|
|
|
|
|
|
|
booleanBuilder.and(qLotteryUser.userId.eq(userLoginDto.getUserId()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 头像字段拼接字符串
|
|
|
|
|
|
|
|
StringExpression avatarWithPrefix = Expressions.stringTemplate("{0} || {1}", Constants.RESOURCE_PREFIX, qUserInfo.avatar);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jpaQueryFactory
|
|
|
|
|
|
|
|
.select(Projections.bean(LotteryUserAPPVO.class,
|
|
|
|
|
|
|
|
qLotteryUser.id.as("id"),
|
|
|
|
|
|
|
|
qLotteryUser.lotteryId.as("lotteryId"),
|
|
|
|
|
|
|
|
qLotteryUser.userId.as("userId"),
|
|
|
|
|
|
|
|
qLotteryUser.regionId.as("regionId"),
|
|
|
|
|
|
|
|
qLotteryUser.result.as("result"),
|
|
|
|
|
|
|
|
qLotteryUser.createTime.as("createTime"),
|
|
|
|
|
|
|
|
qLotteryUser.updateTime.as("updateTime"),
|
|
|
|
|
|
|
|
qLotteryUser.createUser.as("createUser"),
|
|
|
|
|
|
|
|
qLotteryUser.updateUser.as("updateUser"),
|
|
|
|
|
|
|
|
qUserInfo.nickName.as("nickName"),
|
|
|
|
|
|
|
|
avatarWithPrefix.as("avatar"),
|
|
|
|
|
|
|
|
qLotteryUser.popup.as("popup"),
|
|
|
|
|
|
|
|
qRegion.name.as("regionName"),
|
|
|
|
|
|
|
|
qRegion.code.as("regionCode")
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.from(qLotteryUser)
|
|
|
|
|
|
|
|
.leftJoin(qUserInfo)
|
|
|
|
|
|
|
|
.on(qLotteryUser.userId.eq(qUserInfo.id))
|
|
|
|
|
|
|
|
.leftJoin(qRegion)
|
|
|
|
|
|
|
|
.on(qLotteryUser.regionId.eq(qRegion.id))
|
|
|
|
|
|
|
|
.where(booleanBuilder)
|
|
|
|
|
|
|
|
.fetchOne();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -668,7 +703,9 @@ public class LotteryService {
|
|
|
|
qLottery.description,
|
|
|
|
qLottery.description,
|
|
|
|
qLottery.status,
|
|
|
|
qLottery.status,
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.createTime,
|
|
|
|
qLottery.stopReason
|
|
|
|
qLottery.stopReason,
|
|
|
|
|
|
|
|
qLottery.price,
|
|
|
|
|
|
|
|
qLottery.publishTime
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.from(qLottery)
|
|
|
|
.from(qLottery)
|
|
|
|
.where(qLottery.id.eq(lotteryId))
|
|
|
|
.where(qLottery.id.eq(lotteryId))
|
|
|
@ -772,6 +809,13 @@ public class LotteryService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public void popup(String lotteryUserId) {
|
|
|
|
|
|
|
|
LotteryUser one = lotteryUserDao.getOne(lotteryUserId);
|
|
|
|
|
|
|
|
one.setPopup(PointEnums.ALREADY_POPUP.getCode());
|
|
|
|
|
|
|
|
lotteryUserDao.save(one);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkLotteryUserCondition(BooleanBuilder booleanBuilder, QLotteryUser qLotteryUser, String lotteryId, Integer userType) {
|
|
|
|
private void checkLotteryUserCondition(BooleanBuilder booleanBuilder, QLotteryUser qLotteryUser, String lotteryId, Integer userType) {
|
|
|
|
booleanBuilder.and(qLotteryUser.lotteryId.eq(lotteryId));
|
|
|
|
booleanBuilder.and(qLotteryUser.lotteryId.eq(lotteryId));
|
|
|
|
if (Objects.nonNull(userType)) {
|
|
|
|
if (Objects.nonNull(userType)) {
|
|
|
|