This commit is contained in:
dzc committed 2026-09-11 15:29:06 +08:00
1 parent 58a8a1ffde
commit fdec7bed06
16 files changed
+637 -118

No files matched your search

@@ -89,6 +89,8 @@ public class DataBaseUtils {
// 状态检查专用轻量查询:只读取数量与 sampleId 集合所需列,不加载 faceModel 特征大字段。
// face 表把特征以 JSON 文本存在行内(每条约数 KB),SELECT * 全表读取会反复撑爆 2MB
// CursorWindow 并把调用线程阻塞数秒;状态一致性比较不需要特征数据。
// 空特征行(含 NULL、空串和 '[]')永远注册不进虹软内存库,不计入一致性集合,
// 避免它们让 memoryCount 与 databaseCount 永久不等、收银弹框反复触发整库重装。
static public List<FaceEntity> getFaceProfiles(Context context, String queryUserId) {
List<FaceEntity> result = new ArrayList<>();
DatabaseHelper databaseHelper = null;
@@ -97,9 +99,10 @@ public class DataBaseUtils {
try {
databaseHelper = new DatabaseHelper(context);
database = databaseHelper.getWritableDatabase();
String sql = "SELECT userId, sampleId, userName, path FROM face";
String sql = "SELECT userId, sampleId, userName, path FROM face"
+ " WHERE faceModel IS NOT NULL AND faceModel != '' AND faceModel != '[]'";
if (Objects.nonNull(queryUserId) && !Objects.equals(queryUserId, "")) {
sql = sql.concat(" WHERE userId = ?");
sql = sql.concat(" AND userId = ?");
cursor = database.rawQuery(sql, new String[]{queryUserId});
} else {
cursor = database.rawQuery(sql, null);
@@ -15,8 +15,13 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_PATH = "pj_cashier/database";
private static final String DATABASE_NAME = "cash_register.db";
/** 与 Flutter Floor 的 @Database 版本保持一致,避免原生层提前推进 user_version。 */
private static final int DATABASE_VERSION = 13;
/**
* 必须与 Flutter Floor 的 @Database 版本保持同步
* (lib/common/services/database/database.dart)。
* 历史上此值曾误用兄弟项目编号 13,把 user_version 提前盖章到 13 导致
* Floor 跳过 11-13 区间迁移;双方现已一致跳到 14,后续升级必须同时修改。
*/
private static final int DATABASE_VERSION = 14;
public DatabaseHelper(Context context) {
super(context, getCustomDatabasePath(context), null, DATABASE_VERSION);
@@ -44,6 +49,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
if (oldVersion < 12) {
migrateFaceQuality(db);
}
if (oldVersion < 14) {
migrateFaceQualityReport(db);
}
}
/**
* 从版本13无损补齐质量上报确认列,与 Flutter Floor 的 migration13To14 内容一致。
* 正常时序下 Floor 总是先打开数据库完成迁移,本方法只是极端时序下的兜底。
*/
private void migrateFaceQualityReport(SQLiteDatabase db) {
if (!hasColumn(db, "face", "qualityReportedAt")) {
db.execSQL("ALTER TABLE face ADD COLUMN qualityReportedAt TEXT");
}
// Floor 读取 faceModel 使用非空强转,NULL 历史脏行规范化为空串。
db.execSQL("UPDATE face SET faceModel = '' WHERE faceModel IS NULL");
}
/**
@@ -120,6 +120,7 @@ public class FlutterTool {
if (activated) faceServer.init(context);
// 状态检查只需要数量与 sampleId 集合,走不含 faceModel 大字段的轻量查询,
// 避免整库特征 JSON 反序列化把调用线程(主线程)阻塞数秒。
// 查询已过滤空特征行:databaseCount 与一致性集合都只统计可注册样本。
List<FaceEntity> databaseFaces = getFaceProfiles(context, null);
int databaseCount = databaseFaces.size();
int memoryCount = activated && faceServer.isEngineReady() ? Math.max(faceServer.getTotalFaceCount(), 0) : 0;