From 5a2d9d14df7b90e468bac1a6c0dc530f975b8a28 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 22 Aug 2023 01:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98:=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=A0=87=E7=AD=BE,=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E6=97=B6,=20=E6=A0=A1=E9=AA=8C=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=85=B3=E8=81=94=E4=BA=86=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/dal/mysql/user/MemberUserMapper.java | 10 ++++++++++ .../service/level/MemberLevelServiceImpl.java | 11 ++++++++++- .../member/service/tag/MemberTagServiceImpl.java | 15 +++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 0c2758527c..d85b5d0e58 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -67,4 +67,14 @@ public interface MemberUserMapper extends BaseMapperX { default Long selectCountByGroupId(Long groupId) { return selectCount(MemberUserDO::getGroupId, groupId); } + + default Long selectCountByLevelId(Long levelId) { + return selectCount(MemberUserDO::getLevelId, levelId); + } + + default Long selectCountByTagId(Long tagId) { + return selectCount(new LambdaQueryWrapperX() + .apply("FIND_IN_SET({0}, tag_ids)", tagId)); + } + } 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 9ff169a237..947d100f90 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 @@ -74,9 +74,10 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Override public void deleteLevel(Long id) { - // TODO @疯狂:校验是否有用户使用该等级 // 校验存在 validateLevelExists(id); + // 校验分组下是否有用户 + validateLevelHasUser(id); // 删除 levelMapper.deleteById(id); } @@ -149,6 +150,14 @@ public class MemberLevelServiceImpl implements MemberLevelService { validateExperienceOutRange(list, id, level, experience); } + @VisibleForTesting + void validateLevelHasUser(Long id) { + Long count = memberUserMapper.selectCountByLevelId(id); + if (count > 0) { + throw exception(GROUP_HAS_USER); + } + } + @Override public MemberLevelDO getLevel(Long id) { return levelMapper.selectById(id); 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 2c11c55cb5..93e09d747d 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,6 +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 org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -18,8 +19,7 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.TAG_NAME_EXISTS; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.TAG_NOT_EXISTS; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; /** * 会员标签 Service 实现类 @@ -32,6 +32,8 @@ public class MemberTagServiceImpl implements MemberTagService { @Resource private MemberTagMapper tagMapper; + @Resource + private MemberUserMapper memberUserMapper; @Override public Long createTag(MemberTagCreateReqVO createReqVO) { @@ -59,6 +61,8 @@ public class MemberTagServiceImpl implements MemberTagService { public void deleteTag(Long id) { // 校验存在 validateTagExists(id); + // 校验标签下是否有用户 + validateTagHasUser(id); // 删除 tagMapper.deleteById(id); } @@ -87,6 +91,13 @@ public class MemberTagServiceImpl implements MemberTagService { } } + void validateTagHasUser(Long id) { + Long count = memberUserMapper.selectCountByTagId(id); + if (count > 0) { + throw exception(TAG_HAS_USER); + } + } + @Override public MemberTagDO getTag(Long id) { return tagMapper.selectById(id);