interro_robot/src/main/java/com/supervision/dto/QueryProcessDTO.java

122 lines
3.1 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.supervision.dto;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Data
@Builder
public class QueryProcessDTO {
/**
* 处理状态 0正常 1参数校验异常 2系统异常
*/
private Integer state;
/**
* 内容类型 1-文本2-音频3-文件4-图片5-视频 6-档案文件
*/
private Integer contentType;
/**
* 字符串类型的内容
*/
private String stringContent;
/**
* 字节数组类型的内容
*/
private byte[] byteContent;
private File fileContent;
/**
* 字节数组类型的id
*/
private String byteContentId;
/**
* 参数校验的参数列表
*/
private List<ParamCheckDTO> paramCheckList;
public String paramCheckToMessage(){
if (CollUtil.isEmpty(paramCheckList)){
return "";
}
String paraDescJoin = paramCheckList.stream().map(ParamCheckDTO::getParamDesc).filter(StrUtil::isNotEmpty).collect(Collectors.joining(","));
return "请设置必要信息:"+paraDescJoin;
}
/**
* 判断参数是否为空 为空则添加到参数校验列表中
* @param paramName 参数名
* @param value 参数值
* @param errorMsgTemplate 错误信息模板
* @param <T>
*/
public <T> void notNullParam(String paramName, T value, String errorMsgTemplate){
if(Objects.isNull(value)){
this.state = 1;
if (null == paramCheckList){
paramCheckList = new ArrayList<>();
}
this.paramCheckList.add(new ParamCheckDTO(paramName, errorMsgTemplate,1));
}
}
/**
* 判断参数是否为空 为空则添加到参数校验列表中
* @param paramName 参数名
* @param value 参数值
* @param errorMsgTemplate 错误信息模板
* @param <T>
*/
public <T extends CharSequence> void notEmptyParam(String paramName, T value, String errorMsgTemplate){
if(StrUtil.isEmpty(value)){
this.state = 1;
this.paramCheckList.add(new ParamCheckDTO(paramName, errorMsgTemplate,2));
}
}
@Data
@AllArgsConstructor
static class ParamCheckDTO {
private String paramName;
private String paramDesc;
/**
* 错误类型 1参数缺失 2参数值错误 3参数类型错误
*/
private Integer errorType;
public String toMessage(){
if (Integer.valueOf(1).equals(errorType)){
return String.format("参数%s缺失",paramName);
}
if (Integer.valueOf(2).equals(errorType)){
return String.format("参数%s值错误",paramName);
}
if (Integer.valueOf(3).equals(errorType)){
return String.format("参数%s类型错误",paramName);
}
return "";
}
}
}