mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 14:13:42 +08:00
Merge remote-tracking branch 'origin/main' into chat
# Conflicts: # mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/strategy/msg/TextMsgHandler.java
This commit is contained in:
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -20,12 +22,15 @@ import java.io.Serializable;
|
||||
public class FileMsgDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ApiModelProperty("大小(字节)")
|
||||
@NotNull
|
||||
private Long size;
|
||||
|
||||
@ApiModelProperty("下载地址")
|
||||
@NotBlank
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty("文件名(带后缀)")
|
||||
@NotBlank
|
||||
private String fileName;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -20,11 +22,14 @@ import java.io.Serializable;
|
||||
public class SoundMsgDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ApiModelProperty("大小(字节)")
|
||||
@NotNull
|
||||
private Long size;
|
||||
|
||||
@ApiModelProperty("时长(秒)")
|
||||
@NotNull
|
||||
private Integer second;
|
||||
|
||||
@ApiModelProperty("下载地址")
|
||||
@NotBlank
|
||||
private String url;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import lombok.NoArgsConstructor;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Description: 视频消息入参
|
||||
@@ -23,20 +22,23 @@ import java.math.BigDecimal;
|
||||
public class VideoMsgDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ApiModelProperty("大小(字节)")
|
||||
@NotNull
|
||||
private Long size;
|
||||
|
||||
@ApiModelProperty("下载地址")
|
||||
@NotBlank
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty("缩略图宽度(像素)")
|
||||
@NotNull
|
||||
private Integer thumbWidth = BigDecimal.ROUND_HALF_DOWN;
|
||||
private Integer thumbWidth;
|
||||
|
||||
@ApiModelProperty("缩略图高度(像素)")
|
||||
@NotNull
|
||||
private Integer thumbHeight;
|
||||
|
||||
@ApiModelProperty("缩略图大小(字节)")
|
||||
@NotNull
|
||||
private Long thumbSize;
|
||||
|
||||
@ApiModelProperty("缩略图下载地址")
|
||||
|
||||
@@ -22,7 +22,7 @@ public class GlobalExceptionHandler {
|
||||
e.getBindingResult().getFieldErrors().forEach(x -> errorMsg.append(x.getField()).append(x.getDefaultMessage()).append(","));
|
||||
String message = errorMsg.toString();
|
||||
log.info("validation parameters error!The reason is:{}", message);
|
||||
return ApiResult.fail(-1, message.substring(0, message.length() - 1));
|
||||
return ApiResult.fail(CommonErrorEnum.PARAM_VALID.getErrorCode(), message.substring(0, message.length() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ public class GlobalExceptionHandler {
|
||||
e.getBindingResult().getFieldErrors().forEach(x -> errorMsg.append(x.getField()).append(x.getDefaultMessage()).append(","));
|
||||
String message = errorMsg.toString();
|
||||
log.info("validation parameters error!The reason is:{}", message);
|
||||
return ApiResult.fail(-1, message.substring(0, message.length() - 1));
|
||||
return ApiResult.fail(CommonErrorEnum.PARAM_VALID.getErrorCode(), message.substring(0, message.length() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,16 +3,83 @@ package com.abin.mallchat.common.common.utils;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.abin.mallchat.common.common.exception.BusinessErrorEnum;
|
||||
import com.abin.mallchat.common.common.exception.BusinessException;
|
||||
import com.abin.mallchat.common.common.exception.CommonErrorEnum;
|
||||
import com.abin.mallchat.common.common.exception.ErrorEnum;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 校验工具类
|
||||
*/
|
||||
public class AssertUtil {
|
||||
|
||||
/**
|
||||
* 校验到失败就结束
|
||||
*/
|
||||
private static Validator failFastValidator = Validation.byProvider(HibernateValidator.class)
|
||||
.configure()
|
||||
.failFast(true)
|
||||
.buildValidatorFactory().getValidator();
|
||||
|
||||
/**
|
||||
* 全部校验
|
||||
*/
|
||||
private static Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
|
||||
/**
|
||||
* 注解验证参数(校验到失败就结束)
|
||||
* @param obj
|
||||
*/
|
||||
public static <T> void fastFailValidate(T obj) {
|
||||
Set<ConstraintViolation<T>> constraintViolations = failFastValidator.validate(obj);
|
||||
if (constraintViolations.size() > 0) {
|
||||
throwException(CommonErrorEnum.PARAM_VALID,constraintViolations.iterator().next().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注解验证参数(全部校验,抛出异常)
|
||||
* @param obj
|
||||
*/
|
||||
public static <T> void allCheckValidateThrow(T obj) {
|
||||
Set<ConstraintViolation<T>> constraintViolations = validator.validate(obj);
|
||||
if (constraintViolations.size() > 0) {
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
Iterator<ConstraintViolation<T>> iterator = constraintViolations.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ConstraintViolation<T> violation = iterator.next();
|
||||
//拼接异常信息
|
||||
errorMsg.append(violation.getPropertyPath().toString()).append(":").append(violation.getMessage()).append(",");
|
||||
}
|
||||
//去掉最后一个逗号
|
||||
throwException(CommonErrorEnum.PARAM_VALID, errorMsg.toString().substring(0, errorMsg.length() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注解验证参数(全部校验,返回异常信息集合)
|
||||
* @param obj
|
||||
*/
|
||||
public static <T> Map<String,String> allCheckValidate(T obj) {
|
||||
Set<ConstraintViolation<T>> constraintViolations = validator.validate(obj);
|
||||
if (constraintViolations.size() > 0) {
|
||||
Map<String,String> errorMessages= new HashMap<>();
|
||||
Iterator<ConstraintViolation<T>> iterator = constraintViolations.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ConstraintViolation<T> violation = iterator.next();
|
||||
errorMessages.put(violation.getPropertyPath().toString(),violation.getMessage());
|
||||
}
|
||||
return errorMessages;
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
//如果不是true,则抛异常
|
||||
public static void isTrue(boolean expression, String msg) {
|
||||
if (!expression) {
|
||||
|
||||
Reference in New Issue
Block a user