初始提交

This commit is contained in:
wyf
2026-01-20 09:26:55 +08:00
commit dd4447a029
106 changed files with 11690 additions and 0 deletions

9
.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
.dockerignore
Dockerfile
build/
.dart_tool/
.git/
.github/
.gitignore
.idea/
.packages

8
.flutter-plugins Normal file
View File

@@ -0,0 +1,8 @@
# This is a generated file; do not edit or check into version control.
file_picker=D:\\flutters\\hosted\\pub.flutter-io.cn\\file_picker-8.3.7\\
flutter_plugin_android_lifecycle=D:\\flutters\\hosted\\pub.flutter-io.cn\\flutter_plugin_android_lifecycle-2.0.26\\
path_provider=D:\\flutters\\hosted\\pub.flutter-io.cn\\path_provider-2.1.5\\
path_provider_android=D:\\flutters\\hosted\\pub.flutter-io.cn\\path_provider_android-2.2.15\\
path_provider_foundation=D:\\flutters\\hosted\\pub.flutter-io.cn\\path_provider_foundation-2.4.1\\
path_provider_linux=D:\\flutters\\hosted\\pub.flutter-io.cn\\path_provider_linux-2.2.1\\
path_provider_windows=D:\\flutters\\hosted\\pub.flutter-io.cn\\path_provider_windows-2.3.0\\

View File

@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\path_provider_foundation-2.4.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\flutter_plugin_android_lifecycle-2.0.26\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\path_provider_android-2.2.15\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\path_provider_foundation-2.4.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\path_provider_windows-2.3.0\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"file_picker","path":"D:\\\\flutters\\\\hosted\\\\pub.flutter-io.cn\\\\file_picker-8.3.7\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2026-01-17 10:13:16.955655","version":"3.24.4","swift_package_manager_enabled":false}

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

3
CHANGELOG.md Normal file
View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
# Use latest stable channel SDK.
FROM dart:3.5.4 AS build
LABEL qmqz=admin@ipayl.com
# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get
ADD bin /app/bin
RUN dart compile exe bin/main.dart -o bin/server
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/
CMD ["/app/bin/server"]

49
README.md Normal file
View File

@@ -0,0 +1,49 @@
A server app built using [Shelf](https://pub.dev/packages/shelf),
configured to enable running with [Docker](https://www.docker.com/).
This sample code handles HTTP GET requests to `/` and `/echo/<message>`
# Running the sample
## Running with the Dart SDK
You can run the example with the [Dart SDK](https://dart.dev/get-dart)
like this:
```
$ dart run bin/server.dart
Server listening on port 8080
```
And then from a second terminal:
```
$ curl http://0.0.0.0:8080
Hello, World!
$ curl http://0.0.0.0:8080/echo/I_love_Dart
I_love_Dart
```
## Running with Docker
If you have [Docker Desktop](https://www.docker.com/get-started) installed, you
can build and run with the `docker` command:
```
$ docker build . -t myserver
$ docker run -it -p 8080:8080 myserver
Server listening on port 8080
```
And then from a second terminal:
```
$ curl http://0.0.0.0:8080
Hello, World!
$ curl http://0.0.0.0:8080/echo/I_love_Dart
I_love_Dart
```
You should see the logging printed in the first terminal:
```
2021-05-06T15:47:04.620417 0:00:00.000158 GET [200] /
2021-05-06T15:47:08.392928 0:00:00.001216 GET [200] /echo/I_love_Dart
```

30
analysis_options.yaml Normal file
View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

118
bin/assets/algConfig.json Normal file
View File

@@ -0,0 +1,118 @@
[
{
"id": 1,
"name": "心率预警",
"level": 1,
"cond": [
{
"field": "heartRate",
"min": 50,
"max": 110
}
],
"startTime": "9:00",
"endTime": "9:00",
"triggerCount": 5,
"interval": 30,
"enable": true,
"type": 1,
"dataType": 1
},
{
"id": 2,
"name": "呼吸预警",
"level": 1,
"cond": [
{
"field": "breathRate",
"min": 7,
"max": 30
}
],
"startTime": "9:00",
"endTime": "9:00",
"triggerCount": 5,
"interval": 30,
"enable": true,
"type": 2,
"dataType": 1
}
,
{
"id": 3,
"name": "睡眠异常",
"level": 2,
"cond": [
{
"field": "sleepScore.score",
"min": 51
}
],
"startTime": "9:00",
"endTime": "9:00",
"triggerCount": 0,
"interval": 30,
"enable": true,
"type": 3,
"dataType": 2
}
,
{
"id": 4,
"name": "呼吸暂停",
"level": 1,
"cond": [
{
"field": "breathStat.typeList id=306=value",
"max": 3
}
],
"startTime": "18:00",
"endTime": "9:00",
"triggerCount": 0,
"interval": 30,
"enable": true,
"type": 2,
"dataType": 2
}
,
{
"id": 5,
"name": "离床过长",
"level": 2,
"cond": [
{
"field": "inBed",
"value": "离床"
}
],
"startTime": "9:00",
"endTime": "9:00",
"triggerCount": 600,
"interval": 30,
"enable": false,
"type": 5,
"dataType": 1
}
,
{
"id": 6,
"name": "心率骤停",
"level": 1,
"cond": [
{
"field": "heartRate",
"min": 1
}
],
"startTime": "9:00",
"endTime": "9:00",
"triggerCount": 60,
"interval": 30,
"enable": false,
"process": true,
"pd": [5,7,15],
"type": 5,
"dataType": 1
}
]

View File

@@ -0,0 +1,63 @@
class CommonVariables {
static bool isNetWorkOn = false;
static String supabaseUrl = "https://zhmht.swes.com.cn:3443";
// 企业微信客服拉起的url地址
// static String wxKfUrl = "https://work.weixin.qq.com/kfid/kfcab6a07e8aac68945";
static String wxKfUrl = "https://work.weixin.qq.com/kfid/kfc7d2337b9c07b1269";
// 企业微信ID
// static String wxCorpId = "wwc17348c75dbde1dc";
static String wxCorpId = "ww51feda6026280cd0";
//ICP备案号
static String ICPRightCode = "皖ICP备2024068219号-1A";
//公司名称
static String enterpriseName = "合肥眠花糖家具有限责任公司";
//备案时间
static String ICPTime = "2019-2029";
static String shoph5Url = "https://zhmht.swes.com.cn:1443";
static Map<String, Function(dynamic)> callMap = {};
static const String weather_apiKey =
'40e23445cf0a29561af2b5b7d506a38b'; // 替换为你的 API 密钥
static String shareText = "您的朋友邀请您使用《智慧眠花糖》APP请复制后面链接在浏览器中打开 " +
shoph5Url +
"/#/pages/download/download";
//容器圆角
static double filter_selector_border_radius = 50;
static double slider_container_border_radius = 10;
static double dialog_selector_border_radius = 6;
//列表数据(X秒内为刚刚数据)
static int recent_data_time = 60 * 5;
//表格间距
static int form_padding_small = 1;
static int form_padding_medium = 5;
static int form_padding_large = 8;
//内容容器最小高度百分比
static double text_height_small_percent = 0.036; //注释
static double text_height_medium_percent = 0.037; //正文
static double text_height_large_percent = 0.046; //标题/搜索栏
static double text_height_more_large_percent = 0.074; //菜单
static double icon_height_medium_percent = 0.014; //icon
static int default_page = 1;
static int default_limit_max = 999999;
static int default_limit = 10;
//下拉最大高度
static double dropdown_max_height = 200;
//详情弹窗左边字段显示宽度百分比
static double dialog_attribute_width_percent = 0.15;
static String default_gender = "1";
static bool default_vibrate = true;
static int default_weight = 65;
static int default_age = 30;
static String default_phone = "18612345678";
static int default_height = 170;
static String default_username = "眠眠";
}

9
bin/const/Constants.dart Normal file
View File

@@ -0,0 +1,9 @@
class Constants {
static const int port = 9200;
static const String serviceName = "vsbs_room";
static int default_page = 1;
static int default_limit_max = 999999;
static int default_limit = 10;
}

View File

@@ -0,0 +1,4 @@
class HttpStatusCode {
static const int ok = 200; // 请求成功,服务器已返回请求的数据。
static const int internalServerError = 500; // 服务器内部错误。
}

View File

@@ -0,0 +1,10 @@
class MessageConstants {
// 成功提示
static const String DELETE_ERROR = "删除失败,请联系管理员";
static const String UPDATE_ERROR = "更新失败,请联系管理员";
static const String ADD_ERROR = "添加失败,请联系管理员";
static const String ADD_SUCCESS = "添加成功";
static const String UPDATE_SUCCESS = "更新成功";
static const String DELETE_SUCCESS = "删除成功";
}

View File

@@ -0,0 +1,13 @@
enum MessageType {
instant_alarm("1", "实时体征消息"), // 实时体征消息
check_in("2", "入住消息"), // 入住消息
service("3", "服务消息"), // 服务消息
system("4", "系统消息"); // 系统消息
// 枚举的值
final String code; // 整数值
final String description; // 字符串描述
// 构造函数
const MessageType(this.code, this.description);
}

View File

@@ -0,0 +1,4 @@
class ResponseJsonCode {
static const int success = 200; // 操作成功
static const int fail = 400; // 操作失败
}

View File

@@ -0,0 +1,12 @@
enum RuzhuMessageType {
reservation("1", "预约消息"), // 预约消息
check_in("2", "入住消息"), // 入住消息
check_out("3", "退住消息"); // 退住消息
// 枚举的值
final String code; // 整数值
final String description; // 字符串描述
// 构造函数
const RuzhuMessageType(this.code, this.description);
}

View File

@@ -0,0 +1,37 @@
class ServiceConstant {
//基础地址
// static const String baseHost = "vsbs.he-info.cn";
static const String baseHost = "vsbst-api.he-info.cn";
static const String apibaseHost = "songxia.he-info.com";
//服务地址
static String service_address = "https://$apibaseHost";
static String web_service_address = "https://$baseHost";
static String app_server_service = "/wx/app/bizreport/app"; //服务名称
//服务名称及api
//房间类型
//房间
static const String room_service = "/vsbs_room";
static const String room_list = "/room/roomList"; //房间列表
static const String disease_range_data = "/statistics/disease";
//日志
static String logService = "$web_service_address/vsbs_log";
//websocket网关
static const String webSocketService = "wss://$baseHost/vsbs_ws_gateway/ws";
//数据中心
static String dataCenterService = "$service_address/vsbs_data_center";
static const String sleepReportData = "/api/sleep/data/list"; //睡眠报告数据
//机构数据
static String agency_service = "$service_address/vsbs_agency"; //机构服务
static const String agency_list = "/agency/allAgencyList"; //获取机构列表
//用户中心
static String userCenterService = "$service_address/vsbs_user_center";
//添加报警
static const String addMessage = "/api/message/info";
static const String message_service = "/vsbs_message_center";
static const String message_list = "/api/message/info"; //查询消息
set serviceAddress(String host) {
service_address = host;
}
}

View File

@@ -0,0 +1,241 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
import '../model/ApiResponse.dart';
import '../service/AreaService.dart';
part 'AreaController.route.dart';
@RequestMapping(path: "/report")
class AreaController {
final AreaService areaService = AreaService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
AreaController();
// 获取实时数据
@RequestMapping(path: "/getInstantData", method: HttpMethod.GET,auth: false)
Future<Response> getInstantData(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<List> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
String? mac = queryParameters['mac'];
String? openId = queryParameters['openId'];
if (mac == null || mac.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败设备mac不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
if (openId == null || openId.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败设备openId不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
Map result = await areaService.getInstantData(mac,openId);
if (result['flag'] == 1) {
// 成功
// apiResponse.code = ResponseJsonCode.success;
// apiResponse.message = result['msg'] ?? "查询成功";
// apiResponse.data = result['data'];
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result['msg'] ?? "查询成功";
// 2. 将 result['data'] 包装成 List<Map<String, dynamic>>
if (result['data'] != null) {
// result['data'] 是一个 Map包装成 List
Map<String, dynamic> dataMap =
Map<String, dynamic>.from(result['data']);
// 可以在这里添加一些额外字段(可选)
dataMap['responseTime'] = DateTime.now().millisecondsSinceEpoch;
// 将单个 Map 放入 List 中
apiResponse.data = [dataMap];
} else {
apiResponse.data = [];
}
} else {
// 失败
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result['msg'] ?? "查询失败";
apiResponse.data = null;
}
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e";
return Response(
HttpStatusCode.internalServerError,
body: apiResponse.serialize(),
);
}
}
// 开始体验设备
@RequestMapping(path: "/start", method: HttpMethod.POST,auth: false)
Future<Response> start(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
if (data == null || data.isEmpty || data['mac'] == null) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "请求失败设备mac不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
if (data == null || data.isEmpty || data['openId'] == null) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "请求失败设备openId不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
Map result = await areaService.startKuaijian(data);
if (result['flag'] == 1) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result['msg'] ?? MessageConstants.ADD_SUCCESS;
} else {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result['msg'] ?? "操作失败";
}
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e";
return Response(
HttpStatusCode.internalServerError,
body: apiResponse.serialize(),
);
}
}
// 结束体验设备
@RequestMapping(path: "/end", method: HttpMethod.POST,auth: false)
Future<Response> end(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
if (data == null || data.isEmpty || data['mac'] == null) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "请求失败设备mac不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
if (data == null || data.isEmpty || data['openId'] == null) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "请求失败设备openId不能为空";
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
}
Map result = await areaService.endKuaijian(data);
if (result['flag'] == 1) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result['msg'] ?? MessageConstants.ADD_SUCCESS;
} else {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result['msg'] ?? "操作失败";
}
return Response(
HttpStatusCode.ok,
body: apiResponse.serialize(),
);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e";
return Response(
HttpStatusCode.internalServerError,
body: apiResponse.serialize(),
);
}
}
// // 更新区域
// @RequestMapping(path: "/updateArea", method: HttpMethod.PUT)
// Future<Response> updateArea(Request request) async {
// ApiResponse<String> apiResponse = ApiResponse();
// try {
// var data = jsonDecode(await request.readAsString());
// var areaId = data['_id'];
// var updatedArea = Area.fromJson(data);
// if (updatedArea.id == null || updatedArea.id!.isEmpty) {
// apiResponse.code = ResponseJsonCode.fail;
// apiResponse.message = "区域ID不能为空";
// String serializedJson = apiResponse.serialize();
// return Response(HttpStatusCode.ok, body: serializedJson);
// }
// var result = await areaService.updateArea(areaId, updatedArea);
// apiResponse.code = 1;
// apiResponse.message = result;
// String serializedJson = apiResponse.serialize();
// return Response(200, body: serializedJson); // 发送成功响应
// } catch (e) {
// apiResponse.code = -1;
// apiResponse.message = "更新失败: $e"; // 包含异常信息
// String serializedJson = apiResponse.serialize();
// return Response(500, body: serializedJson); // 发送失败响应
// }
// }
// 删除区域
// @RequestMapping(path: "/deleteArea", method: HttpMethod.DELETE)
// Future<Response> deleteArea(Request request) async {
// ApiResponse<String> apiResponse = ApiResponse();
// try {
// var data = jsonDecode(await request.readAsString());
// var areaId = data['areaId'];
// var result = await areaService.deleteArea(areaId);
// apiResponse.code = 1;
// if (result.isEmpty) {
// apiResponse.code = ResponseJsonCode.success;
// apiResponse.message = MessageConstants.DELETE_SUCCESS;
// String serializedJson = apiResponse.serialize();
// return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
// }
// apiResponse.code = ResponseJsonCode.fail;
// apiResponse.message = result;
// String serializedJson = apiResponse.serialize();
// return Response(HttpStatusCode.ok, body: serializedJson);
// } catch (e) {
// apiResponse.code = -1;
// apiResponse.message = "删除失败: $e"; // 包含异常信息
// String serializedJson = apiResponse.serialize();
// return Response(500, body: serializedJson); // 发送失败响应
// }
// }
}

View File

@@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'AreaController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/report/getInstantData",
HttpResponseType.JSON,
_callHandler.getInstantData,
2,
false
]
],
HttpMethod.POST: [
["/report/start", HttpResponseType.JSON, _callHandler.start, 1, false],
["/report/end", HttpResponseType.JSON, _callHandler.end, 1, false]
],
};

View File

@@ -0,0 +1,181 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
import '../model/ApiResponse.dart';
import '../model/Bed.dart';
import '../service/BedService.dart';
import '../model/Reservation.dart';
part 'BedController.route.dart';
@RequestMapping(path: "/bed")
class BedController {
final BedService bedService = BedService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
BedController();
// 获取床位列表
@RequestMapping(path: "/bedList", method: HttpMethod.GET)
Future<Response> getBedList(Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
Bed query = Bed.fromQueryParameters(queryParameters,jwt);
List<dynamic> bedList = await bedService.getBedList(query);
int bedCount = await bedService.getBedCount(query);
List<Map<String, dynamic>> bedListMap =
bedList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = bedListMap;
apiResponse.total = bedCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 获取单个床位信息
/* @RequestMapping(path: "/getBed", method: HttpMethod.GET)
Future<Response> getBedById(Request request) async {
ApiResponse<Map<String, dynamic>> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedId = data['bed_id'];
if (bedId == null) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = '床位ID不能为空';
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送错误响应
}
var bed = await bedService.getBedById(bedId);
if (bed != null) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = bed.toJson();
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} else {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = '未找到床位';
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送未找到响应
}
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = '查询失败: $e';
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
} */
// 添加床位信息
@RequestMapping(path: "/addBed", method: HttpMethod.POST)
Future<Response> addBed(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bed = Bed.fromJson(data);
var result = await bedService.createBed(bed);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 更新床位信息
@RequestMapping(path: "/updateBed", method: HttpMethod.PUT)
Future<Response> updateBed(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedId = data['bed_id'];
var updatedBed = Bed.fromJson(data);
if (updatedBed.id == null || updatedBed.id!.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "床位ID不能为空";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
var result = await bedService.updateBed(bedId, updatedBed);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 删除床位信息
@RequestMapping(path: "/deleteBed", method: HttpMethod.DELETE)
Future<Response> deleteBed(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedId = data['bed_id'];
var result = await bedService.deleteBed(bedId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 查询预约信息
@RequestMapping(path: "/orderCheckIn", method: HttpMethod.GET)
Future<Response> orderCheckIn(Request request,Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
Reservation query = Reservation.fromQueryParameters(queryParameters,jwt);
List<dynamic> bedList = await bedService.getOrderCheckIn(query);
// int bedCount = await bedService.getBedCount(query);
List<Map<String, dynamic>> bedListMap =
bedList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = bedListMap;
// apiResponse.total = bedCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
}

View File

@@ -0,0 +1,30 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'BedController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
["/bed/bedList", HttpResponseType.JSON, _callHandler.getBedList, 2, true],
[
"/bed/orderCheckIn",
HttpResponseType.JSON,
_callHandler.orderCheckIn,
2,
true
]
],
HttpMethod.POST: [
["/bed/addBed", HttpResponseType.JSON, _callHandler.addBed, 1, true]
],
HttpMethod.PUT: [
["/bed/updateBed", HttpResponseType.JSON, _callHandler.updateBed, 1, true]
],
HttpMethod.DELETE: [
["/bed/deleteBed", HttpResponseType.JSON, _callHandler.deleteBed, 1, true]
],
};

View File

@@ -0,0 +1,121 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../model/BedType.dart';
import '../service/BedTypeService.dart';
import '../model/ApiResponse.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
part 'BedTypeController.route.dart';
@RequestMapping(path: "/bedType")
class BedTypeController {
final BedTypeService bedTypeService = BedTypeService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
BedTypeController();
// 获取床位类型列表
@RequestMapping(path: "/bedTypeList", method: HttpMethod.GET)
Future<Response> getBedTypeList(Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
BedType query = BedType.fromQueryParameters(queryParameters,jwt);
List<dynamic> bedTypeList = await bedTypeService.getBedTypeList(query);
int bedTypeCount = await bedTypeService.getBedTypeCount(query);
List<Map<String, dynamic>> bedTypeListMap =
bedTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = bedTypeListMap;
apiResponse.total = bedTypeCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加床位类型
@RequestMapping(path: "/addBedType", method: HttpMethod.POST)
Future<Response> addBedType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedType = BedType.fromJson(data);
var result = await bedTypeService.addBedType(bedType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 更新床位类型
@RequestMapping(path: "/updateBedType", method: HttpMethod.PUT)
Future<Response> updateBedType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedTypeId = data['bed_type_id'];
var updatedBedType = BedType.fromJson(data);
if (updatedBedType.id == null || updatedBedType.id!.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "床位类型ID不能为空";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
var result =
await bedTypeService.updateBedType(bedTypeId, updatedBedType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 删除床位类型
@RequestMapping(path: "/deleteBedType", method: HttpMethod.DELETE)
Future<Response> deleteBedType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var bedTypeId = data['bed_type_id'];
var result = await bedTypeService.deleteBedType(bedTypeId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'BedTypeController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/bedType/bedTypeList",
HttpResponseType.JSON,
_callHandler.getBedTypeList,
2,
true
]
],
HttpMethod.POST: [
[
"/bedType/addBedType",
HttpResponseType.JSON,
_callHandler.addBedType,
1,
true
]
],
HttpMethod.PUT: [
[
"/bedType/updateBedType",
HttpResponseType.JSON,
_callHandler.updateBedType,
1,
true
]
],
HttpMethod.DELETE: [
[
"/bedType/deleteBedType",
HttpResponseType.JSON,
_callHandler.deleteBedType,
1,
true
]
],
};

View File

@@ -0,0 +1,111 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../const/HttpStatusCode.dart';
import '../const/ResponseJsonCode.dart';
import '../model/ApiResponse.dart';
import '../model/DictionaryType.dart';
import '../service/DictionaryService.dart';
import '../const/MessageConstants.dart';
part 'DictionaryTypeController.route.dart';
@RequestMapping(path: "/dictionary")
class DictionaryTypeController {
final DictionaryService dictionaryService = DictionaryService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
DictionaryTypeController();
// 获取字典列表
@RequestMapping(path: "/list", method: HttpMethod.GET)
Future<Response> getDictionaryList(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
DictionaryType query =
DictionaryType.fromQueryParameters(queryParameters, jwt);
List<DictionaryType> dictionaryList =
await dictionaryService.getDictionaryList(query);
List<Map<String, dynamic>> dictionaryListMap =
dictionaryList.map((e) => e.toJson()).toList(); // 转换为 Map
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = dictionaryListMap;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加字典
@RequestMapping(path: "/add", method: HttpMethod.POST)
Future<Response> addDictionary(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var dictionary = DictionaryType.fromJson(data);
var result = await dictionaryService.addDictionary(dictionary);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 更新字典
@RequestMapping(path: "/update", method: HttpMethod.PUT)
Future<Response> updateDictionary(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var dictionaryId = data['_id'];
var updatedDictionary = DictionaryType.fromJson(data);
var result = await dictionaryService.updateDictionary(
dictionaryId, updatedDictionary);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 删除字典
@RequestMapping(path: "/delete", method: HttpMethod.DELETE)
Future<Response> deleteDictionary(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var dictionaryId = data['_id'];
var result = await dictionaryService.deleteDictionary(dictionaryId);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "删除失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'DictionaryTypeController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/dictionary/list",
HttpResponseType.JSON,
_callHandler.getDictionaryList,
2,
true
]
],
HttpMethod.POST: [
[
"/dictionary/add",
HttpResponseType.JSON,
_callHandler.addDictionary,
1,
true
]
],
HttpMethod.PUT: [
[
"/dictionary/update",
HttpResponseType.JSON,
_callHandler.updateDictionary,
1,
true
]
],
HttpMethod.DELETE: [
[
"/dictionary/delete",
HttpResponseType.JSON,
_callHandler.deleteDictionary,
1,
true
]
],
};

View File

@@ -0,0 +1,117 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../model/DiseaseType.dart';
import '../service/DiseaseTypeService.dart';
import '../model/ApiResponse.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
part 'DiseaseTypeController.route.dart';
@RequestMapping(path: "/diseaseType")
class DiseaseTypeController {
final DiseaseTypeService diseaseTypeService = DiseaseTypeService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
DiseaseTypeController();
// 获取疾病类型列表
@RequestMapping(path: "/diseaseTypeList", method: HttpMethod.GET)
Future<Response> getDiseaseTypeList(Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
DiseaseType query = DiseaseType.fromQueryParameters(queryParameters,jwt);
List<dynamic> diseaseTypeList = await diseaseTypeService.getDiseaseTypeList(query);
int diseaseTypeCount = await diseaseTypeService.getDiseaseTypeCount(query);
List<Map<String, dynamic>> diseaseTypeListMap =
diseaseTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = diseaseTypeListMap;
apiResponse.total = diseaseTypeCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加疾病类型
@RequestMapping(path: "/addDiseaseType", method: HttpMethod.POST)
Future<Response> addDiseaseType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var diseaseType = DiseaseType.fromJson(data);
var result = await diseaseTypeService.addDiseaseType(diseaseType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
}
}
// 更新疾病类型
@RequestMapping(path: "/updateDiseaseType", method: HttpMethod.PUT)
Future<Response> updateDiseaseType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var diseaseTypeId = data['_id'];
var updatedDiseaseType = DiseaseType.fromJson(data);
if (updatedDiseaseType.id == null || updatedDiseaseType.id!.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "疾病类型ID不能为空";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
var result = await diseaseTypeService.updateDiseaseType(diseaseTypeId, updatedDiseaseType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
}
}
// 删除疾病类型
@RequestMapping(path: "/deleteDiseaseType", method: HttpMethod.DELETE)
Future<Response> deleteDiseaseType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var diseaseTypeId = data['id'];
var result = await diseaseTypeService.deleteDiseaseType(diseaseTypeId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'DiseaseTypeController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/diseaseType/diseaseTypeList",
HttpResponseType.JSON,
_callHandler.getDiseaseTypeList,
2,
true
]
],
HttpMethod.POST: [
[
"/diseaseType/addDiseaseType",
HttpResponseType.JSON,
_callHandler.addDiseaseType,
1,
true
]
],
HttpMethod.PUT: [
[
"/diseaseType/updateDiseaseType",
HttpResponseType.JSON,
_callHandler.updateDiseaseType,
1,
true
]
],
HttpMethod.DELETE: [
[
"/diseaseType/deleteDiseaseType",
HttpResponseType.JSON,
_callHandler.deleteDiseaseType,
1,
true
]
],
};

View File

@@ -0,0 +1,98 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import 'package:intl/intl.dart';
import 'package:shelf_multipart/shelf_multipart.dart'; // 导入 shelf_multipart 插件
import '../const/HttpStatusCode.dart';
import '../const/ResponseJsonCode.dart';
import '../model/ApiResponse.dart';
part 'FileUploadController.route.dart';
@RequestMapping(path: "/file")
class FileUploadController {
FileUploadController();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
// 上传文件
@RequestMapping(path: "/upload", method: HttpMethod.POST)
Future<Response> uploadFile(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
request.formData();
try {
// 检查请求的 Content-Type 是否为 multipart/form-data
var contentType = request.headers['content-type'];
if (contentType == null ||
!contentType.startsWith('multipart/form-data')) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "请求格式必须是 multipart/form-data";
return Response(HttpStatusCode.internalServerError,
body: apiResponse.serialize());
}
if (request.formData() case var form?) {
String description = "上传成功";
String bucket = "";
String? fileExtension; // 文件后缀
var file;
await for (final formData in form.formData) {
if (formData.name == 'bucket') {
bucket = await formData.part.readString();
}
if (formData.name == 'file') {
final filename = formData.filename;
if (filename != null && filename.isNotEmpty) {
fileExtension = filename.split('.').last; // 提取文件后缀
}
file = await formData.part.readBytes();
}
}
if (bucket.isEmpty) {
description = "桶名不能为空";
}
if (file == null) {
description = "文件不能为空";
}
final String folderName =
DateFormat('yyyy-MM-dd').format(DateTime.now());
String objectName =
"$folderName/${DateTime.now().millisecondsSinceEpoch}.$fileExtension";
// 创建存储桶(如果不存在)
await EasyDartModule.storage.createBucket(bucket);
// 上传文件
var path =
await EasyDartModule.storage.uploadObject(bucket, objectName, file);
// EasyDartModule.storage.getObject(bucket, objectName).then((data) {
// print("下载文件");
// File("b.gif").writeAsBytesSync(data);
// print("下载完毕");
// });
return Response.ok(path);
} else if (request.multipart() case var multipart?) {
final description = StringBuffer('Regular multipart request\n');
await for (final part in multipart.parts) {
description.writeln('new part');
part.headers.forEach(
(key, value) => description.writeln('Header $key=$value'));
final content = await part.readString();
description.writeln('content: $content');
description.writeln('end of part');
}
return Response.ok(description.toString());
} else {
return Response.ok('Not a multipart request');
}
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "文件上传失败: $e";
return Response(HttpStatusCode.internalServerError,
body: apiResponse.serialize());
}
}
}

View File

@@ -0,0 +1,14 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'FileUploadController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.POST: [
["/file/upload", HttpResponseType.JSON, _callHandler.uploadFile, 1, true]
],
};

View File

@@ -0,0 +1,114 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
import '../model/ApiResponse.dart';
import '../model/Person.dart';
import '../service/PersonService.dart';
part 'PersonController.route.dart';
@RequestMapping(path: "/person")
class PersonController {
final PersonService personService = PersonService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
PersonController();
// 获取人员列表
@RequestMapping(path: "/personList", method: HttpMethod.GET)
Future<Response> getPersonList(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
Person query = Person.fromQueryParameters(queryParameters, jwt);
var personList = await personService.getPersonList(query);
int personCount = await personService.getPersonCount(query);
print(personList);
List<Map<String, dynamic>> personListMap =
personList.map((e) => e as Map<String, dynamic>).toList();
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = personListMap;
apiResponse.total = personCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加人员
@RequestMapping(path: "/addPerson", method: HttpMethod.POST)
Future<Response> addPerson(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var person = Person.fromJson(data);
var result = await personService.addPerson(person);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 更新人员信息
@RequestMapping(path: "/updatePerson", method: HttpMethod.PUT)
Future<Response> updatePerson(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var personId = data['_id'];
var updatedPerson = Person.fromJson(data);
var result = await personService.updatePerson(personId, updatedPerson);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 删除人员
@RequestMapping(path: "/deletePerson", method: HttpMethod.DELETE)
Future<Response> deletePerson(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var personId = data['_id'];
var result = await personService.deletePerson(personId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "删除失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'PersonController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/person/personList",
HttpResponseType.JSON,
_callHandler.getPersonList,
2,
true
]
],
HttpMethod.POST: [
[
"/person/addPerson",
HttpResponseType.JSON,
_callHandler.addPerson,
1,
true
]
],
HttpMethod.PUT: [
[
"/person/updatePerson",
HttpResponseType.JSON,
_callHandler.updatePerson,
1,
true
]
],
HttpMethod.DELETE: [
[
"/person/deletePerson",
HttpResponseType.JSON,
_callHandler.deletePerson,
1,
true
]
],
};

View File

@@ -0,0 +1,111 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../model/PersonType.dart';
import '../service/PersonTypeService.dart';
import '../model/ApiResponse.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
part 'PersonTypeController.route.dart';
@RequestMapping(path: "/personType")
class PersonTypeController {
final PersonTypeService personTypeService = PersonTypeService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
PersonTypeController();
// 获取人员类型列表
@RequestMapping(path: "/personTypeList", method: HttpMethod.GET)
Future<Response> getPersonTypeList(Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
PersonType query = PersonType.fromQueryParameters(queryParameters,jwt);
var personTypeList = await personTypeService.getPersonTypeList(query);
List<Map<String, dynamic>> personTypeListMap =
personTypeList.map((e) => e as Map<String, dynamic>).toList();
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = personTypeListMap;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加人员类型
@RequestMapping(path: "/addPersonType", method: HttpMethod.POST)
Future<Response> addPersonType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var personType = PersonType.fromJson(data);
var result = await personTypeService.addPersonType(personType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 更新人员类型
@RequestMapping(path: "/updatePersonType", method: HttpMethod.PUT)
Future<Response> updatePersonType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var personTypeId = data['person_type_id'];
var updatedPersonType = PersonType.fromJson(data);
var result = await personTypeService.updatePersonType(
personTypeId, updatedPersonType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.UPDATE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 删除人员类型
@RequestMapping(path: "/deletePersonType", method: HttpMethod.DELETE)
Future<Response> deletePersonType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var personTypeId = data['person_type_id'];
var result = await personTypeService.deletePersonType(personTypeId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "删除失败: $e";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'PersonTypeController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/personType/personTypeList",
HttpResponseType.JSON,
_callHandler.getPersonTypeList,
2,
true
]
],
HttpMethod.POST: [
[
"/personType/addPersonType",
HttpResponseType.JSON,
_callHandler.addPersonType,
1,
true
]
],
HttpMethod.PUT: [
[
"/personType/updatePersonType",
HttpResponseType.JSON,
_callHandler.updatePersonType,
1,
true
]
],
HttpMethod.DELETE: [
[
"/personType/deletePersonType",
HttpResponseType.JSON,
_callHandler.deletePersonType,
1,
true
]
],
};

View File

@@ -0,0 +1,235 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../model/Room.dart';
import '../service/RoomService.dart';
import '../model/ApiResponse.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
import '../const/HttpStatusCode.dart';
part 'RoomController.route.dart';
@RequestMapping(path: "/room")
class RoomController {
final RoomService roomService = RoomService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
RoomController();
// 获取房间列表
@RequestMapping(path: "/roomList", method: HttpMethod.GET)
Future<Response> getRoomList(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
Room query = Room.fromQueryParameters(queryParameters, jwt);
List<dynamic> roomList = await roomService.getRoomList(query,
page: queryParameters['page'] == null
? 1
: int.parse(queryParameters['page']!),
pageSize: queryParameters['limit'] == null
? 10
: int.parse(queryParameters['limit']!));
int roomTypeCount = await roomService.getRoomCount(query);
List<Map<String, dynamic>> roomListMap =
roomList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data = roomListMap;
apiResponse.total = roomTypeCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加房间
@RequestMapping(path: "/addRoom", method: HttpMethod.POST)
Future<Response> addRoom(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var room = Room.fromJson(data);
var result = await roomService.addRoom(room);
if (result == null || result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
// 更新房间
@RequestMapping(path: "/updateRoom", method: HttpMethod.PUT)
Future<Response> updateRoom(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var roomId = data['_id'];
var updatedRoom = Room.fromJson(data);
if (updatedRoom.id == null || updatedRoom.id!.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "房间类型ID不能为空";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
var result = await roomService.updateRoom(roomId, updatedRoom);
apiResponse.code = 1;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(200, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = -1;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
// 删除房间
@RequestMapping(path: "/deleteRoom", method: HttpMethod.DELETE)
Future<Response> deleteRoom(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var roomId = data['roomId'];
var result = await roomService.deleteRoom(roomId);
apiResponse.code = 1;
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = -1;
apiResponse.message = "删除失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
//办理预约信息
@RequestMapping(path: "/addOrderCheckIn", method: HttpMethod.POST)
Future<Response> addOrderCheckIn(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var result = await roomService.addOrderCheckIn(data,jwt);
if (result == null || result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
roomService.addReservationMessage(data, jwt);
return Response(HttpStatusCode.ok, body: serializedJson);
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
//删除预约入住信息
@RequestMapping(path: "/delOrderCheckIn", method: HttpMethod.POST)
Future<Response> delOrderCheckIn(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var result = await roomService.delOrderCheckIn(data);
if (result == null || result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
//办理入住信息
@RequestMapping(path: "/addRuzhuCheckIn", method: HttpMethod.POST)
Future<Response> addRuzhuCheckIn(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var result = await roomService.addRuzhuCheckIn(data, jwt);
if (result == null || result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
//办理退住信息
@RequestMapping(path: "/checkout", method: HttpMethod.POST)
Future<Response> checkout(
Request request, Map<String, dynamic> jwt) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var result = await roomService.checkout(data, jwt);
if (result == null || result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "添加失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(500, body: serializedJson); // 发送失败响应
}
}
}

View File

@@ -0,0 +1,57 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'RoomController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
["/room/roomList", HttpResponseType.JSON, _callHandler.getRoomList, 2, true]
],
HttpMethod.POST: [
["/room/addRoom", HttpResponseType.JSON, _callHandler.addRoom, 1, true],
[
"/room/addOrderCheckIn",
HttpResponseType.JSON,
_callHandler.addOrderCheckIn,
2,
true
],
[
"/room/delOrderCheckIn",
HttpResponseType.JSON,
_callHandler.delOrderCheckIn,
1,
true
],
[
"/room/addRuzhuCheckIn",
HttpResponseType.JSON,
_callHandler.addRuzhuCheckIn,
2,
true
],
["/room/checkout", HttpResponseType.JSON, _callHandler.checkout, 2, true]
],
HttpMethod.PUT: [
[
"/room/updateRoom",
HttpResponseType.JSON,
_callHandler.updateRoom,
1,
true
]
],
HttpMethod.DELETE: [
[
"/room/deleteRoom",
HttpResponseType.JSON,
_callHandler.deleteRoom,
1,
true
]
],
};

View File

@@ -0,0 +1,122 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/webserver/WebServer.dart';
import '../model/RoomType.dart';
import '../service/RoomTypeService.dart';
import '../model/ApiResponse.dart';
import '../const/HttpStatusCode.dart';
import '../const/MessageConstants.dart';
import '../const/ResponseJsonCode.dart';
part 'RoomTypeController.route.dart';
@RequestMapping(path: "/roomType")
class RoomTypeController {
final RoomTypeService roomTypeService = RoomTypeService();
set callHandler(handler) => _callHandler = handler;
Map<HttpMethod, List<List>> get routeMap => routes;
RoomTypeController();
// 获取房间类型列表
@RequestMapping(path: "/roomTypeList", method: HttpMethod.GET)
Future<Response> getRoomTypeList(Request request, Map<String, dynamic> jwt) async {
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
try {
var queryParameters = request.requestedUri.queryParameters;
RoomType query = RoomType.fromQueryParameters(queryParameters,jwt);
List<dynamic> roomTypeList = await roomTypeService.getRoomTypeList(query);
int roomTypeCount = await roomTypeService.getRoomTypeCount(query);
List<Map<String, dynamic>> roomTypeListMap =
roomTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
apiResponse.code = ResponseJsonCode.success;
apiResponse.data =
roomTypeListMap;
apiResponse.total = roomTypeCount;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "查询失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError, body: serializedJson);
}
}
// 添加房间类型
@RequestMapping(path: "/addRoomType", method: HttpMethod.POST)
Future<Response> addRoomType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var roomType = RoomType.fromJson(data);
var result = await roomTypeService.addRoomType(roomType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.ADD_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 更新房间类型
@RequestMapping(path: "/updateRoomType", method: HttpMethod.PUT)
Future<Response> updateRoomType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var roomTypeId = data['_id'];
var updatedRoomType = RoomType.fromJson(data);
if (updatedRoomType.id == null || updatedRoomType.id!.isEmpty) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "房间类型ID不能为空";
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
}
var result =
await roomTypeService.updateRoomType(roomTypeId, updatedRoomType);
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = "更新失败: $e"; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
// 删除房间类型
@RequestMapping(path: "/deleteRoomType", method: HttpMethod.DELETE)
Future<Response> deleteRoomType(Request request) async {
ApiResponse<String> apiResponse = ApiResponse();
try {
var data = jsonDecode(await request.readAsString());
var roomTypeId = data['id'];
var result = await roomTypeService.deleteRoomType(roomTypeId);
if (result.isEmpty) {
apiResponse.code = ResponseJsonCode.success;
apiResponse.message = MessageConstants.DELETE_SUCCESS;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
}
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = result;
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.ok, body: serializedJson);
} catch (e) {
apiResponse.code = ResponseJsonCode.fail;
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
String serializedJson = apiResponse.serialize();
return Response(HttpStatusCode.internalServerError,
body: serializedJson); // 发送失败响应
}
}
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// RouteGenerator
// **************************************************************************
part of 'RoomTypeController.dart';
late var _callHandler;
final Map<HttpMethod, List<List>> routes = {
HttpMethod.GET: [
[
"/roomType/roomTypeList",
HttpResponseType.JSON,
_callHandler.getRoomTypeList,
2,
true
]
],
HttpMethod.POST: [
[
"/roomType/addRoomType",
HttpResponseType.JSON,
_callHandler.addRoomType,
1,
true
]
],
HttpMethod.PUT: [
[
"/roomType/updateRoomType",
HttpResponseType.JSON,
_callHandler.updateRoomType,
1,
true
]
],
HttpMethod.DELETE: [
[
"/roomType/deleteRoomType",
HttpResponseType.JSON,
_callHandler.deleteRoomType,
1,
true
]
],
};

11
bin/enum/BedStatus.dart Normal file
View File

@@ -0,0 +1,11 @@
enum BedStatus {
using(0, "使用中"), //使用中
no_using(1, "未使用"); //未使用
// 枚举的值
final int code; // 整数值
final String description; // 字符串描述
// 构造函数
const BedStatus(this.code, this.description);
}

View File

@@ -0,0 +1,11 @@
enum DeviceStatus {
OFFLONE(0, "离线"), //离线
ONLINE(1, "在线"); //在线
// 枚举的值
final int code; // 整数值
final String description; // 字符串描述
// 构造函数
const DeviceStatus(this.code, this.description);
}

View File

@@ -0,0 +1,13 @@
enum MessageStatus {
//消息状态 0:无需处理 1:待处理 2:已处理
notify(0, "无需处理"),
waring(1, "待处理"),
dealed(2, "已处理");
// 枚举的值
final int code; // 整数值
final String description; // 字符串描述
// 构造函数
const MessageStatus(this.code, this.description);
}

View File

@@ -0,0 +1,80 @@
/// 报告状态枚举
enum ReportStatus {
experienceing, // 0 - 体验中 ok
generating, // 1 - 生成报告中 ok
appNormalClose, // 2 - APP正常关闭 ok
appAbnormalClose, // 3 - APP异常关闭 ok 可以捕获到的异常
appActiveClose, // 4 - APP主动关闭 ok
reportExceptionClose,// 5 - 报告生成异常关闭 ok
completed, // 9 - 完成
//网络断掉了怎么办todo websocket心跳 弹窗提示 微信视频结束之后要将微信标志重置 监听网络状态
//网络 蓝牙 视频播放 设备连接
//todo 监听网络状态 失败了停止播放视频
//todo 监听蓝牙状态 断掉就停止播放视频并且发送异常关闭
//todo 重新打开app
}
/// 扩展方法,提供数字映射和文本描述
extension ReportStatusExtension on ReportStatus {
/// 获取对应的数字状态值
int get value {
switch (this) {
case ReportStatus.experienceing:
return 0;
case ReportStatus.generating:
return 1;
case ReportStatus.appNormalClose:
return 2;
case ReportStatus.appAbnormalClose:
return 3;
case ReportStatus.appActiveClose:
return 4;
case ReportStatus.reportExceptionClose:
return 5;
case ReportStatus.completed:
return 9;
}
}
/// 获取文本描述
String get label {
switch (this) {
case ReportStatus.experienceing:
return "体验中";
case ReportStatus.generating:
return "生成报告中";
case ReportStatus.appNormalClose:
return "APP正常关闭";
case ReportStatus.appAbnormalClose:
return "APP异常关闭";
case ReportStatus.appActiveClose:
return "APP主动关闭";
case ReportStatus.reportExceptionClose:
return "报告生成异常关闭";
case ReportStatus.completed:
return "完成";
}
}
/// 根据数字获取枚举
static ReportStatus fromValue(int value) {
switch (value) {
case 0:
return ReportStatus.experienceing;
case 1:
return ReportStatus.generating;
case 2:
return ReportStatus.appNormalClose;
case 3:
return ReportStatus.appAbnormalClose;
case 4:
return ReportStatus.appActiveClose;
case 5:
return ReportStatus.reportExceptionClose;
case 9:
return ReportStatus.completed;
default:
throw Exception("未知报告状态: $value");
}
}
}

View File

@@ -0,0 +1,11 @@
enum StatisticsResultType {
score(1, "睡眠评分统计"),
hrv(2, "hrv统计");
// 枚举的值
final int code; // 整数值
final String description; // 字符串描述
// 构造函数
const StatisticsResultType(this.code, this.description);
}

View File

@@ -0,0 +1,12 @@
enum StatisticsType {
area("1", "区域统计"),
room("2", "房间统计"),
person("3", "个人统计"); //在线
// 枚举的值
final String code; // 整数值
final String description; // 字符串描述
// 构造函数
const StatisticsType(this.code, this.description);
}

View File

@@ -0,0 +1,17 @@
class MqttHandler {
// 报警处理 单独线程 todo
void message(String topic, String msg) {
// print("topic: $topic, msg:$msg");
try {
// statisticsService.saveDeviceStatus(msg);
// alarmRuleService.judgeInstantAlarm(msg);
} catch (e) {
// print(e);
}
//遍历路径获取匹配的topic 进行websocket数据转发
// _topicPathHandler.forwardMessageByTopic(topic, msg);
}
}

211
bin/main.dart Normal file
View File

@@ -0,0 +1,211 @@
import 'dart:convert';
import 'dart:io';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:EasyDartModule/base/database/DataBase.dart';
import 'package:EasyDartModule/base/discovery/Discovery.dart';
import 'package:EasyDartModule/base/logger/Logger.dart';
import 'package:EasyDartModule/base/mqtt/mqtt.dart';
import 'package:EasyDartModule/base/redis/redis.dart';
import 'package:EasyDartModule/base/storage/Storage.dart';
import 'package:EasyDartModule/base/websocket/WebSocket.dart';
import './const/Constants.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 'handler/MqttHandler.dart';
import 'const/ServiceConstant.dart';
// import 'service/DailyTaskService.dart';
import './const/CommonVariables.dart';
void main(List<String> args) async {
if (true) {
initEasyDartModule();
await EasyDartModule.redis.connect();
// return;
}
if (false) {
String? ep = Platform.environment["vsbs_server_port"];
int port = ep == null ? 9200 : int.parse(ep);
String nacosServer =
Platform.environment["nacos_server"] ?? "http://10.20.1.2:8848";
String nacosNameSpaceId = Platform.environment["nacos_namespaceId"] ??
"d3b43bfe-f584-4b8f-a390-353abc69c856";
String nacosBindIp = Platform.environment["nacos_bindIp"] ?? "";
//初始化服务发现
EasyDartModule.init(
discoveryConfig:
DiscoveryConfig(host: nacosServer, namespaceId: nacosNameSpaceId));
//注册实例
await EasyDartModule.discovery
.registerInstance(Constants.serviceName, nacosBindIp, Constants.port);
//查询日志服务配置信息
String logger = await EasyDartModule.discovery.getConfig("logger");
var loggerConfig = jsonDecode(logger);
//查询数据库配置信息
String mongodb = await EasyDartModule.discovery.getConfig("mongodb");
var mongodbConfig = jsonDecode(mongodb);
//查询存储配置
String storage = await EasyDartModule.discovery.getConfig("storage");
var storageConfig = jsonDecode(storage);
//查询mqtt配置
String mqtt = await EasyDartModule.discovery.getConfig("mqtt");
var mqttConfig = jsonDecode(mqtt);
var redisConfig =
jsonDecode(await EasyDartModule.discovery.getConfig("redis"));
var gatewayConfig =
jsonDecode(await EasyDartModule.discovery.getConfig("gateway"));
ServiceConstant.service_address = gatewayConfig["host"];
// ServiceConstant.service_address = "https://vsbst-api.he-info.cn";
MqttHandler mqttHandler = MqttHandler();
EasyDartModule.init(
loggerConfig: LoggerConfig(
host: loggerConfig["host"], serviceName: Constants.serviceName),
dataBaseConfig: DataBaseConfig(
host: mongodbConfig["host"],
userName: mongodbConfig["userName"],
password: mongodbConfig["password"],
dataBase: mongodbConfig["dataBase"]),
storageConfig: StorageConfig(
host: storageConfig["host"],
port: storageConfig["port"],
accessKey: storageConfig["accessKey"],
secretKey: storageConfig["secretKey"]),
mqttConfig: MqttConfig(
host: mqttConfig["host"],
clientId: mqttConfig["clientId"],
topic: [mqttConfig["topic"]],
messgae: (topic, msg) {
mqttHandler.message(topic, msg);
// print("topic: $topic, msg:$msg");
}),
redisConfig:
RedisConfig(host: redisConfig["host"], port: redisConfig["port"]));
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(port);
//测试mqtt 订阅
// EasyDartModule.mqtt
// .subscribe("/vsbs/sensor/mattress/676a227a1e121f98e5000000", 0);
// EasyDartModule.mqtt.connect();
// EasyDartModule.mqtt.
//推送
// EasyDartModule.mqtt.publish(topic, msg);
//测试db
// Future.delayed(Duration(seconds: 5), () async {
// var db = EasyDartModule.dataBase;
// var r = await db.query("uc_sys_user");
// print(r);
// });
//测试storage
// String bucketName = "test-bu";
// String objectName = "/aa/bb/objectName.gif";
// EasyDartModule.storage.createBucket(bucketName).then((v) {
// EasyDartModule.storage
// .uploadObject(bucketName, objectName, File("a.gif").readAsBytesSync())
// .then((path) {
// print("上传文件: $path");
// EasyDartModule.storage.getObject(bucketName, objectName).then((data) {
// print("下载文件");
// File("b.gif").writeAsBytesSync(data);
// print("下载完毕");
// });
// });
// // EasyDartModule.storage.deleteObject(bucketName, "objectName");
// });
await EasyDartModule.redis.connect();
// AlarmRuleService();
// DailyTaskService();
// EasyDartModule.logger
// .info("${Constants.serviceName}启动完毕", tag: Constants.serviceName);
}
}
void initEasyDartModule() {
try {
EasyDartModule.init(
loggerConfig: LoggerConfig(
host: ServiceConstant.logService, serviceName: "快检报告服务"),
redisConfig: RedisConfig(host: "192.168.1.129", port: 6379),
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");
}));
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(9200,);
} catch (e) {
print(e);
EasyDartModule.logger.error("websocket连接失败--》:$e");
}
}

View File

@@ -0,0 +1,66 @@
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
import 'package:fixnum/fixnum.dart'; // 用于处理 Int64 类型
part 'ApiResponse.g.dart';
@JsonSerializable(genericArgumentFactories: true)
class ApiResponse<T> {
int? code;
int? total;
T? data;
String? message;
ApiResponse();
// JSON 反序列化
factory ApiResponse.fromJson(
Map<String, dynamic> json,
T Function(Object? json) fromJsonT,
) =>
_$ApiResponseFromJson(json, fromJsonT);
// JSON 序列化
Map<String, dynamic> toJson(Object? Function(T value) toJsonT) =>
_$ApiResponseToJson(this, toJsonT);
// 添加自定义的 toJson 序列化方法,确保能正确序列化泛型数据
String serialize() {
// 手动处理 data 中的 Int64 转换为 int
var serializedData = _serializeData(data);
return jsonEncode({
'code': code,
'total': total,
'data': serializedData,
'message': message,
});
}
// 递归处理 data 中的每个项,转换 Int64 为 int
dynamic _serializeData(dynamic data) {
if (data is List) {
// 处理 List 中的 Int64 类型
return data.map((e) => _serializeData(e)).toList();
} else if (data is Map) {
// 处理 Map 中的 Int64 类型
var map = Map<String, dynamic>.from(data);
map.forEach((key, value) {
if (value is Int64) {
map[key] = value.toInt();
} else {
map[key] = _serializeData(value);
}
});
return map;
} else if (data is Int64) {
// 如果是 Int64 类型,转换为 int
return data.toInt();
}
return data;
}
@override
String toString() {
return serialize();
}
}

View File

@@ -0,0 +1,40 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'ApiResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
ApiResponse<T> _$ApiResponseFromJson<T>(
Map<String, dynamic> json,
T Function(Object? json) fromJsonT,
) =>
ApiResponse<T>()
..code = (json['code'] as num?)?.toInt()
..total = (json['total'] as num?)?.toInt()
..data = _$nullableGenericFromJson(json['data'], fromJsonT)
..message = json['message'] as String?;
Map<String, dynamic> _$ApiResponseToJson<T>(
ApiResponse<T> instance,
Object? Function(T value) toJsonT,
) =>
<String, dynamic>{
'code': instance.code,
'total': instance.total,
'data': _$nullableGenericToJson(instance.data, toJsonT),
'message': instance.message,
};
T? _$nullableGenericFromJson<T>(
Object? input,
T Function(Object? json) fromJson,
) =>
input == null ? null : fromJson(input);
Object? _$nullableGenericToJson<T>(
T? input,
Object? Function(T value) toJson,
) =>
input == null ? null : toJson(input);

37
bin/model/Area.dart Normal file
View File

@@ -0,0 +1,37 @@
import 'package:json_annotation/json_annotation.dart';
part 'Area.g.dart';
@JsonSerializable()
class Area {
@JsonKey(name: '_id')
String? id; // 区域id
String? area_name; // 区域名称
String? area_desc; // 区域描述
int? created_at; // 创建时间(毫秒)
int? updated_at; // 更新时间(毫秒)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
String? oid; // 机构ID
int? deleted; // 是否删除
String? points; // 坐标点集合
String? tid; // 所属机构
int? level; // 权限等级
Area();
static Area fromJson(Map<String, dynamic> json) => _$AreaFromJson(json);
Map<String, dynamic> toJson() => _$AreaToJson(this);
// 使用查询参数填充 Area 对象
static Area fromQueryParameters(Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return Area.fromJson(json);
}
}

40
bin/model/Area.g.dart Normal file
View File

@@ -0,0 +1,40 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'Area.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Area _$AreaFromJson(Map<String, dynamic> json) => Area()
..id = json['_id'] as String?
..area_name = json['area_name'] as String?
..area_desc = json['area_desc'] as String?
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..oid = json['oid'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..points = json['points'] as String?
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$AreaToJson(Area instance) => <String, dynamic>{
'_id': instance.id,
'area_name': instance.area_name,
'area_desc': instance.area_desc,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'oid': instance.oid,
'deleted': instance.deleted,
'points': instance.points,
'tid': instance.tid,
'level': instance.level,
};

61
bin/model/Bed.dart Normal file
View File

@@ -0,0 +1,61 @@
import 'package:json_annotation/json_annotation.dart';
part 'Bed.g.dart';
@JsonSerializable()
class Bed {
@JsonKey(name: '_id')
String? id; // 床位id
String? bed_type_id; // 床位类型ID
@JsonKey(ignore: true)
String? bed_type_name; // 床位类型名称
String? bed_name; // 床位名称
bool? is_mapped; // 是否映射
String? mapped_coordinates; // 映射坐标点
String? device_model; // 设备型号
String? device_name; // 设备名称
String? device_id; // 设备ID
int? status; // 当前状态 (0: 离线, 1: 在线)
int? created_at; // 创建时间(毫秒数)
int? updated_at; // 更新时间(毫秒数)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
String? oid; // 机构ID
@JsonKey(ignore: true)
int? start_time;
@JsonKey(ignore: true)
int? end_time;
String? room_id; //房间id
int? deleted; // 是否删除(逻辑删除标识)
String? tid; // 所属机构
int? level; // 权限等级
String? areaIds; //区域id集合
String? roomIds; //房间id集合
String? mapping; //是否映射
String? device_status; //设备状态
String? page;
String? limit;
List<String>? deviceIds;
String? roomTypes; //房间类型
Bed();
// 从JSON中反序列化
static Bed fromJson(Map<String, dynamic> json) => _$BedFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$BedToJson(this);
static Bed fromQueryParameters(Map<String, String> queryParameters, jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return Bed.fromJson(json);
}
}

69
bin/model/Bed.g.dart Normal file
View File

@@ -0,0 +1,69 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'Bed.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Bed _$BedFromJson(Map<String, dynamic> json) => Bed()
..id = json['_id'] as String?
..bed_type_id = json['bed_type_id'] as String?
..bed_name = json['bed_name'] as String?
..is_mapped = json['is_mapped'] as bool?
..mapped_coordinates = json['mapped_coordinates'] as String?
..device_model = json['device_model'] as String?
..device_name = json['device_name'] as String?
..device_id = json['device_id'] as String?
..status = (json['status'] as num?)?.toInt()
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..oid = json['oid'] as String?
..room_id = json['room_id'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt()
..areaIds = json['areaIds'] as String?
..roomIds = json['roomIds'] as String?
..mapping = json['mapping'] as String?
..device_status = json['device_status'] as String?
..page = json['page'] as String?
..limit = json['limit'] as String?
..deviceIds =
(json['deviceIds'] as List<dynamic>?)?.map((e) => e as String).toList()
..roomTypes = json['roomTypes'] as String?;
Map<String, dynamic> _$BedToJson(Bed instance) => <String, dynamic>{
'_id': instance.id,
'bed_type_id': instance.bed_type_id,
'bed_name': instance.bed_name,
'is_mapped': instance.is_mapped,
'mapped_coordinates': instance.mapped_coordinates,
'device_model': instance.device_model,
'device_name': instance.device_name,
'device_id': instance.device_id,
'status': instance.status,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'oid': instance.oid,
'room_id': instance.room_id,
'deleted': instance.deleted,
'tid': instance.tid,
'level': instance.level,
'areaIds': instance.areaIds,
'roomIds': instance.roomIds,
'mapping': instance.mapping,
'device_status': instance.device_status,
'page': instance.page,
'limit': instance.limit,
'deviceIds': instance.deviceIds,
'roomTypes': instance.roomTypes,
};

44
bin/model/BedType.dart Normal file
View File

@@ -0,0 +1,44 @@
import 'package:json_annotation/json_annotation.dart';
part 'BedType.g.dart';
@JsonSerializable()
class BedType {
@JsonKey(name: '_id')
String? id; // 房间id
String? bed_type_name; // 床位类型名称
String? description; // 类型描述
int? created_at; // 创建时间(毫秒数)
int? updated_at; // 更新时间(毫秒数)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
int? deleted; // 是否删除(逻辑删除标识)
String? oid; // 机构ID
@JsonKey(ignore: true)
int? start_time;
@JsonKey(ignore: true)
int? end_time;
String? tid; // 所属机构
int? level; // 权限等级
BedType();
// 从JSON中反序列化
static BedType fromJson(Map<String, dynamic> json) => _$BedTypeFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$BedTypeToJson(this);
static BedType fromQueryParameters(
Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return BedType.fromJson(json);
}
}

38
bin/model/BedType.g.dart Normal file
View File

@@ -0,0 +1,38 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'BedType.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
BedType _$BedTypeFromJson(Map<String, dynamic> json) => BedType()
..id = json['_id'] as String?
..bed_type_name = json['bed_type_name'] as String?
..description = json['description'] as String?
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..oid = json['oid'] as String?
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$BedTypeToJson(BedType instance) => <String, dynamic>{
'_id': instance.id,
'bed_type_name': instance.bed_type_name,
'description': instance.description,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'deleted': instance.deleted,
'oid': instance.oid,
'tid': instance.tid,
'level': instance.level,
};

View File

@@ -0,0 +1,36 @@
import 'package:json_annotation/json_annotation.dart';
part 'DictionaryType.g.dart';
@JsonSerializable()
class DictionaryType {
@JsonKey(name: '_id')
String? id; // 字典ID
String? dict_name; // 字典名称
String? dict_type; // 字典类型
String? status; // 状态
String? create_by; // 创建者
int? create_time; // 创建时间(毫秒)
String? update_by; // 更新者
int? update_time; // 更新时间(毫秒)
String? remark; // 备注
DictionaryType();
// 从 JSON 创建 Dictionary 实例
static DictionaryType fromJson(Map<String, dynamic> json) => _$DictionaryTypeFromJson(json);
// 将 Dictionary 实例转换为 JSON
Map<String, dynamic> toJson() => _$DictionaryTypeToJson(this);
// 使用查询参数填充 Dictionary 对象
static DictionaryType fromQueryParameters(Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return DictionaryType.fromJson(json);
}
}

View File

@@ -0,0 +1,32 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'DictionaryType.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DictionaryType _$DictionaryTypeFromJson(Map<String, dynamic> json) =>
DictionaryType()
..id = json['_id'] as String?
..dict_name = json['dict_name'] as String?
..dict_type = json['dict_type'] as String?
..status = json['status'] as String?
..create_by = json['create_by'] as String?
..create_time = (json['create_time'] as num?)?.toInt()
..update_by = json['update_by'] as String?
..update_time = (json['update_time'] as num?)?.toInt()
..remark = json['remark'] as String?;
Map<String, dynamic> _$DictionaryTypeToJson(DictionaryType instance) =>
<String, dynamic>{
'_id': instance.id,
'dict_name': instance.dict_name,
'dict_type': instance.dict_type,
'status': instance.status,
'create_by': instance.create_by,
'create_time': instance.create_time,
'update_by': instance.update_by,
'update_time': instance.update_time,
'remark': instance.remark,
};

View File

@@ -0,0 +1,47 @@
import 'package:json_annotation/json_annotation.dart';
part 'DiseaseType.g.dart';
@JsonSerializable()
class DiseaseType {
@JsonKey(name: '_id')
String? id; // 疾病类型ID
String? disease_type_name; // 疾病类型名称
String? description; // 类型描述
int? created_at; // 创建时间(毫秒数)
int? updated_at; // 更新时间(毫秒数)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
int? deleted; // 是否删除(逻辑删除标识)
String? oid; // 机构ID
@JsonKey(ignore: true)
int? start_time;
@JsonKey(ignore: true)
int? end_time;
String? color; //疾病颜色
int? num; //统计人数
String? tid; // 所属机构
int? level; // 权限等级
DiseaseType();
// 从JSON中反序列化
static DiseaseType fromJson(Map<String, dynamic> json) =>
_$DiseaseTypeFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$DiseaseTypeToJson(this);
static DiseaseType fromQueryParameters(Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return DiseaseType.fromJson(json);
}
}

View File

@@ -0,0 +1,43 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'DiseaseType.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DiseaseType _$DiseaseTypeFromJson(Map<String, dynamic> json) => DiseaseType()
..id = json['_id'] as String?
..disease_type_name = json['disease_type_name'] as String?
..description = json['description'] as String?
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..oid = json['oid'] as String?
..color = json['color'] as String?
..num = (json['num'] as num?)?.toInt()
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$DiseaseTypeToJson(DiseaseType instance) =>
<String, dynamic>{
'_id': instance.id,
'disease_type_name': instance.disease_type_name,
'description': instance.description,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'deleted': instance.deleted,
'oid': instance.oid,
'color': instance.color,
'num': instance.num,
'tid': instance.tid,
'level': instance.level,
};

78
bin/model/Person.dart Normal file
View File

@@ -0,0 +1,78 @@
import 'package:json_annotation/json_annotation.dart';
part 'Person.g.dart';
@JsonSerializable()
class Person {
@JsonKey(name: '_id')
String? id; // 人员id
String? room_id; // 选择的房间id
String? room_name; // 选择的房间名称
String? bed_id; // 选择的床位id
String? bed_name; // 选择的床位名称
int? check_in_start_time; // 入住的开始时间(毫秒数)
int? check_in_end_time; // 入住的结束时间(毫秒数)
String? contact_name; // 联系人名称
String? contact_relationship; // 联系人关系类型
String? contact_phone; // 联系人手机号码
String? person_name; // 人员姓名
String? gender; // 性别
String? ethnicity; // 民族
String? person_type_id; // 人员类型id
String? person_type_name; // 人员类型名称
String? id_card_number; // 身份证号码
String? phone_number; // 手机号码
String? service_level; // 服务等级
String? health_info; // 健康信息
String? height; // 身高
String? weight; // 体重
String? tid; // 机构ID
String? oid; // 机构ID
int? deleted;
int? created_at; // 创建时间(毫秒)
int? updated_at; // 更新时间(毫秒)
int? data_level; //数据等级
String? age;
String? desc; //备注
int? level; // 权限等级
// @JsonKey(ignore: true)
String? bed_ids; //床位id列表
//查询条件
// @JsonKey(ignore: true)
String? query_gender; //性别
// @JsonKey(ignore: true)
String? deviceID; //设备id
// @JsonKey(ignore: true)
String? status; //入住状态
// @JsonKey(ignore: true)
String? start_time;
// @JsonKey(ignore: true)
String? end_time;
// @JsonKey(ignore: true)
String? query_person_type;
// @JsonKey(ignore: true)
String? page;
// @JsonKey(ignore: true)
String? limit;
Person();
// 从JSON中反序列化
static Person fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$PersonToJson(this);
static Person fromQueryParameters(
Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return Person.fromJson(json);
}
}

90
bin/model/Person.g.dart Normal file
View File

@@ -0,0 +1,90 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'Person.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Person _$PersonFromJson(Map<String, dynamic> json) => Person()
..id = json['_id'] as String?
..room_id = json['room_id'] as String?
..room_name = json['room_name'] as String?
..bed_id = json['bed_id'] as String?
..bed_name = json['bed_name'] as String?
..check_in_start_time = (json['check_in_start_time'] as num?)?.toInt()
..check_in_end_time = (json['check_in_end_time'] as num?)?.toInt()
..contact_name = json['contact_name'] as String?
..contact_relationship = json['contact_relationship'] as String?
..contact_phone = json['contact_phone'] as String?
..person_name = json['person_name'] as String?
..gender = json['gender'] as String?
..ethnicity = json['ethnicity'] as String?
..person_type_id = json['person_type_id'] as String?
..person_type_name = json['person_type_name'] as String?
..id_card_number = json['id_card_number'] as String?
..phone_number = json['phone_number'] as String?
..service_level = json['service_level'] as String?
..health_info = json['health_info'] as String?
..height = json['height'] as String?
..weight = json['weight'] as String?
..tid = json['tid'] as String?
..oid = json['oid'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..data_level = (json['data_level'] as num?)?.toInt()
..age = json['age'] as String?
..desc = json['desc'] as String?
..level = (json['level'] as num?)?.toInt()
..bed_ids = json['bed_ids'] as String?
..query_gender = json['query_gender'] as String?
..deviceID = json['deviceID'] as String?
..status = json['status'] as String?
..start_time = json['start_time'] as String?
..end_time = json['end_time'] as String?
..query_person_type = json['query_person_type'] as String?
..page = json['page'] as String?
..limit = json['limit'] as String?;
Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{
'_id': instance.id,
'room_id': instance.room_id,
'room_name': instance.room_name,
'bed_id': instance.bed_id,
'bed_name': instance.bed_name,
'check_in_start_time': instance.check_in_start_time,
'check_in_end_time': instance.check_in_end_time,
'contact_name': instance.contact_name,
'contact_relationship': instance.contact_relationship,
'contact_phone': instance.contact_phone,
'person_name': instance.person_name,
'gender': instance.gender,
'ethnicity': instance.ethnicity,
'person_type_id': instance.person_type_id,
'person_type_name': instance.person_type_name,
'id_card_number': instance.id_card_number,
'phone_number': instance.phone_number,
'service_level': instance.service_level,
'health_info': instance.health_info,
'height': instance.height,
'weight': instance.weight,
'tid': instance.tid,
'oid': instance.oid,
'deleted': instance.deleted,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'data_level': instance.data_level,
'age': instance.age,
'desc': instance.desc,
'level': instance.level,
'bed_ids': instance.bed_ids,
'query_gender': instance.query_gender,
'deviceID': instance.deviceID,
'status': instance.status,
'start_time': instance.start_time,
'end_time': instance.end_time,
'query_person_type': instance.query_person_type,
'page': instance.page,
'limit': instance.limit,
};

40
bin/model/PersonType.dart Normal file
View File

@@ -0,0 +1,40 @@
import 'package:json_annotation/json_annotation.dart';
part 'PersonType.g.dart';
@JsonSerializable()
class PersonType {
@JsonKey(name: '_id')
String? id; // 人员类型id
String? person_type_name; // 人员类型名称
String? description; // 类型描述
int? created_at; // 创建时间(毫秒数)
int? updated_at; // 更新时间(毫秒数)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
int? deleted; // 是否删除(逻辑删除标识)
String? oid; // 机构ID
String? tid; // 所属机构
int? level; // 权限等级
PersonType();
// 从JSON中反序列化
static PersonType fromJson(Map<String, dynamic> json) =>
_$PersonTypeFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$PersonTypeToJson(this);
static PersonType fromQueryParameters(Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return PersonType.fromJson(json);
}
}

View File

@@ -0,0 +1,39 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'PersonType.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
PersonType _$PersonTypeFromJson(Map<String, dynamic> json) => PersonType()
..id = json['_id'] as String?
..person_type_name = json['person_type_name'] as String?
..description = json['description'] as String?
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..oid = json['oid'] as String?
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$PersonTypeToJson(PersonType instance) =>
<String, dynamic>{
'_id': instance.id,
'person_type_name': instance.person_type_name,
'description': instance.description,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'deleted': instance.deleted,
'oid': instance.oid,
'tid': instance.tid,
'level': instance.level,
};

View File

@@ -0,0 +1,47 @@
import 'package:json_annotation/json_annotation.dart';
part 'Reservation.g.dart';
@JsonSerializable()
class Reservation {
int? created_at; // 创建时间(毫秒数)
String? created_by_name; // 创建人名称
int? updated_at; // 更新时间(毫秒数)
String? updated_by_name; // 更新人名称
int? deleted; // 是否删除(逻辑删除标识)
String? room_id; // 房间ID
String? bed_id; // 床位ID
int? start_time; // 开始时间(毫秒数)
int? end_time; // 结束时间(毫秒数)
int? total_days; // 总天数
String? contact_name; // 联系人名称
String? relationship_type; // 关系类型
String? phone_number; // 手机号码
int? oid; // 机构id
String? desc; // 备注
@JsonKey(name: '_id')
String? id; // ID
String? tid; // 所属机构
int? level; // 权限等级
Reservation();
// 从JSON中反序列化
static Reservation fromJson(Map<String, dynamic> json) =>
_$ReservationFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$ReservationToJson(this);
// 辅助方法:从查询参数生成对象
static Reservation fromQueryParameters(Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return Reservation.fromJson(json);
}
}

View File

@@ -0,0 +1,49 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'Reservation.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Reservation _$ReservationFromJson(Map<String, dynamic> json) => Reservation()
..created_at = (json['created_at'] as num?)?.toInt()
..created_by_name = json['created_by_name'] as String?
..updated_at = (json['updated_at'] as num?)?.toInt()
..updated_by_name = json['updated_by_name'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..room_id = json['room_id'] as String?
..bed_id = json['bed_id'] as String?
..start_time = (json['start_time'] as num?)?.toInt()
..end_time = (json['end_time'] as num?)?.toInt()
..total_days = (json['total_days'] as num?)?.toInt()
..contact_name = json['contact_name'] as String?
..relationship_type = json['relationship_type'] as String?
..phone_number = json['phone_number'] as String?
..oid = (json['oid'] as num?)?.toInt()
..desc = json['desc'] as String?
..id = json['_id'] as String?
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$ReservationToJson(Reservation instance) =>
<String, dynamic>{
'created_at': instance.created_at,
'created_by_name': instance.created_by_name,
'updated_at': instance.updated_at,
'updated_by_name': instance.updated_by_name,
'deleted': instance.deleted,
'room_id': instance.room_id,
'bed_id': instance.bed_id,
'start_time': instance.start_time,
'end_time': instance.end_time,
'total_days': instance.total_days,
'contact_name': instance.contact_name,
'relationship_type': instance.relationship_type,
'phone_number': instance.phone_number,
'oid': instance.oid,
'desc': instance.desc,
'_id': instance.id,
'tid': instance.tid,
'level': instance.level,
};

52
bin/model/Room.dart Normal file
View File

@@ -0,0 +1,52 @@
import 'package:json_annotation/json_annotation.dart';
part 'Room.g.dart';
@JsonSerializable()
class Room {
@JsonKey(name: '_id')
String? id; // 房间id
String? room_name; // 房间名称
String? room_desc; // 房间描述
double? bed_num; // 总床位数
double? bed_num_use; // 剩余可用床位数
String? room_type; // 房间类型
// @JsonKey(ignore: true)
String? room_type_name; // 房间类型名称
List<String>? imgs; // 图片地址列表
int? deleted; //是否删除
int? created_at; // 创建时间(毫秒)
int? updated_at; // 更新时间(毫秒)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
String? oid; // 机构ID
@JsonKey(ignore: true)
int? start_time;
@JsonKey(ignore: true)
int? end_time;
String? area_id; // 区域ID
String? area_name; // 区域名称
String? tid; // 所属机构
int? level; // 权限等级
int? bed_count;//床位总数
int? bed_use_count;//床位为使用
Room();
static Room fromJson(Map<String, dynamic> json) => _$RoomFromJson(json);
Map<String, dynamic> toJson() => _$RoomToJson(this);
// 使用查询参数填充 RoomType 对象
static Room fromQueryParameters(
Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return Room.fromJson(json);
}
}

56
bin/model/Room.g.dart Normal file
View File

@@ -0,0 +1,56 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'Room.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Room _$RoomFromJson(Map<String, dynamic> json) => Room()
..id = json['_id'] as String?
..room_name = json['room_name'] as String?
..room_desc = json['room_desc'] as String?
..bed_num = (json['bed_num'] as num?)?.toDouble()
..bed_num_use = (json['bed_num_use'] as num?)?.toDouble()
..room_type = json['room_type'] as String?
..room_type_name = json['room_type_name'] as String?
..imgs = (json['imgs'] as List<dynamic>?)?.map((e) => e as String).toList()
..deleted = (json['deleted'] as num?)?.toInt()
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..oid = json['oid'] as String?
..area_id = json['area_id'] as String?
..area_name = json['area_name'] as String?
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt()
..bed_count = (json['bed_count'] as num?)?.toInt()
..bed_use_count = (json['bed_use_count'] as num?)?.toInt();
Map<String, dynamic> _$RoomToJson(Room instance) => <String, dynamic>{
'_id': instance.id,
'room_name': instance.room_name,
'room_desc': instance.room_desc,
'bed_num': instance.bed_num,
'bed_num_use': instance.bed_num_use,
'room_type': instance.room_type,
'room_type_name': instance.room_type_name,
'imgs': instance.imgs,
'deleted': instance.deleted,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'oid': instance.oid,
'area_id': instance.area_id,
'area_name': instance.area_name,
'tid': instance.tid,
'level': instance.level,
'bed_count': instance.bed_count,
'bed_use_count': instance.bed_use_count,
};

26
bin/model/RoomTest.dart Normal file
View File

@@ -0,0 +1,26 @@
import 'package:json_annotation/json_annotation.dart';
part 'RoomTest.g.dart';
@JsonSerializable()
class RoomTest {
String? room_id; // 房间id
String? room_name; // 房间名称
String? room_desc; // 房间描述
double? bed_num; // 总床位数
double? bed_num_use; // 剩余可用床位数
String? room_type; // 房间类型
List<String>? imgs; // 图片地址列表
String? oid; // 机构ID
int? deleted; //是否删除
int? created_at; // 创建时间(毫秒)
int? updated_at; // 更新时间(毫秒)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
RoomTest();
static RoomTest fromJson(Map<String, dynamic> json) => _$RoomTestFromJson(json);
Map<String, dynamic> toJson() => _$RoomTestToJson(this);
}

42
bin/model/RoomTest.g.dart Normal file
View File

@@ -0,0 +1,42 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'RoomTest.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
RoomTest _$RoomTestFromJson(Map<String, dynamic> json) => RoomTest()
..room_id = json['room_id'] as String?
..room_name = json['room_name'] as String?
..room_desc = json['room_desc'] as String?
..bed_num = (json['bed_num'] as num?)?.toDouble()
..bed_num_use = (json['bed_num_use'] as num?)?.toDouble()
..room_type = json['room_type'] as String?
..imgs = (json['imgs'] as List<dynamic>?)?.map((e) => e as String).toList()
..oid = json['oid'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?;
Map<String, dynamic> _$RoomTestToJson(RoomTest instance) => <String, dynamic>{
'room_id': instance.room_id,
'room_name': instance.room_name,
'room_desc': instance.room_desc,
'bed_num': instance.bed_num,
'bed_num_use': instance.bed_num_use,
'room_type': instance.room_type,
'imgs': instance.imgs,
'oid': instance.oid,
'deleted': instance.deleted,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
};

47
bin/model/RoomType.dart Normal file
View File

@@ -0,0 +1,47 @@
import 'package:json_annotation/json_annotation.dart';
part 'RoomType.g.dart';
@JsonSerializable()
class RoomType {
@JsonKey(name: '_id')
String? id; // 房间类型ID
String? room_type_name; // 房间类型名称
String? description; // 房间类型描述
int? created_at; // 创建时间(毫秒)
int? updated_at; // 更新时间(毫秒)
String? created_by_id; // 创建人ID
String? created_by_name; // 创建人名称
String? updated_by_id; // 更新人ID
String? updated_by_name; // 更新人名称
String? oid; //机构id
@JsonKey(ignore: true)
int? start_time;
@JsonKey(ignore: true)
int? end_time;
int? deleted;
String? tid; // 所属机构
int? level; // 权限等级
RoomType();
// 从 JSON 中生成 RoomType 对象
static RoomType fromJson(Map<String, dynamic> json) =>
_$RoomTypeFromJson(json);
// 将 RoomType 对象转化为 JSON
Map<String, dynamic> toJson() => _$RoomTypeToJson(this);
// 使用查询参数填充 RoomType 对象
static RoomType fromQueryParameters(
Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return RoomType.fromJson(json);
}
}

38
bin/model/RoomType.g.dart Normal file
View File

@@ -0,0 +1,38 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'RoomType.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
RoomType _$RoomTypeFromJson(Map<String, dynamic> json) => RoomType()
..id = json['_id'] as String?
..room_type_name = json['room_type_name'] as String?
..description = json['description'] as String?
..created_at = (json['created_at'] as num?)?.toInt()
..updated_at = (json['updated_at'] as num?)?.toInt()
..created_by_id = json['created_by_id'] as String?
..created_by_name = json['created_by_name'] as String?
..updated_by_id = json['updated_by_id'] as String?
..updated_by_name = json['updated_by_name'] as String?
..oid = json['oid'] as String?
..deleted = (json['deleted'] as num?)?.toInt()
..tid = json['tid'] as String?
..level = (json['level'] as num?)?.toInt();
Map<String, dynamic> _$RoomTypeToJson(RoomType instance) => <String, dynamic>{
'_id': instance.id,
'room_type_name': instance.room_type_name,
'description': instance.description,
'created_at': instance.created_at,
'updated_at': instance.updated_at,
'created_by_id': instance.created_by_id,
'created_by_name': instance.created_by_name,
'updated_by_id': instance.updated_by_id,
'updated_by_name': instance.updated_by_name,
'oid': instance.oid,
'deleted': instance.deleted,
'tid': instance.tid,
'level': instance.level,
};

View File

@@ -0,0 +1,33 @@
import 'package:json_annotation/json_annotation.dart';
part 'StatisticsResult.g.dart';
@JsonSerializable()
class StatisticsResult {
@JsonKey(name: '_id')
String? id; // ID
int? type; // type 1睡眠评分统计 2.hrv统计
int? start_time; // 开始时间
int? end_time; // 结束时间
String? data; // 统计数据
StatisticsResult();
// 从 JSON 中生成 RoomType 对象
static StatisticsResult fromJson(Map<String, dynamic> json) =>
_$StatisticsResultFromJson(json);
// 将 RoomType 对象转化为 JSON
Map<String, dynamic> toJson() => _$StatisticsResultToJson(this);
// 使用查询参数填充 RoomType 对象
static StatisticsResult fromQueryParameters(
Map<String, String> queryParameters, Map<String, dynamic> jwt) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
json['tid'] = jwt['tid'];
json['level'] = jwt['level'];
return StatisticsResult.fromJson(json);
}
}

View File

@@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'StatisticsResult.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
StatisticsResult _$StatisticsResultFromJson(Map<String, dynamic> json) =>
StatisticsResult()
..id = json['_id'] as String?
..type = (json['type'] as num?)?.toInt()
..start_time = (json['start_time'] as num?)?.toInt()
..end_time = (json['end_time'] as num?)?.toInt()
..data = json['data'] as String?;
Map<String, dynamic> _$StatisticsResultToJson(StatisticsResult instance) =>
<String, dynamic>{
'_id': instance.id,
'type': instance.type,
'start_time': instance.start_time,
'end_time': instance.end_time,
'data': instance.data,
};

1
bin/model/Test.dart Normal file
View File

@@ -0,0 +1 @@
class Test {}

View File

@@ -0,0 +1,18 @@
import 'package:json_annotation/json_annotation.dart';
part 'WebSocketMessage.g.dart';
@JsonSerializable()
class WebSocketMessage {
String path;
int? type;
dynamic data;
String? to;
String? mac;
WebSocketMessage({required this.path, this.type, this.data, this.to,this.mac});
static WebSocketMessage fromJson(Map<String, dynamic> json) =>
_$WebSocketMessageFromJson(json);
Map<String, dynamic> toJson() => _$WebSocketMessageToJson(this);
}

View File

@@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'WebSocketMessage.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
WebSocketMessage _$WebSocketMessageFromJson(Map<String, dynamic> json) =>
WebSocketMessage(
path: json['path'] as String,
type: (json['type'] as num?)?.toInt(),
data: json['data'],
to: json['to'] as String?,
mac: json['mac'] as String?,
);
Map<String, dynamic> _$WebSocketMessageToJson(WebSocketMessage instance) =>
<String, dynamic>{
'path': instance.path,
'type': instance.type,
'data': instance.data,
'to': instance.to,
'mac': instance.mac,
};

View File

@@ -0,0 +1,29 @@
class ApiResponse<T> {
int? code;
T? data;
String? msg;
int? total;
dynamic rawResponse; // 原始 Dio 响应对象
ApiResponse({
required this.code,
this.data,
this.msg,
this.total,
this.rawResponse,
});
factory ApiResponse.fromJson(
Map<String, dynamic> json,
T Function(Object?) fromJsonT, {
dynamic rawResponse,
}) {
return ApiResponse<T>(
code: json['code'] as int?,
data: json['data'] != null ? fromJsonT(json['data']) : null,
msg: json['msg'] as String?,
total: json['total'] as int?,
rawResponse: rawResponse, // 保留 Dio 原始响应对象
);
}
}

View File

@@ -0,0 +1,19 @@
// lib/http_status_codes.dart
class HttpStatusCodes {
// Success codes
static const int ok = 200;
static const int created = 201;
static const int accepted = 202;
// Client error codes
static const int badRequest = 400;
static const int unauthorized = 401;//401 参数错误
static const int forbidden = 403;//403 禁止,多条数据,不允许修改
static const int notFound = 404;//404 没有报告
// Server error codes
static const int internalServerError = 500;//500 内部异常
static const int notImplemented = 501;
static const int serviceUnavailable = 503;
}

View File

@@ -0,0 +1,27 @@
import 'package:json_annotation/json_annotation.dart';
import '../DiseaseType.dart';
part 'DiseaseStatistics.g.dart';
@JsonSerializable()
class DiseaseStatistics {
int? total; // 总数
List<DiseaseType>? disease_type_list; // 疾病类型列表
DiseaseStatistics();
// 从JSON中反序列化
static DiseaseStatistics fromJson(Map<String, dynamic> json) =>
_$DiseaseStatisticsFromJson(json);
// 转换成JSON
Map<String, dynamic> toJson() => _$DiseaseStatisticsToJson(this);
static DiseaseStatistics fromQueryParameters(Map<String, String> queryParameters) {
var json = <String, dynamic>{};
queryParameters.forEach((key, value) {
json[key] = value;
});
return DiseaseStatistics.fromJson(json);
}
}

View File

@@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'DiseaseStatistics.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DiseaseStatistics _$DiseaseStatisticsFromJson(Map<String, dynamic> json) =>
DiseaseStatistics()
..total = (json['total'] as num?)?.toInt()
..disease_type_list = (json['disease_type_list'] as List<dynamic>?)
?.map((e) => DiseaseType.fromJson(e as Map<String, dynamic>))
.toList();
Map<String, dynamic> _$DiseaseStatisticsToJson(DiseaseStatistics instance) =>
<String, dynamic>{
'total': instance.total,
'disease_type_list': instance.disease_type_list,
};

View File

@@ -0,0 +1,165 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/Area.dart';
import '../const/MessageConstants.dart';
class AreaRepository {
// 获取所有区域列表
Future<List> fetchAreaList(Area query,
{int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.id != null) {
select.eq('area_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('level', query.level);
}
if (query.area_name != null) {
select.match('area_name', query.area_name!, caseInsensitive: true);
}
if (query.area_desc != null) {
select.eq('area_desc', query.area_desc);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.created_at != null) {
select.gte('created_at', query.created_at);
}
if (query.updated_at != null) {
select.lte('updated_at', query.updated_at);
}
select.eq('deleted', 0);
// 设置分页
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at"); // 按创建时间排序
// 执行查询
var result = await db.query(
'bus_area_info',
condition: select, // 查询条件 + 分页 + 排序
);
if (result.isEmpty) {
return [];
}
return result;
}
// 获取单个区域信息
Future<Area?> fetchAreaById(int areaId) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
var condition = {'area_id': areaId};
// 执行查询
var result = await db.query(
'bus_area_info',
condition: condition,
);
if (result.isNotEmpty) {
return Area.fromJson(result.first);
}
return null;
}
// 添加区域
Future<bool> insertArea(Area area) async {
var db = EasyDartModule.dataBase;
// 执行插入操作
var result = await db.insert('bus_area_info', area.toJson());
// 返回是否插入成功
return true;
}
// 更新区域信息
Future<String> updateArea(String areaId, Area updatedArea) async {
String message = "";
var db = EasyDartModule.dataBase;
var str = updatedArea.toJson();
str.remove("_id");
var updateCondition = {
'_id': ObjectId.fromHexString(areaId),
};
try {
var result = await db.update('bus_area_info', str, updateCondition);
return message; // 返回受影响的行数
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
return message;
}
}
// 删除区域 (逻辑删除)
Future<String> deleteArea(String areaId) async {
var db = EasyDartModule.dataBase;
String message = "";
try {
var areaIdList = areaId.split(',');
var objectIdList =
areaIdList.map((id) => ObjectId.fromHexString(id)).toList();
var condition = {
'_id': {'\$in': objectIdList}
}; // 使用 \$in 操作符查询多个 ID
var update = {
'\$set': {'deleted': 1}
}; // 逻辑删除,只更新 deleted 字段
var result = await db.update('bus_area_info', update, condition);
return message; // 返回受影响的行数
} catch (e) {
print("Error during deleteArea: $e");
message = MessageConstants.DELETE_ERROR;
return message;
}
}
// 获取区域数量
Future<int> getAreaCount(Area query) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
SelectorBuilder select = SelectorBuilder();
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('level', query.level);
}
if (query.area_name != null) {
select.match('area_name', query.area_name!, caseInsensitive: true);
}
if (query.area_desc != null) {
select.eq('area_desc', query.area_desc);
}
select.eq('deleted', 0);
// 执行查询并返回计数
var result = await db.query(
'bus_area_info',
condition: select,
);
return result.length;
}
}

View File

@@ -0,0 +1,481 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../const/MessageConstants.dart';
import '../model/Bed.dart';
import '../model/Person.dart';
import '../model/Reservation.dart';
import '../enum/DeviceStatus.dart';
import '../const/Constants.dart';
class BedRepository {
// 获取床位列表,支持查询条件
Future<List> fetchBedList(Bed query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_id != null) {
// List<String> roomTypes = query.roomIds!.split(',');
// select.oneFrom('room_id', roomTypes);
select.eq('room_id', query.room_id);
}
if (query.mapping != null) {
if (query.mapping!.length == 1) {
if (query.mapping == "1") {
select.nin('mapped_coordinates', [null, '']);
} else if (query.mapping == "0") {
select.oneFrom('mapped_coordinates', [null, '']);
}
}
}
if (query.device_status != null) {
List deviceIdList = [];
if (query.device_status!.length == 1) {
var allDevices =
await EasyDartModule.redis.get("oid_${query.tid}_devices");
if (allDevices != null) {
if (query.device_status == DeviceStatus.ONLINE.code.toString()) {
if (allDevices != null && allDevices.isNotEmpty) {
List<String> deviceIds = allDevices.split(',');
for (var deviceId in deviceIds) {
var deviceStatus =
await EasyDartModule.redis.get("mac_$deviceId");
if (deviceStatus != null && deviceStatus.isNotEmpty) {
deviceIdList.add(deviceId);
}
}
}
if (deviceIdList.isNotEmpty) {
select.oneFrom('device_id', deviceIdList);
} else {
return [];
}
} else if (query.device_status ==
DeviceStatus.OFFLONE.code.toString()) {
if (allDevices != null && allDevices.isNotEmpty) {
List<String> deviceIds = allDevices.split(',');
for (var deviceId in deviceIds) {
var deviceStatus =
await EasyDartModule.redis.get("mac_$deviceId");
if (deviceStatus == null || deviceStatus.isEmpty) {
deviceIdList.add(deviceId);
}
}
if (deviceIdList.isNotEmpty) {
select.oneFrom('device_id', deviceIdList);
}
}
}
}
}
}
if (query.areaIds != null) {
List<String> areaIds = query.areaIds!.split(',');
SelectorBuilder newSelect = SelectorBuilder();
var newquery = newSelect.oneFrom('area_id', areaIds);
var result = await db.query(
'bus_room_info',
condition: newquery,
);
if (result.isNotEmpty) {
List<String> roomIds = [];
for (var item in result) {
roomIds.add(item['_id'].toHexString());
}
select.oneFrom('room_id', roomIds);
}
}
if (query.room_id != null) {
select.eq('room_id', query.room_id);
}
if (query.bed_type_id != null) {
// select.eq('bed_type_id', query.bed_type_id);
List<String> roomTypes = query.bed_type_id!.split(',');
select.oneFrom('bed_type_id', roomTypes);
}
if (query.bed_type_name != null) {
select.match('bed_type_name', query.bed_type_name!,
caseInsensitive: true);
}
if (query.bed_name != null) {
select.match('bed_name', query.bed_name!, caseInsensitive: true);
}
if (query.is_mapped != null) {
select.eq('is_mapped', query.is_mapped == true ? 1 : 0);
}
if (query.device_model != null) {
select.match('device_model', query.device_model!, caseInsensitive: true);
}
if (query.device_name != null) {
select.match('device_name', query.device_name!, caseInsensitive: true);
}
if (query.device_id != null) {
select.match('device_id', query.device_id!, caseInsensitive: false);
}
if (query.status != null) {
select.eq('status', query.status);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_at', query.start_time);
}
if (query.end_time != null) {
select.lte('created_at', query.end_time);
}
if (query.deviceIds != null && query.deviceIds!.isNotEmpty) {
select.oneFrom('device_id', query.deviceIds!);
}
select.eq('deleted', 0);
// 设置分页
select
.skip(((int.tryParse(query.page ?? Constants.default_page.toString()) ??
Constants.default_page) -
1) *
(int.tryParse(query.limit ?? Constants.default_limit.toString()) ??
Constants.default_limit))
.limit(
int.tryParse(query.limit ?? Constants.default_limit.toString()) ??
Constants.default_limit);
// 设置排序
select.sortBy("created_at"); // 按创建时间排序
// 执行查询
var result = await db.query('bus_bed_info', condition: select);
// 如果查询结果为空,返回空列表
return result.isEmpty ? [] : result;
}
// 获取单个床位信息
Future<Map?> fetchBedById(String bedId) async {
var db = EasyDartModule.dataBase;
var condition = {'_id': ObjectId.fromHexString(bedId)}; // 使用 bed_id 作为条件
var result = await db.query('bus_bed_info', condition: condition);
return result.isNotEmpty ? result.first : null;
}
// 插入床位信息
Future<bool> insertBed(Bed bed) async {
var db = EasyDartModule.dataBase;
int currentTime = DateTime.now().millisecondsSinceEpoch;
bed.created_at = currentTime;
bed.updated_at = currentTime;
bed.deleted = 0; // 初始化为未删除
var result = await db.insert('bus_bed_info', bed.toJson());
return true;
}
// 更新床位信息
Future<String> updateBed(String bedId, Bed updatedBed) async {
var db = EasyDartModule.dataBase;
String message = "";
updatedBed.updated_at = DateTime.now().millisecondsSinceEpoch;
var condition = {'bed_id': bedId}; // 使用 bed_id 作为条件
try {
var result =
await db.update('bus_bed_info', updatedBed.toJson(), condition);
message = MessageConstants.UPDATE_SUCCESS;
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
}
return message;
}
// 删除床位(逻辑删除)
Future<String> deleteBed(String bedId) async {
var db = EasyDartModule.dataBase;
String message = "";
var condition = {'bed_id': bedId}; // 使用 bed_id 作为查询条件
var result = await db.query('bus_bed_info', condition: condition);
if (result.isNotEmpty) {
// 标记为已删除
var update = {'deleted': 1};
try {
var updateResult = await db.update('bus_bed_info', update, condition);
message = MessageConstants.DELETE_SUCCESS;
} catch (e) {
message = MessageConstants.DELETE_ERROR;
}
} else {
message = "未找到床位";
}
return message;
}
Future<int> getBedCount(Bed query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_id != null) {
// List<String> roomTypes = query.roomIds!.split(',');
// select.oneFrom('room_id', roomTypes);
select.eq('room_id', query.room_id);
}
if (query.mapping != null) {
if (query.mapping!.length == 1) {
if (query.mapping == "1") {
select.nin('mapped_coordinates', [null, '']);
} else if (query.mapping == "0") {
select.oneFrom('mapped_coordinates', [null, '']);
}
}
}
if (query.device_status != null) {
List deviceIdList = [];
if (query.device_status!.length == 1) {
var allDevices =
await EasyDartModule.redis.get("oid_${query.tid}_devices");
if (allDevices != null) {
if (query.device_status == DeviceStatus.ONLINE.code.toString()) {
if (allDevices != null && allDevices.isNotEmpty) {
List<String> deviceIds = allDevices.split(',');
for (var deviceId in deviceIds) {
var deviceStatus =
await EasyDartModule.redis.get("mac_$deviceId");
if (deviceStatus != null && deviceStatus.isNotEmpty) {
deviceIdList.add(deviceId);
}
}
}
if (deviceIdList.isNotEmpty) {
select.oneFrom('device_id', deviceIdList);
} else {
return 0;
}
} else if (query.device_status ==
DeviceStatus.OFFLONE.code.toString()) {
if (allDevices != null && allDevices.isNotEmpty) {
List<String> deviceIds = allDevices.split(',');
for (var deviceId in deviceIds) {
var deviceStatus =
await EasyDartModule.redis.get("mac_$deviceId");
if (deviceStatus == null || deviceStatus.isEmpty) {
deviceIdList.add(deviceId);
}
}
if (deviceIdList.isNotEmpty) {
select.oneFrom('device_id', deviceIdList);
}
}
}
}
}
}
if (query.areaIds != null) {
List<String> areaIds = query.areaIds!.split(',');
SelectorBuilder newSelect = SelectorBuilder();
var newquery = newSelect.oneFrom('area_id', areaIds);
var result = await db.query(
'bus_room_info',
condition: newquery,
);
if (result.isNotEmpty) {
List<String> roomIds = [];
for (var item in result) {
roomIds.add(item['_id'].toHexString());
}
select.oneFrom('room_id', roomIds);
}
}
if (query.room_id != null) {
select.eq('room_id', query.room_id);
}
if (query.bed_type_id != null) {
// select.eq('bed_type_id', query.bed_type_id);
List<String> roomTypes = query.bed_type_id!.split(',');
select.oneFrom('bed_type_id', roomTypes);
}
if (query.bed_type_name != null) {
select.match('bed_type_name', query.bed_type_name!,
caseInsensitive: true);
}
if (query.bed_name != null) {
select.match('bed_name', query.bed_name!, caseInsensitive: true);
}
if (query.is_mapped != null) {
select.eq('is_mapped', query.is_mapped == true ? 1 : 0);
}
if (query.device_model != null) {
select.match('device_model', query.device_model!, caseInsensitive: true);
}
if (query.device_name != null) {
select.match('device_name', query.device_name!, caseInsensitive: true);
}
if (query.device_id != null) {
select.match('device_id', query.device_id!, caseInsensitive: false);
}
if (query.status != null) {
select.eq('status', query.status);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_at', query.start_time);
}
if (query.end_time != null) {
select.lte('created_at', query.end_time);
}
if (query.deviceIds != null && query.deviceIds!.isNotEmpty) {
select.oneFrom('device_id', query.deviceIds!);
}
select.eq('deleted', 0);
// 执行查询,获取符合条件的记录数量
var result = await db.query(
'bus_bed_info',
condition: select, // 查询条件
);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
Future<List> getOrderCheckInList(Reservation query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.room_id != null) {
select.eq('room_id', query.room_id);
}
if (query.bed_id != null) {
select.eq('bed_id', query.bed_id!);
}
if (query.start_time != null) {
select.gte('start_time', query.start_time);
}
if (query.end_time != null) {
select.lte('end_time', query.end_time);
}
if (query.total_days != null) {
select.eq('total_days', query.total_days);
}
if (query.contact_name != null) {
select.match('contact_name', query.contact_name!, caseInsensitive: true);
}
if (query.relationship_type != null) {
select.match('relationship_type', query.relationship_type!,
caseInsensitive: true);
}
if (query.phone_number != null) {
select.match('phone_number', query.phone_number!, caseInsensitive: true);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.desc != null) {
select.match('desc', query.desc!, caseInsensitive: true);
}
// 添加默认查询条件
select.eq('deleted', 0);
// 执行查询
var result = await db.query('bus_room_check_info', condition: select);
// 如果查询结果为空,返回空列表
return result.isEmpty ? [] : result;
}
Future<void> updateBedStatus(String bed_id, int code, Person person) async {
var start_time = person.check_in_start_time;
var end_time = person.check_in_end_time;
var db = EasyDartModule.dataBase;
var condition = {'_id': ObjectId.fromHexString(bed_id)}; // 使用 bed_id 作为条件
var update = {
'\$set': {
'status': code,
'updated_at': DateTime.now().millisecondsSinceEpoch,
'start_time': start_time,
'end_time': end_time,
},
};
try {
var result = await db.update('bus_bed_info', update, condition);
} catch (e) {
print(e);
}
}
//存储统计信息
Future<void> addStatistics(
Map result, int code, int queryStartTime, int queryEndTime) async {
var db = EasyDartModule.dataBase;
try {
if (result != null && result.isNotEmpty) {
result.forEach((tid, statistics) async {
Map<String, dynamic> info = {};
info['tid'] = tid;
info['type'] = code;
info['start_time'] = queryStartTime;
info['end_time'] = queryEndTime;
info['data'] = statistics;
var result = await db.insert('bus_statistics_info', info);
print("object");
});
}
} catch (e) {
print(e);
}
}
findResultByQuery(Map query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
select.eq('type', query['type']);
select.gte('start_time', query['startTime']);
select.lte('end_time', query['endTime']);
select.eq('tid', query['tid']);
var result = await db.query(
'bus_statistics_info',
condition: select,
);
if (result.isEmpty) {
return [];
}
return result;
}
}

View File

@@ -0,0 +1,191 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/BedType.dart';
import '../const/MessageConstants.dart';
class BedTypeRepository {
// 获取所有床位类型列表,根据床位类型的查询条件
Future<List> fetchBedTypeList(BedType query, {int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.bed_type_name != null) {
select.match('bed_type_name', query.bed_type_name!, caseInsensitive: true);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_at', query.start_time);
}
if (query.end_time != null) {
select.lte('created_at', query.end_time);
}
// 设置分页
select.eq('deleted', 0);
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at"); // 按创建时间排序
// 执行查询
var result = await db.query('bus_bed_type', condition: select);
// 如果查询结果为空,返回空列表
if (result.isEmpty) {
return [];
}
// 返回查询结果
return result;
}
// 获取单个床位类型信息
Future<BedType?> fetchBedTypeById(String bedTypeId) async {
var db = EasyDartModule.dataBase;
var condition = {'bed_type_id': bedTypeId}; // 使用 Map 格式作为条件
var result = await db.query('bus_bed_type', condition: condition);
// 如果查询到结果,返回床位类型数据
if (result.isNotEmpty) {
return BedType.fromJson(result.first);
}
// 如果没有找到,返回 null
return null;
}
// 添加床位类型
Future<bool> insertBedType(BedType bedType) async {
var db = EasyDartModule.dataBase;
// 设置创建时间和更新时间
int currentTime = DateTime.now().millisecondsSinceEpoch;
bedType.created_at = currentTime;
bedType.updated_at = currentTime;
bedType.deleted = 0; // 初始化为未删除
// 执行插入 SQL
var result = await db.insert('bus_bed_type', bedType.toJson());
// 如果影响行数大于 0说明插入成功
return true;
}
// 更新床位类型信息
Future<String> updateBedType(String bedTypeId, BedType updatedBedType) async {
var db = EasyDartModule.dataBase;
String message = "";
// 设置更新时间
updatedBedType.updated_at = DateTime.now().millisecondsSinceEpoch;
// 使用 bed_type_id 作为条件
var condition = {'bed_type_id': bedTypeId};
try {
// 执行更新 SQL
var result = await db.update('bus_bed_type', updatedBedType.toJson(), condition);
message = MessageConstants.UPDATE_SUCCESS;
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
}
return message;
}
// 删除床位类型(逻辑删除)
Future<String> deleteBedType(String bedTypeId) async {
var db = EasyDartModule.dataBase;
String message = "";
// 检查是否有床位绑定了该床位类型
var condition = {'bed_type_id': bedTypeId}; // 使用 Map 格式作为条件
var beds = await db.query(
'bus_bed_info',
condition: condition, // 修正:条件应使用 Map 格式
);
// 如果有床位绑定该类型,返回错误信息
if (beds.isNotEmpty) {
message = "床位类型已经被绑定,请先解除床位类型绑定.";
return message;
}
// 如果没有床位绑定,执行逻辑删除操作
try {
var update = {'deleted': 1}; // 标记为已删除
var result = await db.update('bus_bed_type', update, condition);
message = MessageConstants.DELETE_SUCCESS;
} catch (e) {
message = MessageConstants.DELETE_ERROR;
}
return message;
}
Future<int> getBedTypeCount(BedType query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('bed_type_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.bed_type_name != null) {
select.match('bed_type_name', query.bed_type_name!, caseInsensitive: true);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_at', query.start_time);
}
if (query.end_time != null) {
select.lte('created_at', query.end_time);
}
select.eq('deleted', 0);
// 执行查询,获取符合条件的记录数量
var result = await db.query(
'bus_bed_type',
condition: select, // 查询条件
);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
}

View File

@@ -0,0 +1,149 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/DictionaryType.dart';
class DictionaryTypeRepository {
// 获取字典列表,支持查询条件
Future<List<DictionaryType>> fetchDictionaryList(DictionaryType query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', ObjectId.fromHexString(query.id!));
}
if (query.dict_name != null) {
select.match('dict_name', query.dict_name!, caseInsensitive: true);
}
if (query.dict_type != null) {
select.match('dict_type', query.dict_type!, caseInsensitive: true);
}
if (query.status != null) {
select.eq('status', query.status);
}
if (query.create_by != null) {
select.eq('create_by', query.create_by);
}
if (query.update_by != null) {
select.eq('update_by', query.update_by);
}
if (query.remark != null) {
select.match('remark', query.remark!, caseInsensitive: true);
}
if (query.create_time != null) {
select.gte('create_time', query.create_time);
}
if (query.update_time != null) {
select.lte('update_time', query.update_time);
}
// 设置排序
select.sortBy("create_time"); // 按创建时间排序
// 执行查询
var result = await db.query('bus_dict_types', condition: select);
// 如果查询结果为空,返回空列表
return result.isEmpty ? [] : result.map((e) => DictionaryType.fromJson(e)).toList();
}
// 获取单个字典信息
Future<DictionaryType?> fetchDictionaryById(String id) async {
var db = EasyDartModule.dataBase;
var condition = {'_id': ObjectId.fromHexString(id)}; // 使用 id 作为条件
var result = await db.query('bus_dict_types', condition: condition);
return result.isNotEmpty ? DictionaryType.fromJson(result.first) : null;
}
// 插入字典信息
Future<bool> insertDictionary(DictionaryType DictionaryType) async {
var db = EasyDartModule.dataBase;
int currentTime = DateTime.now().millisecondsSinceEpoch;
DictionaryType.create_time = currentTime;
DictionaryType.update_time = currentTime;
var result = await db.insert('bus_dict_types', DictionaryType.toJson());
return true;
}
// 更新字典信息
Future<String> updateDictionary(String id, DictionaryType updatedDictionary) async {
var db = EasyDartModule.dataBase;
String message = "";
updatedDictionary.update_time = DateTime.now().millisecondsSinceEpoch;
var condition = {'_id': ObjectId.fromHexString(id)}; // 使用 id 作为条件
try {
var result = await db.update('bus_dict_types', updatedDictionary.toJson(), condition);
message = "更新成功";
} catch (e) {
message = "更新失败: $e";
}
return message;
}
// 删除字典(逻辑删除)
Future<String> deleteDictionary(String id) async {
var db = EasyDartModule.dataBase;
String message = "";
var condition = {'_id': ObjectId.fromHexString(id)}; // 使用 id 作为查询条件
var result = await db.query('bus_dict_types', condition: condition);
if (result.isNotEmpty) {
// 标记为已删除
var update = {'deleted': 1};
try {
var updateResult = await db.update('bus_dict_types', update, condition);
message = "删除成功";
} catch (e) {
message = "删除失败: $e";
}
} else {
message = "未找到字典";
}
return message;
}
// 获取字典数量
Future<int> getDictionaryCount(DictionaryType query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', ObjectId.fromHexString(query.id!));
}
if (query.dict_name != null) {
select.match('dict_name', query.dict_name!, caseInsensitive: true);
}
if (query.dict_type != null) {
select.match('dict_type', query.dict_type!, caseInsensitive: true);
}
if (query.status != null) {
select.eq('status', query.status);
}
if (query.create_by != null) {
select.eq('create_by', query.create_by);
}
if (query.update_by != null) {
select.eq('update_by', query.update_by);
}
if (query.remark != null) {
select.match('remark', query.remark!, caseInsensitive: true);
}
if (query.create_time != null) {
select.gte('create_time', query.create_time);
}
if (query.update_time != null) {
select.lte('update_time', query.update_time);
}
// 执行查询,获取符合条件的记录数量
var result = await db.query('bus_dict_types', condition: select);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
}

View File

@@ -0,0 +1,209 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/DiseaseType.dart';
import '../const/MessageConstants.dart';
class DiseaseTypeRepository {
// 获取所有疾病类型列表
Future<List> fetchDiseaseTypeList(DiseaseType query, {int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.disease_type_name != null) {
select.match('disease_type_name', query.disease_type_name!, caseInsensitive: true);
}
if (query.description != null) {
select.eq('description', query.description);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.updated_by_name != null) {
select.eq('updated_by_name', query.updated_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_time', query.start_time);
}
if (query.end_time != null) {
select.lte('created_time', query.end_time);
}
// 设置分页
select.eq('deleted', 0);
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at"); // 按创建时间排序
// 执行查询
var result = await db.query('bus_disease_type', condition: select);
// 如果查询结果为空,返回空列表
if (result.isEmpty) {
return [];
}
// 返回查询结果
return result;
}
// 获取单个疾病类型信息
Future<DiseaseType?> fetchDiseaseTypeById(int diseaseTypeId) async {
var db = EasyDartModule.dataBase;
var condition = {'disease_type_id': diseaseTypeId}; // 使用 disease_type_id 为条件
// 执行查询 SQL
var result = await db.query('bus_disease_type', condition: condition);
// 如果查询到结果,返回疾病类型数据
if (result.isNotEmpty) {
return DiseaseType.fromJson(result.first);
}
// 如果没有找到,返回 null
return null;
}
// 添加疾病类型
Future<bool> insertDiseaseType(DiseaseType diseaseType) async {
var db = EasyDartModule.dataBase;
// 执行插入 SQL
var result = await db.insert('bus_disease_type', diseaseType.toJson());
// 如果返回的影响行数大于0说明插入成功
return true; // 确保返回的是影响的行数
}
// 更新疾病类型
Future<String> updateDiseaseType(String diseaseTypeId, DiseaseType updatedDiseaseType) async {
String message = "";
var db = EasyDartModule.dataBase;
var str = updatedDiseaseType.toJson();
str.remove("_id");
var updateCondition = {
'_id': ObjectId.fromHexString(diseaseTypeId),
};
try {
var result = await db.update('bus_disease_type', str, updateCondition);
return message; // 返回受影响的行数
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
return message;
}
}
// 删除疾病类型 (逻辑删除前检查是否有疾病绑定)
Future<String> deleteDiseaseType(String diseaseTypeIds) async {
String message = "";
var db = EasyDartModule.dataBase;
// 将逗号分隔的多个 diseaseTypeIds 字符串转换为 List
var diseaseTypeIdList = diseaseTypeIds.split(',');
// 检查是否有疾病绑定这些疾病类型
var condition = {
'disease_type': {'\$in': diseaseTypeIdList}
}; // 使用 \$in 操作符查询多个 ID
var diseases = await db.query('bus_disease_info', condition: condition);
if (diseases.isNotEmpty) {
// 如果有疾病绑定这些疾病类型,返回 false
message = "疾病类型已经被绑定,请先解除疾病类型绑定.";
return message;
}
// 如果没有疾病绑定,执行逻辑删除操作
try {
var objectIdList = diseaseTypeIdList.map((id) => ObjectId.fromHexString(id)).toList();
var deleteCondition = {
'_id': {'\$in': objectIdList}
}; // 使用 \$in 操作符查询多个 ID
var update = {
'\$set': {'deleted': 1}
}; // 逻辑删除,只更新 deleted 字段
var result = await db.update('bus_disease_type', update, deleteCondition);
message = MessageConstants.DELETE_SUCCESS;
} catch (e) {
print("Error during deleteDiseaseType: $e");
message = MessageConstants.DELETE_ERROR;
}
return message;
}
Future<int> getDiseaseTypeCount(DiseaseType query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('disease_type_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.disease_type_name != null) {
select.match('disease_type_name', query.disease_type_name!, caseInsensitive: true);
}
if (query.description != null) {
select.eq('description', query.description);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.updated_by_name != null) {
select.eq('updated_by_name', query.updated_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_time', query.start_time);
}
if (query.end_time != null) {
select.lte('created_time', query.end_time);
}
select.eq('deleted', 0);
// 执行查询,获取符合条件的记录数量
var result = await db.query('bus_disease_type', condition: select);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
Future<List> fetchDiseaseTypeListByOrganization(String oid) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
select.eq('oid', oid);
select.eq('deleted', 0);
// 执行查询
var result = await db.query('bus_disease_type', condition: select);
// 如果查询结果为空,返回空列表
if (result.isEmpty) {
return [];
}
// 返回查询结果
return result;
}
}

View File

@@ -0,0 +1,391 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../const/Constants.dart';
import '../model/Person.dart';
class PersonRepository {
// 获取所有人员列表
Future<List> fetchPersonList(
Person query,
) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', ObjectId.fromHexString(query.id!));
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_id != null) {
select.eq('room_id', query.room_id);
}
if (query.room_name != null) {
select.match('room_name', query.room_name!, caseInsensitive: true);
}
if (query.bed_id != null) {
select.eq('bed_id', query.bed_id);
}
if (query.bed_ids != null) {
List<String> bedIds = query.bed_ids!.split(',');
select.oneFrom('bed_id', bedIds);
}
if (query.bed_name != null) {
select.match('bed_name', query.bed_name!, caseInsensitive: true);
}
if (query.check_in_start_time != null) {
select.gte('check_in_start_time', query.check_in_start_time);
}
if (query.check_in_end_time != null) {
select.lte('check_in_end_time', query.check_in_end_time);
}
if (query.contact_name != null) {
select.match('contact_name', query.contact_name!, caseInsensitive: true);
}
if (query.contact_relationship != null) {
select.eq('contact_relationship', query.contact_relationship);
}
if (query.contact_phone != null) {
select.eq('contact_phone', query.contact_phone);
}
if (query.person_name != null) {
select.match('person_name', query.person_name!, caseInsensitive: false);
}
if (query.gender != null) {
List<String> genders = query.gender!.split(",");
if (genders.length == 1) {
select.eq('gender', genders.first);
}
// select.eq('gender', query.gender);
}
if (query.ethnicity != null) {
select.eq('ethnicity', query.ethnicity);
}
if (query.person_type_id != null) {
List<String> bedIds = query.person_type_id!.split(',');
select.oneFrom('person_type_id', bedIds);
// select.eq('person_type_id', query.person_type_id);
}
if (query.person_type_name != null) {
select.match('person_type_name', query.person_type_name!,
caseInsensitive: true);
}
if (query.id_card_number != null) {
select.eq('id_card_number', query.id_card_number);
}
if (query.phone_number != null) {
select.eq('phone_number', query.phone_number);
}
if (query.service_level != null) {
select.eq('service_level', query.service_level);
}
if (query.health_info != null) {
select.eq('health_info', query.health_info);
}
if (query.height != null) {
select.eq('height', query.height);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.query_gender != null) {
List<String> genders = query.query_gender!.split(",");
if (genders.length == 1) {
select.eq('gender', genders.first);
}
}
if (query.start_time != null &&
query.start_time!.isNotEmpty &&
query.end_time != null &&
query.end_time!.isNotEmpty) {
SelectorBuilder select1 = SelectorBuilder();
SelectorBuilder select2 = SelectorBuilder();
select1.gte('check_in_start_time', int.parse(query.start_time!));
select2.lte('check_in_start_time', int.parse(query.end_time!));
select1.and(select2);
SelectorBuilder select3 = SelectorBuilder();
SelectorBuilder select4 = SelectorBuilder();
select3.gte('check_in_end_time', int.parse(query.start_time!));
select4.lte('check_in_end_time', int.parse(query.end_time!));
select3.and(select4);
select1.or(select3);
SelectorBuilder select5 = SelectorBuilder();
SelectorBuilder select6 = SelectorBuilder();
select5.lte('check_in_start_time', int.parse(query.start_time!));
select6.gte('check_in_end_time', int.parse(query.end_time!));
select5.and(select6);
SelectorBuilder select7 = SelectorBuilder();
SelectorBuilder select8 = SelectorBuilder();
select7.gte('check_in_end_time', int.parse(query.start_time!));
select8.lte('check_in_end_time', int.parse(query.end_time!));
select7.and(select8);
select5.and(select7);
select1.or(select5);
select.and(select1);
}
if (query.status != null) {
List<String> status = query.status!.split(",");
if (status.length == 1) {
if (status.first == "1") {
select.nin('bed_id', [null, '']);
} else if (status.first == "2") {
select.oneFrom('bed_id', [null, '']);
}
}
}
if (query.query_person_type != null) {
List<String> personTypes = query.query_person_type!.split(',');
select.oneFrom('person_type_id', personTypes);
}
// 设置分页
select.eq('deleted', 0);
select
.skip(((int.tryParse(query.page ?? Constants.default_page.toString()) ??
Constants.default_page) -
1) *
(int.tryParse(query.limit ?? Constants.default_limit.toString()) ??
Constants.default_limit))
.limit(
int.tryParse(query.limit ?? Constants.default_limit.toString()) ??
Constants.default_limit);
// 设置排序
select.sortBy("created_at");
// 执行查询
var result = await db.query(
'bus_person',
condition: select,
);
return result.isEmpty ? [] : result;
}
// 获取单个人员信息
Future<Person?> fetchPersonById(String personId) async {
var db = EasyDartModule.dataBase;
var condition = {'_id': personId};
var result = await db.query(
'bus_person',
condition: condition,
);
if (result.isNotEmpty) {
return Person.fromJson(result.first);
}
return null;
}
// 插入人员
Future<bool> insertPerson(Person person) async {
var db = EasyDartModule.dataBase;
var result = await db.insert('bus_person', person.toJson());
return true;
}
// 更新人员信息
Future<String> updatePerson(String personId, Person updatedPerson) async {
String message = "";
var db = EasyDartModule.dataBase;
var condition = {'_id': ObjectId.fromHexString(personId)};
var update = {
'\$set': {
'room_id': updatedPerson.room_id,
'room_name': updatedPerson.room_name,
'bed_id': updatedPerson.bed_id,
'bed_name': updatedPerson.bed_name,
},
};
try {
var result = await db.update('bus_person', update, condition);
return "";
} catch (e) {
print("Error updating person: $e");
return "更新失败: $e";
}
}
// 删除人员 (逻辑删除)
Future<String> deletePerson(String personId) async {
String message = "";
var db = EasyDartModule.dataBase;
var condition = {'person_id': personId};
try {
var result = await db.update('bus_person', {'deleted': 1}, condition);
return "";
} catch (e) {
print("Error deleting person: $e");
return "删除失败: $e";
}
}
Future<List> fetchPersonsByOrganizationId(String oid) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
select.eq('oid', oid);
select.eq('deleted', 0);
// 设置排序
select.sortBy("created_at");
// 执行查询
var result = await db.query('bus_person', condition: select);
// 如果查询结果为空,返回空列表
if (result.isEmpty) {
return [];
}
// 返回查询结果
return result;
}
getPersonCount(Person query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', ObjectId.fromHexString(query.id!));
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_id != null) {
select.eq('room_id', query.room_id);
}
if (query.room_name != null) {
select.match('room_name', query.room_name!, caseInsensitive: true);
}
if (query.bed_id != null) {
select.eq('bed_id', query.bed_id);
}
if (query.bed_name != null) {
select.match('bed_name', query.bed_name!, caseInsensitive: true);
}
if (query.check_in_start_time != null) {
select.gte('check_in_start_time', query.check_in_start_time);
}
if (query.check_in_end_time != null) {
select.lte('check_in_end_time', query.check_in_end_time);
}
if (query.contact_name != null) {
select.match('contact_name', query.contact_name!, caseInsensitive: true);
}
if (query.contact_relationship != null) {
select.eq('contact_relationship', query.contact_relationship);
}
if (query.contact_phone != null) {
select.eq('contact_phone', query.contact_phone);
}
if (query.person_name != null) {
select.match('person_name', query.person_name!, caseInsensitive: true);
}
if (query.gender != null) {
List<String> genders = query.gender!.split(",");
if (genders.length == 1) {
select.eq('gender', genders.first);
}
// select.eq('gender', query.gender);
}
if (query.ethnicity != null) {
select.eq('ethnicity', query.ethnicity);
}
if (query.person_type_id != null) {
List<String> bedIds = query.person_type_id!.split(',');
select.oneFrom('person_type_id', bedIds);
// select.eq('person_type_id', query.person_type_id);
}
if (query.person_type_name != null) {
select.match('person_type_name', query.person_type_name!,
caseInsensitive: true);
}
if (query.id_card_number != null) {
select.eq('id_card_number', query.id_card_number);
}
if (query.phone_number != null) {
select.eq('phone_number', query.phone_number);
}
if (query.service_level != null) {
select.eq('service_level', query.service_level);
}
if (query.health_info != null) {
select.eq('health_info', query.health_info);
}
if (query.height != null) {
select.eq('height', query.height);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.query_gender != null) {
List<String> genders = query.query_gender!.split(",");
if (genders.length == 1) {
select.eq('gender', genders.first);
}
}
if (query.start_time != null &&
query.start_time!.isNotEmpty &&
query.end_time != null &&
query.end_time!.isNotEmpty) {
SelectorBuilder select1 = SelectorBuilder();
SelectorBuilder select2 = SelectorBuilder();
select1.gte('check_in_start_time', int.parse(query.start_time!));
select2.lte('check_in_start_time', int.parse(query.end_time!));
select1.and(select2);
SelectorBuilder select3 = SelectorBuilder();
SelectorBuilder select4 = SelectorBuilder();
select3.gte('check_in_end_time', int.parse(query.start_time!));
select4.lte('check_in_end_time', int.parse(query.end_time!));
select3.and(select4);
select1.or(select3);
SelectorBuilder select5 = SelectorBuilder();
SelectorBuilder select6 = SelectorBuilder();
select5.lte('check_in_start_time', int.parse(query.start_time!));
select6.gte('check_in_end_time', int.parse(query.end_time!));
select5.and(select6);
SelectorBuilder select7 = SelectorBuilder();
SelectorBuilder select8 = SelectorBuilder();
select7.gte('check_in_end_time', int.parse(query.start_time!));
select8.lte('check_in_end_time', int.parse(query.end_time!));
select7.and(select8);
select5.and(select7);
select1.or(select5);
select.and(select1);
}
if (query.status != null) {
List<String> status = query.status!.split(",");
if (status.length == 1) {
if (status.first == "1") {
select.nin('bed_id', [null, '']);
} else if (status.first == "2") {
select.oneFrom('bed_id', [null, '']);
}
}
}
if (query.query_person_type != null) {
List<String> personTypes = query.query_person_type!.split(',');
select.oneFrom('person_type_id', personTypes);
}
// 设置分页
select.eq('deleted', 0);
// 执行查询,获取符合条件的记录数量
var result = await db.query(
'bus_person',
condition: select, // 查询条件
);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
}

View File

@@ -0,0 +1,136 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/PersonType.dart';
import '../const/MessageConstants.dart';
class PersonTypeRepository {
// 获取所有人员类型列表
Future<List> fetchPersonTypeList(PersonType query,
{int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.person_type_name != null) {
select.match('bus_person_type_name', query.person_type_name!,
caseInsensitive: true);
}
if (query.description != null) {
select.eq('description', query.description);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.updated_by_name != null) {
select.eq('updated_by_name', query.updated_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.created_at != null) {
select.gte('created_at', query.created_at);
}
if (query.updated_at != null) {
select.lte('updated_at', query.updated_at);
}
// 设置分页
select.eq('deleted', 0);
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at");
// 执行查询
var result = await db.query(
'bus_person_type',
condition: select,
);
return result.isEmpty ? [] : result;
}
// 获取单个人员类型信息
Future<PersonType?> fetchPersonTypeById(String personTypeId) async {
var db = EasyDartModule.dataBase;
var condition = {'bus_person_type_id': personTypeId};
var result = await db.query(
'bus_person_type',
condition: condition,
);
if (result.isNotEmpty) {
return PersonType.fromJson(result.first);
}
return null;
}
// 插入人员类型
Future<bool> insertPersonType(PersonType personType) async {
var db = EasyDartModule.dataBase;
var result = await db.insert('bus_person_type', personType.toJson());
return true;
}
// 更新人员类型
Future<String> updatePersonType(
String personTypeId, PersonType updatedPersonType) async {
String message = "";
var db = EasyDartModule.dataBase;
var str = updatedPersonType.toJson();
str.remove("bus_person_type_id");
var updateCondition = {'bus_person_type_id': personTypeId};
try {
var result = await db.update('bus_person_type', str, updateCondition);
return message;
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
return message;
}
}
// 删除人员类型 (逻辑删除前检查是否有人员绑定)
Future<String> deletePersonType(String personTypeId) async {
String message = "";
var db = EasyDartModule.dataBase;
var condition = {'bus_person_type_id': personTypeId};
var persons = await db.query(
'person',
condition: condition,
);
if (persons.isNotEmpty) {
message = "人员类型已经被绑定,请先解除人员类型绑定.";
return message;
}
try {
var update = {'deleted': 1};
var result = await db.update('bus_person_type', update, condition);
return message;
} catch (e) {
print("Error during deletePersonType: $e");
message = MessageConstants.DELETE_ERROR;
return message;
}
}
Future<bool> checkPersonTypeBinding(String personTypeId) async {
var db = EasyDartModule.dataBase;
var condition = {'person_type_id': personTypeId};
var result = await db.query(
'bus_person',
condition: condition,
);
return result.isNotEmpty; // 如果有绑定,返回 true
}
}

View File

@@ -0,0 +1,302 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/Room.dart';
import '../const/MessageConstants.dart';
class RoomRepository {
// 获取所有房间列表
Future<List> fetchRoomList(Room query,
{int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', ObjectId.fromHexString(query.id!));
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_name != null) {
select.match('room_name', query.room_name!, caseInsensitive: true);
}
if (query.room_type != null) {
List<String> roomTypes = query.room_type!.split(',');
select.oneFrom('room_type', roomTypes);
}
if (query.room_desc != null) {
select.eq('room_desc', query.room_desc);
}
if (query.bed_num != null) {
select.eq('bed_num', query.bed_num);
}
if (query.bed_num_use != null) {
select.eq('bed_num_use', query.bed_num_use);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.created_at != null) {
select.gte('created_at', query.created_at);
}
if (query.updated_at != null) {
select.lte('updated_at', query.updated_at);
}
if (query.area_id != null) {
select.eq('area_id', query.area_id);
}
select.eq('deleted', 0);
// 设置分页
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at"); // 按创建时间排序
// 执行查询
var result = await db.query(
'bus_room_info',
condition: select, // 查询条件 + 分页 + 排序
);
if (result.isEmpty) {
return [];
}
return result;
}
// 获取单个房间信息
Future<Room?> fetchRoomById(int roomId) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
var condition = {'room_id': roomId};
// 执行查询
var result = await db.query(
'bus_room_info',
condition: condition,
);
if (result.isNotEmpty) {
return Room.fromJson(result.first);
}
return null;
}
// 添加房间
Future<bool> insertRoom(Room room) async {
var db = EasyDartModule.dataBase;
// 执行插入操作
var result = await db.insert('bus_room_info', room.toJson());
// 返回是否插入成功
return true;
}
// 更新房间信息
Future<String> updateRoom(String roomId, Room updatedRoom) async {
String message = "";
var db = EasyDartModule.dataBase;
var str = updatedRoom.toJson();
str.remove("_id");
var updateCondition = {
'_id': ObjectId.fromHexString(roomId),
};
try {
// var result = await db.update('bus_room_type', update, condition);
var result = await db.update('bus_room_info', str, updateCondition);
return message; // 返回受影响的行数
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
return message;
}
}
// 删除房间 (逻辑删除)
Future<String> deleteRoom(String roomId) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
var condition = {'room_id': roomId};
String message = "";
// try {
try {
var roomIdList = roomId.split(',');
var objectIdList =
roomIdList.map((id) => ObjectId.fromHexString(id)).toList();
var condition = {
'_id': {'\$in': objectIdList}
}; // 使用 \$in 操作符查询多个 ID
var update = {
'\$set': {'deleted': 1}
}; // 逻辑删除,只更新 deleted 字段
var result = await db.update('bus_room_info', update, condition);
return message; // 返回受影响的行数
} catch (e) {
print("Error during deleteRoomType: $e");
message = MessageConstants.DELETE_ERROR;
return message;
}
}
// 获取房间数量
Future<int> getRoomCount(Room query) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
SelectorBuilder select = SelectorBuilder();
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_type != null) {
select.eq('room_type', query.room_type);
}
if (query.room_desc != null) {
select.eq('room_desc', query.room_desc);
}
if (query.bed_num != null) {
select.eq('bed_num', query.bed_num);
}
if (query.bed_num_use != null) {
select.eq('bed_num_use', query.bed_num_use);
}
// 执行查询并返回计数
var result = await db.query(
'bus_room_info',
condition: select,
);
return result.length;
}
//办理预约入住
addOrderCheckIn(data) async {
var db = EasyDartModule.dataBase;
// 执行插入操作
var result = await db.insert('bus_room_check_info', data);
// 返回是否插入成功
final pipeline = AggregationPipelineBuilder()
// .addStage(Match(where.eq('type', 1).map['\$query']))
// 关联房间表
.addStage(AddFields({
'data.room_info.id': {'\$toObjectId': '\$data.room_info.id'},
'data.bed_info.id': {'\$toObjectId': '\$data.bed_info.id'}
}))
.addStage(Lookup(
from: 'bus_room_info',
localField: 'data.room_info.id',
foreignField: '_id',
as: 'room_info'))
// 关联床位表
.addStage(Lookup(
from: 'bus_bed_info',
localField: 'data.bed_info.id',
foreignField: '_id',
as: 'bed_info'))
// 选择需要的字段
.addStage(Project({
'_id': 1, // 预约表的 _id
'level': 1, // 预约人姓名
'appointment_date': 1, // 预约时间
'status': 1, // 预约状态
'data': 1,
'room_id': {
'\$arrayElemAt': ['\$room_info._id', 0]
}, // 取房间ID
'room_name': {
'\$arrayElemAt': ['\$room_info.room_name', 0]
}, // 取房间名称
'bed_id': {
'\$arrayElemAt': ['\$bed_info._id', 0]
}, // 取床位ID
'bed_name': {
'\$arrayElemAt': ['\$bed_info.bed_name', 0]
} // 取床位名称
}))
.build();
try {
// final db1 = Db('mongodb://192.168.1.80:27017/test');
const host = "192.168.1.80:27017";
const userName = "root";
const password = "123456";
const dataBase = "test";
// 创建连接字符串
final connectionString =
"mongodb://$userName:$password@$host/$dataBase?authSource=admin";
var db1 = await Db.create(connectionString);
await db1.open();
final result1 = await DbCollection(db1, 'bus_message')
.aggregateToStream(pipeline)
.toList();
print(result1);
} catch (e) {
print(e);
}
return result;
}
//删除预约入住
delOrderCheckIn(data) async {
var db = EasyDartModule.dataBase;
// 构建查询条件
// var condition = {'room_id': roomId};
String message = "";
// try {
try {
var roomIdList = data['id'].split(',');
var objectIdList =
roomIdList.map((id) => ObjectId.fromHexString(id)).toList();
var condition = {
'_id': {'\$in': objectIdList}
}; // 使用 \$in 操作符查询多个 ID
var update = {
'\$set': {'deleted': 1}
}; // 逻辑删除,只更新 deleted 字段
var result = await db.update('bus_room_check_info', update, condition,
multiUpdate: true);
return message; // 返回受影响的行数
} catch (e) {
print("Error during deleteRoomType: $e");
message = MessageConstants.DELETE_ERROR;
return message;
}
}
Future<void> addOrderCheckInRuZhuRecord(data) async {
try {
var db = EasyDartModule.dataBase;
// 执行插入操作
var result = await db.insert('bus_ruzhu_info', data);
} catch (e) {
print(e);
}
}
Future<void> addCheckOutRecord(data) async {
try {
var db = EasyDartModule.dataBase;
// 执行插入操作
var result = await db.insert('bus_checkout_info', data);
} catch (e) {
print(e);
}
}
}

View File

@@ -0,0 +1,214 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/RoomType.dart';
import '../const/MessageConstants.dart';
class RoomTypeRepository {
// 获取所有房间类型列表
Future<List> fetchRoomTypeList(RoomType query,
{int page = 1, int pageSize = 10}) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_type_name != null) {
select.match('room_type_name', query.room_type_name!,
caseInsensitive: true);
}
if (query.description != null) {
select.eq('description', query.description);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.updated_by_name != null) {
select.eq('updated_by_name', query.updated_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_time', query.start_time);
}
if (query.end_time != null) {
select.lte('created_time', query.end_time);
}
// 设置分页
select.eq('deleted', 0);
select.skip((page - 1) * pageSize).limit(pageSize);
// 设置排序
select.sortBy("created_at"); // 按 room_type_id 降序排序
// 执行查询,组合查询条件与分页、排序
var result = await db.query(
'bus_room_type',
condition: select, // 查询条件 + 分页 + 排序
);
// 如果查询结果为空,返回空列表
if (result.isEmpty) {
return [];
}
// 返回查询结果
return result;
}
// 获取单个房间类型信息
Future<RoomType?> fetchRoomTypeById(int roomTypeId) async {
var db = EasyDartModule.dataBase;
var condition = {'room_type_id': roomTypeId}; // 使用 room_type_id 为条件
// 执行查询 SQL
var result = await db.query(
'bus_room_type',
condition: condition, // 修正:应该使用 Map 格式的条件
);
// 如果查询到结果,返回房间类型数据
if (result.isNotEmpty) {
return RoomType.fromJson(result.first);
}
// 如果没有找到,返回 null
return null;
}
// 添加房间类型
Future<bool> insertRoomType(RoomType roomType) async {
var db = EasyDartModule.dataBase;
// 执行插入 SQL
var result = await db.insert('bus_room_type', roomType.toJson());
// 如果返回的影响行数大于0说明插入成功
return true; // 确保返回的是影响的行数
}
// 更新房间类型
Future<String> updateRoomType(
String roomTypeId, RoomType updatedRoomType) async {
String message = "";
var db = EasyDartModule.dataBase;
var str = updatedRoomType.toJson();
str.remove("_id");
var updateCondition = {
'_id': ObjectId.fromHexString(roomTypeId),
};
try {
// var result = await db.update('bus_room_type', update, condition);
var result = await db.update('bus_room_type', str, updateCondition);
return message; // 返回受影响的行数
} catch (e) {
message = MessageConstants.UPDATE_ERROR;
return message;
}
}
// 删除房间类型 (逻辑删除前检查是否有房间绑定)
Future<String> deleteRoomType(String roomTypeIds) async {
String message = "";
var db = EasyDartModule.dataBase;
// 将逗号分隔的多个 roomTypeIds 字符串转换为 List
var roomTypeIdList = roomTypeIds.split(',');
// 检查是否有房间绑定这些房间类型
var condition = {
'room_type': {'\$in': roomTypeIdList}
}; // 使用 \$in 操作符查询多个 ID
var rooms = await db.query(
'bus_room_info',
condition: condition,
);
if (rooms.isNotEmpty) {
// 如果有房间绑定这些房间类型,返回 false
message = "房间类型已经被绑定,请先解除房间类型绑定.";
return message;
}
// 如果没有房间绑定,执行逻辑删除操作
try {
var objectIdList =
roomTypeIdList.map((id) => ObjectId.fromHexString(id)).toList();
var condition = {
'_id': {'\$in': objectIdList}
}; // 使用 \$in 操作符查询多个 ID
var update = {
'\$set': {'deleted': 1}
}; // 逻辑删除,只更新 deleted 字段
var result = await db.update('bus_room_type', update, condition);
return message; // 返回受影响的行数
} catch (e) {
print("Error during deleteRoomType: $e");
message = MessageConstants.DELETE_ERROR;
return message;
}
}
Future<int> getRoomTypeCount(RoomType query) async {
var db = EasyDartModule.dataBase;
// 创建查询构建器
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('room_type_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.room_type_name != null) {
select.match('room_type_name', query.room_type_name!,
caseInsensitive: true);
}
if (query.description != null) {
select.eq('description', query.description);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.created_by_name != null) {
select.eq('created_by_name', query.created_by_name);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.updated_by_name != null) {
select.eq('updated_by_name', query.updated_by_name);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_time', query.start_time);
}
if (query.end_time != null) {
select.lte('created_time', query.end_time);
}
select.eq('deleted', 0);
// 执行查询,获取符合条件的记录数量
var result = await db.query(
'bus_room_type',
condition: select, // 查询条件
);
// 如果查询结果为空,返回 0
if (result.isEmpty) {
return 0;
}
// 返回计数结果
return result.length;
}
}

View File

@@ -0,0 +1,75 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/Bed.dart';
class StatisticsRepository {
// 获取床位列表,支持查询条件
Future<List> fetchBedList(Bed query) async {
var db = EasyDartModule.dataBase;
SelectorBuilder select = SelectorBuilder();
// 添加查询条件
if (query.id != null) {
select.eq('_id', query.id);
}
if (query.tid != null) {
select.eq('oid', query.tid);
}
if (query.level != null) {
select.gte('data_level', query.level);
}
if (query.bed_type_id != null) {
select.eq('bed_type_id', query.bed_type_id);
}
if (query.bed_type_name != null) {
select.match('bed_type_name', query.bed_type_name!,
caseInsensitive: true);
}
if (query.bed_name != null) {
select.match('bed_name', query.bed_name!, caseInsensitive: true);
}
if (query.is_mapped != null) {
select.eq('is_mapped', query.is_mapped == true ? 1 : 0);
}
if (query.device_model != null) {
select.match('device_model', query.device_model!, caseInsensitive: true);
}
if (query.device_name != null) {
select.match('device_name', query.device_name!, caseInsensitive: true);
}
if (query.device_id != null) {
select.eq('device_id', query.device_id);
}
if (query.status != null) {
select.eq('status', query.status);
}
if (query.created_by_id != null) {
select.eq('created_by_id', query.created_by_id);
}
if (query.updated_by_id != null) {
select.eq('updated_by_id', query.updated_by_id);
}
if (query.oid != null) {
select.eq('oid', query.oid);
}
if (query.start_time != null) {
select.gte('created_at', query.start_time);
}
if (query.end_time != null) {
select.lte('created_at', query.end_time);
}
if (query.deleted != null) {
select.eq('deleted', query.deleted);
}
// 执行查询
var result = await db.query('bus_bed_info', condition: select);
// 如果查询结果为空,返回空列表
return result.isEmpty ? [] : result;
}
addStatisticsDayResult() {
}
}

View File

@@ -0,0 +1,9 @@
import 'package:EasyDartModule/EasyDartModule.dart';
class TestRepository {
static Future<List<Map<String, dynamic>>> query() {
return EasyDartModule.dataBase.query(
"test",
);
}
}

File diff suppressed because it is too large Load Diff

1692
bin/service/AreaService.dart Normal file

File diff suppressed because it is too large Load Diff

124
bin/service/BedService.dart Normal file
View File

@@ -0,0 +1,124 @@
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/Bed.dart';
import '../model/Person.dart';
import '../model/Reservation.dart';
import '../repository/BedRepository.dart';
import '../enum/DeviceStatus.dart';
class BedService {
final BedRepository bedRepository = BedRepository();
BedService();
// 获取床位列表,支持查询参数
Future<List> getBedList(Bed query) async {
if (query.device_status != null && query.device_status!.isNotEmpty) {
List<String> status = query.device_status!.split(",");
if (status.length != 2) {
// 查询所有的设备
var allDevices =
await EasyDartModule.redis.get("oid_${query.tid}_devices");
if (allDevices != null && allDevices.isNotEmpty) {
List<String> deviceList = allDevices.split(',');
if (status[0] == '0') {
// 查询离线设备
List<String> offlineDevices = [];
for (var deviceId in deviceList) {
var isOnline = await EasyDartModule.redis.get("oid_${deviceId}");
if (isOnline == null) {
offlineDevices.add(deviceId);
}
}
query.deviceIds = offlineDevices;
}
if (status[0] == '1') {
// 查询在线设备
List<String> onlineDevices = [];
for (var deviceId in deviceList) {
var isOnline = await EasyDartModule.redis.get("oid_${deviceId}");
if (isOnline != null) {
onlineDevices.add(deviceId);
}
}
query.deviceIds = onlineDevices;
}
}
}
}
List bedList = await bedRepository.fetchBedList(query);
if (bedList.isNotEmpty) {
fillDeviceStatus(bedList);
}
return bedList;
}
// 获取单个床位信息
Future<Map?> getBedById(String bedId) async {
return await bedRepository.fetchBedById(bedId);
}
// 创建床位
Future<bool> createBed(Bed bed) async {
// 直接将异常抛给调用者
bed.created_at = DateTime.now().millisecondsSinceEpoch;
bed.deleted = 0;
return await bedRepository.insertBed(bed);
}
// 更新床位信息
Future<String> updateBed(String bedId, Bed updatedBed) async {
// 直接将异常抛给调用者
updatedBed.updated_at = DateTime.now().millisecondsSinceEpoch;
return await bedRepository.updateBed(bedId, updatedBed);
}
// 删除床位
Future<String> deleteBed(String bedId) async {
// 直接将异常抛给调用者
if (bedId == null || bedId.isEmpty) {
return "ID不能为空";
}
return await bedRepository.deleteBed(bedId);
}
Future<int> getBedCount(Bed query) async {
return await bedRepository.getBedCount(query);
}
//查询预约入住信息
getOrderCheckIn(Reservation query) async {
return await bedRepository.getOrderCheckInList(query);
}
//设备在离线
void fillDeviceStatus(List bedList) {
try {
if (bedList.isNotEmpty) {
bedList.forEach((bed) async {
if (bed['device_id'] != null) {
String deviceId = bed['device_id'];
if (deviceId != null && deviceId.isNotEmpty) {
var deviceStatus =
await EasyDartModule.redis.get("mac_$deviceId");
if (deviceStatus != null) {
bed['device_status'] = DeviceStatus.ONLINE.code;
} else {
bed['device_status'] = DeviceStatus.OFFLONE.code;
}
bed['map_device_status'] = deviceStatus;//地图设备状态
}
}
});
}
} catch (e) {
print(e);
}
}
//更新床位状态
Future<void> updateBedStatus(String bed_id, int code, Person person) async {
await bedRepository.updateBedStatus(bed_id, code, person);
}
}

View File

@@ -0,0 +1,38 @@
import '../model/BedType.dart';
import '../repository/BedTypeRepository.dart';
class BedTypeService {
final BedTypeRepository bedTypeRepository = BedTypeRepository();
BedTypeService();
// 获取床位类型列表
Future<List> getBedTypeList(BedType query) async {
return await bedTypeRepository.fetchBedTypeList(query);
}
// 添加床位类型
Future<bool> addBedType(BedType bedType) async {
bedType.created_at = DateTime.now().millisecondsSinceEpoch;
bedType.deleted = 0;
return await bedTypeRepository.insertBedType(bedType);
}
// 更新床位类型
Future<String> updateBedType(String bedTypeId, BedType updatedBedType) {
updatedBedType.updated_at = DateTime.now().millisecondsSinceEpoch;
return bedTypeRepository.updateBedType(bedTypeId, updatedBedType);
}
// 删除床位类型
Future<String> deleteBedType(String bedTypeId) async {
if (bedTypeId == null || bedTypeId.isEmpty) {
return "ID不能为空";
}
return await bedTypeRepository.deleteBedType(bedTypeId);
}
Future<int> getBedTypeCount(BedType query) async {
return await bedTypeRepository.getBedTypeCount(query);
}
}

View File

@@ -0,0 +1,22 @@
import '../repository/DictionaryTypeRepository.dart';
import '../model/DictionaryType.dart';
class DictionaryService {
final DictionaryTypeRepository dictionaryRepository = DictionaryTypeRepository();
Future<List<DictionaryType>> getDictionaryList(DictionaryType query) async {
return await dictionaryRepository.fetchDictionaryList(query);
}
Future<bool> addDictionary(DictionaryType DictionaryType) async {
return await dictionaryRepository.insertDictionary(DictionaryType);
}
Future<String> updateDictionary(String id, DictionaryType DictionaryType) async {
return await dictionaryRepository.updateDictionary(id, DictionaryType);
}
Future<String> deleteDictionary(String id) async {
return await dictionaryRepository.deleteDictionary(id);
}
}

View File

@@ -0,0 +1,43 @@
import '../model/DiseaseType.dart';
import '../repository/DiseaseTypeRepository.dart';
class DiseaseTypeService {
final DiseaseTypeRepository diseaseTypeRepository = DiseaseTypeRepository();
DiseaseTypeService();
// 获取疾病类型列表
Future<List> getDiseaseTypeList(DiseaseType query) async {
return await diseaseTypeRepository.fetchDiseaseTypeList(query);
}
// 添加疾病类型
Future<bool> addDiseaseType(DiseaseType diseaseType) async {
diseaseType.created_at = DateTime.now().millisecondsSinceEpoch;
diseaseType.deleted = 0;
return await diseaseTypeRepository.insertDiseaseType(diseaseType);
}
// 更新疾病类型
Future<String> updateDiseaseType(String diseaseTypeId, DiseaseType updatedDiseaseType) {
updatedDiseaseType.updated_at = DateTime.now().millisecondsSinceEpoch;
return diseaseTypeRepository.updateDiseaseType(diseaseTypeId, updatedDiseaseType);
}
// 删除疾病类型
Future<String> deleteDiseaseType(String diseaseTypeId) async {
if (diseaseTypeId == null || diseaseTypeId.isEmpty) {
return "ID不能为空";
}
return await diseaseTypeRepository.deleteDiseaseType(diseaseTypeId);
}
Future<int> getDiseaseTypeCount(DiseaseType query) async {
return await diseaseTypeRepository.getDiseaseTypeCount(query);
}
// 获取疾病类型
Future<List> fetchDiseaseTypesByOrganizationId(String oid) async {
return await diseaseTypeRepository.fetchDiseaseTypeListByOrganization(oid);
}
}

View File

@@ -0,0 +1,12 @@
class InstantAlarmService {
InstantAlarmService();
void judgeAlarm(var instantData) {
}
}

View File

@@ -0,0 +1,64 @@
import '../repository/PersonRepository.dart';
import '../model/Person.dart';
import '../service/BedService.dart';
class PersonService {
final PersonRepository personRepository = PersonRepository();
final BedService bedService = BedService();
// 获取所有人员
Future<List> getPersonList(Person query,
{int page = 1, int pageSize = 10}) async {
var personList = await personRepository.fetchPersonList(
query,
);
try {
if (personList.isNotEmpty) {
for (var person in personList) {
if (person['bed_id'] != null && person['bed_id']!.isNotEmpty) {
var bedInfo = await bedService.getBedById(person['bed_id']);
if (bedInfo != null) {
person['device_mac'] = bedInfo!['device_id'];
}
}
}
return personList;
}
} catch (e) {
print(e);
}
return [];
}
// 获取单个人员信息
Future<Person?> getPersonById(String personId) async {
return await personRepository.fetchPersonById(personId);
}
// 添加人员
Future<bool> addPerson(Person person) async {
person.created_at = DateTime.now().millisecondsSinceEpoch;
person.deleted = 0;
return await personRepository.insertPerson(person);
}
// 更新人员信息
Future<String> updatePerson(String personId, Person updatedPerson) async {
updatedPerson.updated_at = DateTime.now().millisecondsSinceEpoch;
return await personRepository.updatePerson(personId, updatedPerson);
}
// 删除人员,检查是否有绑定
Future<String> deletePerson(String personId) async {
return await personRepository.deletePerson(personId);
}
fetchPersonsByOrganizationId(String oid) async {
return await personRepository.fetchPersonsByOrganizationId(oid);
}
getPersonCount(Person query) async {
return await personRepository.getPersonCount(query);
}
}

View File

@@ -0,0 +1,33 @@
import '../model/PersonType.dart';
import '../repository/PersonTypeRepository.dart';
class PersonTypeService {
final PersonTypeRepository personTypeRepository = PersonTypeRepository();
// 获取所有人员类型
Future<List> getPersonTypeList(PersonType query, {int page = 1, int pageSize = 10}) async {
return await personTypeRepository.fetchPersonTypeList(query, page: page, pageSize: pageSize);
}
// 添加人员类型
Future<bool> addPersonType(PersonType personType) async {
personType.created_at = DateTime.now().millisecondsSinceEpoch;
personType.deleted = 0;
return await personTypeRepository.insertPersonType(personType);
}
// 更新人员类型
Future<String> updatePersonType(String personTypeId, PersonType updatedPersonType) async {
updatedPersonType.updated_at = DateTime.now().millisecondsSinceEpoch;
return await personTypeRepository.updatePersonType(personTypeId, updatedPersonType);
}
// 删除人员类型,检查是否有人员绑定该类型
Future<String> deletePersonType(String personTypeId) async {
bool isBoundToPerson = await personTypeRepository.checkPersonTypeBinding(personTypeId);
if (isBoundToPerson) {
return "人员类型已经被绑定,请先解除人员类型绑定."; // 如果有人员绑定,不能删除
}
return await personTypeRepository.deletePersonType(personTypeId);
}
}

View File

@@ -0,0 +1,336 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import '../model/Room.dart';
import '../repository/RoomRepository.dart';
import '../service/BedService.dart';
import '../service/PersonService.dart';
import '../model/Bed.dart';
import '../model/Person.dart';
import '../const/ServiceConstant.dart';
import '../const/MessageType.dart';
import '../const/RuzhuMessageType.dart';
import '../const/Constants.dart';
import '../enum/BedStatus.dart';
import '../enum/MessageStatus.dart';
class RoomService {
final RoomRepository roomRepository = RoomRepository();
final BedService bedService = BedService();
final PersonService personService = PersonService();
RoomService();
// 获取房间列表
Future<List> getRoomList(Room query,
{int page = 1, int pageSize = 10,bool fill = true,}) async {
var roomList = await roomRepository.fetchRoomList(query,
page: page, pageSize: pageSize);
if (roomList != null && roomList.isNotEmpty && fill) {
await fillRoomInfo(roomList);
}
return roomList;
}
// 获取房间数量
Future<int> getRoomCount(Room query) async {
return await roomRepository.getRoomCount(query);
}
// 添加房间
Future<String> addRoom(Room room) async {
if (room.room_type == null || room.room_type!.isEmpty) {
return "请选择房间类型";
}
int currentTime = DateTime.now().millisecondsSinceEpoch;
room.created_at = currentTime;
room.deleted = 0;
await roomRepository.insertRoom(room);
return "";
}
// 更新房间
Future<String> updateRoom(String roomId, Room updatedRoom) {
int currentTime = DateTime.now().millisecondsSinceEpoch;
updatedRoom.updated_at = currentTime;
return roomRepository.updateRoom(roomId, updatedRoom);
}
// 删除房间
Future<String> deleteRoom(String roomId) async {
if (roomId == null || roomId.isEmpty) {
return "ID不能为空";
}
return await roomRepository.deleteRoom(roomId);
}
//办理预约入住
addOrderCheckIn(data, Map<String, dynamic> jwt) {
int currentTime = DateTime.now().millisecondsSinceEpoch;
data['create_at'] = currentTime;
data['deleted'] = 0;
data['create_user_id'] = jwt['uid'];
return roomRepository.addOrderCheckIn(data);
}
//删除预约入住
delOrderCheckIn(data) {
return roomRepository.delOrderCheckIn(data);
}
//填充床位信息
Future<String> fillRoomInfo(List roomList) async {
try {
if (roomList == null || roomList.isEmpty) {
return "";
}
for (var item in roomList) {
String roomId = item['_id'].toHexString();
//根据roomid查询床位数
Bed bedQuery = Bed();
bedQuery.room_id = roomId;
bedQuery.limit = Constants.default_limit_max.toString();
List bedList = await bedService.getBedList(bedQuery);
if (bedList == null || bedList.isEmpty) {
item['bed_count'] = 0; //总床位数
item['bed_use_count'] = 0; //可使用床位数
} else {
item['bed_count'] = bedList.length;
//根据床位id查询使用数
try {
String bedIdsString = bedList
.map((bed) {
var id = bed['_id'];
return id is ObjectId ? id.toHexString() : id.toString();
}) // 提取 _id 字段并转换为字符串
.where((id) => id != null) // 过滤掉 null 的值
.join(','); // 用逗号连接成一个字符串
Person personQuery = Person();
personQuery.bed_ids = bedIdsString;
personQuery.limit = Constants.default_limit_max.toString();
var persons = await personService.getPersonList(personQuery,
page: 1, pageSize: Constants.default_limit_max);
if (persons == null || persons.isEmpty) {
item['bed_use_count'] = item['bed_count'];
} else {
item['bed_use_count'] = item['bed_count'] - persons.length;
}
} catch (e) {
print(e);
}
}
}
return "";
} catch (e) {
print(e);
return "";
}
}
//添加预约消息
Future<void> addReservationMessage(data, Map<String, dynamic> jwt) async {
//todo 根据jwt取登录用户信息
data['ruzhu_msg_type'] = RuzhuMessageType.reservation.code;
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.message_service;
String serviceApi = ServiceConstant.addMessage;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
var createTime = DateTime.now().millisecondsSinceEpoch;
var status = MessageStatus.notify.code; //消息状态 0:无需处理 1:待处理 2:已处理
var info = {
'room_id': data['room_id'],
'bed_id': data['bed_id'],
'start_time': data['start_time'].toString(),
'end_time': data['end_time'].toString(),
'rel_name': data['rel_name'],
'ship': data['ship'],
'ruzhu_msg_type': data['ruzhu_msg_type'],
'create_user_id': jwt['uid'],
'bed_name':data['bed_name'],
'room_name':data['room_name'],
};
var pushData = {
'level': 1,
'createTime': createTime,
'type': MessageType.check_in.code,
'status': status,
'tid': jwt['tid'],
'data': info,
};
try {
var res =
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(pushData));
print(res);
} catch (e) {
print(e);
}
}
//办理入住信息
addRuzhuCheckIn(data, Map<String, dynamic> jwt) async {
//添加人员信息
//todo 如果是已有人员信息??
int currentTime = DateTime.now().millisecondsSinceEpoch;
Person person = Person();
person.room_id = data['room_id'];
person.room_name = data['room_name'];
person.bed_id = data['bed_id'];
person.bed_name = data['bed_name'];
person.check_in_start_time = data['start_time'];
person.check_in_end_time = data['end_time'];
person.contact_name = data['rel_name'];
person.person_name = data['person_name'];
person.gender = data['gender'];
person.ethnicity = data['minzu'];
person.person_type_id = data['person_type'];
person.person_type_name = data['person_type_name'];
person.id_card_number = data['cardNo'];
person.phone_number = data['phone'];
person.service_level = data['service_level'];
person.height = data['height'];
person.weight = data['weight'];
person.tid = jwt['tid'];
person.level = jwt['level'];
person.age = data['age'];
person.desc = data['desc'];
person.contact_relationship = data['ship'];
person.contact_phone = data['tel'];
person.oid = jwt['tid'];
person.data_level = jwt['level'];
personService.addPerson(person);
//更改床位状态
await bedService.updateBedStatus(
data['bed_id'], BedStatus.using.code, person);
//发送入住消息
addRuzhuMessage(data, jwt);
//添加入住记录
addRuzhuRecord(data, jwt);
}
//添加入住消息
Future<void> addRuzhuMessage(data, Map<String, dynamic> jwt) async {
data['ruzhu_msg_type'] = RuzhuMessageType.check_in.code;
data['create_user_id'] = jwt['uid'];
data['start_time'] = data['start_time'].toString();
data['end_time'] = data['end_time'].toString();
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.message_service;
String serviceApi = ServiceConstant.addMessage;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
var createTime = DateTime.now().millisecondsSinceEpoch;
var status = MessageStatus.notify.code; //消息状态 0:无需处理 1:待处理 2:已处理
// var info = {
// 'room_id': data['room_id'],
// 'bed_id': data['bed_id'],
// 'start_time': data['start_time'],
// 'end_time': data['end_time'],
// 'rel_name': data['rel_name'],
// 'ship': data['ship'],
// 'ruzhu_msg_type': data['ruzhu_msg_type'],
// };
var pushData = {
'level': 1,
'createTime': createTime,
'type': MessageType.check_in.code,
'status': status,
'tid': jwt['tid'],
'data': data,
};
try {
var res =
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(pushData));
print(res);
} catch (e) {
print(e);
}
}
//办理退住
checkout(data, Map<String, dynamic> jwt) async {
// 1.更新人员信息 当前正在该床位入住的人员??有什么需要更新,正在入住的房间,床位?
// 2.添加退住记录
// 3.发送退住消息
// 4.更新床位状态
String bedId = data['bed_id'];
data['create_user_id'] = jwt['uid'];
//更新床位状态
Person person = Person();
await bedService.updateBedStatus(bedId, BedStatus.no_using.code, person);
person.bed_id = bedId;
List personlist = await personService.getPersonList(person);
try {
if (personlist != null && personlist.isNotEmpty) {
var personSelect = personlist[0];
// 添加退住记录
await addCheckOutRecord(data, jwt, personSelect);
//发送退住消息
await addCheckOutMessage(personSelect, jwt,data);
//更新人员信息
await personService.updatePerson(
personSelect['_id'].toHexString(), person);
}
} catch (e) {
print(e);
}
}
//添加入住记录
void addRuzhuRecord(data, Map<String, dynamic> jwt) {
//问题 记录人员入住,怎么查询人员入住历史
int currentTime = DateTime.now().millisecondsSinceEpoch;
data['create_at'] = currentTime;
data['deleted'] = 0;
data['create_user_id'] = jwt['uid'];
roomRepository.addOrderCheckInRuZhuRecord(data);
}
//添加退住消息
Future<void> addCheckOutMessage(data, Map<String, dynamic> jwt, bedInfo) async {
Map info = {};
info['ruzhu_msg_type'] = RuzhuMessageType.check_out.code;
info['bed_id'] = bedInfo['bed_id'];
info['bed_name'] = bedInfo['bed_name'];
info['room_name'] = bedInfo['room_name'];
info['room_id'] = bedInfo['room_id'];
info['person_id'] = data['_id'].toHexString();
info['person_name'] = data['person_name'];
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.message_service;
String serviceApi = ServiceConstant.addMessage;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
var createTime = DateTime.now().millisecondsSinceEpoch;
var status = MessageStatus.notify.code; //消息状态 0:无需处理 1:待处理 2:已处理
var pushData = {
'level': 1,
'createTime': createTime,
'type': MessageType.check_in.code,
'status': status,
'tid': jwt['tid'],
'data': info,
};
try {
var res =
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(pushData));
print(res);
} catch (e) {
print(e);
}
}
//添加退住记录
Future<void> addCheckOutRecord(
data, Map<String, dynamic> jwt, personSelect) async {
//问题 记录人员入住,怎么查询人员入住历史
int currentTime = DateTime.now().millisecondsSinceEpoch;
data['create_at'] = currentTime;
data['deleted'] = 0;
data['create_user_id'] = jwt['uid'];
data['person_id'] = personSelect['_id'];
data['person_name'] = personSelect['person_name'];
//查询当前使用该床位的人员
await roomRepository.addCheckOutRecord(data);
}
}

Some files were not shown because too many files have changed in this diff Show More