|
|
|
@ -3,18 +3,31 @@ package com.luoo.user.service;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import com.luoo.user.dao.TaskPointDao;
|
|
|
|
|
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.mysql.fabric.xmlrpc.base.Param;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.PointEnums;
|
|
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
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;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
@ -130,15 +143,40 @@ public class UserPointLogService {
|
|
|
|
|
* @param size 每页数量
|
|
|
|
|
* @return 用户积分列表
|
|
|
|
|
*/
|
|
|
|
|
public PageResult<UserPointLog> getUserPointLogList(String token, Integer page, Integer size) {
|
|
|
|
|
Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
|
|
|
|
|
|
|
public PageResult<UserPointLog> getUserPointLogList(String token, UserPointLogSearchDto userPointLogSearchDto, Integer page,
|
|
|
|
|
Integer size) {
|
|
|
|
|
//
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
Page<UserPointLog> taskPointPage = userPointLogDao.getUserPointLogList(userLoginDto.getUserId(),
|
|
|
|
|
pageable);
|
|
|
|
|
long totalElements = taskPointPage.getTotalElements();
|
|
|
|
|
|
|
|
|
|
return new PageResult<>(totalElements, taskPointPage.getContent());
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
long totalElements = userPointLogPage.getTotalElements();
|
|
|
|
|
return new PageResult<>(totalElements, userPointLogPage.getContent());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) {
|
|
|
|
|
return (Root<UserPointLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
|
|
|
|
|
if (param.getType() != null) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(root.get("type"), param.getType())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|