import 'dart:convert'; import 'dart:io'; import 'package:EasyDartModule/EasyDartModule.dart'; import 'package:EasyDartModule/base/logger/Logger.dart'; import 'package:EasyDartModule/base/redis/redis.dart'; import 'package:EasyDartModule/base/websocket/WebSocket.dart'; import './controller/AreaController.dart'; import './controller/BedController.dart'; import './controller/BedTypeController.dart'; import './controller/DiseaseTypeController.dart'; import './controller/PersonController.dart'; import './controller/PersonTypeController.dart'; import './controller/RoomController.dart'; import './controller/RoomTypeController.dart'; // import './controller/StatisticsController.dart'; // import './service/AlarmRuleService.dart'; import './controller/FileUploadController.dart'; import 'const/ServiceConstant.dart'; // import 'service/DailyTaskService.dart'; import './const/CommonVariables.dart'; void main(List args) async { initEasyDartModule(); } Future initEasyDartModule() async { try { String? web = Platform.environment["web_port"] ?? "9200"; List redis = (Platform.environment["redis"] ?? "127.0.0.1:6379").split(":"); if (redis.length == 1) { redis.add("6379"); } EasyDartModule.init( loggerConfig: LoggerConfig( host: ServiceConstant.logService, serviceName: "快检报告服务"), redisConfig: RedisConfig(host: redis[0], port: int.parse(redis[1])), webSocketConfig: WebSocketConfig(ServiceConstant.webSocketService, (data) { // 接收到服务消息 var json = jsonDecode(data); // ef.log("[websokcet]:${json}"); EasyDartModule.logger.info("[websokcet数据]:${json}"); if (json['wsId'] != null) { // ef.kvRoot.websocketId = json['wsId']; } if (json['code'] != null && json['code'] != 200) { EasyDartModule.logger .error("[websokcet数据]:websocket连接失败--》" + json['msg']); } if (json["path"] != null) { var call = CommonVariables.callMap[json["path"]]; if (call != null) { try { if (json['path'] != "/smartbed/connect") { call(json["data"]); } else { call(json); } } catch (e) { print(e); } } else { print("未找到当前路径: ${json["path"]} 回调函数"); EasyDartModule.logger.error("未找到当前路径: ${json["path"]} 回调函数"); } } // print(data); }, onOpen: () { // 连接建立完毕 // EasyDartModule.websocket // .sendData(jsonEncode({"path": "/aa/bb", "type": 1})); print("object"); })); while (!EasyDartModule.redis.isConnected()) { await Future.delayed(Duration(seconds: 1)); } EasyDartModule.webServer.addHandler(RoomController()); EasyDartModule.webServer.addHandler(RoomTypeController()); EasyDartModule.webServer.addHandler(BedTypeController()); EasyDartModule.webServer.addHandler(BedController()); EasyDartModule.webServer.addHandler(DiseaseTypeController()); EasyDartModule.webServer.addHandler(PersonController()); EasyDartModule.webServer.addHandler(PersonTypeController()); // EasyDartModule.webServer.addHandler(StatisticsController()); EasyDartModule.webServer.addHandler(AreaController()); EasyDartModule.webServer.addHandler(FileUploadController()); EasyDartModule.webServer.start( int.parse(web), ); } catch (e) { print(e); EasyDartModule.logger.error("websocket连接失败--》:$e"); } }