feat:挂单

This commit is contained in:
dzc committed 2026-02-06 17:12:02 +08:00
1 parent 988247f3cd
commit 2b956342f4
12 files changed
+545 -36

No files matched your search

@@ -12,4 +12,29 @@ abstract class OrderHoldBillDao {
@delete
Future<void> del(OrderHoldBillEntity entity);
@Query("""
SELECT * FROM order_hold_bill
WHERE
createTime >= :startTime
AND createTime <= :endTime
ORDER BY createTime DESC
LIMIT :pageSize OFFSET :offset
""")
Future<List<OrderHoldBillEntity>> list(
String startTime,
String endTime,
int pageSize,
int offset,
);
@Query("""
SELECT COUNT(*) FROM order_hold_bill WHERE createTime >= :startTime AND createTime <= :endTime
""")
Future<int?> count(String startTime, String endTime);
@Query("""
DELETE FROM order_hold_bill WHERE createTime < datetime('now', '-7 days')
""")
Future<int?> deleteOlderThan7Days();
}
+33 -9
View File
@@ -85,9 +85,11 @@ abstract class AppDatabase extends FloorDatabase {
CREATE TABLE IF NOT EXISTS order_hold_bill (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sysType TEXT NOT NULL,
orderListJson TEXT,
carListJson TEXT,
userJson TEXT,
orderJson TEXT,
price INTEGER DEFAULT 0 NOT NULL,
extraPrice INTEGER DEFAULT 0 NOT NULL,
payPrice INTEGER DEFAULT 0 NOT NULL,
createTime TEXT NOT NULL
)
''');
@@ -101,16 +103,22 @@ abstract class AppDatabase extends FloorDatabase {
final columns =
await database.rawQuery("PRAGMA table_info(order_hold_bill)");
bool hasSysType = false;
bool hasCarListJson = false;
bool hasOrderListJson = false;
bool hasUserJson = false;
bool hasOrderJson = false;
bool hasPrice = false;
bool hasExtraPrice = false;
bool hasPayPrice = false;
bool hasCreateTime = false;
for (final c in columns) {
final name = c['name'];
if (name == 'sysType') hasSysType = true;
if (name == 'carListJson') hasCarListJson = true;
if (name == 'orderListJson') hasOrderListJson = true;
if (name == 'userJson') hasUserJson = true;
if (name == 'orderJson') hasOrderJson = true;
if (name == 'price') hasPrice = true;
if (name == 'extraPrice') hasExtraPrice = true;
if (name == 'payPrice') hasPayPrice = true;
if (name == 'createTime') hasCreateTime = true;
}
if (!hasSysType) {
@@ -118,24 +126,40 @@ abstract class AppDatabase extends FloorDatabase {
'ALTER TABLE order_hold_bill ADD COLUMN sysType TEXT',
);
}
if (!hasOrderListJson) {
if (!hasCarListJson) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN orderListJson TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN carListJson TEXT',
);
if (hasOrderListJson) {
// 旧列迁移到新列
await database.execute(
"UPDATE order_hold_bill SET carListJson = orderListJson WHERE carListJson IS NULL",
);
}
}
if (!hasUserJson) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN userJson TEXT',
);
}
if (!hasOrderJson) {
if (!hasPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN orderJson TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN price INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasExtraPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN extraPrice INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasPayPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN payPrice INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasCreateTime) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT DEFAULT "" NOT NULL',
);
}
await database.execute(
+48 -8
View File
@@ -124,7 +124,7 @@ class _$AppDatabase extends AppDatabase {
await database.execute(
'CREATE TABLE IF NOT EXISTS `order_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `uniqueCode` TEXT NOT NULL, `serviceUniqueCode` TEXT NOT NULL, `sysType` TEXT NOT NULL, `userCode` TEXT NOT NULL, `username` TEXT, `hourType` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `walletId` TEXT, `orderSourceTypeId` TEXT, `type` TEXT NOT NULL, `status` TEXT NOT NULL, `payType` TEXT NOT NULL, `productDesc` TEXT, `count` INTEGER NOT NULL, `weight` REAL NOT NULL, `payTime` TEXT, `createTime` TEXT NOT NULL)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `order_hold_bill` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `sysType` TEXT NOT NULL, `orderListJson` TEXT, `userJson` TEXT, `orderJson` TEXT, `createTime` TEXT NOT NULL)');
'CREATE TABLE IF NOT EXISTS `order_hold_bill` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `sysType` TEXT NOT NULL, `carListJson` TEXT, `userJson` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `createTime` TEXT NOT NULL)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `canteen_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `hourType` INTEGER, `saleDate` TEXT NOT NULL, `name` TEXT NOT NULL, `price` INTEGER NOT NULL, `image` TEXT, `isDefault` INTEGER NOT NULL, `status` INTEGER NOT NULL, `sort` INTEGER NOT NULL, `createTime` TEXT NOT NULL, `updateTime` TEXT NOT NULL)');
await database.execute(
@@ -608,15 +608,18 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
_$OrderHoldBillDao(
this.database,
this.changeListener,
) : _orderHoldBillEntityInsertionAdapter = InsertionAdapter(
) : _queryAdapter = QueryAdapter(database),
_orderHoldBillEntityInsertionAdapter = InsertionAdapter(
database,
'order_hold_bill',
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
}),
_orderHoldBillEntityUpdateAdapter = UpdateAdapter(
@@ -626,9 +629,11 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
}),
_orderHoldBillEntityDeletionAdapter = DeletionAdapter(
@@ -638,9 +643,11 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
});
@@ -648,6 +655,8 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
final StreamController<String> changeListener;
final QueryAdapter _queryAdapter;
final InsertionAdapter<OrderHoldBillEntity>
_orderHoldBillEntityInsertionAdapter;
@@ -656,6 +665,37 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
final DeletionAdapter<OrderHoldBillEntity>
_orderHoldBillEntityDeletionAdapter;
@override
Future<List<OrderHoldBillEntity>> list(
String startTime,
String endTime,
int pageSize,
int offset,
) async {
return _queryAdapter.queryList(
'SELECT * FROM order_hold_bill WHERE createTime >= ?1 AND createTime <= ?2 ORDER BY createTime DESC LIMIT ?3 OFFSET ?4',
mapper: (Map<String, Object?> row) => OrderHoldBillEntity(id: row['id'] as int?, sysType: _sysTypeConverter.decode(row['sysType'] as String), carListJson: row['carListJson'] as String?, userJson: row['userJson'] as String?, price: row['price'] as int, extraPrice: row['extraPrice'] as int, payPrice: row['payPrice'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String)),
arguments: [startTime, endTime, pageSize, offset]);
}
@override
Future<int?> count(
String startTime,
String endTime,
) async {
return _queryAdapter.query(
'SELECT COUNT(*) FROM order_hold_bill WHERE createTime >= ?1 AND createTime <= ?2',
mapper: (Map<String, Object?> row) => row.values.first as int,
arguments: [startTime, endTime]);
}
@override
Future<int?> deleteOlderThan7Days() async {
return _queryAdapter.query(
'DELETE FROM order_hold_bill WHERE createTime < datetime(\'now\', \'-7 days\')',
mapper: (Map<String, Object?> row) => row.values.first as int);
}
@override
Future<int> save(OrderHoldBillEntity entity) {
return _orderHoldBillEntityInsertionAdapter.insertAndReturnId(
@@ -16,22 +16,31 @@ class OrderHoldBillEntity {
SysType sysType;
/// 订单列表json
String? orderListJson;
String? carListJson;
/// 支付订单json
String? userJson;
String? orderJson;
/// 购物车的总金额
int price;
/// 购物车额外金额
int extraPrice;
/// 结算总金额
int payPrice;
/// 创建时间
DateTime createTime;
OrderHoldBillEntity({
this.id,
this.orderListJson,
this.userJson,
this.orderJson,
required this.sysType,
this.carListJson,
this.userJson,
required this.price,
required this.extraPrice,
required this.payPrice,
required this.createTime,
});
@@ -9,10 +9,12 @@ part of 'order_hold_bill_entity.dart';
OrderHoldBillEntity _$OrderHoldBillEntityFromJson(Map<String, dynamic> json) =>
OrderHoldBillEntity(
id: (json['id'] as num?)?.toInt(),
orderListJson: json['orderListJson'] as String?,
userJson: json['userJson'] as String?,
orderJson: json['orderJson'] as String?,
sysType: $enumDecode(_$SysTypeEnumMap, json['sysType']),
carListJson: json['carListJson'] as String?,
userJson: json['userJson'] as String?,
price: (json['price'] as num).toInt(),
extraPrice: (json['extraPrice'] as num).toInt(),
payPrice: (json['payPrice'] as num).toInt(),
createTime: DateTime.parse(json['createTime'] as String),
);
@@ -21,9 +23,11 @@ Map<String, dynamic> _$OrderHoldBillEntityToJson(
<String, dynamic>{
'id': instance.id,
'sysType': _$SysTypeEnumMap[instance.sysType]!,
'orderListJson': instance.orderListJson,
'carListJson': instance.carListJson,
'userJson': instance.userJson,
'orderJson': instance.orderJson,
'price': instance.price,
'extraPrice': instance.extraPrice,
'payPrice': instance.payPrice,
'createTime': instance.createTime.toIso8601String(),
};