From 0a06c4a0446c2f6d5a9d9ed814d2b4f6d435c90a Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 31 Jul 2024 16:53:04 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 15 + .../java/constants/TaskPointIdConstants.java | 12 +- .../src/main/java/pojo/UserPointLog.java | 58 +++ .../luoo/user/controller/PointController.java | 427 +++++++++--------- .../com/luoo/user/dao/UserPointLogDao.java | 6 + .../user/service/UserPointLogService.java | 329 ++++++++------ 6 files changed, 496 insertions(+), 351 deletions(-) create mode 100644 luoo_common/src/main/java/pojo/UserPointLog.java diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 5d2715d..47ce5bd 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -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); } diff --git a/luoo_common/src/main/java/constants/TaskPointIdConstants.java b/luoo_common/src/main/java/constants/TaskPointIdConstants.java index 02f9ddf..0721e67 100644 --- a/luoo_common/src/main/java/constants/TaskPointIdConstants.java +++ b/luoo_common/src/main/java/constants/TaskPointIdConstants.java @@ -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"; diff --git a/luoo_common/src/main/java/pojo/UserPointLog.java b/luoo_common/src/main/java/pojo/UserPointLog.java new file mode 100644 index 0000000..3ea8428 --- /dev/null +++ b/luoo_common/src/main/java/pojo/UserPointLog.java @@ -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; + +} 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 cd1a426..b07abb3 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 @@ -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 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 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 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", paramType = "body"), + @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")} + ) + public Result batchUpdate( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody List 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 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", 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 batchDisable( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody List 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", paramType = "body"), - @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")} - ) - public Result batchUpdate( - @RequestHeader(value = "Authorization", required = true) String authorization, - @RequestBody List 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 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", 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 batchDisable( - @RequestHeader(value = "Authorization", required = true) String authorization, - @RequestBody List ids, - @RequestParam Integer valid) { - taskPointService.batchDisable(ids, authorization, valid); - return Result.success(); - } + @ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表") + @GetMapping("/task/list/{page}/{size}") + public Result> 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 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 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> 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 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 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> 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 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 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> 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 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 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> 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 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 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> 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 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 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 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 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 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 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 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 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 auto(@RequestHeader("Authorization") String token, @NotNull String id) { + lotteryService.auto(id, token); + return Result.success(); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java index 1aa176b..44f5ab4 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java @@ -15,4 +15,10 @@ public interface UserPointLogDao extends JpaRepository, Jp @Query(value = " select * from tb_user_point_log where user_id = ?1 order by create_time desc", countProjection = "id", nativeQuery = true) public Page 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 findDaysByUserIdAndTaskPointId(String userId, String pointId, Integer days); } 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 cb67367..a8c1537 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 @@ -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 用户的token,用于验证用户身份并获取用户ID。 - */ - 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(); - } - - /** - * 通过任务添加积分明细。 - *

- * 此方法用于处理用户完成特定任务后增加积分的逻辑。它首先根据任务点ID获取任务点信息, 然后根据用户token获取用户信息,最后创建一个积分日志对象并将其发送到RabbitMQ, - * 以异步方式记录用户的积分变动。 - * - * @param taskPointId 任务点ID,用于查找任务点信息。 - * @param token 用户的token,用于验证用户身份并获取用户ID。 - */ - 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); - } - - /** - * 添加用户积分记录。 - *

- * 通过@Transactional注解确保该方法操作的数据库事务一致性,任何异常都将导致事务回滚。 - * - * @param userPointLog 用户积分记录对象,包含积分任务ID、用户ID和积分得分。 - */ - @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 用户的token,用于验证用户身份并获取用户ID。 + */ + 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(); + } + + /** + * 通过任务添加积分明细。 + *

+ * 此方法用于处理用户完成特定任务后增加积分的逻辑。它首先根据任务点ID获取任务点信息, 然后根据用户token获取用户信息,最后创建一个积分日志对象并将其发送到RabbitMQ, + * 以异步方式记录用户的积分变动。 + * + * @param taskPointId 任务点ID,用于查找任务点信息。 + * @param token 用户的token,用于验证用户身份并获取用户ID。 + */ + 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); + } + /** + * 添加用户积分记录。 + *

+ * 通过@Transactional注解确保该方法操作的数据库事务一致性,任何异常都将导致事务回滚。 + * + * @param userPointLog 用户积分记录对象,包含积分任务ID、用户ID和积分得分。 + */ + @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 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 daysByUserIdAndTaskPointId3 = userPointLogDao.findDaysByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN, 3 - 1); + if (daysByUserIdAndTaskPointId3.size() == 3) { + addByTaskDaily(TaskPointIdConstants.DAILY_SIGN_3, token); + } + + // 连续7天 + List daysByUserIdAndTaskPointId7 = userPointLogDao.findDaysByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN, 7 - 1); + if (daysByUserIdAndTaskPointId7.size() == 7) { + addByTaskDaily(TaskPointIdConstants.DAILY_SIGN_7, token); + } + + // 连续30天 + List 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 specification = buildSearchSpecification(userPointLogSearchDto); - Page userPointLogPage = userPointLogDao.findAll(specification, pageRequest); + /** + * 分页查询用户积分列表 + * + * @param token 用户token + * @param page 页码 + * @param size 每页数量 + * @return 用户积分列表 + */ + public PageResult 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 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(); + 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 (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()])); + }; + } }