提取OperationResult错误信息并以字符串返回原创
金蝶云社区-cosmicstudio
cosmicstudio
6人赞赏了该文章 2,262次浏览 未经作者许可,禁止转载编辑于2024年04月16日 10:43:37


提取OperationResult错误信息并以字符串返回

/**
 * 获取操作错误信息
 * @param operationResult
 * @return
 */
private String getOperationResultErrorInfos(OperationResult operationResult){
    if(operationResult.isSuccess()){
        return StringUtils.EMPTY;
    }

    List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo();
    int size = errorInfos.size() + operationResult.getSuccessPkIds().size();
    if (size > 1) {
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        for(int len = errorInfos.size(); i < 5 && i < len; ++i) {
            stringBuilder.append((errorInfos.get(i)).getMessage());
        }
        return stringBuilder.toString();
    } else if (!errorInfos.isEmpty()) {
        OperateErrorInfo errorInfo = (OperateErrorInfo)errorInfos.get(0);
        String msg = errorInfo.getMessage() == null ? "" : errorInfo.getMessage();
        return msg;
    } else{
        String msg = operationResult.getMessage() == null ? "" : operationResult.getMessage();
        return msg;
    }
}

赞 6