初始提交
This commit is contained in:
1606
bin/service/AreaService copy.dart
Normal file
1606
bin/service/AreaService copy.dart
Normal file
File diff suppressed because it is too large
Load Diff
1692
bin/service/AreaService.dart
Normal file
1692
bin/service/AreaService.dart
Normal file
File diff suppressed because it is too large
Load Diff
124
bin/service/BedService.dart
Normal file
124
bin/service/BedService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
38
bin/service/BedTypeService.dart
Normal file
38
bin/service/BedTypeService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
22
bin/service/DictionaryService.dart
Normal file
22
bin/service/DictionaryService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
43
bin/service/DiseaseTypeService.dart
Normal file
43
bin/service/DiseaseTypeService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
12
bin/service/InstantAlarmService.dart
Normal file
12
bin/service/InstantAlarmService.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
class InstantAlarmService {
|
||||
|
||||
|
||||
InstantAlarmService();
|
||||
|
||||
void judgeAlarm(var instantData) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
bin/service/PersonService.dart
Normal file
64
bin/service/PersonService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
33
bin/service/PersonTypeService.dart
Normal file
33
bin/service/PersonTypeService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
336
bin/service/RoomService.dart
Normal file
336
bin/service/RoomService.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
38
bin/service/RoomTypeService.dart
Normal file
38
bin/service/RoomTypeService.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import '../model/RoomType.dart';
|
||||
import '../repository/RoomTypeRepository.dart';
|
||||
|
||||
class RoomTypeService {
|
||||
final RoomTypeRepository roomTypeRepository = RoomTypeRepository();
|
||||
|
||||
RoomTypeService();
|
||||
|
||||
// 获取房间类型列表
|
||||
Future<List> getRoomTypeList(RoomType query) async {
|
||||
return await roomTypeRepository.fetchRoomTypeList(query);
|
||||
}
|
||||
|
||||
// 添加房间类型
|
||||
Future<bool> addRoomType(RoomType roomType) async {
|
||||
roomType.created_at = DateTime.now().millisecondsSinceEpoch;
|
||||
roomType.deleted = 0;
|
||||
return await roomTypeRepository.insertRoomType(roomType);
|
||||
}
|
||||
|
||||
// 更新房间类型
|
||||
Future<String> updateRoomType(String roomTypeId, RoomType updatedRoomType) {
|
||||
updatedRoomType.updated_at = DateTime.now().millisecondsSinceEpoch;
|
||||
return roomTypeRepository.updateRoomType(roomTypeId, updatedRoomType);
|
||||
}
|
||||
|
||||
// 删除房间类型
|
||||
Future<String> deleteRoomType(String roomTypeId) async {
|
||||
if (roomTypeId == null || roomTypeId.isEmpty) {
|
||||
return "ID不能为空";
|
||||
}
|
||||
return await roomTypeRepository.deleteRoomType(roomTypeId);
|
||||
}
|
||||
|
||||
Future<int> getRoomTypeCount(RoomType query) async {
|
||||
return await roomTypeRepository.getRoomTypeCount(query);
|
||||
}
|
||||
}
|
||||
14
bin/service/TokenService.dart
Normal file
14
bin/service/TokenService.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
|
||||
import '../repository/AreaRepository.dart';
|
||||
|
||||
class TokenService {
|
||||
final AreaRepository areaRepository = AreaRepository();
|
||||
|
||||
TokenService();
|
||||
|
||||
// 获取token信息
|
||||
Future<String?> getToken(String oid) async {
|
||||
return await EasyDartModule.redis.get("oid_token_"+oid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user