65 lines
1.9 KiB
Dart
65 lines
1.9 KiB
Dart
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);
|
|
}
|
|
}
|