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;
@ -45,227 +47,250 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "积分模块") @Api(tags = "积分模块")
public class PointController { public class PointController {
@Autowired @Autowired
private TaskPointService taskPointService; private TaskPointService taskPointService;
@Autowired
private UserPointLogService userPointLogService;
@Autowired
private LotteryService lotteryService;
@Autowired
private UserPointLogService userPointLogService;
@Autowired @ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用")
private LotteryService lotteryService; @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权限用户调用") @ApiOperation(value = "1.3.批量修改任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/add") @PostMapping("/task/batch/update")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"), @ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}) @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
public Result<Void> add( )
@RequestHeader(value = "Authorization", required = true) String authorization, public Result<Void> batchUpdate(
@RequestBody TaskPoint taskPoint) { @RequestHeader(value = "Authorization", required = true) String authorization,
taskPointService.add(taskPoint, authorization); @RequestBody List<TaskPoint> taskPoints) {
return Result.success(); taskPointService.batchUpdate(taskPoints, authorization);
} return Result.success();
}
@ApiOperation(value = "1.2.修改任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.4.批量禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/update") @PostMapping("/task/batch/disable")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"), @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 = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
) @ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
public Result<Void> update( }
@RequestHeader(value = "Authorization", required = true) String authorization, )
@RequestBody TaskPoint taskPoint) { public Result<Void> batchDisable(
taskPointService.update(taskPoint, authorization); @RequestHeader(value = "Authorization", required = true) String authorization,
return Result.success(); @RequestBody List<String> ids,
} @RequestParam Integer valid) {
taskPointService.batchDisable(ids, authorization, valid);
return Result.success();
}
@ApiOperation(value = "1.3.批量修改任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.5.禁用任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/batch/update") @PostMapping("/task/disable")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"), @ApiImplicitParam(name = "id", value = "任务积分配置id", required = true, dataType = "String", paramType = "body"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")} @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> batchUpdate( })
@RequestHeader(value = "Authorization", required = true) String authorization, public Result<Void> disable(
@RequestBody List<TaskPoint> taskPoints) { @RequestHeader(value = "Authorization", required = true) String authorization,
taskPointService.batchUpdate(taskPoints, authorization); @RequestParam String id,
return Result.success(); @RequestParam Integer valid) {
} taskPointService.disable(id, authorization, valid);
return Result.success();
}
@ApiOperation(value = "1.4.批量禁用任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表")
@PostMapping("/task/batch/disable") @GetMapping("/task/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true) public Result<PageResult<TaskPoint>> getUnApproveList(
@ApiImplicitParams({ @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List<String>", paramType = "body"), @ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query") return Result.success(taskPointService.getTaskPointList(page, size));
} }
)
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.5.禁用任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/task/disable") @PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({ @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 = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query") })
}) public Result<Void> addLogNew(
public Result<Void> disable( @RequestHeader(value = "Authorization", required = true) String authorization,
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestBody String taskPointId) {
@RequestParam String id, userPointLogService.addByTaskNew(taskPointId, authorization);
@RequestParam Integer valid) { return Result.success();
taskPointService.disable(id, authorization, valid); }
return Result.success();
}
@ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表") @ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用")
@GetMapping("/task/list/{page}/{size}") @PostMapping("/log/earn/task/daily")
public Result<PageResult<TaskPoint>> getUnApproveList( @GlobalInterceptor(checkAppUserLogin = true)
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiImplicitParams({
@ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { @ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
return Result.success(taskPointService.getTaskPointList(page, size)); })
} 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用户调用") @ApiOperation(value = "2.3.用户积分日志列表", notes = "用户积分日志列表")
@PostMapping("/log/earn/task/new") @PostMapping("/log/list/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({ public Result<PageResult<UserPointLog>> getUserPointLogList(
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body") @ApiParam(value = "查询对象") @RequestBody UserPointLogSearchDto userPointLogSearchDto,
}) @ApiParam(value = "页码", required = true) @PathVariable Integer page,
public Result<Void> addLogNew( @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
@RequestHeader(value = "Authorization", required = true) String authorization, return Result.success(
@RequestBody String taskPointId) { userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size));
userPointLogService.addByTaskNew(taskPointId, authorization); }
return Result.success();
}
@ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用") @ApiOperation(value = "2.4.每日签到", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/daily") @PostMapping("/log/earn/sign")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body") })
}) public Result<Void> addLogSign(@RequestHeader(value = "Authorization", required = true) String authorization) {
public Result<Void> addLogDaily( userPointLogService.dailySign(authorization);
@RequestHeader(value = "Authorization", required = true) String authorization, return Result.success();
@RequestBody String taskPointId) { }
userPointLogService.addByTaskDaily(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "2.3.用户积分日志列表", notes = "用户积分日志列表") @ApiOperation(value = "2.5.分享期刊", notes = "仅限app用户调用")
@PostMapping("/log/list/{page}/{size}") @PostMapping("/log/share/journal")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserPointLog>> getUserPointLogList( @ApiImplicitParams({
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiParam(value = "查询对象") @RequestBody UserPointLogSearchDto userPointLogSearchDto, @ApiImplicitParam(name = "journalId", value = "期刊id", required = true, dataType = "String", paramType = "query")
@ApiParam(value = "页码", required = true) @PathVariable Integer page, })
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { public Result<Void> addLogShareJournal(@RequestHeader(value = "Authorization", required = true) String authorization, @RequestParam String journalId) {
return Result.success( userPointLogService.shareJournal(authorization);
userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size)); 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权限用户调用") @ApiOperation(value = "3.1.添加抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/list/{page}/{size}") @PostMapping("/lottery/add")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<Lottery>> lotteryList( @ApiImplicitParams({
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto, @ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
@ApiParam(value = "页码", required = true) @PathVariable Integer page, })
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { public Result<Void> addLottery(@RequestHeader("Authorization") String token,
return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto)); @RequestBody Lottery lottery) {
} lotteryService.add(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.3.编辑抽奖", notes = "仅限admin权限用户调用") @ApiOperation(value = "3.2.抽奖列表页", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/edit") @PostMapping("/lottery/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ public Result<PageResult<Lottery>> lotteryList(
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body") @ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
}) @ApiParam(value = "页码", required = true) @PathVariable Integer page,
public Result<Void> editLottery(@RequestHeader("Authorization") String token, @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
@RequestBody Lottery lottery) { return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto));
lotteryService.edit(lottery, token); }
return Result.success();
}
@ApiOperation(value = "3.4.发布抽奖", notes = "仅限admin权限用户调用") @ApiOperation(value = "3.3.编辑抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/publish") @PostMapping("/lottery/edit")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body") @ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
}) })
public Result<Void> publishLottery(@RequestHeader("Authorization") String token, public Result<Void> editLottery(@RequestHeader("Authorization") String token,
@RequestBody String id) { @RequestBody Lottery lottery) {
lotteryService.publish(id, token); lotteryService.edit(lottery, token);
return Result.success(); return Result.success();
} }
@ApiOperation(value = "3.5.停止抽奖", notes = "仅限admin权限用户调用") @ApiOperation(value = "3.4.发布抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/stop") @PostMapping("/lottery/publish")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body")
@ApiImplicitParam(name = "stopReason", value = "停止原因", required = true, dataType = "String", paramType = "body") })
}) public Result<Void> publishLottery(@RequestHeader("Authorization") String token,
public Result<Void> stopLottery(@RequestHeader("Authorization") String token, @RequestBody String id) {
@NotNull String id, @RequestBody @NotNull String stopReason) { lotteryService.publish(id, token);
lotteryService.stop(id, token, stopReason); return Result.success();
return Result.success(); }
}
@ApiOperation(value = "3.6.参与抽奖") @ApiOperation(value = "3.5.停止抽奖", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/participate") @PostMapping("/lottery/stop")
@ApiImplicitParams({ @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "String", paramType = "query") @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
}) @ApiImplicitParam(name = "stopReason", value = "停止原因", required = true, dataType = "String", paramType = "body")
public Result<Void> participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) { })
lotteryService.participate(id, token, regionId); public Result<Void> stopLottery(@RequestHeader("Authorization") String token,
return Result.success(); @NotNull String id, @RequestBody @NotNull String stopReason) {
} lotteryService.stop(id, token, stopReason);
return Result.success();
}
@ApiOperation(value = "3.7.自动抽奖结果", notes = "用这个方法主动触发自动抽奖结果") @ApiOperation(value = "3.6.参与抽奖")
@PostMapping("/lottery/auto") @PostMapping("/lottery/participate")
@GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({
@ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@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> auto(@RequestHeader("Authorization") String token, @NotNull String id) { public Result<Void> participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) {
lotteryService.auto(id, token); lotteryService.participate(id, token, regionId);
return Result.success(); 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) @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;
@ -41,180 +44,218 @@ import util.JwtUtil;
@Slf4j @Slf4j
public class UserPointLogService { public class UserPointLogService {
private final UserPointLogDao userPointLogDao; private final UserPointLogDao userPointLogDao;
private final IdWorker idWorker;
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; public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao) {
@Autowired this.userPointLogDao = userPointLogDao;
private void setTaskPointService(TaskPointService taskPointService) { this.idWorker = idWorker;
this.taskPointService = taskPointService; this.jwtUtil = jwtUtil;
} this.taskPointDao = taskPointDao;
this.rabbitTemplate = rabbitTemplate;
this.userInfoDao = userInfoDao;
}
/** private TaskPointService taskPointService;
*
*
* @param taskPointId ID
* @param token tokenID
*/
public Integer addByTaskNew(String taskPointId, String token) {
// todo 缓存优化
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
// 新手任务,只触发一次 @Autowired
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), private void setTaskPointService(TaskPointService taskPointService) {
taskPointId).isEmpty()) { this.taskPointService = taskPointService;
return 0;
} }
addByTask(taskPointId, userLoginDto); /**
TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); *
return taskPoint.getScore(); *
} * @param taskPointId ID
* @param token tokenID
/** */
* public Integer addByTaskNew(String taskPointId, String token) {
* <p> // todo 缓存优化
* ID tokenRabbitMQ UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
*
*
* @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())) {
// 新手任务,只触发一次 // 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(), if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(),
userPointLog.getTaskPointId()).isEmpty()) { taskPointId).isEmpty()) {
return; return 0;
} }
}
userPointLog.setScore(taskPoint.getScore()); addByTask(taskPointId, userLoginDto);
userPointLog.setDescription(taskPoint.getDescription()); 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);
userPointLogDao.save(userPointLog);
log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId());
} }
// 如果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();
// 更新用户积分,获取用户信息并累加积分得分 rabbitTemplate.convertAndSend("pointLog", userPointLog);
// 对用户进行积分计算 }
UserInfo userInfo = userInfoDao.findById(userPointLog.getUserId()).get();
Integer point = userInfo.getPoint();
point += userPointLog.getScore();
userInfo.setPoint(point);
// 更新用户积分信息
userInfoDao.save(userInfo);
/**
*
* <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(); Sort sort = new Sort(Direction.DESC, "createTime");
return new PageResult<>(totalElements, userPointLogPage.getContent()); 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) { private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) {
return (Root<UserPointLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> { return (Root<UserPointLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>(); List<Predicate> predicateList = new ArrayList<Predicate>();
if (param.getType() != null) { if (param.getType() != null) {
predicateList.add( predicateList.add(
criteriaBuilder.and(criteriaBuilder.equal(root.get("type"), param.getType()))); criteriaBuilder.and(criteriaBuilder.equal(root.get("type"), param.getType())));
} }
if (StringUtils.isNotBlank(param.getUserId())) { if (StringUtils.isNotBlank(param.getUserId())) {
predicateList.add( predicateList.add(
criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId()))); 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