feat(REQ-2997): message空校验响应正常处理
This commit is contained in:
parent
7d955d1499
commit
4b158e12cc
@ -41,6 +41,5 @@ public class LogAddReq {
|
||||
/**
|
||||
* 日志内容,需要是json格式
|
||||
*/
|
||||
@NotBlank(message = "message is required")
|
||||
private String message;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@ -29,4 +30,10 @@ public class ExceptionAdviceHandler {
|
||||
log.warn("业务异常", e);
|
||||
return ApiResult.err(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||
public ApiResult<Void> exceptionHandler(MethodArgumentNotValidException e) {
|
||||
log.error("参数异常", e);
|
||||
return ApiResult.err(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +78,9 @@ public class LogServiceImpl implements LogService {
|
||||
*/
|
||||
@Override
|
||||
public String addLog(LogAddReq req) {
|
||||
if (StringUtils.isBlank(req.getMessage())) {
|
||||
return "";
|
||||
}
|
||||
LogEntity logEntity = buildToLogEntity(req);
|
||||
logMapper.save(logEntity);
|
||||
return logEntity.getId();
|
||||
@ -145,8 +148,12 @@ public class LogServiceImpl implements LogService {
|
||||
*/
|
||||
@Override
|
||||
public List<String> batchAddLogs(LogBatchAddReq req) {
|
||||
if (req.getLogs().stream().allMatch(l -> StringUtils.isBlank(l.getMessage()))) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<LogEntity> logEntities = req.getLogs()
|
||||
.stream()
|
||||
.filter(l -> StringUtils.isNotBlank(l.getMessage()))
|
||||
.map(this::buildToLogEntity)
|
||||
.collect(Collectors.toList());
|
||||
logMapper.saveAll(logEntities);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user