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