新增数据库 联表查询支持

This commit is contained in:
2025-03-21 10:33:19 +08:00
parent a15345adeb
commit 5acd63eb99
4 changed files with 75 additions and 29 deletions

View File

@@ -1,5 +1,3 @@
import 'dart:io';
import 'package:EasyDartModule/base/database/DataBase.dart'; import 'package:EasyDartModule/base/database/DataBase.dart';
import 'package:mongo_dart/mongo_dart.dart'; import 'package:mongo_dart/mongo_dart.dart';
@@ -52,8 +50,14 @@ class MongoDb implements DataBase {
if (condition == null) { if (condition == null) {
return await getCollection(table).find().toList(); 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(); return await getCollection(table).find(condition).toList();
} }
}
@override @override
Future<void> update( Future<void> update(

View File

@@ -18,7 +18,7 @@ class TraceDio {
// 设置连接超时 // 设置连接超时
_dio.options.connectTimeout = Duration(seconds: 60); _dio.options.connectTimeout = Duration(seconds: 60);
// 设置接收超时 // 设置接收超时
_dio.options.receiveTimeout = Duration(seconds: 60); _dio.options.receiveTimeout = Duration(seconds: 5 * 60);
//保留原始大小写 //保留原始大小写
_dio.options.preserveHeaderCase = true; _dio.options.preserveHeaderCase = true;
@@ -103,12 +103,18 @@ class TraceDio {
sf.Request? request, sf.Request? request,
ResponseType? responseType, ResponseType? responseType,
Duration? receiveTimeout}) async { Duration? receiveTimeout}) async {
try {
return await _dio.get(url, return await _dio.get(url,
queryParameters: queryParameters, queryParameters: queryParameters,
options: Options( options: Options(
receiveTimeout: receiveTimeout, receiveTimeout: receiveTimeout,
headers: getHeader(request: request), headers: getHeader(request: request),
responseType: responseType)); responseType: responseType));
} catch (e) {
//api接口报错
var a = e as DioException;
return a.response!;
}
} }
// 发起 POST 请求 // 发起 POST 请求

View File

@@ -10,13 +10,29 @@ abstract class Logger {
} }
void debug(String msg, 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, 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, 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, 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 { class LoggerConfig {

View File

@@ -35,46 +35,66 @@ class LokiLogger implements Logger {
} }
@override @override
void debug(String msg, 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, log(msg,
level: LoggerLevel.debug, level: LoggerLevel.debug,
tag: tag, tag: tag,
traceId: traceId, traceId: traceId,
spanId: spanId, spanId: spanId,
parentSpanId: parentSpanId); parentSpanId: parentSpanId,
lable: lable);
} }
@override @override
void info(String msg, 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, log(msg,
level: LoggerLevel.info, level: LoggerLevel.info,
tag: tag, tag: tag,
traceId: traceId, traceId: traceId,
spanId: spanId, spanId: spanId,
parentSpanId: parentSpanId); parentSpanId: parentSpanId,
lable: lable);
} }
@override @override
void warning(String msg, 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, log(msg,
level: LoggerLevel.warning, level: LoggerLevel.warning,
tag: tag, tag: tag,
traceId: traceId, traceId: traceId,
spanId: spanId, spanId: spanId,
parentSpanId: parentSpanId); parentSpanId: parentSpanId,
lable: lable);
} }
@override @override
void error(String msg, 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, log(msg,
level: LoggerLevel.error, level: LoggerLevel.error,
tag: tag, tag: tag,
traceId: traceId, traceId: traceId,
spanId: spanId, spanId: spanId,
parentSpanId: parentSpanId); parentSpanId: parentSpanId,
lable: lable);
} }
void log(String msg, void log(String msg,
@@ -82,7 +102,8 @@ class LokiLogger implements Logger {
String? tag, String? tag,
String? traceId, String? traceId,
String? spanId, String? spanId,
String? parentSpanId}) { String? parentSpanId,
Map<String, String>? lable}) {
if (level.level < this.level.level) { if (level.level < this.level.level) {
//日志等级小于设置的输出日志等级 //日志等级小于设置的输出日志等级
return; return;
@@ -97,15 +118,14 @@ class LokiLogger implements Logger {
var now = DateTime.now(); var now = DateTime.now();
// 转换为纳秒 // 转换为纳秒
int nanoseconds = now.microsecondsSinceEpoch * 1000; int nanoseconds = now.microsecondsSinceEpoch * 1000;
var lableMap = {"service_name": _config.serviceName};
if (lable != null) {
lableMap.addAll(lable);
}
var data = jsonEncode({ var data = jsonEncode({
"streams": [ "streams": [
{ {
"stream": { "stream": lableMap,
"service_name": _config.serviceName,
// "traceId": traceId,
// "spanId": spanId,
// "parentSpanId": parentSpanId
},
"values": [ "values": [
[nanoseconds.toString(), log] [nanoseconds.toString(), log]
] ]