会员:修改Review的代码

This commit is contained in:
owen 2023-08-25 21:12:31 +08:00
parent 2895ae3ddb
commit 9aee08ee0e
7 changed files with 66 additions and 29 deletions

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.member.enums;
import cn.hutool.core.util.EnumUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* 会员经验 - 业务类型
*
@ -15,16 +18,20 @@ public enum MemberExperienceBizTypeEnum {
/**
* 管理员调整邀请新用户下单退单签到抽奖
*/
ADMIN(0, "管理员调整","管理员调整获得 {} 经验"),
INVITE_REGISTER(1, "邀新奖励","邀请好友获得 {} 经验"),
ADMIN(0, "管理员调整", "管理员调整获得 {} 经验"),
INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验"),
ORDER(2, "下单奖励", "下单获得 {} 经验"),
REFUND(3, "退单扣除","退单获得 {} 经验"),
SIGN_IN(4, "签到奖励","签到获得 {} 经验"),
LOTTERY(5, "抽奖奖励","抽奖获得 {} 经验"),
REFUND(3, "退单扣除", "退单获得 {} 经验"),
SIGN_IN(4, "签到奖励", "签到获得 {} 经验"),
LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验"),
;
private final int type;
private final String title;
private final String description;
public static MemberExperienceBizTypeEnum getByType(Integer type) {
return EnumUtil.getBy(MemberExperienceBizTypeEnum.class,
e -> Objects.equals(type, e.getType()));
}
}

View File

@ -1,13 +1,11 @@
package cn.iocoder.yudao.module.member.api.level;
import cn.hutool.core.util.EnumUtil;
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.EXPERIENCE_BIZ_NOT_SUPPORT;
@ -26,9 +24,7 @@ public class MemberLevelApiImpl implements MemberLevelApi {
@Override
public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) {
// TODO @疯狂可以在 MemberExperienceBizTypeEnum 增加一个方法获得哈
MemberExperienceBizTypeEnum bizTypeEnum = EnumUtil.getBy(MemberExperienceBizTypeEnum.class,
e -> Objects.equals(bizType, e.getType()));
MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType);
if (bizTypeEnum == null) {
throw exception(EXPERIENCE_BIZ_NOT_SUPPORT);
}

View File

@ -9,7 +9,7 @@ import cn.iocoder.yudao.module.member.controller.admin.group.vo.MemberGroupUpdat
import cn.iocoder.yudao.module.member.convert.group.MemberGroupConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO;
import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper;
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -33,7 +33,7 @@ public class MemberGroupServiceImpl implements MemberGroupService {
@Resource
private MemberGroupMapper groupMapper;
@Resource
private MemberUserMapper memberUserMapper;
private MemberUserService memberUserService;
@Override
public Long createGroup(MemberGroupCreateReqVO createReqVO) {
@ -69,9 +69,8 @@ public class MemberGroupServiceImpl implements MemberGroupService {
}
}
// TODO @疯狂不要直接调用 memberUserMapper需要对方 service 提供方法
void validateGroupHasUser(Long id) {
Long count = memberUserMapper.selectCountByGroupId(id);
Long count = memberUserService.getUserCountByGroupId(id);
if (count > 0) {
throw exception(GROUP_HAS_USER);
}

View File

@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO;
import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelMapper;
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import com.google.common.annotations.VisibleForTesting;
@ -49,8 +48,6 @@ public class MemberLevelServiceImpl implements MemberLevelService {
@Resource
private MemberExperienceRecordService memberExperienceRecordService;
@Resource
private MemberUserMapper memberUserMapper;
@Resource
private MemberUserService memberUserService;
@Override
@ -157,7 +154,7 @@ public class MemberLevelServiceImpl implements MemberLevelService {
// TODO Service 提供接口哈不直接调用对方的 memberUserMapper
@VisibleForTesting
void validateLevelHasUser(Long id) {
Long count = memberUserMapper.selectCountByLevelId(id);
Long count = memberUserService.getUserCountByLevelId(id);
if (count > 0) {
throw exception(LEVEL_HAS_USER);
}
@ -239,7 +236,7 @@ public class MemberLevelServiceImpl implements MemberLevelService {
return;
}
MemberUserDO user = memberUserMapper.selectById(userId);
MemberUserDO user = memberUserService.getUser(userId);
int userExperience = NumberUtil.max(user.getExperience() + experience, 0);
MemberLevelRecordDO levelRecord = new MemberLevelRecordDO()

View File

@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagUpdateReq
import cn.iocoder.yudao.module.member.convert.tag.MemberTagConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
import cn.iocoder.yudao.module.member.dal.mysql.tag.MemberTagMapper;
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -33,7 +33,7 @@ public class MemberTagServiceImpl implements MemberTagService {
@Resource
private MemberTagMapper tagMapper;
@Resource
private MemberUserMapper memberUserMapper;
private MemberUserService memberUserService;
@Override
public Long createTag(MemberTagCreateReqVO createReqVO) {
@ -92,7 +92,7 @@ public class MemberTagServiceImpl implements MemberTagService {
}
void validateTagHasUser(Long id) {
Long count = memberUserMapper.selectCountByTagId(id);
Long count = memberUserService.getUserCountByTagId(id);
if (count > 0) {
throw exception(TAG_HAS_USER);
}

View File

@ -5,9 +5,9 @@ import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserResetPasswordReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateMobileReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdatePasswordReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateMobileReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import javax.validation.Valid;
@ -135,4 +135,27 @@ public interface MemberUserService {
*/
void updateUserLevel(Long id, Long levelId, Integer experience);
/**
* 获得指定用户分组下的用户数量
*
* @param groupId 用户分组编号
* @return 用户数量
*/
Long getUserCountByGroupId(Long groupId);
/**
* 获得指定用户等级下的用户数量
*
* @param levelId 用户等级编号
* @return 用户数量
*/
Long getUserCountByLevelId(Long levelId);
/**
* 获得指定会员标签下的用户数量
*
* @param tagId 用户标签编号
* @return 用户数量
*/
Long getUserCountByTagId(Long tagId);
}

View File

@ -239,4 +239,19 @@ public class MemberUserServiceImpl implements MemberUserService {
);
}
@Override
public Long getUserCountByGroupId(Long groupId) {
return memberUserMapper.selectCountByGroupId(groupId);
}
@Override
public Long getUserCountByLevelId(Long levelId) {
return memberUserMapper.selectCountByLevelId(levelId);
}
@Override
public Long getUserCountByTagId(Long tagId) {
return memberUserMapper.selectCountByTagId(tagId);
}
}