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.MySensitiveWordReplaceUtils;
import constants.Constants;
import constants.TaskPointIdConstants;
import controller.BaseController;
import dto.UserLoginDto;
import dto.UserMessageDto;
import enums.MessageTypeEnum;
import enums.PointEnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import pojo.UserPointLog;
import util.IdWorker;
import util.StringTools;
@ -360,6 +363,18 @@ public class CommentController extends BaseController {
});
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);
}

@ -30,22 +30,22 @@ public class TaskPointIdConstants {
// 每日登录 todo
public static final String DAILY_LOGIN = "10";
// 每日签到 todo
// 每日签到
public static final String DAILY_SIGN = "11";
// 分享期刊 todo
// 分享期刊
public static final String SHARE_JOURNAL = "12";
// 新用户邀请 todo
public static final String NEW_USER_INVITE = "13";
// 每日评论 todo
// 每日评论
public static final String DAILY_COMMENT = "14";
// 动态发布 todo
public static final String DYNAMIC_PUBLISH = "15";
// 连续签到3天 todo
// 连续签到3天
public static final String DAILY_SIGN_3 = "16";
// 连续签到7天 todo
// 连续签到7天
public static final String DAILY_SIGN_7 = "17";
// 连续签到30天 todo
// 连续签到30天
public static final String DAILY_SIGN_30 = "18";
// 邀请用户3人 todo
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.ApiOperationSort;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
@ -45,227 +47,250 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "积分模块")
public class PointController {
@Autowired
private TaskPointService taskPointService;
@Autowired
private TaskPointService taskPointService;
@Autowired
private UserPointLogService userPointLogService;
@Autowired
private LotteryService lotteryService;
@Autowired
private UserPointLogService userPointLogService;
@Autowired
private LotteryService lotteryService;
@ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/add")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")})
public Result<Void> add(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody TaskPoint taskPoint) {
taskPointService.add(taskPoint, authorization);
return Result.success();
}
@ApiOperation(value = "1.2.修改任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/update")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
)
public Result<Void> update(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody TaskPoint taskPoint) {
taskPointService.update(taskPoint, authorization);
return Result.success();
}
@ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/add")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")})
public Result<Void> add(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody TaskPoint taskPoint) {
taskPointService.add(taskPoint, authorization);
return Result.success();
}
@ApiOperation(value = "1.3.批量修改任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/batch/update")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
)
public Result<Void> batchUpdate(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody List<TaskPoint> taskPoints) {
taskPointService.batchUpdate(taskPoints, authorization);
return Result.success();
}
@ApiOperation(value = "1.2.修改任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/update")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
)
public Result<Void> update(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody TaskPoint taskPoint) {
taskPointService.update(taskPoint, authorization);
return Result.success();
}
@ApiOperation(value = "1.4.批量禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/batch/disable")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List<String>", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
}
)
public Result<Void> batchDisable(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody List<String> ids,
@RequestParam Integer valid) {
taskPointService.batchDisable(ids, authorization, valid);
return Result.success();
}
@ApiOperation(value = "1.3.批量修改任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/batch/update")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
)
public Result<Void> batchUpdate(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody List<TaskPoint> taskPoints) {
taskPointService.batchUpdate(taskPoints, authorization);
return Result.success();
}
@ApiOperation(value = "1.5.禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/disable")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "任务积分配置id", required = true, dataType = "String", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
})
public Result<Void> disable(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestParam String id,
@RequestParam Integer valid) {
taskPointService.disable(id, authorization, valid);
return Result.success();
}
@ApiOperation(value = "1.4.批量禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/batch/disable")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List<String>", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
}
)
public Result<Void> batchDisable(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody List<String> ids,
@RequestParam Integer valid) {
taskPointService.batchDisable(ids, authorization, valid);
return Result.success();
}
@ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表")
@GetMapping("/task/list/{page}/{size}")
public Result<PageResult<TaskPoint>> getUnApproveList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(taskPointService.getTaskPointList(page, size));
}
@ApiOperation(value = "1.5.禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/disable")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "任务积分配置id", required = true, dataType = "String", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
})
public Result<Void> disable(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestParam String id,
@RequestParam Integer valid) {
taskPointService.disable(id, authorization, valid);
return Result.success();
}
@ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogNew(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskNew(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表")
@GetMapping("/task/list/{page}/{size}")
public Result<PageResult<TaskPoint>> getUnApproveList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(taskPointService.getTaskPointList(page, size));
}
@ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/daily")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogDaily(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskDaily(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogNew(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskNew(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "2.3.用户积分日志列表", notes = "用户积分日志列表")
@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, userPointLogSearchDto, page, size));
}
@ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/daily")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogDaily(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskDaily(taskPointId, authorization);
return Result.success();
}
@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.3.用户积分日志列表", notes = "用户积分日志列表")
@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, userPointLogSearchDto, page, size));
}
@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权限用户调用")
@PostMapping("/lottery/add")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
})
public Result<Void> addLottery(@RequestHeader("Authorization") String token,
@RequestBody Lottery lottery) {
lotteryService.add(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.2.抽奖列表页", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<Lottery>> lotteryList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto));
}
@ApiOperation(value = "3.1.添加抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/add")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
})
public Result<Void> addLottery(@RequestHeader("Authorization") String token,
@RequestBody Lottery lottery) {
lotteryService.add(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.3.编辑抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/edit")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
})
public Result<Void> editLottery(@RequestHeader("Authorization") String token,
@RequestBody Lottery lottery) {
lotteryService.edit(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.2.抽奖列表页", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<Lottery>> lotteryList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto));
}
@ApiOperation(value = "3.4.发布抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/publish")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> publishLottery(@RequestHeader("Authorization") String token,
@RequestBody String id) {
lotteryService.publish(id, token);
return Result.success();
}
@ApiOperation(value = "3.3.编辑抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/edit")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
})
public Result<Void> editLottery(@RequestHeader("Authorization") String token,
@RequestBody Lottery lottery) {
lotteryService.edit(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.5.停止抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/stop")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "stopReason", value = "停止原因", required = true, dataType = "String", paramType = "body")
})
public Result<Void> stopLottery(@RequestHeader("Authorization") String token,
@NotNull String id, @RequestBody @NotNull String stopReason) {
lotteryService.stop(id, token, stopReason);
return Result.success();
}
@ApiOperation(value = "3.4.发布抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/publish")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> publishLottery(@RequestHeader("Authorization") String token,
@RequestBody String id) {
lotteryService.publish(id, token);
return Result.success();
}
@ApiOperation(value = "3.6.参与抽奖")
@PostMapping("/lottery/participate")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) {
lotteryService.participate(id, token, regionId);
return Result.success();
}
@ApiOperation(value = "3.5.停止抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/stop")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "stopReason", value = "停止原因", required = true, dataType = "String", paramType = "body")
})
public Result<Void> stopLottery(@RequestHeader("Authorization") String token,
@NotNull String id, @RequestBody @NotNull String stopReason) {
lotteryService.stop(id, token, stopReason);
return Result.success();
}
@ApiOperation(value = "3.7.自动抽奖结果", notes = "用这个方法主动触发自动抽奖结果")
@PostMapping("/lottery/auto")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> auto(@RequestHeader("Authorization") String token, @NotNull String id) {
lotteryService.auto(id, token);
return Result.success();
}
@ApiOperation(value = "3.6.参与抽奖")
@PostMapping("/lottery/participate")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) {
lotteryService.participate(id, token, regionId);
return Result.success();
}
@ApiOperation(value = "3.7.自动抽奖结果", notes = "用这个方法主动触发自动抽奖结果")
@PostMapping("/lottery/auto")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> auto(@RequestHeader("Authorization") String token, @NotNull String id) {
lotteryService.auto(id, token);
return Result.success();
}
}

@ -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)
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.UserInfo;
import com.luoo.user.pojo.UserPointLog;
import constants.TaskPointIdConstants;
import dto.UserLoginDto;
import enums.PointEnums;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -17,6 +19,7 @@ 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.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -41,180 +44,218 @@ import util.JwtUtil;
@Slf4j
public class UserPointLogService {
private final UserPointLogDao userPointLogDao;
private final IdWorker idWorker;
private final UserPointLogDao userPointLogDao;
private final JwtUtil jwtUtil;
private final IdWorker idWorker;
private final TaskPointDao taskPointDao;
private final JwtUtil jwtUtil;
private final RabbitTemplate rabbitTemplate;
private final TaskPointDao taskPointDao;
private final UserInfoDao userInfoDao;
private final RabbitTemplate rabbitTemplate;
private final UserInfoDao userInfoDao;
public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao) {
this.userPointLogDao = userPointLogDao;
this.idWorker = idWorker;
this.jwtUtil = jwtUtil;
this.taskPointDao = taskPointDao;
this.rabbitTemplate = rabbitTemplate;
this.userInfoDao = userInfoDao;
}
private TaskPointService taskPointService;
@Autowired
private void setTaskPointService(TaskPointService taskPointService) {
this.taskPointService = taskPointService;
}
public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao) {
this.userPointLogDao = userPointLogDao;
this.idWorker = idWorker;
this.jwtUtil = jwtUtil;
this.taskPointDao = taskPointDao;
this.rabbitTemplate = rabbitTemplate;
this.userInfoDao = userInfoDao;
}
/**
*
*
* @param taskPointId ID
* @param token tokenID
*/
public Integer addByTaskNew(String taskPointId, String token) {
// todo 缓存优化
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
private TaskPointService taskPointService;
// 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(),
taskPointId).isEmpty()) {
return 0;
@Autowired
private void setTaskPointService(TaskPointService taskPointService) {
this.taskPointService = taskPointService;
}
addByTask(taskPointId, userLoginDto);
TaskPoint taskPoint = taskPointDao.findById(taskPointId).get();
return taskPoint.getScore();
}
/**
*
* <p>
* ID tokenRabbitMQ
*
*
* @param taskPointId ID
* @param token tokenID
*/
public void addByTaskDaily(String taskPointId, String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
addByTask(taskPointId, userLoginDto);
}
private void addByTask(String taskPointId, UserLoginDto userLoginDto) {
UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
.createUser(userLoginDto.getUserId())
.taskPointId(taskPointId)
.userId(userLoginDto.getUserId())
.build();
rabbitTemplate.convertAndSend("pointLog", userPointLog);
}
/**
*
* <p>
* @Transactional
*
* @param userPointLog IDID
*/
@Transactional(rollbackFor = Exception.class)
public void add(UserPointLog userPointLog) {
// 根据积分任务ID获取积分任务详情
// 保存积分记录
String taskPointId = userPointLog.getTaskPointId();
if (taskPointId != null) {
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
// 获取积分任务类型
Integer type = taskPoint.getType();
// 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分
if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) {
/**
*
*
* @param taskPointId ID
* @param token tokenID
*/
public Integer addByTaskNew(String taskPointId, String token) {
// todo 缓存优化
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
// 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(),
userPointLog.getTaskPointId()).isEmpty()) {
return;
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(),
taskPointId).isEmpty()) {
return 0;
}
}
userPointLog.setScore(taskPoint.getScore());
userPointLog.setDescription(taskPoint.getDescription());
addByTask(taskPointId, userLoginDto);
TaskPoint taskPoint = taskPointDao.findById(taskPointId).get();
return taskPoint.getScore();
}
/**
*
* <p>
* ID tokenRabbitMQ
*
*
* @param taskPointId ID
* @param token tokenID
*/
public void addByTaskDaily(String taskPointId, String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
// 保存用户积分记录
userPointLogDao.save(userPointLog);
log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId());
addByTask(taskPointId, userLoginDto);
}
// 如果id不存在按传入的增加积分如取消抽奖返还用户积分
private void addByTask(String taskPointId, UserLoginDto userLoginDto) {
UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
.createUser(userLoginDto.getUserId())
.taskPointId(taskPointId)
.userId(userLoginDto.getUserId())
.build();
// 更新用户积分,获取用户信息并累加积分得分
// 对用户进行积分计算
UserInfo userInfo = userInfoDao.findById(userPointLog.getUserId()).get();
Integer point = userInfo.getPoint();
point += userPointLog.getScore();
userInfo.setPoint(point);
// 更新用户积分信息
userInfoDao.save(userInfo);
rabbitTemplate.convertAndSend("pointLog", userPointLog);
}
/**
*
* <p>
* @Transactional
*
* @param userPointLog IDID
*/
@Transactional(rollbackFor = Exception.class)
public void add(UserPointLog userPointLog) {
// 根据积分任务ID获取积分任务详情
// 保存积分记录
String taskPointId = userPointLog.getTaskPointId();
if (taskPointId != null) {
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
// 获取积分任务类型
Integer type = taskPoint.getType();
// 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分
if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) {
// 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(),
userPointLog.getTaskPointId()).isEmpty()) {
return;
}
}
userPointLog.setScore(taskPoint.getScore());
userPointLog.setDescription(taskPoint.getDescription());
// 保存用户积分记录
userPointLogDao.save(userPointLog);
log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId());
}
}
// 如果id不存在按传入的增加积分如取消抽奖返还用户积分
/**
*
*
* @param token token
* @param page
* @param size
* @return
*/
public PageResult<UserPointLog> getUserPointLogList(String token,
UserPointLogSearchDto userPointLogSearchDto, Integer page,
Integer size) {
//
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
Sort sort = new Sort(Direction.DESC, "createTime");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
// 更新用户积分,获取用户信息并累加积分得分
// 对用户进行积分计算
UserInfo userInfo = userInfoDao.findById(userPointLog.getUserId()).get();
Integer point = userInfo.getPoint();
point += userPointLog.getScore();
userInfo.setPoint(point);
// 更新用户积分信息
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);
}
userPointLogSearchDto.setUserId(userLoginDto.getUserId());
Specification<UserPointLog> specification = buildSearchSpecification(userPointLogSearchDto);
Page<UserPointLog> userPointLogPage = userPointLogDao.findAll(specification, pageRequest);
/**
*
*
* @param token token
* @param page
* @param size
* @return
*/
public PageResult<UserPointLog> getUserPointLogList(String token,
UserPointLogSearchDto userPointLogSearchDto, Integer page,
Integer size) {
//
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
long totalElements = userPointLogPage.getTotalElements();
return new PageResult<>(totalElements, userPointLogPage.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>();
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 (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())));
}
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()]));
};
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
}
}

Loading…
Cancel
Save