diff --git a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java index 072d32f..e44e034 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java @@ -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> 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)); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java new file mode 100644 index 0000000..5d7e5ad --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java @@ -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; + +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 1436e2d..991882b 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -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 getUserPointLogList(String token, Integer page, Integer size) { - Pageable pageable = PageRequest.of(page - 1, size); - + public PageResult getUserPointLogList(String token, UserPointLogSearchDto userPointLogSearchDto, Integer page, + Integer size) { +// UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - Page 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 specification = buildSearchSpecification(userPointLogSearchDto); + Page userPointLogPage = userPointLogDao.findAll(specification, pageRequest); + + long totalElements = userPointLogPage.getTotalElements(); + return new PageResult<>(totalElements, userPointLogPage.getContent()); + + + } + + private Specification buildSearchSpecification(UserPointLogSearchDto param) { + return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { + List predicateList = new ArrayList(); + + 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()])); + }; } }