新增数据库 联表查询支持
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:EasyDartModule/base/database/DataBase.dart';
|
||||
import 'package:mongo_dart/mongo_dart.dart';
|
||||
|
||||
@@ -52,8 +50,14 @@ class MongoDb implements DataBase {
|
||||
if (condition == null) {
|
||||
return await getCollection(table).find().toList();
|
||||
}
|
||||
if (condition is AggregationPipelineBuilder) {
|
||||
return await getCollection(table)
|
||||
.aggregateToStream(condition.build())
|
||||
.toList();
|
||||
} else {
|
||||
return await getCollection(table).find(condition).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(
|
||||
|
||||
@@ -18,7 +18,7 @@ class TraceDio {
|
||||
// 设置连接超时
|
||||
_dio.options.connectTimeout = Duration(seconds: 60);
|
||||
// 设置接收超时
|
||||
_dio.options.receiveTimeout = Duration(seconds: 60);
|
||||
_dio.options.receiveTimeout = Duration(seconds: 5 * 60);
|
||||
//保留原始大小写
|
||||
_dio.options.preserveHeaderCase = true;
|
||||
|
||||
@@ -103,12 +103,18 @@ class TraceDio {
|
||||
sf.Request? request,
|
||||
ResponseType? responseType,
|
||||
Duration? receiveTimeout}) async {
|
||||
try {
|
||||
return await _dio.get(url,
|
||||
queryParameters: queryParameters,
|
||||
options: Options(
|
||||
receiveTimeout: receiveTimeout,
|
||||
headers: getHeader(request: request),
|
||||
responseType: responseType));
|
||||
} catch (e) {
|
||||
//api接口报错
|
||||
var a = e as DioException;
|
||||
return a.response!;
|
||||
}
|
||||
}
|
||||
|
||||
// 发起 POST 请求
|
||||
|
||||
@@ -10,13 +10,29 @@ abstract class Logger {
|
||||
}
|
||||
|
||||
void debug(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId});
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable});
|
||||
void info(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId});
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable});
|
||||
void warning(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId});
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable});
|
||||
void error(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId});
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable});
|
||||
}
|
||||
|
||||
class LoggerConfig {
|
||||
|
||||
@@ -35,46 +35,66 @@ class LokiLogger implements Logger {
|
||||
}
|
||||
@override
|
||||
void debug(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable}) {
|
||||
log(msg,
|
||||
level: LoggerLevel.debug,
|
||||
tag: tag,
|
||||
traceId: traceId,
|
||||
spanId: spanId,
|
||||
parentSpanId: parentSpanId);
|
||||
parentSpanId: parentSpanId,
|
||||
lable: lable);
|
||||
}
|
||||
|
||||
@override
|
||||
void info(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable}) {
|
||||
log(msg,
|
||||
level: LoggerLevel.info,
|
||||
tag: tag,
|
||||
traceId: traceId,
|
||||
spanId: spanId,
|
||||
parentSpanId: parentSpanId);
|
||||
parentSpanId: parentSpanId,
|
||||
lable: lable);
|
||||
}
|
||||
|
||||
@override
|
||||
void warning(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable}) {
|
||||
log(msg,
|
||||
level: LoggerLevel.warning,
|
||||
tag: tag,
|
||||
traceId: traceId,
|
||||
spanId: spanId,
|
||||
parentSpanId: parentSpanId);
|
||||
parentSpanId: parentSpanId,
|
||||
lable: lable);
|
||||
}
|
||||
|
||||
@override
|
||||
void error(String msg,
|
||||
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
|
||||
{String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable}) {
|
||||
log(msg,
|
||||
level: LoggerLevel.error,
|
||||
tag: tag,
|
||||
traceId: traceId,
|
||||
spanId: spanId,
|
||||
parentSpanId: parentSpanId);
|
||||
parentSpanId: parentSpanId,
|
||||
lable: lable);
|
||||
}
|
||||
|
||||
void log(String msg,
|
||||
@@ -82,7 +102,8 @@ class LokiLogger implements Logger {
|
||||
String? tag,
|
||||
String? traceId,
|
||||
String? spanId,
|
||||
String? parentSpanId}) {
|
||||
String? parentSpanId,
|
||||
Map<String, String>? lable}) {
|
||||
if (level.level < this.level.level) {
|
||||
//日志等级小于设置的输出日志等级
|
||||
return;
|
||||
@@ -97,15 +118,14 @@ class LokiLogger implements Logger {
|
||||
var now = DateTime.now();
|
||||
// 转换为纳秒
|
||||
int nanoseconds = now.microsecondsSinceEpoch * 1000;
|
||||
var lableMap = {"service_name": _config.serviceName};
|
||||
if (lable != null) {
|
||||
lableMap.addAll(lable);
|
||||
}
|
||||
var data = jsonEncode({
|
||||
"streams": [
|
||||
{
|
||||
"stream": {
|
||||
"service_name": _config.serviceName,
|
||||
// "traceId": traceId,
|
||||
// "spanId": spanId,
|
||||
// "parentSpanId": parentSpanId
|
||||
},
|
||||
"stream": lableMap,
|
||||
"values": [
|
||||
[nanoseconds.toString(), log]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user