release: 每日签到积分获取

release-2024-08-08
huangyw 4 months ago
parent 42bcd7fddf
commit 0a06c4a044

@ -16,10 +16,12 @@ import com.luoo.comment.util.EmojiConverterUtil;
import com.luoo.comment.util.IpUtil; import com.luoo.comment.util.IpUtil;
import com.luoo.comment.util.MySensitiveWordReplaceUtils; import com.luoo.comment.util.MySensitiveWordReplaceUtils;
import constants.Constants; import constants.Constants;
import constants.TaskPointIdConstants;
import controller.BaseController; import controller.BaseController;
import dto.UserLoginDto; import dto.UserLoginDto;
import dto.UserMessageDto; import dto.UserMessageDto;
import enums.MessageTypeEnum; import enums.MessageTypeEnum;
import enums.PointEnums;
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;
@ -35,6 +37,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import pojo.UserPointLog;
import util.IdWorker; import util.IdWorker;
import util.StringTools; import util.StringTools;
@ -360,6 +363,18 @@ public class CommentController extends BaseController {
}); });
commentResp.setBadgeList(new ArrayList<>(badgeSet)); commentResp.setBadgeList(new ArrayList<>(badgeSet));
} }
// 评论积分
UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
.createUser(userLoginDto.getUserId())
.taskPointId(TaskPointIdConstants.DAILY_COMMENT)
.userId(userLoginDto.getUserId())
.build();
rabbitTemplate.convertAndSend("pointLog", userPointLog);
return Result.success(commentResp); return Result.success(commentResp);
} }

@ -30,22 +30,22 @@ public class TaskPointIdConstants {
// 每日登录 todo // 每日登录 todo
public static final String DAILY_LOGIN = "10"; public static final String DAILY_LOGIN = "10";
// 每日签到 todo // 每日签到
public static final String DAILY_SIGN = "11"; public static final String DAILY_SIGN = "11";
// 分享期刊 todo // 分享期刊
public static final String SHARE_JOURNAL = "12"; public static final String SHARE_JOURNAL = "12";
// 新用户邀请 todo // 新用户邀请 todo
public static final String NEW_USER_INVITE = "13"; public static final String NEW_USER_INVITE = "13";
// 每日评论 todo // 每日评论
public static final String DAILY_COMMENT = "14"; public static final String DAILY_COMMENT = "14";
// 动态发布 todo // 动态发布 todo
public static final String DYNAMIC_PUBLISH = "15"; public static final String DYNAMIC_PUBLISH = "15";
// 连续签到3天 todo // 连续签到3天
public static final String DAILY_SIGN_3 = "16"; public static final String DAILY_SIGN_3 = "16";
// 连续签到7天 todo // 连续签到7天
public static final String DAILY_SIGN_7 = "17"; public static final String DAILY_SIGN_7 = "17";
// 连续签到30天 todo // 连续签到30天
public static final String DAILY_SIGN_30 = "18"; public static final String DAILY_SIGN_30 = "18";
// 邀请用户3人 todo // 邀请用户3人 todo
public static final String INVITE_USER_3 = "19"; public static final String INVITE_USER_3 = "19";

@ -0,0 +1,58 @@
package pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-07-31 16:28
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Builder
public class UserPointLog implements Serializable {
@ApiModelProperty(value = "主键")
private String id;
@ApiModelProperty(value = "积分")
private Integer score;
@ApiModelProperty(value = "类型 1-增加 2-减少")
private Integer type;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "任务积分id")
private String taskPointId;
@ApiModelProperty(value = "事件描述")
private String description;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
@ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
@ApiModelProperty(value = "创建人")
private String createUser;
@ApiModelProperty(value = "更新人")
private String updateUser;
}

@ -17,8 +17,10 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort; import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import java.util.List; import java.util.List;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
@ -178,6 +180,30 @@ public class PointController {
userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size)); userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size));
} }
@ApiOperation(value = "2.4.每日签到", notes = "仅限app用户调用")
@PostMapping("/log/earn/sign")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")
})
public Result<Void> addLogSign(@RequestHeader(value = "Authorization", required = true) String authorization) {
userPointLogService.dailySign(authorization);
return Result.success();
}
@ApiOperation(value = "2.5.分享期刊", notes = "仅限app用户调用")
@PostMapping("/log/share/journal")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "journalId", value = "期刊id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> addLogShareJournal(@RequestHeader(value = "Authorization", required = true) String authorization, @RequestParam String journalId) {
userPointLogService.shareJournal(authorization);
return Result.success();
}
@ApiOperation(value = "3.1.添加抽奖", notes = "仅限admin权限用户调用") @ApiOperation(value = "3.1.添加抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/add") @PostMapping("/lottery/add")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ -267,5 +293,4 @@ public class PointController {
} }
} }

@ -15,4 +15,10 @@ public interface UserPointLogDao extends JpaRepository<UserPointLog, String>, Jp
@Query(value = " select * from tb_user_point_log where user_id = ?1 order by create_time desc", countProjection = "id", nativeQuery = true) @Query(value = " select * from tb_user_point_log where user_id = ?1 order by create_time desc", countProjection = "id", nativeQuery = true)
public Page<UserPointLog> getUserPointLogList(String userId, Pageable pageable); public Page<UserPointLog> getUserPointLogList(String userId, Pageable pageable);
@Query(value = "select * from tb_user_point_log where user_id = ?1 and task_point_id = ?2 and Date(create_time) = CURDATE() limit 1", nativeQuery = true)
public UserPointLog findTodayByUserIdAndTaskPointId(String userId, String pointId);
@Query(value = "select * from tb_user_point_log where user_id = ?1 and task_point_id = ?2 and Date(create_time) BETWEEN DATE_SUB(CURDATE(), INTERVAL ?3 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY)", nativeQuery = true)
public List<UserPointLog> findDaysByUserIdAndTaskPointId(String userId, String pointId, Integer days);
} }

@ -8,8 +8,10 @@ import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.pojo.UserPointLog; import com.luoo.user.pojo.UserPointLog;
import constants.TaskPointIdConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.PointEnums;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -17,6 +19,7 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; 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;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -168,8 +171,48 @@ public class UserPointLogService {
userInfo.setPoint(point); userInfo.setPoint(point);
// 更新用户积分信息 // 更新用户积分信息
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
}
/**
*
*
* @param token token
*/
public void dailySign(String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
UserPointLog todayByUserIdAndTaskPointId = userPointLogDao.findTodayByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN);
if (todayByUserIdAndTaskPointId == null) {
// 今天还没签到
addByTaskDaily(TaskPointIdConstants.DAILY_SIGN, token);
// 连续3天
List<UserPointLog> daysByUserIdAndTaskPointId3 = userPointLogDao.findDaysByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN, 3 - 1);
if (daysByUserIdAndTaskPointId3.size() == 3) {
addByTaskDaily(TaskPointIdConstants.DAILY_SIGN_3, token);
}
// 连续7天
List<UserPointLog> daysByUserIdAndTaskPointId7 = userPointLogDao.findDaysByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN, 7 - 1);
if (daysByUserIdAndTaskPointId7.size() == 7) {
addByTaskDaily(TaskPointIdConstants.DAILY_SIGN_7, token);
}
// 连续30天
List<UserPointLog> daysByUserIdAndTaskPointId30 = userPointLogDao.findDaysByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN, 30 - 1);
if (daysByUserIdAndTaskPointId30.size() == 30) {
addByTaskDaily(TaskPointIdConstants.DAILY_SIGN_30, token);
}
}
}
/**
*
*
* @param token token
*/
public void shareJournal(String token) {
addByTaskDaily(TaskPointIdConstants.SHARE_JOURNAL, token);
} }
/** /**
@ -195,8 +238,6 @@ public class UserPointLogService {
long totalElements = userPointLogPage.getTotalElements(); long totalElements = userPointLogPage.getTotalElements();
return new PageResult<>(totalElements, userPointLogPage.getContent()); return new PageResult<>(totalElements, userPointLogPage.getContent());
} }
private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) { private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) {

Loading…
Cancel
Save