|
|
@ -9,6 +9,7 @@ import com.luoo.user.dao.UserPointLogDao;
|
|
|
|
import com.luoo.user.dto.point.DrawDTO;
|
|
|
|
import com.luoo.user.dto.point.DrawDTO;
|
|
|
|
import com.luoo.user.dto.point.UserPointLogSearchDto;
|
|
|
|
import com.luoo.user.dto.point.UserPointLogSearchDto;
|
|
|
|
import com.luoo.user.pojo.*;
|
|
|
|
import com.luoo.user.pojo.*;
|
|
|
|
|
|
|
|
import com.luoo.user.vo.point.UserInvitationLogVO;
|
|
|
|
import com.luoo.user.vo.point.UserPointLogVO;
|
|
|
|
import com.luoo.user.vo.point.UserPointLogVO;
|
|
|
|
import com.querydsl.core.BooleanBuilder;
|
|
|
|
import com.querydsl.core.BooleanBuilder;
|
|
|
|
import com.querydsl.core.types.Projections;
|
|
|
|
import com.querydsl.core.types.Projections;
|
|
|
@ -23,6 +24,7 @@ import enums.PointEnums;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
@ -124,16 +126,15 @@ public class UserPointLogService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 通过任务添加积分明细,直接使用userId
|
|
|
|
* 通过任务添加积分明细,直接使用userId
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void addByTaskDailyAndUserId(String taskPointId, String userId) {
|
|
|
|
public void addByTaskDailyAndUserId(String taskPointId, String userId) {
|
|
|
|
UserPointLog userPointLog = UserPointLog.builder()
|
|
|
|
UserPointLog userPointLog = UserPointLog.builder()
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
|
|
|
|
.createUser(userId)
|
|
|
|
.createUser(userId)
|
|
|
|
.taskPointId(taskPointId)
|
|
|
|
.taskPointId(taskPointId)
|
|
|
|
.userId(userId)
|
|
|
|
.userId(userId)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
|
@ -184,8 +185,8 @@ public class UserPointLogService {
|
|
|
|
|
|
|
|
|
|
|
|
if (taskPointId != null) {
|
|
|
|
if (taskPointId != null) {
|
|
|
|
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
|
|
|
|
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
|
|
|
|
if(taskPoint == null) {
|
|
|
|
if (taskPoint == null) {
|
|
|
|
return ;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取积分任务类型
|
|
|
|
// 获取积分任务类型
|
|
|
@ -227,7 +228,7 @@ public class UserPointLogService {
|
|
|
|
// 调整用户积分
|
|
|
|
// 调整用户积分
|
|
|
|
UserInfo userInfo = userInfoDao.findById(drawDTO.getUserId()).get();
|
|
|
|
UserInfo userInfo = userInfoDao.findById(drawDTO.getUserId()).get();
|
|
|
|
int point = userInfo.getPoint() == null ? 0 : userInfo.getPoint();
|
|
|
|
int point = userInfo.getPoint() == null ? 0 : userInfo.getPoint();
|
|
|
|
if(point < drawDTO.getScore()) {
|
|
|
|
if (point < drawDTO.getScore()) {
|
|
|
|
throw new BizException(ErrorConstants.POINT_NOT_ENOUGH);
|
|
|
|
throw new BizException(ErrorConstants.POINT_NOT_ENOUGH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfo.setPoint(point - drawDTO.getScore());
|
|
|
|
userInfo.setPoint(point - drawDTO.getScore());
|
|
|
@ -301,6 +302,27 @@ public class UserPointLogService {
|
|
|
|
addByTaskDaily(TaskPointIdConstants.SHARE_JOURNAL, token);
|
|
|
|
addByTaskDaily(TaskPointIdConstants.SHARE_JOURNAL, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserInvitationLogVO getUserInvitationLog(String token) {
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> taskPointIds = new ArrayList<>();
|
|
|
|
|
|
|
|
taskPointIds.add(TaskPointIdConstants.NEW_USER_INVITE);
|
|
|
|
|
|
|
|
taskPointIds.add(TaskPointIdConstants.INVITE_USER_3);
|
|
|
|
|
|
|
|
taskPointIds.add(TaskPointIdConstants.INVITE_USER_6);
|
|
|
|
|
|
|
|
taskPointIds.add(TaskPointIdConstants.INVITE_USER_10);
|
|
|
|
|
|
|
|
taskPointIds.add(TaskPointIdConstants.INVITE_USER_20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<UserPointLog> userPointLogByTaskPointIdInAndUserId = userPointLogDao.findUserPointLogByTaskPointIdInAndUserId(taskPointIds, userId);
|
|
|
|
|
|
|
|
UserInvitationLogVO userInvitationLogVO = new UserInvitationLogVO();
|
|
|
|
|
|
|
|
userInvitationLogVO.setNum(userPointLogByTaskPointIdInAndUserId.isEmpty() ? 0 : userPointLogByTaskPointIdInAndUserId.size());
|
|
|
|
|
|
|
|
userInvitationLogVO.setPoint(userPointLogByTaskPointIdInAndUserId.isEmpty() ? 0 :
|
|
|
|
|
|
|
|
userPointLogByTaskPointIdInAndUserId.stream().map(UserPointLog::getScore).reduce(0, Integer::sum)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return userInvitationLogVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 分页查询用户积分列表
|
|
|
|
* 分页查询用户积分列表
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -310,8 +332,8 @@ public class UserPointLogService {
|
|
|
|
* @return 用户积分列表
|
|
|
|
* @return 用户积分列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public PageResult<UserPointLogVO> getUserPointLogList(String token,
|
|
|
|
public PageResult<UserPointLogVO> getUserPointLogList(String token,
|
|
|
|
UserPointLogSearchDto userPointLogSearchDto, Integer page,
|
|
|
|
UserPointLogSearchDto userPointLogSearchDto, Integer page,
|
|
|
|
Integer size) {
|
|
|
|
Integer size) {
|
|
|
|
|
|
|
|
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
BooleanBuilder booleanBuilder = new BooleanBuilder();
|
|
|
|
QUserPointLog qUserPointLog = QUserPointLog.userPointLog;
|
|
|
|
QUserPointLog qUserPointLog = QUserPointLog.userPointLog;
|
|
|
@ -327,15 +349,15 @@ public class UserPointLogService {
|
|
|
|
|
|
|
|
|
|
|
|
List<UserPointLogVO> userPointLogPage = jpaQueryFactory.select(
|
|
|
|
List<UserPointLogVO> userPointLogPage = jpaQueryFactory.select(
|
|
|
|
Projections.constructor(UserPointLogVO.class,
|
|
|
|
Projections.constructor(UserPointLogVO.class,
|
|
|
|
qUserPointLog.id,
|
|
|
|
qUserPointLog.id,
|
|
|
|
qUserPointLog.score,
|
|
|
|
qUserPointLog.score,
|
|
|
|
qUserPointLog.type,
|
|
|
|
qUserPointLog.type,
|
|
|
|
qUserPointLog.userId,
|
|
|
|
qUserPointLog.userId,
|
|
|
|
qUserPointLog.taskPointId,
|
|
|
|
qUserPointLog.taskPointId,
|
|
|
|
qUserPointLog.description,
|
|
|
|
qUserPointLog.description,
|
|
|
|
qUserPointLog.createTime,
|
|
|
|
qUserPointLog.createTime,
|
|
|
|
formattedCreateTime.as("createMonth")
|
|
|
|
formattedCreateTime.as("createMonth")
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.from(qUserPointLog)
|
|
|
|
.from(qUserPointLog)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.where(booleanBuilder)
|
|
|
|
.orderBy(qUserPointLog.createTime.desc())
|
|
|
|
.orderBy(qUserPointLog.createTime.desc())
|
|
|
@ -349,14 +371,14 @@ public class UserPointLogService {
|
|
|
|
return new PageResult<>(totalElements, userPointLogPage);
|
|
|
|
return new PageResult<>(totalElements, userPointLogPage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void checkCondition(BooleanBuilder booleanBuilder, QUserPointLog qUserPointLog, UserPointLogSearchDto userPointLogSearchDto){
|
|
|
|
public void checkCondition(BooleanBuilder booleanBuilder, QUserPointLog qUserPointLog, UserPointLogSearchDto userPointLogSearchDto) {
|
|
|
|
if(!StringUtils.isEmpty(userPointLogSearchDto.getUserId())) {
|
|
|
|
if (!StringUtils.isEmpty(userPointLogSearchDto.getUserId())) {
|
|
|
|
booleanBuilder.and(qUserPointLog.createUser.eq(userPointLogSearchDto.getUserId()));
|
|
|
|
booleanBuilder.and(qUserPointLog.createUser.eq(userPointLogSearchDto.getUserId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(userPointLogSearchDto.getType() != null) {
|
|
|
|
if (userPointLogSearchDto.getType() != null) {
|
|
|
|
booleanBuilder.and(qUserPointLog.type.eq(userPointLogSearchDto.getType()));
|
|
|
|
booleanBuilder.and(qUserPointLog.type.eq(userPointLogSearchDto.getType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!StringUtils.isEmpty(userPointLogSearchDto.getCreateMonth())) {
|
|
|
|
if (!StringUtils.isEmpty(userPointLogSearchDto.getCreateMonth())) {
|
|
|
|
// 判断userPointLogSearchDto.getCreateMonth() 是否是当月时间
|
|
|
|
// 判断userPointLogSearchDto.getCreateMonth() 是否是当月时间
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
|
|
@ -365,7 +387,7 @@ public class UserPointLogService {
|
|
|
|
// 判断是否是当前月份
|
|
|
|
// 判断是否是当前月份
|
|
|
|
boolean isCurrentMonth = userPointLogSearchDto.getCreateMonth().equals(currentMonth);
|
|
|
|
boolean isCurrentMonth = userPointLogSearchDto.getCreateMonth().equals(currentMonth);
|
|
|
|
|
|
|
|
|
|
|
|
if(!isCurrentMonth) {
|
|
|
|
if (!isCurrentMonth) {
|
|
|
|
// 不是当前月份,仅展示传入月份的记录
|
|
|
|
// 不是当前月份,仅展示传入月份的记录
|
|
|
|
|
|
|
|
|
|
|
|
StringExpression formattedCreateTime = Expressions.stringTemplate(
|
|
|
|
StringExpression formattedCreateTime = Expressions.stringTemplate(
|
|
|
|