| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- import 'package:http/http.dart' as http;
- import 'dart:convert';
- import '../models/monitor_data_model.dart';
- import '../models/alert_model.dart';
- import '../models/dispatch_model.dart';
- import '../models/quality_model.dart';
-
- /// 供水管理服务层
- class WaterService {
- static const String _baseUrl = 'http://git.xayunmei.com/api/v1';
- static const String _token = 'bot_dev1:yunmei126';
-
- /// 获取监测数据
- static Future<List<MonitorDataModel>> getMonitorData() async {
- try {
- // 模拟 API 调用,返回模拟数据
- await Future.delayed(const Duration(milliseconds: 300));
-
- final stations = [
- ('城东加压站', 'ST-001'),
- ('城西水厂', 'ST-002'),
- ('南区配水站', 'ST-003'),
- ('北区调蓄池', 'ST-004'),
- ('中心泵站', 'ST-005'),
- ('开发区监测点', 'ST-006'),
- ('高新区水厂', 'ST-007'),
- ('工业园加压站', 'ST-008'),
- ];
-
- return stations.map((station) {
- return MonitorDataModel(
- id: station.$2,
- stationName: station.$1,
- stationCode: station.$2,
- pressure: 0.2 + (station.$2.hashCode % 30) / 100.0,
- flow: 100 + (station.$2.hashCode % 500).toDouble(),
- quality: 95 + (station.$2.hashCode % 5).toDouble(),
- status: station.$2.hashCode % 7 == 0 ? 'warning' : 'normal',
- updateTime: DateTime.now().subtract(
- Duration(minutes: station.$2.hashCode % 60),
- ),
- );
- }).toList();
- } catch (e) {
- throw Exception('获取监测数据失败: $e');
- }
- }
-
- /// 获取报警数据
- static Future<List<AlertModel>> getAlertData() async {
- try {
- // 模拟 API 调用,返回模拟数据
- await Future.delayed(const Duration(milliseconds: 300));
-
- return [
- AlertModel(
- id: 'AL-001',
- title: '城东加压站压力异常',
- level: 'critical',
- station: '城东加压站',
- content: '水压达到 3.2 MPa,超过警戒值',
- time: '2026-06-17 08:30',
- isRead: false,
- ),
- AlertModel(
- id: 'AL-002',
- title: '城西水厂流量下降',
- level: 'warning',
- station: '城西水厂',
- content: '流量从 450 m³/h 降至 280 m³/h',
- time: '2026-06-17 09:15',
- isRead: false,
- ),
- AlertModel(
- id: 'AL-003',
- title: '南区配水站水质异常',
- level: 'error',
- station: '南区配水站',
- content: '浊度指标超标,需立即处理',
- time: '2026-06-17 10:20',
- isRead: true,
- ),
- AlertModel(
- id: 'AL-004',
- title: '中心泵站设备维护',
- level: 'info',
- station: '中心泵站',
- content: '计划性维护,预计停机 2 小时',
- time: '2026-06-17 11:00',
- isRead: true,
- ),
- AlertModel(
- id: 'AL-005',
- title: '高新区水厂水质恢复',
- level: 'normal',
- station: '高新区水厂',
- content: '水质指标恢复正常,告警已解除',
- time: '2026-06-16 15:45',
- isRead: true,
- ),
- AlertModel(
- id: 'AL-006',
- title: '工业园加压站供电异常',
- level: 'critical',
- station: '工业园加压站',
- content: '备用电源已启动,需尽快恢复主供电',
- time: '2026-06-17 12:10',
- isRead: false,
- ),
- ];
- } catch (e) {
- throw Exception('获取报警数据失败: $e');
- }
- }
-
- /// 获取调度数据
- static Future<DispatchModel> getDispatchData() async {
- try {
- // 模拟 API 调用,返回模拟数据
- await Future.delayed(const Duration(milliseconds: 300));
-
- return DispatchModel(
- shiftOverview: [
- ShiftInfo(
- shiftName: '早班 (06:00-14:00)',
- status: '3/4 在岗',
- color: Colors.green,
- ),
- ShiftInfo(
- shiftName: '中班 (14:00-22:00)',
- status: '2/3 在岗',
- color: Colors.orange,
- ),
- ShiftInfo(
- shiftName: '夜班 (22:00-06:00)',
- status: '2/3 在岗',
- color: Colors.blue,
- ),
- ],
- dutyPersonnel: [
- PersonnelInfo(
- name: '张明',
- role: '值班长',
- station: '城东加压站',
- status: '在岗',
- phone: '138****1234',
- ),
- PersonnelInfo(
- name: '李强',
- role: '技术员',
- station: '城西水厂',
- status: '在岗',
- phone: '139****5678',
- ),
- PersonnelInfo(
- name: '王芳',
- role: '操作员',
- station: '南区配水站',
- status: '休息',
- phone: '137****9012',
- ),
- PersonnelInfo(
- name: '赵刚',
- role: '安全员',
- station: '北区调蓄池',
- status: '在岗',
- phone: '136****3456',
- ),
- PersonnelInfo(
- name: '刘洋',
- role: '技术员',
- station: '中心泵站',
- status: '在岗',
- phone: '135****7890',
- ),
- ],
- dispatchCommands: [
- CommandInfo(
- id: 'CMD-001',
- type: '设备启停',
- target: '城东加压站 #2泵',
- status: '执行中',
- operator: '张明',
- time: '08:30',
- ),
- CommandInfo(
- id: 'CMD-002',
- type: '参数调整',
- target: '城西水厂出水压力',
- status: '已完成',
- operator: '李强',
- time: '09:15',
- ),
- CommandInfo(
- id: 'CMD-003',
- type: '故障处理',
- target: '北区调蓄池传感器',
- status: '待处理',
- operator: '赵刚',
- time: '10:20',
- ),
- ],
- emergencyContacts: [
- ContactInfo(
- name: '应急指挥中心',
- phone: '119',
- type: '消防',
- ),
- ContactInfo(
- name: '抢修热线',
- phone: '96116',
- type: '抢修',
- ),
- ContactInfo(
- name: '技术支持',
- phone: '400-123-4567',
- type: '技术',
- ),
- ContactInfo(
- name: '环保举报',
- phone: '12369',
- type: '环保',
- ),
- ],
- );
- } catch (e) {
- throw Exception('获取调度数据失败: $e');
- }
- }
-
- /// 获取水质数据
- static Future<QualityModel> getQualityData() async {
- try {
- // 模拟 API 调用,返回模拟数据
- await Future.delayed(const Duration(milliseconds: 300));
-
- return QualityModel(
- rawWater: WaterQualityInfo(
- overallRating: '87.5%',
- monitorCount: 8,
- abnormalCount: 1,
- sources: [
- WaterSourceInfo(
- name: '长江取水口',
- location: '城东',
- quality: '良好',
- updateTime: '2026-06-17 08:30',
- indicators: {
- '浊度': '2.3 NTU',
- 'pH值': '7.2',
- '溶解氧': '6.8 mg/L',
- '氨氮': '0.15 mg/L',
- },
- ),
- WaterSourceInfo(
- name: '汉江取水口',
- location: '城西',
- quality: '合格',
- updateTime: '2026-06-17 08:45',
- indicators: {
- '浊度': '5.1 NTU',
- 'pH值': '7.1',
- '溶解氧': '6.5 mg/L',
- '氨氮': '0.22 mg/L',
- },
- ),
- WaterSourceInfo(
- name: '东湖取水口',
- location: '城南',
- quality: '异常',
- updateTime: '2026-06-17 09:15',
- indicators: {
- '浊度': '15.2 NTU',
- 'pH值': '6.8',
- '溶解氧': '5.2 mg/L',
- '氨氮': '0.45 mg/L',
- },
- ),
- ],
- ),
- treatedWater: TreatedWaterInfo(
- 合格率: '98.5%',
- monitorCount: 24,
- excellentRate: '85.2%',
- plants: [
- PlantInfo(
- name: '城东水厂',
- capacity: '50万吨/日',
- efficiency: '95%',
- quality: '优良',
- ),
- PlantInfo(
- name: '城西水厂',
- capacity: '30万吨/日',
- efficiency: '92%',
- quality: '良好',
- ),
- PlantInfo(
- name: '南区水厂',
- capacity: '20万吨/日',
- efficiency: '88%',
- quality: '良好',
- ),
- ],
- ),
- tapWater: TapWaterInfo(
- 合格率: '97.2%',
- monitorCount: 12,
- distributionPoints: [
- DistributionPointInfo(
- name: '中心广场',
- address: '中山路123号',
- quality: '优良',
- pressure: '0.35 MPa',
- updateTime: '2026-06-17 10:30',
- ),
- DistributionPointInfo(
- name: '东区居民区',
- address: '幸福路456号',
- quality: '良好',
- pressure: '0.28 MPa',
- updateTime: '2026-06-17 10:25',
- ),
- DistributionPointInfo(
- name: '西区商业区',
- address: '解放路789号',
- quality: '良好',
- pressure: '0.32 MPa',
- updateTime: '2026-06-17 10:20',
- ),
- ],
- ),
- );
- } catch (e) {
- throw Exception('获取水质数据失败: $e');
- }
- }
-
- /// 标记报警为已读
- static Future<void> markAlertAsRead(String alertId) async {
- try {
- // 模拟 API 调用
- await Future.delayed(const Duration(milliseconds: 200));
- // 实际项目中这里会调用后端 API
- } catch (e) {
- throw Exception('标记报警已读失败: $e');
- }
- }
-
- /// 刷新数据
- static Future<void> refreshData() async {
- try {
- // 模拟 API 调用
- await Future.delayed(const Duration(milliseconds: 500));
- } catch (e) {
- throw Exception('刷新数据失败: $e');
- }
- }
- }
-
- /// 报警模型
- class AlertModel {
- final String id;
- final String title;
- final String level;
- final String station;
- final String content;
- final String time;
- bool isRead;
-
- AlertModel({
- required this.id,
- required this.title,
- required this.level,
- required this.station,
- required this.content,
- required this.time,
- this.isRead = false,
- });
-
- factory AlertModel.fromJson(Map<String, dynamic> json) {
- return AlertModel(
- id: json['id']?.toString() ?? '',
- title: json['title'] ?? '',
- level: json['level'] ?? 'info',
- station: json['station'] ?? '',
- content: json['content'] ?? '',
- time: json['time'] ?? '',
- isRead: json['isRead'] ?? false,
- );
- }
-
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'title': title,
- 'level': level,
- 'station': station,
- 'content': content,
- 'time': time,
- 'isRead': isRead,
- };
- }
- }
-
- /// 调度模型
- class DispatchModel {
- final List<ShiftInfo> shiftOverview;
- final List<PersonnelInfo> dutyPersonnel;
- final List<CommandInfo> dispatchCommands;
- final List<ContactInfo> emergencyContacts;
-
- DispatchModel({
- required this.shiftOverview,
- required this.dutyPersonnel,
- required this.dispatchCommands,
- required this.emergencyContacts,
- });
- }
-
- /// 班次信息
- class ShiftInfo {
- final String shiftName;
- final String status;
- final Color color;
-
- ShiftInfo({
- required this.shiftName,
- required this.status,
- required this.color,
- });
- }
-
- /// 人员信息
- class PersonnelInfo {
- final String name;
- final String role;
- final String station;
- final String status;
- final String phone;
-
- PersonnelInfo({
- required this.name,
- required this.role,
- required this.station,
- required this.status,
- required this.phone,
- });
- }
-
- /// 指令信息
- class CommandInfo {
- final String id;
- final String type;
- final String target;
- final String status;
- final String operator;
- final String time;
-
- CommandInfo({
- required this.id,
- required this.type,
- required this.target,
- required this.status,
- required this.operator,
- required this.time,
- });
- }
-
- /// 联系人信息
- class ContactInfo {
- final String name;
- final String phone;
- final String type;
-
- ContactInfo({
- required this.name,
- required this.phone,
- required this.type,
- });
- }
-
- /// 水质模型
- class QualityModel {
- final RawWaterInfo rawWater;
- final TreatedWaterInfo treatedWater;
- final TapWaterInfo tapWater;
-
- QualityModel({
- required this.rawWater,
- required this.treatedWater,
- required this.tapWater,
- });
- }
-
- /// 原水信息
- class RawWaterInfo {
- final String overallRating;
- final int monitorCount;
- final int abnormalCount;
- final List<WaterSourceInfo> sources;
-
- RawWaterInfo({
- required this.overallRating,
- required this.monitorCount,
- required this.abnormalCount,
- required this.sources,
- });
- }
-
- /// 水源信息
- class WaterSourceInfo {
- final String name;
- final String location;
- final String quality;
- final String updateTime;
- final Map<String, String> indicators;
-
- WaterSourceInfo({
- required this.name,
- required this.location,
- required this.quality,
- required this.updateTime,
- required this.indicators,
- });
- }
-
- /// 出厂水信息
- class TreatedWaterInfo {
- final String 合格率;
- final int monitorCount;
- final String excellentRate;
- final List<PlantInfo> plants;
-
- TreatedWaterInfo({
- required this.合格率,
- required this.monitorCount,
- required this.excellentRate,
- required this.plants,
- });
- }
-
- /// 水厂信息
- class PlantInfo {
- final String name;
- final String capacity;
- final String efficiency;
- final String quality;
-
- PlantInfo({
- required this.name,
- required this.capacity,
- required this.efficiency,
- required this.quality,
- });
- }
-
- /// 末梢水信息
- class TapWaterInfo {
- final String 合格率;
- final int monitorCount;
- final List<DistributionPointInfo> distributionPoints;
-
- TapWaterInfo({
- required this.合格率,
- required this.monitorCount,
- required this.distributionPoints,
- });
- }
-
- /// 供水点信息
- class DistributionPointInfo {
- final String name;
- final String address;
- final String quality;
- final String pressure;
- final String updateTime;
-
- DistributionPointInfo({
- required this.name,
- required this.address,
- required this.quality,
- required this.pressure,
- required this.updateTime,
- });
- }
|