|
|
|
@ -5,20 +5,24 @@ import com.luoo.user.dao.TaskPointDao;
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.dao.UserPointLogDao;
|
|
|
|
|
import com.luoo.user.dto.point.UserPointLogSearchDto;
|
|
|
|
|
import com.luoo.user.pojo.TaskPoint;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.pojo.UserPointLog;
|
|
|
|
|
import com.luoo.user.pojo.*;
|
|
|
|
|
import com.luoo.user.vo.point.UserPointLogVO;
|
|
|
|
|
import com.querydsl.core.BooleanBuilder;
|
|
|
|
|
import com.querydsl.core.types.Projections;
|
|
|
|
|
import com.querydsl.core.types.dsl.Expressions;
|
|
|
|
|
import com.querydsl.core.types.dsl.StringExpression;
|
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
|
import constants.TaskPointIdConstants;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.PointEnums;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import javax.persistence.criteria.*;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
@ -26,6 +30,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
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;
|
|
|
|
@ -56,15 +61,19 @@ public class UserPointLogService {
|
|
|
|
|
|
|
|
|
|
private final UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
private final JPAQueryFactory jpaQueryFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
|
|
|
|
|
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao) {
|
|
|
|
|
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao, JPAQueryFactory jpaQueryFactory) {
|
|
|
|
|
this.userPointLogDao = userPointLogDao;
|
|
|
|
|
this.idWorker = idWorker;
|
|
|
|
|
this.jwtUtil = jwtUtil;
|
|
|
|
|
this.taskPointDao = taskPointDao;
|
|
|
|
|
this.rabbitTemplate = rabbitTemplate;
|
|
|
|
|
this.userInfoDao = userInfoDao;
|
|
|
|
|
this.jpaQueryFactory = jpaQueryFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskPointService taskPointService;
|
|
|
|
@ -242,39 +251,74 @@ public class UserPointLogService {
|
|
|
|
|
* @param size 每页数量
|
|
|
|
|
* @return 用户积分列表
|
|
|
|
|
*/
|
|
|
|
|
public PageResult<UserPointLog> getUserPointLogList(String token,
|
|
|
|
|
public PageResult<UserPointLogVO> getUserPointLogList(String token,
|
|
|
|
|
UserPointLogSearchDto userPointLogSearchDto, Integer page,
|
|
|
|
|
Integer size) {
|
|
|
|
|
//
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
|
|
Sort sort = new Sort(Direction.DESC, "createTime");
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
|
|
|
|
|
|
userPointLogSearchDto.setUserId(userLoginDto.getUserId());
|
|
|
|
|
Specification<UserPointLog> specification = buildSearchSpecification(userPointLogSearchDto);
|
|
|
|
|
Page<UserPointLog> userPointLogPage = userPointLogDao.findAll(specification, pageRequest);
|
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
|
QUserPointLog qUserPointLog = QUserPointLog.userPointLog;
|
|
|
|
|
checkCondition(booleanBuilder, qUserPointLog, userPointLogSearchDto);
|
|
|
|
|
StringExpression formattedCreateTime = Expressions.stringTemplate(
|
|
|
|
|
"DATE_FORMAT({0}, {1})",
|
|
|
|
|
qUserPointLog.createTime,
|
|
|
|
|
Expressions.constant("%Y%m")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 创建分页对象
|
|
|
|
|
Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
|
|
|
|
|
|
|
List<UserPointLogVO> userPointLogPage = jpaQueryFactory.select(
|
|
|
|
|
Projections.constructor(UserPointLogVO.class,
|
|
|
|
|
qUserPointLog.id,
|
|
|
|
|
qUserPointLog.score,
|
|
|
|
|
qUserPointLog.type,
|
|
|
|
|
qUserPointLog.userId,
|
|
|
|
|
qUserPointLog.taskPointId,
|
|
|
|
|
qUserPointLog.description,
|
|
|
|
|
qUserPointLog.createTime,
|
|
|
|
|
formattedCreateTime.as("createMonth")
|
|
|
|
|
))
|
|
|
|
|
.from(qUserPointLog)
|
|
|
|
|
.where(booleanBuilder)
|
|
|
|
|
.orderBy(qUserPointLog.createTime.desc())
|
|
|
|
|
.offset(pageable.getOffset())
|
|
|
|
|
.limit(pageable.getPageSize())
|
|
|
|
|
.fetch();
|
|
|
|
|
long totalElements = jpaQueryFactory.select(qUserPointLog.id.count()).from(qUserPointLog)
|
|
|
|
|
.where(booleanBuilder)
|
|
|
|
|
.fetchCount();
|
|
|
|
|
|
|
|
|
|
return new PageResult<>(totalElements, userPointLogPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long totalElements = userPointLogPage.getTotalElements();
|
|
|
|
|
return new PageResult<>(totalElements, userPointLogPage.getContent());
|
|
|
|
|
public void checkCondition(BooleanBuilder booleanBuilder, QUserPointLog qUserPointLog, UserPointLogSearchDto userPointLogSearchDto){
|
|
|
|
|
if(!StringUtils.isEmpty(userPointLogSearchDto.getUserId())) {
|
|
|
|
|
booleanBuilder.and(qUserPointLog.createUser.eq(userPointLogSearchDto.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
if(userPointLogSearchDto.getType() != null) {
|
|
|
|
|
booleanBuilder.and(qUserPointLog.type.eq(userPointLogSearchDto.getType()));
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(userPointLogSearchDto.getCreateMonth())) {
|
|
|
|
|
// 判断userPointLogSearchDto.getCreateMonth() 是否是当月时间
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
|
|
|
|
String currentMonth = now.format(formatter);
|
|
|
|
|
|
|
|
|
|
private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) {
|
|
|
|
|
return (Root<UserPointLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
// 判断是否是当前月份
|
|
|
|
|
boolean isCurrentMonth = userPointLogSearchDto.getCreateMonth().equals(currentMonth);
|
|
|
|
|
|
|
|
|
|
if (param.getType() != null) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(root.get("type"), param.getType())));
|
|
|
|
|
}
|
|
|
|
|
if(!isCurrentMonth) {
|
|
|
|
|
// 不是当前月份,仅展示传入月份的记录
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId())));
|
|
|
|
|
}
|
|
|
|
|
StringExpression formattedCreateTime = Expressions.stringTemplate(
|
|
|
|
|
"DATE_FORMAT({0}, {1})",
|
|
|
|
|
qUserPointLog.createTime,
|
|
|
|
|
Expressions.constant("%Y%m")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
booleanBuilder.and(formattedCreateTime.eq(userPointLogSearchDto.getCreateMonth()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|