mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +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 '用户编号',
|
||||
`level_id` bigint 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 '升级经验',
|
||||
`user_experience` int NOT NULL DEFAULT 0 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` (
|
||||
`id` int NOT NULL AUTO_INCREMENT 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 '状态',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' 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
|
||||
-- ----------------------------
|
||||
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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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 (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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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`, `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;
|
||||
|
||||
-- ----------------------------
|
||||
@ -925,7 +926,8 @@ CREATE TABLE `member_sign_in_record` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '签到自增id',
|
||||
`user_id` 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 '创建者',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP 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
|
||||
) 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
|
||||
-- ----------------------------
|
||||
|
@ -38,6 +38,7 @@ public interface ErrorCodeConstants {
|
||||
//========== 签到配置 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_AWARD_EMPTY = new ErrorCode(1_004_009_002, "签到奖励积分和经验不能同时为空");
|
||||
|
||||
//========== 签到配置 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 javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
|
||||
/**
|
||||
* 签到规则 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
@ -20,8 +21,14 @@ public class MemberSignInConfigBaseVO {
|
||||
|
||||
@Schema(description = "奖励积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@NotNull(message = "奖励积分不能为空")
|
||||
@PositiveOrZero(message = "奖励积分不能小于 0")
|
||||
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")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
|
@ -21,7 +21,7 @@ public class MemberSignInRecordRespVO {
|
||||
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer day;
|
||||
|
||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@Schema(description = "签到的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer point;
|
||||
|
||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
@ -1,13 +1,10 @@
|
||||
package cn.iocoder.yudao.module.member.controller.app.signin;
|
||||
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
|
||||
@ -29,17 +26,8 @@ public class AppMemberSignInController {
|
||||
// TODO @xiaqing:合并到 AppMemberSignInRecordController 的 getSignInRecordSummary 里哈。
|
||||
@Operation(summary = "个人签到信息")
|
||||
@GetMapping("/get-summary")
|
||||
public CommonResult getUserSummary(){
|
||||
public CommonResult getUserSummary() {
|
||||
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 javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
@ -50,16 +49,12 @@ public class AppMemberSignInRecordController {
|
||||
return success(respVO);
|
||||
}
|
||||
|
||||
// TODO 芋艿:临时 mock => UserSignController.info
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "签到")
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppMemberSignInRecordRespVO> createSignInRecord() {
|
||||
AppMemberSignInRecordRespVO respVO = new AppMemberSignInRecordRespVO()
|
||||
.setPoint(10)
|
||||
.setDay(10)
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
return success(respVO);
|
||||
MemberSignInRecordDO recordDO = signInRecordService.createSignRecord(getLoginUserId());
|
||||
return success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
|
@ -12,9 +12,12 @@ public class AppMemberSignInRecordRespVO {
|
||||
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer day;
|
||||
|
||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@Schema(description = "签到的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer point;
|
||||
|
||||
@Schema(description = "签到的经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer experience;
|
||||
|
||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
@ -15,6 +15,9 @@ public class AppMemberSignInRecordRespVO {
|
||||
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer point;
|
||||
|
||||
@Schema(description = "签到的经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer experience;
|
||||
|
||||
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
@ -35,6 +35,10 @@ public class MemberSignInConfigDO extends BaseDO {
|
||||
* 奖励积分
|
||||
*/
|
||||
private Integer point;
|
||||
/**
|
||||
* 奖励经验
|
||||
*/
|
||||
private Integer experience;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
|
@ -35,10 +35,12 @@ public class MemberSignInRecordDO extends BaseDO {
|
||||
*/
|
||||
private Integer day;
|
||||
/**
|
||||
* 签到的分数
|
||||
* 签到的积分
|
||||
*/
|
||||
private Integer point;
|
||||
|
||||
// TODO 疯狂:签到的经验
|
||||
/**
|
||||
* 签到的经验
|
||||
*/
|
||||
private Integer experience;
|
||||
|
||||
}
|
||||
|
@ -239,7 +239,8 @@ public class MemberLevelServiceImpl implements MemberLevelService {
|
||||
|
||||
// 1. 创建经验记录
|
||||
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()
|
||||
.setUserId(user.getId())
|
||||
.setExperience(experience)
|
||||
|
@ -66,6 +66,9 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) {
|
||||
if (point == 0) {
|
||||
return;
|
||||
}
|
||||
// 1. 校验用户积分余额
|
||||
MemberUserDO user = memberUserService.getUser(userId);
|
||||
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
||||
|
@ -11,10 +11,10 @@ import org.springframework.validation.annotation.Validated;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
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.SIGN_IN_CONFIG_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 签到规则 Service 实现类
|
||||
@ -30,6 +30,8 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
||||
|
||||
@Override
|
||||
public Long createSignInConfig(MemberSignInConfigCreateReqVO createReqVO) {
|
||||
// 校验奖励积分、奖励经验
|
||||
validatePointAndExperience(createReqVO.getPoint(), createReqVO.getExperience());
|
||||
// 判断是否重复插入签到天数
|
||||
validateSignInConfigDayDuplicate(createReqVO.getDay(), null);
|
||||
|
||||
@ -42,6 +44,8 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
||||
|
||||
@Override
|
||||
public void updateSignInConfig(MemberSignInConfigUpdateReqVO updateReqVO) {
|
||||
// 校验奖励积分、奖励经验
|
||||
validatePointAndExperience(updateReqVO.getPoint(), updateReqVO.getExperience());
|
||||
// 校验存在
|
||||
validateSignInConfigExists(updateReqVO.getId());
|
||||
// 判断是否重复插入签到天数
|
||||
@ -70,7 +74,7 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
|
||||
* 校验 day 是否重复
|
||||
*
|
||||
* @param day 天
|
||||
* @param id 编号,只有更新的时候会传递
|
||||
* @param id 编号,只有更新的时候会传递
|
||||
*/
|
||||
private void validateSignInConfigDayDuplicate(Integer day, Long id) {
|
||||
MemberSignInConfigDO config = memberSignInConfigMapper.selectByDay(day);
|
||||
@ -84,13 +88,20 @@ 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
|
||||
public MemberSignInConfigDO getSignInConfig(Long id) {
|
||||
return memberSignInConfigMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List <MemberSignInConfigDO> getSignInConfigList() {
|
||||
public List<MemberSignInConfigDO> getSignInConfigList() {
|
||||
List<MemberSignInConfigDO> list = memberSignInConfigMapper.selectList();
|
||||
list.sort(Comparator.comparing(MemberSignInConfigDO::getDay));
|
||||
return list;
|
||||
|
@ -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.pojo.PageParam;
|
||||
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.module.member.api.user.MemberUserApi;
|
||||
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.MemberSignInRecordMapper;
|
||||
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.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -40,20 +46,24 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
||||
private MemberSignInRecordMapper signInRecordMapper;
|
||||
@Resource
|
||||
private MemberSignInConfigMapper signInConfigMapper;
|
||||
@Resource
|
||||
private MemberPointRecordService pointRecordService;
|
||||
@Resource
|
||||
private MemberLevelService memberLevelService;
|
||||
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@Override
|
||||
public AppMemberSignInSummaryRespVO getSignInRecordSummary(Long userId) {
|
||||
AppMemberSignInSummaryRespVO vo = new AppMemberSignInSummaryRespVO();
|
||||
AppMemberSignInSummaryRespVO vo = new AppMemberSignInSummaryRespVO();
|
||||
vo.setTotalDay(0);
|
||||
vo.setContinuousDay(0);
|
||||
vo.setTodaySignIn(false);
|
||||
//获取用户签到的记录,按照天数倒序获取
|
||||
List <MemberSignInRecordDO> signInRecordDOList = signInRecordMapper.selectListByUserId(userId);
|
||||
List<MemberSignInRecordDO> signInRecordDOList = signInRecordMapper.selectListByUserId(userId);
|
||||
// TODO @xiaqing:if 空的时候,直接 return;这样括号少,逻辑更简洁;
|
||||
if(!CollectionUtils.isEmpty(signInRecordDOList)){
|
||||
if (!CollectionUtils.isEmpty(signInRecordDOList)) {
|
||||
//设置总签到天数
|
||||
vo.setTotalDay(signInRecordDOList.size()); // TODO @xiaqing:是不是不用读取 signInRecordDOList 所有的,而是 count下,然后另外再读取一条最后一条;
|
||||
//判断当天是否有签到复用校验方法
|
||||
@ -61,11 +71,11 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
||||
try {
|
||||
validSignDay(signInRecordDOList.get(0));
|
||||
vo.setTodaySignIn(false);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
vo.setTodaySignIn(true);
|
||||
}
|
||||
//如果当天签到了则说明连续签到天数有意义,否则直接用默认值0
|
||||
if(vo.getTodaySignIn()){
|
||||
if (vo.getTodaySignIn()) {
|
||||
//下方计算连续签到从2天开始,此处直接设置一天连续签到
|
||||
vo.setContinuousDay(1);
|
||||
//判断连续签到天数
|
||||
@ -73,10 +83,10 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
||||
for (int i = 1; i < signInRecordDOList.size(); i++) {
|
||||
//前一天减1等于当前天数则说明连续,继续循环
|
||||
LocalDate cur = signInRecordDOList.get(i).getCreateTime().toLocalDate();
|
||||
LocalDate pre = signInRecordDOList.get(i-1).getCreateTime().toLocalDate();
|
||||
if(1==daysBetween(cur,pre)){
|
||||
vo.setContinuousDay(i+1);
|
||||
}else{
|
||||
LocalDate pre = signInRecordDOList.get(i - 1).getCreateTime().toLocalDate();
|
||||
if (1 == daysBetween(cur, pre)) {
|
||||
vo.setContinuousDay(i + 1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -87,16 +97,16 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
||||
return vo;
|
||||
}
|
||||
|
||||
private long daysBetween(LocalDate date1,LocalDate date2){
|
||||
private long daysBetween(LocalDate date1, LocalDate date2) {
|
||||
return ChronoUnit.DAYS.between(date1, date2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult <MemberSignInRecordDO> getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) {
|
||||
public PageResult<MemberSignInRecordDO> getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) {
|
||||
// 根据用户昵称查询出用户ids
|
||||
Set <Long> userIds = null;
|
||||
Set<Long> userIds = null;
|
||||
if (StringUtils.isNotBlank(pageReqVO.getNickname())) {
|
||||
List <MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageReqVO.getNickname());
|
||||
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageReqVO.getNickname());
|
||||
// 如果查询用户结果为空直接返回无需继续查询
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
return PageResult.empty();
|
||||
@ -113,50 +123,63 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MemberSignInRecordDO createSignRecord(Long userId) {
|
||||
// 获取当前用户签到的最大天数
|
||||
// TODO @xiaqing:db 操作,dou封装到 mapper 中;
|
||||
// TODO @xiaqing:maxSignDay,是不是变量叫 lastRecord 会更容易理解哈;
|
||||
MemberSignInRecordDO maxSignDay = signInRecordMapper.selectOne(new LambdaQueryWrapperX <MemberSignInRecordDO>()
|
||||
MemberSignInRecordDO maxSignDay = signInRecordMapper.selectOne(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
||||
.eq(MemberSignInRecordDO::getUserId, userId)
|
||||
.orderByDesc(MemberSignInRecordDO::getDay)
|
||||
.last("limit 1"));
|
||||
// 判断是否重复签到
|
||||
validSignDay(maxSignDay);
|
||||
|
||||
// TODO @xiaqing:可以使用 // 进行注释
|
||||
/**1.查询出当前签到的天数**/
|
||||
// 1. 查询出当前签到的天数
|
||||
MemberSignInRecordDO sign = new MemberSignInRecordDO().setUserId(userId); // TODO @xiaqing:应该使用 record 变量,会更合适
|
||||
sign.setDay(1); // 设置签到初始化天数
|
||||
sign.setPoint(0); // 设置签到分数默认为 0
|
||||
sign.setPoint(0); // 设置签到积分默认为 0
|
||||
sign.setExperience(0); // 设置签到经验默认为 0
|
||||
// 如果不为空则修改当前签到对应的天数
|
||||
// TODO @xiaqing:应该是要判断连续哈,就是昨天;
|
||||
if (maxSignDay != null) {
|
||||
sign.setDay(maxSignDay.getDay() + 1);
|
||||
}
|
||||
/**2.获取签到对应的分数**/
|
||||
// 2. 获取签到对应的积分数
|
||||
// 获取所有的签到规则,按照天数排序,只获取启用的 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())
|
||||
.orderByAsc(MemberSignInConfigDO::getDay));
|
||||
// 如果签到的天数大于最大启用的规则天数,直接给最大签到的分数
|
||||
// 如果签到的天数大于最大启用的规则天数,直接给最大签到的积分数
|
||||
// TODO @xiaqing:超过最大配置的天数,应该直接重置到第一天哈;
|
||||
MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1);
|
||||
if (sign.getDay() > lastConfig.getDay()) {
|
||||
sign.setPoint(lastConfig.getPoint());
|
||||
sign.setExperience(lastConfig.getExperience());
|
||||
} else {
|
||||
configDOList.forEach(el -> {
|
||||
// 循环匹配对应天数,设置对应分数
|
||||
// 循环匹配对应天数,设置对应积分数
|
||||
// TODO @xiaqing:使用 equals;另外,这种不应该去遍历比较,从可读性来说,应该 CollUtil.findOne()
|
||||
if (el.getDay() == sign.getDay()) {
|
||||
sign.setPoint(el.getPoint());
|
||||
sign.setExperience(el.getExperience());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 插入当前签到获取的分数
|
||||
// 3. 插入签到记录
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user