feat:交易记录、日期组建
This commit is contained in:
1 parent
08ad1c2d81
commit
88e73ad950
32 files changed
+672
-279
No files matched your search
@@ -4,14 +4,15 @@ import 'package:common_utils/common_utils.dart';
|
||||
import 'package:external_path/external_path.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
abstract class AppFileTool {
|
||||
static const _tag = "app文件工具";
|
||||
static const _baseDir = "pj";
|
||||
static const _baseBackupDir = "backup";
|
||||
static const _backupDatabaseDir = ".database";
|
||||
static const _backupDatabaseDir = "database";
|
||||
static const _backupLoggerDir = "logger";
|
||||
static const _backupFaceDir = ".face";
|
||||
static const _backupFaceDir = "face";
|
||||
|
||||
/// 检查并创建目录
|
||||
static Future<String> _checkAndcreateDir(String dir) async {
|
||||
@@ -53,14 +54,14 @@ abstract class AppFileTool {
|
||||
|
||||
/// 创建数据库文件备份地址
|
||||
static Future<String?> getDatabaseBackupPath() async {
|
||||
String backupDir = await getExternalPath();
|
||||
String backupDir = await getExternalPath(backupExternalPath: false);
|
||||
String dir = "$backupDir/$_baseBackupDir/$_backupDatabaseDir";
|
||||
DateTime now = DateTime.now();
|
||||
int year = now.year;
|
||||
int month = now.month;
|
||||
int day = now.day;
|
||||
dir = "$dir/$year-$month";
|
||||
dir = await _checkAndcreateDir(backupDir);
|
||||
dir = await _checkAndcreateDir(dir);
|
||||
dir = "$dir/$day.db";
|
||||
return dir;
|
||||
}
|
||||
@@ -104,13 +105,18 @@ abstract class AppFileTool {
|
||||
logger.e("|$_tag|备份sql文件失败,无效的sourcePath路径path:|$sourcePath|");
|
||||
return false;
|
||||
}
|
||||
final databaseFilePath = "$sourcePath${Constants.databaseName}";
|
||||
if (await File(databaseFilePath).exists()) {
|
||||
logger.w("|$_tag|备份sql文件失败,无效的sourcePath路径path|$databaseFilePath|");
|
||||
return false;
|
||||
}
|
||||
String? backupPath = await getDatabaseBackupPath();
|
||||
if (ObjectUtil.isEmpty(backupPath)) {
|
||||
logger.e("|$_tag|备份sql文件失败,无效的backupPath路径path:|$backupPath|");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await File("$sourcePath/${Constants.databaseName}").copy(backupPath!);
|
||||
await File(databaseFilePath).copy(backupPath!);
|
||||
return true;
|
||||
} catch (e, stack) {
|
||||
logger.e("|$_tag|备份sql文件失败,意外的错误error|$e|stack|$stack|");
|
||||
@@ -118,5 +124,45 @@ abstract class AppFileTool {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有数据库将最新的数据库移动为使用的数据库
|
||||
static Future<void> useLastBackDatabase() async {
|
||||
final databasePath = getDatabasesPath();
|
||||
final databaseFilePath = "$databasePath${Constants.databaseName}";
|
||||
if (await File(databaseFilePath).exists()) {
|
||||
logger.w("|$_tag|替换数据库错误,数据库文件已存在path|$databaseFilePath|");
|
||||
return;
|
||||
}
|
||||
final path = await getDatabaseBackupPath();
|
||||
if (ObjectUtil.isEmpty(path)) {
|
||||
logger.w("|$_tag|替换数据库错误,无效的数据库备份path|$path|");
|
||||
return;
|
||||
}
|
||||
final dir = Directory(path!).parent;
|
||||
if (!await dir.exists()) {
|
||||
logger.w("|$_tag|替换数据库错误,无效的数据库备份目录path|$dir|");
|
||||
return;
|
||||
}
|
||||
final files = dir.listSync();
|
||||
files.sort(
|
||||
(a, b) => b.statSync().modified.compareTo(a.statSync().modified),
|
||||
);
|
||||
if (files.isEmpty) {
|
||||
logger.w("|$_tag|替换数据库错误,数据库备份目录为空path|$dir|");
|
||||
return;
|
||||
}
|
||||
final lastFile = files.first;
|
||||
try {
|
||||
if (lastFile is File) {
|
||||
final sourcePath = lastFile.path;
|
||||
await File(sourcePath).copy(databaseFilePath);
|
||||
logger.i(
|
||||
"|$_tag|替换数据库成功,sourcePath|$sourcePath|targetPath|$databaseFilePath|",
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logger.e("|$_tag|替换数据库错误,意外的错误error|$e|stack|$stack|");
|
||||
}
|
||||
}
|
||||
|
||||
// 备份日志
|
||||
}
|
||||
@@ -31,8 +31,6 @@ class AppControl extends GetxController {
|
||||
// 是否有网络
|
||||
RxBool isNetwork = RxBool(false);
|
||||
|
||||
Rx<ProductHourType> hourType = Rx(ProductHourType.morning);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
|
||||
@@ -16,9 +16,9 @@ class AppThemeControl extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> initAsync() async {
|
||||
final userInfo = await AppSettingTool.getUserSetting();
|
||||
if (userInfo.globalFontSize != null) {
|
||||
sizeScalar.value = userInfo.globalFontSize!.fontSize;
|
||||
final appSetting = await AppSettingTool.getSysSetting();
|
||||
if (appSetting.globalFontSize != null) {
|
||||
sizeScalar.value = appSetting.globalFontSize!.fontSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ abstract class SyncProductTool {
|
||||
DateTime.now(),
|
||||
format: DateFormats.y_mo_d,
|
||||
);
|
||||
final dayStr = DateUtil.getDateTime(day);
|
||||
final pa = {
|
||||
"day": day,
|
||||
"hourType": null,
|
||||
@@ -153,6 +154,9 @@ abstract class SyncProductTool {
|
||||
"merchantId": sysSetting.serviceMerchantId,
|
||||
};
|
||||
apiList = await ProductApi.canteenProduct(pa);
|
||||
if (!ObjectUtil.isEmptyList(apiList)) {
|
||||
apiList?.forEach((v) => v.saleDate = dayStr);
|
||||
}
|
||||
} else if (sysType == SysType.supermarket) {
|
||||
apiList = await ProductApi.supermarketProduct(null);
|
||||
}
|
||||
@@ -246,6 +250,7 @@ abstract class SyncProductTool {
|
||||
createTime: DateTime.now(),
|
||||
updateTime: DateTime.now(),
|
||||
hourType: ProductHourType.values.fromCode(v.hourType),
|
||||
saleDate: v.saleDate,
|
||||
isDefault: false,
|
||||
delFlag: false,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user