Skip to content

Commit

Permalink
fix: 修复重载校验方法定义及使用错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Oct 19, 2023
1 parent efe4557 commit a1ccc42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void throwIfNotNull(Object obj, String template, Object... params)
}

/**
* 如果不为空,抛出异常
* 如果存在,抛出异常
*
* @param obj
* 被检测的对象
Expand All @@ -98,7 +98,7 @@ public static void throwIfNotNull(Object obj, String template, Object... params)
* @param fieldValue
* 字段值
*/
public static void throwIfNotNull(Object obj, String entityName, String fieldName, Object fieldValue) {
public static void throwIfExists(Object obj, String entityName, String fieldName, Object fieldValue) {
String message = String.format("%s 为 [%s] 的 %s 记录已存在", fieldName, fieldValue, entityName);
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import cn.hutool.json.JSONUtil;

import top.charles7c.cnadmin.common.enums.SocialSourceEnum;
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
import top.charles7c.cnadmin.system.mapper.UserSocialMapper;
import top.charles7c.cnadmin.system.model.entity.UserSocialDO;
Expand Down Expand Up @@ -76,9 +77,10 @@ public void bind(AuthUser authUser, Long userId) {
String openId = authUser.getUuid();
List<UserSocialDO> userSocialList = this.listByUserId(userId);
Set<String> boundSocialSet = userSocialList.stream().map(UserSocialDO::getSource).collect(Collectors.toSet());
CheckUtils.throwIf(boundSocialSet.contains(source), "您已经绑定过了 [{}] 平台,请先解绑");
String description = SocialSourceEnum.valueOf(source).getDescription();
CheckUtils.throwIf(boundSocialSet.contains(source), "您已经绑定过了 [{}] 平台,请先解绑", description);
UserSocialDO userSocial = this.getBySourceAndOpenId(source, openId);
CheckUtils.throwIfNotNull(userSocial, "[{}] 平台账号 [{}] 已被其他用户绑定", source, authUser.getUsername());
CheckUtils.throwIfNotNull(userSocial, "[{}] 平台账号 [{}] 已被其他用户绑定", description, authUser.getUsername());
userSocial = new UserSocialDO();
userSocial.setUserId(userId);
userSocial.setSource(source);
Expand Down

0 comments on commit a1ccc42

Please sign in to comment.