code review:会员等级

This commit is contained in:
YunaiV 2023-08-22 21:59:00 +08:00
parent 551a968449
commit 54bf24b966
12 changed files with 31 additions and 156 deletions

View File

@ -1,36 +0,0 @@
create table member_group
(
id bigint auto_increment comment '编号' primary key,
name varchar(30) default '' not null comment '名称',
remark varchar(255) default '' not null comment '备注',
status tinyint default 0 not null comment '状态',
creator varchar(64) default '' null comment '创建者',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updater varchar(64) default '' null comment '更新者',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
deleted bit default b'0' not null comment '是否删除',
tenant_id bigint default 0 not null comment '租户编号'
)
comment '用户分组';
alter table member_user add column group_id bigint null comment '用户分组编号';
-- 菜单 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
VALUES ('用户分组', '', 2, 5, 2262, 'group', '', 'member/group/index', 0, 'MemberGroup');
-- 按钮父菜单ID
-- 暂时只支持 MySQL如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('用户分组查询', 'member:group:query', 3, 1, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('用户分组创建', 'member:group:create', 3, 2, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('用户分组更新', 'member:group:update', 3, 3, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('用户分组删除', 'member:group:delete', 3, 4, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('用户分组导出', 'member:group:export', 3, 5, @parentId, '', '', '', 0);

View File

@ -1,71 +1,3 @@
-- 会员表增加字段
alter table member_user add column experience int not null default 0 comment '经验';
alter table member_user add column level_id bigint comment '等级编号';
-- 增加3张表
create table member_level
(
id bigint auto_increment comment '编号' primary key,
name varchar(30) default '' not null comment '等级名称',
experience int default 0 not null comment '升级经验',
level int default 0 not null comment '等级',
discount tinyint default 100 not null comment '享受折扣',
icon varchar(255) default '' not null comment '等级图标',
background_url varchar(255) default '' not null comment '等级背景图',
status tinyint default 0 not null comment '状态',
creator varchar(64) default '' null comment '创建者',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updater varchar(64) default '' null comment '更新者',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
deleted bit default b'0' not null comment '是否删除',
tenant_id bigint default 0 not null comment '租户编号'
)
comment '会员等级';
create table member_level_log
(
id bigint auto_increment comment '编号' primary key,
user_id bigint default 0 not null comment '用户编号',
level_id bigint default 0 not null comment '等级编号',
level int default 0 not null comment '会员等级',
discount tinyint default 100 not null comment '享受折扣',
experience int default 0 not null comment '升级经验',
user_experience int default 0 not null comment '会员此时的经验',
remark varchar(255) default '' not null comment '备注',
description varchar(255) default '' not null comment '描述',
creator varchar(64) default '' null comment '创建者',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updater varchar(64) default '' null comment '更新者',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
deleted bit default b'0' not null comment '是否删除',
tenant_id bigint default 0 not null comment '租户编号'
)
comment '会员等级记录';
create index idx_user_id on member_level_log (user_id) comment '会员等级记录-用户编号';
create table member_experience_log
(
id bigint auto_increment comment '编号' primary key,
user_id bigint default 0 not null comment '用户编号',
biz_id varchar(64) default '' not null comment '业务编号',
biz_type tinyint default 0 not null comment '业务类型',
title varchar(30) default '' not null comment '标题',
experience int default 0 not null comment '经验',
total_experience int default 0 not null comment '变更后的经验',
description varchar(512) default '' not null comment '描述',
creator varchar(64) default '' null comment '创建者',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updater varchar(64) default '' null comment '更新者',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
deleted bit default b'0' not null comment '是否删除',
tenant_id bigint default 0 not null comment '租户编号'
)
comment '会员经验记录';
create index idx_user_id on member_experience_log (user_id) comment '会员经验记录-用户编号';
create index idx_user_biz_type on member_experience_log (user_id, biz_type) comment '会员经验记录-用户业务类型';
-- 增加字典
insert system_dict_type(name, type) values ('会员经验业务类型', 'member_experience_biz_type');
insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '管理员调整', '0', 0);
@ -74,21 +6,3 @@ insert system_dict_data(dict_type, label, value, sort) values ('member_experienc
insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '退单扣除', '3', 3);
insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '签到奖励', '4', 4);
insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '抽奖奖励', '5', 5);
-- 菜单 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
VALUES ('会员等级', '', 2, 3, 2262, 'level', '', 'member/level/index', 0, 'MemberLevel');
-- 按钮父菜单ID
-- 暂时只支持 MySQL如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('会员等级查询', 'member:level:query', 3, 1, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('会员等级创建', 'member:level:create', 3, 2, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('会员等级更新', 'member:level:update', 3, 3, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('会员等级删除', 'member:level:delete', 3, 4, @parentId, '', '', '', 0);

View File

@ -35,7 +35,7 @@ public class MemberLevelBaseVO {
@Schema(description = "享受折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "98")
@NotNull(message = "享受折扣不能为空")
@Range(min = 0, max = 100, message = "享受折扣的范围为 0-100")
private Integer discount;
private Integer discountPercent;
@Schema(description = "等级图标", example = "https://www.iocoder.cn/yudao.jpg")
@URL(message = "等级图标必须是 URL 格式")

View File

@ -26,7 +26,7 @@ public class MemberLevelLogBaseVO {
@Schema(description = "享受折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "13319")
@NotNull(message = "享受折扣不能为空")
private Integer discount;
private Integer discountPercent;
@Schema(description = "升级经验", requiredMode = Schema.RequiredMode.REQUIRED, example = "13319")
@NotNull(message = "升级经验不能为空")

View File

@ -29,9 +29,11 @@ public class MemberUserRespVO extends MemberUserBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
// ========== 其它信息 ==========
@Schema(description = "积分", example = "100")
private Integer point;
@Schema(description = "会员标签", example = "[红色, 快乐]")
private List<String> tagNames;

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.member.dal.dataobject.level;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
@ -29,6 +30,8 @@ public class MemberExperienceLogDO extends BaseDO {
private Long id;
/**
* 用户编号
*
* 关联 {@link MemberUserDO#getId()} 字段
*/
private Long userId;
/**
@ -45,6 +48,10 @@ public class MemberExperienceLogDO extends BaseDO {
* 标题
*/
private String title;
/**
* 描述
*/
private String description;
/**
* 经验
*/
@ -53,9 +60,5 @@ public class MemberExperienceLogDO extends BaseDO {
* 变更后的经验
*/
private Integer totalExperience;
/**
* 描述
*/
private String description;
}

View File

@ -33,18 +33,19 @@ public class MemberLevelDO extends BaseDO {
* 等级名称
*/
private String name;
/**
* 升级经验
*/
private Integer experience;
/**
* 等级
*/
private Integer level;
/**
* 升级经验
*/
private Integer experience;
/**
* 享受折扣
*/
private Integer discount;
private Integer discountPercent;
/**
* 等级图标
*/

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.member.dal.dataobject.level;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -30,20 +31,26 @@ public class MemberLevelLogDO extends BaseDO {
private Long id;
/**
* 用户编号
*
* 关联 {@link MemberUserDO#getId()} 字段
*/
private Long userId;
/**
* 等级编号
*
* 关联 {@link MemberLevelDO#getId()} 字段
*/
private Long levelId;
/**
* 会员等级
*
* 冗余 {@link MemberLevelDO#getLevel()} 字段
*/
private Integer level;
/**
* 享受折扣
*/
private Integer discount;
private Integer discountPercent;
/**
* 升级经验
*/

View File

@ -39,14 +39,6 @@ public interface MemberExperienceLogService {
*/
PageResult<MemberExperienceLogDO> getExperienceLogPage(MemberExperienceLogPageReqVO pageReqVO);
/**
* 获得会员经验记录列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 会员经验记录列表
*/
List<MemberExperienceLogDO> getExperienceLogList(MemberExperienceLogExportReqVO exportReqVO);
// TODO @疯狂类似 MemberLevelLogService 的方法这里也需要提供一个通用的方法用于创建经验变动记录
/**

View File

@ -47,14 +47,6 @@ public interface MemberLevelLogService {
*/
PageResult<MemberLevelLogDO> getLevelLogPage(MemberLevelLogPageReqVO pageReqVO);
/**
* 获得会员等级记录列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 会员等级记录列表
*/
List<MemberLevelLogDO> getLevelLogList(MemberLevelLogExportReqVO exportReqVO);
// TODO @疯狂 createCancelLogcreateAdjustLogcreateAutoUpgradeLog 几个日志合并成一个通用的日志方法整体的内容交给 MemberLevelService 去做以及对应的 level 变化的通知
/**

View File

@ -75,7 +75,7 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService {
levelLogDO.setUserId(user.getId());
levelLogDO.setLevelId(level.getId());
levelLogDO.setLevel(level.getLevel());
levelLogDO.setDiscount(level.getDiscount());
levelLogDO.setDiscountPercent(level.getDiscountPercent());
levelLogDO.setUserExperience(level.getExperience());
levelLogDO.setExperience(experience);
levelLogDO.setRemark(reason);
@ -92,7 +92,7 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService {
levelLogDO.setUserId(user.getId());
levelLogDO.setLevelId(level.getId());
levelLogDO.setLevel(level.getLevel());
levelLogDO.setDiscount(level.getDiscount());
levelLogDO.setDiscountPercent(level.getDiscountPercent());
levelLogDO.setExperience(level.getExperience());
levelLogDO.setUserExperience(user.getExperience());
levelLogDO.setDescription("成为:" + level.getName());

View File

@ -49,7 +49,7 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest {
public void testCreateLevel_success() {
// 准备参数
MemberLevelCreateReqVO reqVO = randomPojo(MemberLevelCreateReqVO.class, o -> {
o.setDiscount(randomInt());
o.setDiscountPercent(randomInt());
o.setIcon(randomURL());
o.setBackgroundUrl(randomURL());
});
@ -76,7 +76,7 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest {
o.setLevel(dbLevel.getLevel());
o.setExperience(dbLevel.getExperience());
//以下是要修改的字段
o.setDiscount(randomInt());
o.setDiscountPercent(randomInt());
o.setIcon(randomURL());
o.setBackgroundUrl(randomURL());
});
@ -256,7 +256,7 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest {
private static MemberLevelDO randomLevelDO(Consumer<MemberLevelDO>... consumers) {
Consumer<MemberLevelDO> consumer = (o) -> {
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
o.setDiscount(randomInt(0, 100));
o.setDiscountPercent(randomInt(0, 100));
o.setIcon(randomURL());
o.setBackgroundUrl(randomURL());
};