release: 根据类型查询积分列表

release-2024-08-08
huangyw 4 months ago
parent 6b2fe92592
commit c3e7a7aced

@ -3,6 +3,7 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor;
import api.PageResult;
import api.Result;
import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.TaskPointService;
@ -144,18 +145,14 @@ public class PointController {
}
@ApiOperation(value = "2.2.用户积分日志列表", notes = "用户积分日志列表")
@GetMapping("/log/list/{page}/{size}")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "Integer", paramType = "path"),
@ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer", paramType = "path")
})
@PostMapping("/log/list/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserPointLog>> getUserPointLogList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象")@RequestBody UserPointLogSearchDto userPointLogSearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(userPointLogService.getUserPointLogList(token, page, size));
return Result.success(userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size));
}

@ -0,0 +1,24 @@
package com.luoo.user.dto.point;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DTO for {@link com.luoo.user.pojo.UserPointLog}
*/
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class UserPointLogSearchDto implements Serializable {
@ApiModelProperty(value = "类型 1-收入 2-支出 null-全部")
public Integer type;
public String userId;
}

@ -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()]));
};
}
}

Loading…
Cancel
Save