智慧水务管理系统 - 精河县供水工程综合管理平台

water_service.dart 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. import 'package:http/http.dart' as http;
  2. import 'dart:convert';
  3. import '../models/monitor_data_model.dart';
  4. import '../models/alert_model.dart';
  5. import '../models/dispatch_model.dart';
  6. import '../models/quality_model.dart';
  7. /// 供水管理服务层
  8. class WaterService {
  9. static const String _baseUrl = 'http://git.xayunmei.com/api/v1';
  10. static const String _token = 'bot_dev1:yunmei126';
  11. /// 获取监测数据
  12. static Future<List<MonitorDataModel>> getMonitorData() async {
  13. try {
  14. // 模拟 API 调用,返回模拟数据
  15. await Future.delayed(const Duration(milliseconds: 300));
  16. final stations = [
  17. ('城东加压站', 'ST-001'),
  18. ('城西水厂', 'ST-002'),
  19. ('南区配水站', 'ST-003'),
  20. ('北区调蓄池', 'ST-004'),
  21. ('中心泵站', 'ST-005'),
  22. ('开发区监测点', 'ST-006'),
  23. ('高新区水厂', 'ST-007'),
  24. ('工业园加压站', 'ST-008'),
  25. ];
  26. return stations.map((station) {
  27. return MonitorDataModel(
  28. id: station.$2,
  29. stationName: station.$1,
  30. stationCode: station.$2,
  31. pressure: 0.2 + (station.$2.hashCode % 30) / 100.0,
  32. flow: 100 + (station.$2.hashCode % 500).toDouble(),
  33. quality: 95 + (station.$2.hashCode % 5).toDouble(),
  34. status: station.$2.hashCode % 7 == 0 ? 'warning' : 'normal',
  35. updateTime: DateTime.now().subtract(
  36. Duration(minutes: station.$2.hashCode % 60),
  37. ),
  38. );
  39. }).toList();
  40. } catch (e) {
  41. throw Exception('获取监测数据失败: $e');
  42. }
  43. }
  44. /// 获取报警数据
  45. static Future<List<AlertModel>> getAlertData() async {
  46. try {
  47. // 模拟 API 调用,返回模拟数据
  48. await Future.delayed(const Duration(milliseconds: 300));
  49. return [
  50. AlertModel(
  51. id: 'AL-001',
  52. title: '城东加压站压力异常',
  53. level: 'critical',
  54. station: '城东加压站',
  55. content: '水压达到 3.2 MPa,超过警戒值',
  56. time: '2026-06-17 08:30',
  57. isRead: false,
  58. ),
  59. AlertModel(
  60. id: 'AL-002',
  61. title: '城西水厂流量下降',
  62. level: 'warning',
  63. station: '城西水厂',
  64. content: '流量从 450 m³/h 降至 280 m³/h',
  65. time: '2026-06-17 09:15',
  66. isRead: false,
  67. ),
  68. AlertModel(
  69. id: 'AL-003',
  70. title: '南区配水站水质异常',
  71. level: 'error',
  72. station: '南区配水站',
  73. content: '浊度指标超标,需立即处理',
  74. time: '2026-06-17 10:20',
  75. isRead: true,
  76. ),
  77. AlertModel(
  78. id: 'AL-004',
  79. title: '中心泵站设备维护',
  80. level: 'info',
  81. station: '中心泵站',
  82. content: '计划性维护,预计停机 2 小时',
  83. time: '2026-06-17 11:00',
  84. isRead: true,
  85. ),
  86. AlertModel(
  87. id: 'AL-005',
  88. title: '高新区水厂水质恢复',
  89. level: 'normal',
  90. station: '高新区水厂',
  91. content: '水质指标恢复正常,告警已解除',
  92. time: '2026-06-16 15:45',
  93. isRead: true,
  94. ),
  95. AlertModel(
  96. id: 'AL-006',
  97. title: '工业园加压站供电异常',
  98. level: 'critical',
  99. station: '工业园加压站',
  100. content: '备用电源已启动,需尽快恢复主供电',
  101. time: '2026-06-17 12:10',
  102. isRead: false,
  103. ),
  104. ];
  105. } catch (e) {
  106. throw Exception('获取报警数据失败: $e');
  107. }
  108. }
  109. /// 获取调度数据
  110. static Future<DispatchModel> getDispatchData() async {
  111. try {
  112. // 模拟 API 调用,返回模拟数据
  113. await Future.delayed(const Duration(milliseconds: 300));
  114. return DispatchModel(
  115. shiftOverview: [
  116. ShiftInfo(
  117. shiftName: '早班 (06:00-14:00)',
  118. status: '3/4 在岗',
  119. color: Colors.green,
  120. ),
  121. ShiftInfo(
  122. shiftName: '中班 (14:00-22:00)',
  123. status: '2/3 在岗',
  124. color: Colors.orange,
  125. ),
  126. ShiftInfo(
  127. shiftName: '夜班 (22:00-06:00)',
  128. status: '2/3 在岗',
  129. color: Colors.blue,
  130. ),
  131. ],
  132. dutyPersonnel: [
  133. PersonnelInfo(
  134. name: '张明',
  135. role: '值班长',
  136. station: '城东加压站',
  137. status: '在岗',
  138. phone: '138****1234',
  139. ),
  140. PersonnelInfo(
  141. name: '李强',
  142. role: '技术员',
  143. station: '城西水厂',
  144. status: '在岗',
  145. phone: '139****5678',
  146. ),
  147. PersonnelInfo(
  148. name: '王芳',
  149. role: '操作员',
  150. station: '南区配水站',
  151. status: '休息',
  152. phone: '137****9012',
  153. ),
  154. PersonnelInfo(
  155. name: '赵刚',
  156. role: '安全员',
  157. station: '北区调蓄池',
  158. status: '在岗',
  159. phone: '136****3456',
  160. ),
  161. PersonnelInfo(
  162. name: '刘洋',
  163. role: '技术员',
  164. station: '中心泵站',
  165. status: '在岗',
  166. phone: '135****7890',
  167. ),
  168. ],
  169. dispatchCommands: [
  170. CommandInfo(
  171. id: 'CMD-001',
  172. type: '设备启停',
  173. target: '城东加压站 #2泵',
  174. status: '执行中',
  175. operator: '张明',
  176. time: '08:30',
  177. ),
  178. CommandInfo(
  179. id: 'CMD-002',
  180. type: '参数调整',
  181. target: '城西水厂出水压力',
  182. status: '已完成',
  183. operator: '李强',
  184. time: '09:15',
  185. ),
  186. CommandInfo(
  187. id: 'CMD-003',
  188. type: '故障处理',
  189. target: '北区调蓄池传感器',
  190. status: '待处理',
  191. operator: '赵刚',
  192. time: '10:20',
  193. ),
  194. ],
  195. emergencyContacts: [
  196. ContactInfo(
  197. name: '应急指挥中心',
  198. phone: '119',
  199. type: '消防',
  200. ),
  201. ContactInfo(
  202. name: '抢修热线',
  203. phone: '96116',
  204. type: '抢修',
  205. ),
  206. ContactInfo(
  207. name: '技术支持',
  208. phone: '400-123-4567',
  209. type: '技术',
  210. ),
  211. ContactInfo(
  212. name: '环保举报',
  213. phone: '12369',
  214. type: '环保',
  215. ),
  216. ],
  217. );
  218. } catch (e) {
  219. throw Exception('获取调度数据失败: $e');
  220. }
  221. }
  222. /// 获取水质数据
  223. static Future<QualityModel> getQualityData() async {
  224. try {
  225. // 模拟 API 调用,返回模拟数据
  226. await Future.delayed(const Duration(milliseconds: 300));
  227. return QualityModel(
  228. rawWater: WaterQualityInfo(
  229. overallRating: '87.5%',
  230. monitorCount: 8,
  231. abnormalCount: 1,
  232. sources: [
  233. WaterSourceInfo(
  234. name: '长江取水口',
  235. location: '城东',
  236. quality: '良好',
  237. updateTime: '2026-06-17 08:30',
  238. indicators: {
  239. '浊度': '2.3 NTU',
  240. 'pH值': '7.2',
  241. '溶解氧': '6.8 mg/L',
  242. '氨氮': '0.15 mg/L',
  243. },
  244. ),
  245. WaterSourceInfo(
  246. name: '汉江取水口',
  247. location: '城西',
  248. quality: '合格',
  249. updateTime: '2026-06-17 08:45',
  250. indicators: {
  251. '浊度': '5.1 NTU',
  252. 'pH值': '7.1',
  253. '溶解氧': '6.5 mg/L',
  254. '氨氮': '0.22 mg/L',
  255. },
  256. ),
  257. WaterSourceInfo(
  258. name: '东湖取水口',
  259. location: '城南',
  260. quality: '异常',
  261. updateTime: '2026-06-17 09:15',
  262. indicators: {
  263. '浊度': '15.2 NTU',
  264. 'pH值': '6.8',
  265. '溶解氧': '5.2 mg/L',
  266. '氨氮': '0.45 mg/L',
  267. },
  268. ),
  269. ],
  270. ),
  271. treatedWater: TreatedWaterInfo(
  272. 合格率: '98.5%',
  273. monitorCount: 24,
  274. excellentRate: '85.2%',
  275. plants: [
  276. PlantInfo(
  277. name: '城东水厂',
  278. capacity: '50万吨/日',
  279. efficiency: '95%',
  280. quality: '优良',
  281. ),
  282. PlantInfo(
  283. name: '城西水厂',
  284. capacity: '30万吨/日',
  285. efficiency: '92%',
  286. quality: '良好',
  287. ),
  288. PlantInfo(
  289. name: '南区水厂',
  290. capacity: '20万吨/日',
  291. efficiency: '88%',
  292. quality: '良好',
  293. ),
  294. ],
  295. ),
  296. tapWater: TapWaterInfo(
  297. 合格率: '97.2%',
  298. monitorCount: 12,
  299. distributionPoints: [
  300. DistributionPointInfo(
  301. name: '中心广场',
  302. address: '中山路123号',
  303. quality: '优良',
  304. pressure: '0.35 MPa',
  305. updateTime: '2026-06-17 10:30',
  306. ),
  307. DistributionPointInfo(
  308. name: '东区居民区',
  309. address: '幸福路456号',
  310. quality: '良好',
  311. pressure: '0.28 MPa',
  312. updateTime: '2026-06-17 10:25',
  313. ),
  314. DistributionPointInfo(
  315. name: '西区商业区',
  316. address: '解放路789号',
  317. quality: '良好',
  318. pressure: '0.32 MPa',
  319. updateTime: '2026-06-17 10:20',
  320. ),
  321. ],
  322. ),
  323. );
  324. } catch (e) {
  325. throw Exception('获取水质数据失败: $e');
  326. }
  327. }
  328. /// 标记报警为已读
  329. static Future<void> markAlertAsRead(String alertId) async {
  330. try {
  331. // 模拟 API 调用
  332. await Future.delayed(const Duration(milliseconds: 200));
  333. // 实际项目中这里会调用后端 API
  334. } catch (e) {
  335. throw Exception('标记报警已读失败: $e');
  336. }
  337. }
  338. /// 刷新数据
  339. static Future<void> refreshData() async {
  340. try {
  341. // 模拟 API 调用
  342. await Future.delayed(const Duration(milliseconds: 500));
  343. } catch (e) {
  344. throw Exception('刷新数据失败: $e');
  345. }
  346. }
  347. }
  348. /// 报警模型
  349. class AlertModel {
  350. final String id;
  351. final String title;
  352. final String level;
  353. final String station;
  354. final String content;
  355. final String time;
  356. bool isRead;
  357. AlertModel({
  358. required this.id,
  359. required this.title,
  360. required this.level,
  361. required this.station,
  362. required this.content,
  363. required this.time,
  364. this.isRead = false,
  365. });
  366. factory AlertModel.fromJson(Map<String, dynamic> json) {
  367. return AlertModel(
  368. id: json['id']?.toString() ?? '',
  369. title: json['title'] ?? '',
  370. level: json['level'] ?? 'info',
  371. station: json['station'] ?? '',
  372. content: json['content'] ?? '',
  373. time: json['time'] ?? '',
  374. isRead: json['isRead'] ?? false,
  375. );
  376. }
  377. Map<String, dynamic> toJson() {
  378. return {
  379. 'id': id,
  380. 'title': title,
  381. 'level': level,
  382. 'station': station,
  383. 'content': content,
  384. 'time': time,
  385. 'isRead': isRead,
  386. };
  387. }
  388. }
  389. /// 调度模型
  390. class DispatchModel {
  391. final List<ShiftInfo> shiftOverview;
  392. final List<PersonnelInfo> dutyPersonnel;
  393. final List<CommandInfo> dispatchCommands;
  394. final List<ContactInfo> emergencyContacts;
  395. DispatchModel({
  396. required this.shiftOverview,
  397. required this.dutyPersonnel,
  398. required this.dispatchCommands,
  399. required this.emergencyContacts,
  400. });
  401. }
  402. /// 班次信息
  403. class ShiftInfo {
  404. final String shiftName;
  405. final String status;
  406. final Color color;
  407. ShiftInfo({
  408. required this.shiftName,
  409. required this.status,
  410. required this.color,
  411. });
  412. }
  413. /// 人员信息
  414. class PersonnelInfo {
  415. final String name;
  416. final String role;
  417. final String station;
  418. final String status;
  419. final String phone;
  420. PersonnelInfo({
  421. required this.name,
  422. required this.role,
  423. required this.station,
  424. required this.status,
  425. required this.phone,
  426. });
  427. }
  428. /// 指令信息
  429. class CommandInfo {
  430. final String id;
  431. final String type;
  432. final String target;
  433. final String status;
  434. final String operator;
  435. final String time;
  436. CommandInfo({
  437. required this.id,
  438. required this.type,
  439. required this.target,
  440. required this.status,
  441. required this.operator,
  442. required this.time,
  443. });
  444. }
  445. /// 联系人信息
  446. class ContactInfo {
  447. final String name;
  448. final String phone;
  449. final String type;
  450. ContactInfo({
  451. required this.name,
  452. required this.phone,
  453. required this.type,
  454. });
  455. }
  456. /// 水质模型
  457. class QualityModel {
  458. final RawWaterInfo rawWater;
  459. final TreatedWaterInfo treatedWater;
  460. final TapWaterInfo tapWater;
  461. QualityModel({
  462. required this.rawWater,
  463. required this.treatedWater,
  464. required this.tapWater,
  465. });
  466. }
  467. /// 原水信息
  468. class RawWaterInfo {
  469. final String overallRating;
  470. final int monitorCount;
  471. final int abnormalCount;
  472. final List<WaterSourceInfo> sources;
  473. RawWaterInfo({
  474. required this.overallRating,
  475. required this.monitorCount,
  476. required this.abnormalCount,
  477. required this.sources,
  478. });
  479. }
  480. /// 水源信息
  481. class WaterSourceInfo {
  482. final String name;
  483. final String location;
  484. final String quality;
  485. final String updateTime;
  486. final Map<String, String> indicators;
  487. WaterSourceInfo({
  488. required this.name,
  489. required this.location,
  490. required this.quality,
  491. required this.updateTime,
  492. required this.indicators,
  493. });
  494. }
  495. /// 出厂水信息
  496. class TreatedWaterInfo {
  497. final String 合格率;
  498. final int monitorCount;
  499. final String excellentRate;
  500. final List<PlantInfo> plants;
  501. TreatedWaterInfo({
  502. required this.合格率,
  503. required this.monitorCount,
  504. required this.excellentRate,
  505. required this.plants,
  506. });
  507. }
  508. /// 水厂信息
  509. class PlantInfo {
  510. final String name;
  511. final String capacity;
  512. final String efficiency;
  513. final String quality;
  514. PlantInfo({
  515. required this.name,
  516. required this.capacity,
  517. required this.efficiency,
  518. required this.quality,
  519. });
  520. }
  521. /// 末梢水信息
  522. class TapWaterInfo {
  523. final String 合格率;
  524. final int monitorCount;
  525. final List<DistributionPointInfo> distributionPoints;
  526. TapWaterInfo({
  527. required this.合格率,
  528. required this.monitorCount,
  529. required this.distributionPoints,
  530. });
  531. }
  532. /// 供水点信息
  533. class DistributionPointInfo {
  534. final String name;
  535. final String address;
  536. final String quality;
  537. final String pressure;
  538. final String updateTime;
  539. DistributionPointInfo({
  540. required this.name,
  541. required this.address,
  542. required this.quality,
  543. required this.pressure,
  544. required this.updateTime,
  545. });
  546. }