提交 a1ccc421 编写于 作者: 查尔斯-BUG万象集's avatar 查尔斯-BUG万象集

fix: 修复重载校验方法定义及使用错误

上级 efe45573
......@@ -87,7 +87,7 @@ public class CheckUtils extends Validator {
}
/**
* 如果不为空,抛出异常
* 如果存在,抛出异常
*
* @param obj
* 被检测的对象
......@@ -98,7 +98,7 @@ public class CheckUtils extends Validator {
* @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);
}
......
......@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
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;
......@@ -76,9 +77,10 @@ public class UserSocialServiceImpl implements UserSocialService {
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册