v2版本登录
This commit is contained in:
169
lib/features/v2/home/domain/entities/home_entity.dart
Normal file
169
lib/features/v2/home/domain/entities/home_entity.dart
Normal file
@@ -0,0 +1,169 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class HomeEntity extends Equatable {
|
||||
final String plantName;
|
||||
final double realTimePower;
|
||||
final double todayGeneration;
|
||||
final double equivalentHours;
|
||||
final int pendingWorkOrders;
|
||||
final WeatherInfo weather;
|
||||
final int alarmCount;
|
||||
final WorkOrderStats workOrderStats;
|
||||
final List<PowerTrendPoint> powerTrendData;
|
||||
final PlantOverview plantOverview;
|
||||
|
||||
const HomeEntity({
|
||||
required this.plantName,
|
||||
required this.realTimePower,
|
||||
required this.todayGeneration,
|
||||
required this.equivalentHours,
|
||||
required this.pendingWorkOrders,
|
||||
required this.weather,
|
||||
required this.alarmCount,
|
||||
required this.workOrderStats,
|
||||
required this.powerTrendData,
|
||||
required this.plantOverview,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
plantName,
|
||||
realTimePower,
|
||||
todayGeneration,
|
||||
equivalentHours,
|
||||
pendingWorkOrders,
|
||||
weather,
|
||||
alarmCount,
|
||||
workOrderStats,
|
||||
powerTrendData,
|
||||
plantOverview,
|
||||
];
|
||||
}
|
||||
|
||||
class WeatherInfo extends Equatable {
|
||||
final String condition;
|
||||
final int tempMin;
|
||||
final int tempMax;
|
||||
final String windDirection;
|
||||
final String windLevel;
|
||||
|
||||
const WeatherInfo({
|
||||
required this.condition,
|
||||
required this.tempMin,
|
||||
required this.tempMax,
|
||||
required this.windDirection,
|
||||
required this.windLevel,
|
||||
});
|
||||
|
||||
factory WeatherInfo.fromJson(Map<String, dynamic> json) {
|
||||
return WeatherInfo(
|
||||
condition: json['condition'] as String,
|
||||
tempMin: json['tempMin'] as int,
|
||||
tempMax: json['tempMax'] as int,
|
||||
windDirection: json['windDirection'] as String,
|
||||
windLevel: json['windLevel'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'condition': condition,
|
||||
'tempMin': tempMin,
|
||||
'tempMax': tempMax,
|
||||
'windDirection': windDirection,
|
||||
'windLevel': windLevel,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [condition, tempMin, tempMax, windDirection, windLevel];
|
||||
}
|
||||
|
||||
class WorkOrderStats extends Equatable {
|
||||
final int pending;
|
||||
final int processing;
|
||||
final int pendingAcceptance;
|
||||
|
||||
const WorkOrderStats({
|
||||
required this.pending,
|
||||
required this.processing,
|
||||
required this.pendingAcceptance,
|
||||
});
|
||||
|
||||
factory WorkOrderStats.fromJson(Map<String, dynamic> json) {
|
||||
return WorkOrderStats(
|
||||
pending: json['pending'] as int,
|
||||
processing: json['processing'] as int,
|
||||
pendingAcceptance: json['pendingAcceptance'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'pending': pending,
|
||||
'processing': processing,
|
||||
'pendingAcceptance': pendingAcceptance,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [pending, processing, pendingAcceptance];
|
||||
}
|
||||
|
||||
class PowerTrendPoint extends Equatable {
|
||||
final String time;
|
||||
final double power;
|
||||
|
||||
const PowerTrendPoint({
|
||||
required this.time,
|
||||
required this.power,
|
||||
});
|
||||
|
||||
factory PowerTrendPoint.fromJson(Map<String, dynamic> json) {
|
||||
return PowerTrendPoint(
|
||||
time: json['time'] as String,
|
||||
power: (json['power'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'time': time,
|
||||
'power': power,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [time, power];
|
||||
}
|
||||
|
||||
class PlantOverview extends Equatable {
|
||||
final double installedCapacity;
|
||||
final String commissionDate;
|
||||
final String backgroundImage;
|
||||
|
||||
const PlantOverview({
|
||||
required this.installedCapacity,
|
||||
required this.commissionDate,
|
||||
this.backgroundImage = 'assets/images/carousel1.png',
|
||||
});
|
||||
|
||||
factory PlantOverview.fromJson(Map<String, dynamic> json) {
|
||||
return PlantOverview(
|
||||
installedCapacity: (json['installedCapacity'] as num).toDouble(),
|
||||
commissionDate: json['commissionDate'] as String,
|
||||
backgroundImage: json['backgroundImage'] as String? ?? 'assets/images/carousel1.png',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'installedCapacity': installedCapacity,
|
||||
'commissionDate': commissionDate,
|
||||
'backgroundImage': backgroundImage,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [installedCapacity, commissionDate, backgroundImage];
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/home_entity.dart';
|
||||
|
||||
abstract class HomeRepository {
|
||||
Future<Either<Failure, HomeEntity>> getHomeData();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/domain/usecases/base_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/home_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/domain/repositories/home_repository.dart';
|
||||
|
||||
class GetHomeDataUseCase implements BaseUseCase<HomeEntity, NoParams> {
|
||||
final HomeRepository repository;
|
||||
|
||||
GetHomeDataUseCase(this.repository);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, HomeEntity>> call(NoParams params) async {
|
||||
try {
|
||||
return await repository.getHomeData();
|
||||
} catch (e) {
|
||||
return Left(Failure('获取首页数据失败:$e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NoParams {
|
||||
const NoParams();
|
||||
}
|
||||
Reference in New Issue
Block a user