优化ai userid和markdown
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:dio/dio.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/data/datasources/device_http_datasource.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
|
||||
@@ -28,41 +30,22 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
Future<int> bindDevice(String deviceId, String deviceAlias) async {
|
||||
final logger = GetIt.I<ILoggerService>() as SentryLoggerImpl;
|
||||
logger.logWithLevel('用户点击bindDevice方法开始触发', level: 'INFO');
|
||||
logger.logWithLevel('用户点击bindDevice方法API 请求开始', level: 'INFO', data: {'url': 'https://serviceri.satabot.com/iot/device/bindDevice'});
|
||||
var response = await dio.post(HttpApiConsts.bindDevice, data: {'deviceId': deviceId, 'deviceAlias': deviceAlias});
|
||||
logger.logWithLevel(
|
||||
'用户点击bindDevice方法API 请求开始',
|
||||
level: 'INFO',
|
||||
data: {'url': 'https://serviceri.satabot.com/iot/device/bindDevice'}
|
||||
);
|
||||
var response = await dio.post(
|
||||
HttpApiConsts.bindDevice,
|
||||
data: {'deviceId': deviceId, 'deviceAlias': deviceAlias},
|
||||
);
|
||||
logger.logWithLevel(
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'https://serviceri.satabot.com/iot/device/bindDevice',
|
||||
'deviceId': deviceId,
|
||||
'deviceAlias': deviceAlias
|
||||
}
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {'url': 'https://serviceri.satabot.com/iot/device/bindDevice', 'deviceId': deviceId, 'deviceAlias': deviceAlias},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
logger.logWithLevel(
|
||||
'API 响应失败',
|
||||
level: 'ERROR',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 响应失败', level: 'ERROR', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
throw Exception('网络请求失败:${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200 || responseData['data'] != true) {
|
||||
logger.logWithLevel(
|
||||
'API 响应失败',
|
||||
level: 'ERROR',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 响应失败', level: 'ERROR', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
@@ -85,12 +68,14 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
await sl<AuthCubit>().logout();
|
||||
throw Exception('网络请求失败:${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
await sl<AuthCubit>().logout();
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
@@ -111,11 +96,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
final token = await _getToken();
|
||||
print('用户点击switchDevice方法开始触发: $token');
|
||||
logger.logWithLevel('用户点击switchDevice方法开始触发', level: 'DEBUG');
|
||||
logger.logWithLevel(
|
||||
'用户点击switchDevice方法API 请求开始',
|
||||
level: 'INFO',
|
||||
data: {'url': 'https://serviceri.satabot.com/iot/device/switchDevice'}
|
||||
);
|
||||
logger.logWithLevel('用户点击switchDevice方法API 请求开始', level: 'INFO', data: {'url': 'https://serviceri.satabot.com/iot/device/switchDevice'});
|
||||
var response = await dio.post(
|
||||
HttpApiConsts.switchDevice,
|
||||
data: {'platform': platform, 'deviceId': deviceId},
|
||||
@@ -127,35 +108,19 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
),
|
||||
);
|
||||
logger.logWithLevel(
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'https://serviceri.satabot.com/iot/device/switchDevice',
|
||||
'platform': platform,
|
||||
'deviceId': deviceId
|
||||
}
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {'url': 'https://serviceri.satabot.com/iot/device/switchDevice', 'platform': platform, 'deviceId': deviceId},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
logger.logWithLevel(
|
||||
'API 请求失败',
|
||||
level: 'ERROR',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 请求失败', level: 'ERROR', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
throw Exception('网络请求失败:${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
logger.logWithLevel(
|
||||
'API 响应成功',
|
||||
level: 'INFO',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 响应成功', level: 'INFO', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
if (responseData['code'] != 200 || responseData['data'] != true) {
|
||||
logger.logWithLevel(
|
||||
'API 响应失败',
|
||||
level: 'ERROR',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 响应失败', level: 'ERROR', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
return 1;
|
||||
@@ -201,14 +166,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
try {
|
||||
// 发起 GET 请求
|
||||
logger.logWithLevel('用户点击getDeviceLocation方法开始触发', level: 'INFO');
|
||||
logger.logWithLevel(
|
||||
'请求详细参数',
|
||||
level: 'DEBUG',
|
||||
data: {
|
||||
'url': 'https://serviceri.satabot.com/iot/device/userDevice',
|
||||
'tenantName': deviceame
|
||||
}
|
||||
);
|
||||
logger.logWithLevel('请求详细参数', level: 'DEBUG', data: {'url': 'https://serviceri.satabot.com/iot/device/userDevice', 'tenantName': deviceame});
|
||||
final response = await dio.get(
|
||||
'https://serviceri.satabot.com/iot/device/userDevice',
|
||||
queryParameters: {'tenantName': deviceame},
|
||||
@@ -223,24 +181,12 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
// 检查响应状态码
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
logger.logWithLevel(
|
||||
'API 响应接收',
|
||||
level: 'DEBUG',
|
||||
data: {'statusCode': response.statusCode, 'data': response.data}
|
||||
);
|
||||
logger.logWithLevel('API 响应接收', level: 'DEBUG', data: {'statusCode': response.statusCode, 'data': response.data});
|
||||
if (data['code'] == 200) {
|
||||
//return data['data']; // 返回设备数据
|
||||
final locationData = data['data']; // 假设数据结构,测试时候如有不妥就修改结果的实例化
|
||||
logger.logWithLevel(
|
||||
'成功获取设备位置',
|
||||
level: 'INFO',
|
||||
data: {'lat': locationData['latitude'], 'lng': locationData['longitude']}
|
||||
);
|
||||
return DeviceLocationEntity(
|
||||
deviceName: locationData['deviceName'],
|
||||
latitude: locationData['latitude'],
|
||||
longitude: locationData['longitude'],
|
||||
);
|
||||
logger.logWithLevel('成功获取设备位置', level: 'INFO', data: {'lat': locationData['latitude'], 'lng': locationData['longitude']});
|
||||
return DeviceLocationEntity(deviceName: locationData['deviceName'], latitude: locationData['latitude'], longitude: locationData['longitude']);
|
||||
} else {
|
||||
logger.logWithLevel(data['msg'] ?? '业务异常', level: 'ERROR');
|
||||
throw Exception(data['msg'] ?? '业务异常');
|
||||
|
||||
@@ -13,15 +13,9 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
DeviceRepositoryImpl(this._deviceHttpDatasource);
|
||||
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> bindDevice(
|
||||
String deviceId,
|
||||
String deviceAlias,
|
||||
) async {
|
||||
Future<Either<DeviceFailure, int>> bindDevice(String deviceId, String deviceAlias) async {
|
||||
try {
|
||||
var result = await _deviceHttpDatasource.bindDevice(
|
||||
deviceId,
|
||||
deviceAlias,
|
||||
);
|
||||
var result = await _deviceHttpDatasource.bindDevice(deviceId, deviceAlias);
|
||||
return Right(result);
|
||||
} on DioException catch (e) {
|
||||
final String serverMessage = e.response?.data['msg'] ?? "网络连接异常";
|
||||
@@ -33,9 +27,7 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<DeviceFailure, List<DeviceEntity>>> getUserDevice(
|
||||
String username,
|
||||
) async {
|
||||
Future<Either<DeviceFailure, List<DeviceEntity>>> getUserDevice(String username) async {
|
||||
try {
|
||||
var result = await _deviceHttpDatasource.getUserDevices(username);
|
||||
return Right(result);
|
||||
@@ -61,6 +53,7 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
return Left(DeviceFailure(cleanMessage));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> updateDeviceName(String deviceId, String deviceName) async {
|
||||
try {
|
||||
@@ -76,10 +69,7 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> switchDevice(
|
||||
String platform,
|
||||
String deviceId,
|
||||
) async {
|
||||
Future<Either<DeviceFailure, int>> switchDevice(String platform, String deviceId) async {
|
||||
try {
|
||||
var result = await _deviceHttpDatasource.switchDevice(platform, deviceId);
|
||||
return Right(result);
|
||||
@@ -91,9 +81,10 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
return Left(DeviceFailure(cleanMessage));
|
||||
}
|
||||
}
|
||||
// TODO: implement switchDevice 实现获取设备的列表
|
||||
|
||||
// TODO: implement switchDevice 实现获取设备的列表
|
||||
@override
|
||||
Future<Either<DeviceFailure, DeviceLocationEntity>>getDeviceLocation(String username) async {
|
||||
Future<Either<DeviceFailure, DeviceLocationEntity>> getDeviceLocation(String username) async {
|
||||
// TODO: implement getDeviceLocation
|
||||
var result = await _deviceHttpDatasource.getDeviceLocation(username);
|
||||
return Right(result);
|
||||
|
||||
Reference in New Issue
Block a user