From 9aee08ee0e8bdccfeca29c5711082608d9374362 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 21:12:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=EF=BC=9A=E4=BF=AE=E6=94=B9Re?= =?UTF-8?q?view=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/MemberExperienceBizTypeEnum.java | 17 ++++++--- .../member/api/level/MemberLevelApiImpl.java | 6 +-- .../service/group/MemberGroupServiceImpl.java | 7 ++-- .../service/level/MemberLevelServiceImpl.java | 7 +--- .../service/tag/MemberTagServiceImpl.java | 6 +-- .../service/user/MemberUserService.java | 37 +++++++++++++++---- .../service/user/MemberUserServiceImpl.java | 15 ++++++++ 7 files changed, 66 insertions(+), 29 deletions(-) diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index d8cb54132..fcd0f6e7a 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -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())); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 3d89663e7..3cd2cad65 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -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); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java index e0e24c776..98ec3cc85 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java @@ -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); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index fb9d5c663..d46465554 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -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() diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java index 93e09d747..d176bcabb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java @@ -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); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 2b8155184..7a0c13380 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -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; @@ -41,7 +41,7 @@ public interface MemberUserService { * 基于手机号创建用户。 * 如果用户已经存在,则直接进行返回 * - * @param mobile 手机号 + * @param mobile 手机号 * @param registerIp 注册 IP * @return 用户对象 */ @@ -50,7 +50,7 @@ public interface MemberUserService { /** * 更新用户的最后登陆信息 * - * @param id 用户编号 + * @param id 用户编号 * @param loginIp 登陆 IP */ void updateUserLogin(Long id, String loginIp); @@ -75,7 +75,7 @@ public interface MemberUserService { * 【会员】修改基本信息 * * @param userId 用户编号 - * @param reqVO 基本信息 + * @param reqVO 基本信息 */ void updateUser(Long userId, AppMemberUserUpdateReqVO reqVO); @@ -83,7 +83,7 @@ public interface MemberUserService { * 【会员】修改手机 * * @param userId 用户编号 - * @param reqVO 请求信息 + * @param reqVO 请求信息 */ void updateUserMobile(Long userId, AppMemberUserUpdateMobileReqVO reqVO); @@ -91,7 +91,7 @@ public interface MemberUserService { * 【会员】修改密码 * * @param userId 用户编号 - * @param reqVO 请求信息 + * @param reqVO 请求信息 */ void updateUserPassword(Long userId, AppMemberUserUpdatePasswordReqVO reqVO); @@ -105,7 +105,7 @@ public interface MemberUserService { /** * 判断密码是否匹配 * - * @param rawPassword 未加密的密码 + * @param rawPassword 未加密的密码 * @param encodedPassword 加密后的密码 * @return 是否匹配 */ @@ -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); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index cfaaf22de..152f87cad 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -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); + } + }