mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
签到:签到后增加用户积分、经验
This commit is contained in:
parent
a04a3a27a9
commit
4f03635fcd
@ -788,7 +788,7 @@ CREATE TABLE `member_level_record` (
|
|||||||
`user_id` bigint NOT NULL DEFAULT 0 COMMENT '用户编号',
|
`user_id` bigint NOT NULL DEFAULT 0 COMMENT '用户编号',
|
||||||
`level_id` bigint NOT NULL DEFAULT 0 COMMENT '等级编号',
|
`level_id` bigint NOT NULL DEFAULT 0 COMMENT '等级编号',
|
||||||
`level` int NOT NULL DEFAULT 0 COMMENT '会员等级',
|
`level` int NOT NULL DEFAULT 0 COMMENT '会员等级',
|
||||||
`discount_percent` tinyint NOT NULL DEFAULT 100 COMMENT '享受折扣',
|
`discount_percent` int NOT NULL DEFAULT 100 COMMENT '享受折扣',
|
||||||
`experience` int NOT NULL DEFAULT 0 COMMENT '升级经验',
|
`experience` int NOT NULL DEFAULT 0 COMMENT '升级经验',
|
||||||
`user_experience` int NOT NULL DEFAULT 0 COMMENT '会员此时的经验',
|
`user_experience` int NOT NULL DEFAULT 0 COMMENT '会员此时的经验',
|
||||||
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
|
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
|
||||||
@ -888,7 +888,8 @@ DROP TABLE IF EXISTS `member_sign_in_config`;
|
|||||||
CREATE TABLE `member_sign_in_config` (
|
CREATE TABLE `member_sign_in_config` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '编号',
|
`id` int NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||||
`day` int NOT NULL COMMENT '第几天',
|
`day` int NOT NULL COMMENT '第几天',
|
||||||
`point` int NOT NULL COMMENT '奖励积分',
|
`point` int NOT NULL DEFAULT 0 COMMENT '奖励积分',
|
||||||
|
`experience` int NOT NULL DEFAULT 0 COMMENT '奖励经验',
|
||||||
`status` tinyint NOT NULL COMMENT '状态',
|
`status` tinyint NOT NULL COMMENT '状态',
|
||||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者',
|
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者',
|
||||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
@ -903,18 +904,18 @@ CREATE TABLE `member_sign_in_config` (
|
|||||||
-- Records of member_sign_in_config
|
-- Records of member_sign_in_config
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (1, 1, 10, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (1, 1, 10, 10, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (2, 2, 20, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (2, 2, 20, 20, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (3, 7, 1001, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (3, 7, 1001, 1001, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (4, 6, 12121, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (4, 6, 12121, 12121, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (5, 2, 12, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (5, 3, 12, 12, 0, '', '2023-08-20 01:38:56', '', '2023-08-20 01:38:56', b'0', 0);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (6, 1, 10, 0, '1', '2023-08-20 19:20:42', '1', '2023-08-20 19:20:56', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (6, 1, 10, 10, 0, '1', '2023-08-20 19:20:42', '1', '2023-08-20 19:20:56', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (7, 7, 22, 0, '1', '2023-08-20 19:20:48', '1', '2023-08-20 19:20:48', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (7, 7, 22, 22, 0, '1', '2023-08-20 19:20:48', '1', '2023-08-20 19:20:48', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (8, 2, 3, 0, '1', '2023-08-21 20:22:44', '1', '2023-08-21 20:22:44', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (8, 2, 3, 3, 0, '1', '2023-08-21 20:22:44', '1', '2023-08-21 20:22:44', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (9, 3, 4, 0, '1', '2023-08-21 20:22:48', '1', '2023-08-21 20:22:48', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (9, 3, 4, 4, 0, '1', '2023-08-21 20:22:48', '1', '2023-08-21 20:22:48', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (10, 4, 5, 0, '1', '2023-08-21 20:22:51', '1', '2023-08-21 20:22:51', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (10, 4, 5, 5, 0, '1', '2023-08-21 20:22:51', '1', '2023-08-21 20:22:51', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (11, 5, 6, 0, '1', '2023-08-21 20:22:56', '1', '2023-08-21 20:22:56', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (11, 5, 6, 6, 0, '1', '2023-08-21 20:22:56', '1', '2023-08-21 20:22:56', b'0', 1);
|
||||||
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (12, 6, 7, 0, '1', '2023-08-21 20:22:59', '1', '2023-08-21 20:22:59', b'0', 1);
|
INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `experience`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (12, 6, 7, 7, 0, '1', '2023-08-21 20:22:59', '1', '2023-08-21 20:22:59', b'0', 1);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
@ -925,7 +926,8 @@ CREATE TABLE `member_sign_in_record` (
|
|||||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '签到自增id',
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '签到自增id',
|
||||||
`user_id` int NULL DEFAULT NULL COMMENT '签到用户',
|
`user_id` int NULL DEFAULT NULL COMMENT '签到用户',
|
||||||
`day` int NULL DEFAULT NULL COMMENT '第几天签到',
|
`day` int NULL DEFAULT NULL COMMENT '第几天签到',
|
||||||
`point` int NULL DEFAULT NULL COMMENT '签到的分数',
|
`point` int NOT NULL DEFAULT 0 COMMENT '签到的积分',
|
||||||
|
`experience` int NOT NULL DEFAULT 0 COMMENT '签到的经验',
|
||||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
||||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
|
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
|
||||||
@ -935,6 +937,8 @@ CREATE TABLE `member_sign_in_record` (
|
|||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '签到记录';
|
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '签到记录';
|
||||||
|
|
||||||
|
CREATE INDEX user_id_index ON member_sign_in_record (user_id);
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of member_sign_in_record
|
-- Records of member_sign_in_record
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
@ -38,6 +38,7 @@ public interface ErrorCodeConstants {
|
|||||||
//========== 签到配置 1-004-009-000 ==========
|
//========== 签到配置 1-004-009-000 ==========
|
||||||
ErrorCode SIGN_IN_CONFIG_NOT_EXISTS = new ErrorCode(1_004_009_000, "签到天数规则不存在");
|
ErrorCode SIGN_IN_CONFIG_NOT_EXISTS = new ErrorCode(1_004_009_000, "签到天数规则不存在");
|
||||||
ErrorCode SIGN_IN_CONFIG_EXISTS = new ErrorCode(1_004_009_001, "签到天数规则已存在");
|
ErrorCode SIGN_IN_CONFIG_EXISTS = new ErrorCode(1_004_009_001, "签到天数规则已存在");
|
||||||
|
ErrorCode SIGN_IN_CONFIG_AWARD_EMPTY = new ErrorCode(1_004_009_002, "签到奖励积分和经验不能同时为空");
|
||||||
|
|
||||||
//========== 签到配置 1-004-010-000 ==========
|
//========== 签到配置 1-004-010-000 ==========
|
||||||
ErrorCode SIGN_IN_RECORD_TODAY_EXISTS = new ErrorCode(1_004_010_000,"今日已签到,请勿重复签到");
|
ErrorCode SIGN_IN_RECORD_TODAY_EXISTS = new ErrorCode(1_004_010_000,"今日已签到,请勿重复签到");
|
||||||
|
@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.PositiveOrZero;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签到规则 Base VO,提供给添加、修改、详细的子 VO 使用
|
* 签到规则 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||||
@ -20,8 +21,14 @@ public class MemberSignInConfigBaseVO {
|
|||||||
|
|
||||||
@Schema(description = "奖励积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
@Schema(description = "奖励积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
@NotNull(message = "奖励积分不能为空")
|
@NotNull(message = "奖励积分不能为空")
|
||||||
|
@PositiveOrZero(message = "奖励积分不能小于 0")
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
|
@Schema(description = "奖励经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
|
@NotNull(message = "奖励经验不能为空")
|
||||||
|
@PositiveOrZero(message = "奖励经验不能小于 0")
|
||||||
|
private Integer experience;
|
||||||
|
|
||||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
@NotNull(message = "状态不能为空")
|
@NotNull(message = "状态不能为空")
|
||||||
@InEnum(CommonStatusEnum.class)
|
@InEnum(CommonStatusEnum.class)
|
||||||
|
@ -21,7 +21,7 @@ public class MemberSignInRecordRespVO {
|
|||||||
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Integer day;
|
private Integer day;
|
||||||
|
|
||||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
@Schema(description = "签到的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.member.controller.app.signin;
|
package cn.iocoder.yudao.module.member.controller.app.signin;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.module.member.convert.signin.MemberSignInRecordConvert;
|
|
||||||
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
|
|
||||||
import cn.iocoder.yudao.module.member.service.signin.MemberSignInRecordService;
|
import cn.iocoder.yudao.module.member.service.signin.MemberSignInRecordService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@ -33,13 +30,4 @@ public class AppMemberSignInController {
|
|||||||
return success(signInRecordService.getSignInRecordSummary(getLoginUserId()));
|
return success(signInRecordService.getSignInRecordSummary(getLoginUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @xiaqing:泛型:
|
|
||||||
// TODO @xiaqing:合并到 AppMemberSignInRecordController 的 createSignInRecord 里哈。
|
|
||||||
@Operation(summary = "会员签到")
|
|
||||||
@PostMapping("/create")
|
|
||||||
public CommonResult create(){
|
|
||||||
MemberSignInRecordDO recordDO = signInRecordService.createSignRecord(getLoginUserId());
|
|
||||||
return success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
@ -50,16 +49,12 @@ public class AppMemberSignInRecordController {
|
|||||||
return success(respVO);
|
return success(respVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:临时 mock => UserSignController.info
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "签到")
|
@Operation(summary = "签到")
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<AppMemberSignInRecordRespVO> createSignInRecord() {
|
public CommonResult<AppMemberSignInRecordRespVO> createSignInRecord() {
|
||||||
AppMemberSignInRecordRespVO respVO = new AppMemberSignInRecordRespVO()
|
MemberSignInRecordDO recordDO = signInRecordService.createSignRecord(getLoginUserId());
|
||||||
.setPoint(10)
|
return success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO));
|
||||||
.setDay(10)
|
|
||||||
.setCreateTime(LocalDateTime.now());
|
|
||||||
return success(respVO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
|
@ -12,9 +12,12 @@ public class AppMemberSignInRecordRespVO {
|
|||||||
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Integer day;
|
private Integer day;
|
||||||
|
|
||||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
@Schema(description = "签到的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
|
@Schema(description = "签到的经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
|
private Integer experience;
|
||||||
|
|
||||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ public class AppMemberSignInRecordRespVO {
|
|||||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
|
||||||
|
@Schema(description = "签到的经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||||
|
private Integer experience;
|
||||||
|
|
||||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@ -35,6 +35,10 @@ public class MemberSignInConfigDO extends BaseDO {
|
|||||||
* 奖励积分
|
* 奖励积分
|
||||||
*/
|
*/
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
/**
|
||||||
|
* 奖励经验
|
||||||
|
*/
|
||||||
|
private Integer experience;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
|
@ -35,10 +35,12 @@ public class MemberSignInRecordDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer day;
|
private Integer day;
|
||||||
/**
|
/**
|
||||||
* 签到的分数
|
* 签到的积分
|
||||||
*/
|
*/
|
||||||
private Integer point;
|
private Integer point;
|
||||||
|
/**
|
||||||
// TODO 疯狂:签到的经验
|
* 签到的经验
|
||||||
|
*/
|
||||||
|
private Integer experience;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,8 @@ public class MemberLevelServiceImpl implements MemberLevelService {
|
|||||||
|
|
||||||
// 1. 创建经验记录
|
// 1. 创建经验记录
|
||||||
MemberUserDO user = memberUserService.getUser(userId);
|
MemberUserDO user = memberUserService.getUser(userId);
|
||||||
int userExperience = NumberUtil.max(user.getExperience() + experience, 0); // 防止扣出负数
|
Integer userExperience = ObjUtil.defaultIfNull(user.getExperience(), 0);
|
||||||
|
userExperience = NumberUtil.max(userExperience + experience, 0); // 防止扣出负数
|
||||||
MemberLevelRecordDO levelRecord = new MemberLevelRecordDO()
|
MemberLevelRecordDO levelRecord = new MemberLevelRecordDO()
|
||||||
.setUserId(user.getId())
|
.setUserId(user.getId())
|
||||||
.setExperience(experience)
|
.setExperience(experience)
|
||||||
|
@ -66,6 +66,9 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) {
|
public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) {
|
||||||
|
if (point == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 1. 校验用户积分余额
|
// 1. 校验用户积分余额
|
||||||
MemberUserDO user = memberUserService.getUser(userId);
|
MemberUserDO user = memberUserService.getUser(userId);
|
||||||
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
||||||
|
@ -11,10 +11,10 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CONFIG_EXISTS;
|
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
|
||||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CONFIG_NOT_EXISTS;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签到规则 Service 实现类
|
* 签到规则 Service 实现类
|
||||||
@ -30,6 +30,8 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createSignInConfig(MemberSignInConfigCreateReqVO createReqVO) {
|
public Long createSignInConfig(MemberSignInConfigCreateReqVO createReqVO) {
|
||||||
|
// 校验奖励积分、奖励经验
|
||||||
|
validatePointAndExperience(createReqVO.getPoint(), createReqVO.getExperience());
|
||||||
// 判断是否重复插入签到天数
|
// 判断是否重复插入签到天数
|
||||||
validateSignInConfigDayDuplicate(createReqVO.getDay(), null);
|
validateSignInConfigDayDuplicate(createReqVO.getDay(), null);
|
||||||
|
|
||||||
@ -42,6 +44,8 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSignInConfig(MemberSignInConfigUpdateReqVO updateReqVO) {
|
public void updateSignInConfig(MemberSignInConfigUpdateReqVO updateReqVO) {
|
||||||
|
// 校验奖励积分、奖励经验
|
||||||
|
validatePointAndExperience(updateReqVO.getPoint(), updateReqVO.getExperience());
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateSignInConfigExists(updateReqVO.getId());
|
validateSignInConfigExists(updateReqVO.getId());
|
||||||
// 判断是否重复插入签到天数
|
// 判断是否重复插入签到天数
|
||||||
@ -84,6 +88,13 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validatePointAndExperience(Integer point, Integer experience) {
|
||||||
|
// 奖励积分、经验 至少要配置一个,否则没有意义
|
||||||
|
if (Objects.equals(point, 0) && Objects.equals(experience, 0)) {
|
||||||
|
throw exception(SIGN_IN_CONFIG_AWARD_EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MemberSignInConfigDO getSignInConfig(Long id) {
|
public MemberSignInConfigDO getSignInConfig(Long id) {
|
||||||
return memberSignInConfigMapper.selectById(id);
|
return memberSignInConfigMapper.selectById(id);
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.service.signin;
|
|||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||||
@ -13,8 +14,13 @@ import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO
|
|||||||
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInConfigMapper;
|
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInConfigMapper;
|
||||||
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInRecordMapper;
|
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInRecordMapper;
|
||||||
import cn.iocoder.yudao.module.member.enums.ErrorCodeConstants;
|
import cn.iocoder.yudao.module.member.enums.ErrorCodeConstants;
|
||||||
|
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
|
||||||
|
import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
@ -40,6 +46,10 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
private MemberSignInRecordMapper signInRecordMapper;
|
private MemberSignInRecordMapper signInRecordMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private MemberSignInConfigMapper signInConfigMapper;
|
private MemberSignInConfigMapper signInConfigMapper;
|
||||||
|
@Resource
|
||||||
|
private MemberPointRecordService pointRecordService;
|
||||||
|
@Resource
|
||||||
|
private MemberLevelService memberLevelService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MemberUserApi memberUserApi;
|
private MemberUserApi memberUserApi;
|
||||||
@ -113,6 +123,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public MemberSignInRecordDO createSignRecord(Long userId) {
|
public MemberSignInRecordDO createSignRecord(Long userId) {
|
||||||
// 获取当前用户签到的最大天数
|
// 获取当前用户签到的最大天数
|
||||||
// TODO @xiaqing:db 操作,dou封装到 mapper 中;
|
// TODO @xiaqing:db 操作,dou封装到 mapper 中;
|
||||||
@ -124,39 +135,51 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||||||
// 判断是否重复签到
|
// 判断是否重复签到
|
||||||
validSignDay(maxSignDay);
|
validSignDay(maxSignDay);
|
||||||
|
|
||||||
// TODO @xiaqing:可以使用 // 进行注释
|
// 1. 查询出当前签到的天数
|
||||||
/**1.查询出当前签到的天数**/
|
|
||||||
MemberSignInRecordDO sign = new MemberSignInRecordDO().setUserId(userId); // TODO @xiaqing:应该使用 record 变量,会更合适
|
MemberSignInRecordDO sign = new MemberSignInRecordDO().setUserId(userId); // TODO @xiaqing:应该使用 record 变量,会更合适
|
||||||
sign.setDay(1); // 设置签到初始化天数
|
sign.setDay(1); // 设置签到初始化天数
|
||||||
sign.setPoint(0); // 设置签到分数默认为 0
|
sign.setPoint(0); // 设置签到积分默认为 0
|
||||||
|
sign.setExperience(0); // 设置签到经验默认为 0
|
||||||
// 如果不为空则修改当前签到对应的天数
|
// 如果不为空则修改当前签到对应的天数
|
||||||
// TODO @xiaqing:应该是要判断连续哈,就是昨天;
|
// TODO @xiaqing:应该是要判断连续哈,就是昨天;
|
||||||
if (maxSignDay != null) {
|
if (maxSignDay != null) {
|
||||||
sign.setDay(maxSignDay.getDay() + 1);
|
sign.setDay(maxSignDay.getDay() + 1);
|
||||||
}
|
}
|
||||||
/**2.获取签到对应的分数**/
|
// 2. 获取签到对应的积分数
|
||||||
// 获取所有的签到规则,按照天数排序,只获取启用的 TODO @xiaqing:不要使用 signInConfigMapper 直接查询,而是要通过 SigninConfigService;
|
// 获取所有的签到规则,按照天数排序,只获取启用的 TODO @xiaqing:不要使用 signInConfigMapper 直接查询,而是要通过 SigninConfigService;
|
||||||
List<MemberSignInConfigDO> configDOList = signInConfigMapper.selectList(new LambdaQueryWrapperX<MemberSignInConfigDO>()
|
List<MemberSignInConfigDO> configDOList = signInConfigMapper.selectList(new LambdaQueryWrapperX<MemberSignInConfigDO>()
|
||||||
.eq(MemberSignInConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
.eq(MemberSignInConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||||
.orderByAsc(MemberSignInConfigDO::getDay));
|
.orderByAsc(MemberSignInConfigDO::getDay));
|
||||||
// 如果签到的天数大于最大启用的规则天数,直接给最大签到的分数
|
// 如果签到的天数大于最大启用的规则天数,直接给最大签到的积分数
|
||||||
// TODO @xiaqing:超过最大配置的天数,应该直接重置到第一天哈;
|
// TODO @xiaqing:超过最大配置的天数,应该直接重置到第一天哈;
|
||||||
MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1);
|
MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1);
|
||||||
if (sign.getDay() > lastConfig.getDay()) {
|
if (sign.getDay() > lastConfig.getDay()) {
|
||||||
sign.setPoint(lastConfig.getPoint());
|
sign.setPoint(lastConfig.getPoint());
|
||||||
|
sign.setExperience(lastConfig.getExperience());
|
||||||
} else {
|
} else {
|
||||||
configDOList.forEach(el -> {
|
configDOList.forEach(el -> {
|
||||||
// 循环匹配对应天数,设置对应分数
|
// 循环匹配对应天数,设置对应积分数
|
||||||
// TODO @xiaqing:使用 equals;另外,这种不应该去遍历比较,从可读性来说,应该 CollUtil.findOne()
|
// TODO @xiaqing:使用 equals;另外,这种不应该去遍历比较,从可读性来说,应该 CollUtil.findOne()
|
||||||
if (el.getDay() == sign.getDay()) {
|
if (el.getDay() == sign.getDay()) {
|
||||||
sign.setPoint(el.getPoint());
|
sign.setPoint(el.getPoint());
|
||||||
|
sign.setExperience(el.getExperience());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 插入当前签到获取的分数
|
// 3. 插入签到记录
|
||||||
signInRecordMapper.insert(sign);
|
signInRecordMapper.insert(sign);
|
||||||
|
|
||||||
|
// 4. 增加积分
|
||||||
|
if (!ObjectUtils.equalsAny(sign.getPoint(), null, 0)) {
|
||||||
|
pointRecordService.createPointRecord(userId, sign.getPoint(), MemberPointBizTypeEnum.SIGN, String.valueOf(sign.getId()));
|
||||||
|
}
|
||||||
|
// 5. 增加经验
|
||||||
|
if (!ObjectUtils.equalsAny(sign.getPoint(), null, 0)) {
|
||||||
|
memberLevelService.addExperience(userId, sign.getExperience(), MemberExperienceBizTypeEnum.SIGN_IN, String.valueOf(sign.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
return sign;
|
return sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user