diff --git a/lib/common/services/database/dao/face_dao.dart b/lib/common/services/database/dao/face_dao.dart index a0223fe..b790cc2 100644 --- a/lib/common/services/database/dao/face_dao.dart +++ b/lib/common/services/database/dao/face_dao.dart @@ -74,4 +74,9 @@ abstract class FaceDao { SELECT DISTINCT a.deptId FROM face a WHERE a.deptId IS NOT NULL ''') Future> findAllUserIds(); + + @Query(''' + SELECT * FROM face WHERE faceModel = '' OR faceModel IS NULL + ''') + Future?> getEmptyFaceList(); } diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 9083bdf..f80be69 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -1624,6 +1624,26 @@ class _$FaceDao extends FaceDao { mapper: (Map row) => row.values.first as String); } + @override + Future?> getEmptyFaceList() async { + return _queryAdapter.queryList( + 'SELECT * FROM face WHERE faceModel = \'\' OR faceModel IS NULL', + mapper: (Map row) => FaceEntity( + id: row['id'] as int?, + userId: row['userId'] as String, + sampleId: row['sampleId'] as String, + userName: row['userName'] as String, + deptId: row['deptId'] as String?, + deptName: row['deptName'] as String?, + imagePath: row['imagePath'] as String, + path: row['path'] as String?, + faceModel: _listIntConverter.decode(row['faceModel'] as String), + createTime: + _dateTimeEmptyConverter.decode(row['createTime'] as String), + updateTime: + _dateTimeEmptyConverter.decode(row['updateTime'] as String))); + } + @override Future save(FaceEntity entity) { return _faceEntityInsertionAdapter.insertAndReturnId( diff --git a/lib/common/utils/sync/sync_face_tool.dart b/lib/common/utils/sync/sync_face_tool.dart index b68cf8d..e83dee5 100644 --- a/lib/common/utils/sync/sync_face_tool.dart +++ b/lib/common/utils/sync/sync_face_tool.dart @@ -9,6 +9,20 @@ import 'package:pj_supermarket_cloud/common/index.dart'; class SyncFaceTool { static const _tag = "sync人脸工具"; + // 删除数据库中为空的人脸 + static Future delEmptyFace() async { + final app = Get.find(); + final faceDao = app.dataBase.getFaceDao; + final faceList = await faceDao.getEmptyFaceList(); + if (ObjectUtil.isEmptyList(faceList)) return; + for (final v in faceList!) { + if (ObjectUtil.isNotEmpty(v.path)) { + await delFaceByStorage(filePath: v.path!); + } + await faceDao.delById(v.id!); + } + } + // 同步人脸 static Future syncFace({ bool isAll = false, diff --git a/lib/common/widgets/order/select_pay_type_dialog.dart b/lib/common/widgets/order/select_pay_type_dialog.dart index 5a7e5ca..af3333b 100644 --- a/lib/common/widgets/order/select_pay_type_dialog.dart +++ b/lib/common/widgets/order/select_pay_type_dialog.dart @@ -327,6 +327,7 @@ class SelectPayTypeDialogController extends GetxController { } final faceCount = await FaceDiscernPlugs.getFaceCount(); if (faceCount == 0) { + await SyncFaceTool.delEmptyFace(); await AppFaceTool.faceRegister(); } final isJump = await AppFaceTool.jumpFacePage(); diff --git a/lib/pages/setting/widgets/setting_face.dart b/lib/pages/setting/widgets/setting_face.dart index b6d0549..74e2ed3 100644 --- a/lib/pages/setting/widgets/setting_face.dart +++ b/lib/pages/setting/widgets/setting_face.dart @@ -100,6 +100,7 @@ class FaceManageController extends GetxController { maskType: EasyLoadingMaskType.black, ); try { + await SyncFaceTool.delEmptyFace(); await SyncFaceTool.syncFace( isAll: isAll, onSyncGroup: () {