初始提交
This commit is contained in:
165
bin/repository/AreaRepository.dart
Normal file
165
bin/repository/AreaRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
481
bin/repository/BedRepository.dart
Normal file
481
bin/repository/BedRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
191
bin/repository/BedTypeRepository.dart
Normal file
191
bin/repository/BedTypeRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
149
bin/repository/DictionaryTypeRepository.dart
Normal file
149
bin/repository/DictionaryTypeRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
209
bin/repository/DiseaseTypeRepository.dart
Normal file
209
bin/repository/DiseaseTypeRepository.dart
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
391
bin/repository/PersonRepository.dart
Normal file
391
bin/repository/PersonRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
136
bin/repository/PersonTypeRepository.dart
Normal file
136
bin/repository/PersonTypeRepository.dart
Normal 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
|
||||
}
|
||||
}
|
||||
302
bin/repository/RoomRepository.dart
Normal file
302
bin/repository/RoomRepository.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
214
bin/repository/RoomTypeRepository.dart
Normal file
214
bin/repository/RoomTypeRepository.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
75
bin/repository/StatisticsRepository.dart
Normal file
75
bin/repository/StatisticsRepository.dart
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
||||
9
bin/repository/TestRepository.dart
Normal file
9
bin/repository/TestRepository.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
|
||||
class TestRepository {
|
||||
static Future<List<Map<String, dynamic>>> query() {
|
||||
return EasyDartModule.dataBase.query(
|
||||
"test",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user