release: 2.3.用户积分日志列表(APP&PC)

release-2024-08-08
huangyw 4 months ago
parent 0b0291e786
commit e52e2ddd0d

@ -9,6 +9,7 @@ import com.luoo.user.service.DrawLotteryService;
import com.luoo.user.service.LotteryService; import com.luoo.user.service.LotteryService;
import com.luoo.user.service.TaskPointService; import com.luoo.user.service.TaskPointService;
import com.luoo.user.service.UserPointLogService; import com.luoo.user.service.UserPointLogService;
import com.luoo.user.vo.point.UserPointLogVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@ -161,38 +162,38 @@ public class PointController {
return Result.success(taskPointService.getTaskPointListForApp(token, type)); return Result.success(taskPointService.getTaskPointListForApp(token, type));
} }
@ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用") // @ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/new") // @PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAppUserLogin = true) // @GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({ // @ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), // @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body") // @ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
}) // })
public Result<Void> addLogNew( // public Result<Void> addLogNew(
@RequestHeader(value = "Authorization", required = true) String authorization, // @RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) { // @RequestBody String taskPointId) {
userPointLogService.addByTaskNew(taskPointId, authorization); // userPointLogService.addByTaskNew(taskPointId, authorization);
return Result.success(); // return Result.success();
} // }
//
@ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用") // @ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/daily") // @PostMapping("/log/earn/task/daily")
@GlobalInterceptor(checkAppUserLogin = true) // @GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({ // @ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), // @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body") // @ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
}) // })
public Result<Void> addLogDaily( // public Result<Void> addLogDaily(
@RequestHeader(value = "Authorization", required = true) String authorization, // @RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) { // @RequestBody String taskPointId) {
userPointLogService.addByTaskDaily(taskPointId, authorization); // userPointLogService.addByTaskDaily(taskPointId, authorization);
return Result.success(); // return Result.success();
} // }
@ApiOperation(value = "2.3.用户积分日志列表(APP&PC)", notes = "用户积分日志列表") @ApiOperation(value = "2.3.用户积分日志列表(APP&PC)", notes = "用户积分日志列表")
@PostMapping("/log/list/{page}/{size}") @PostMapping("/log/list/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserPointLog>> getUserPointLogList( public Result<PageResult<UserPointLogVO>> getUserPointLogList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody UserPointLogSearchDto userPointLogSearchDto, @ApiParam(value = "查询对象") @RequestBody UserPointLogSearchDto userPointLogSearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "页码", required = true) @PathVariable Integer page,

@ -7,6 +7,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.Transient;
/** /**
* DTO for {@link com.luoo.user.pojo.UserPointLog} * DTO for {@link com.luoo.user.pojo.UserPointLog}
*/ */
@ -17,8 +19,12 @@ import lombok.NoArgsConstructor;
public class UserPointLogSearchDto implements Serializable { public class UserPointLogSearchDto implements Serializable {
@ApiModelProperty(value = "类型 1-收入 2-支出 null-全部") @ApiModelProperty(value = "类型 1-收入 2-支出 null-全部")
public Integer type; private Integer type;
private String userId;
public String userId; @Transient
@ApiModelProperty(value = "所在月份", example = "202408")
private String createMonth;
} }

@ -80,4 +80,8 @@ public class UserPointLog implements Serializable {
@ApiModelProperty(value = "更新人") @ApiModelProperty(value = "更新人")
private String updateUser; private String updateUser;
@Transient
@ApiModelProperty(value = "所在月份")
private String createMonth;
} }

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

@ -0,0 +1,37 @@
package com.luoo.user.vo.point;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Value;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* DTO for {@link com.luoo.user.pojo.UserPointLog}
*/
@Value
@AllArgsConstructor
public class UserPointLogVO implements Serializable {
String id;
Integer score;
Integer type;
String userId;
String taskPointId;
String description;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createTime;
@Transient
String createMonth;
}
Loading…
Cancel
Save