feat:超市数据库
This commit is contained in:
1 parent
9a98ac8e1c
commit
fa4bb78f8b
25 files changed
+307
-185
No files matched your search
@@ -112,7 +112,11 @@ 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 `product` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `sysType` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `hourType` INTEGER, `saleDate` TEXT, `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, `delFlag` INTEGER NOT NULL)');
|
||||
'CREATE TABLE IF NOT EXISTS `canteen_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `hourType` INTEGER, `saleDate` TEXT, `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, `delFlag` INTEGER NOT NULL)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `supermarket_sku` (`id` INTEGER PRIMARY KEY AUTOINCREMENT)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `supermarket_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `shop_card` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `orderId` INTEGER NOT NULL, `productServiceUniqueCode` TEXT NOT NULL, `productName` TEXT NOT NULL, `productPic` TEXT NOT NULL, `productPrice` INTEGER NOT NULL, `productNumber` INTEGER NOT NULL, `productWidget` REAL NOT NULL, `totalPrice` INTEGER NOT NULL)');
|
||||
await database.execute(
|
||||
@@ -443,13 +447,12 @@ class _$ProductDao extends ProductDao {
|
||||
this.database,
|
||||
this.changeListener,
|
||||
) : _queryAdapter = QueryAdapter(database),
|
||||
_productEntityInsertionAdapter = InsertionAdapter(
|
||||
_canteenSpuEntityInsertionAdapter = InsertionAdapter(
|
||||
database,
|
||||
'product',
|
||||
(ProductEntity item) => <String, Object?>{
|
||||
'canteen_spu',
|
||||
(CanteenSpuEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'serviceUniqueCode': item.serviceUniqueCode,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'classifyServiceUniqueCode': item.classifyServiceUniqueCode,
|
||||
'hourType': item.hourType?.index,
|
||||
'saleDate': _dateTimeEmptyConverter.encode(item.saleDate),
|
||||
@@ -463,14 +466,13 @@ class _$ProductDao extends ProductDao {
|
||||
'updateTime': _dateTimeConverter.encode(item.updateTime),
|
||||
'delFlag': _boolConverter.encode(item.delFlag)
|
||||
}),
|
||||
_productEntityUpdateAdapter = UpdateAdapter(
|
||||
_canteenSpuEntityUpdateAdapter = UpdateAdapter(
|
||||
database,
|
||||
'product',
|
||||
'canteen_spu',
|
||||
['id'],
|
||||
(ProductEntity item) => <String, Object?>{
|
||||
(CanteenSpuEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'serviceUniqueCode': item.serviceUniqueCode,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'classifyServiceUniqueCode': item.classifyServiceUniqueCode,
|
||||
'hourType': item.hourType?.index,
|
||||
'saleDate': _dateTimeEmptyConverter.encode(item.saleDate),
|
||||
@@ -484,14 +486,13 @@ class _$ProductDao extends ProductDao {
|
||||
'updateTime': _dateTimeConverter.encode(item.updateTime),
|
||||
'delFlag': _boolConverter.encode(item.delFlag)
|
||||
}),
|
||||
_productEntityDeletionAdapter = DeletionAdapter(
|
||||
_canteenSpuEntityDeletionAdapter = DeletionAdapter(
|
||||
database,
|
||||
'product',
|
||||
'canteen_spu',
|
||||
['id'],
|
||||
(ProductEntity item) => <String, Object?>{
|
||||
(CanteenSpuEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'serviceUniqueCode': item.serviceUniqueCode,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'classifyServiceUniqueCode': item.classifyServiceUniqueCode,
|
||||
'hourType': item.hourType?.index,
|
||||
'saleDate': _dateTimeEmptyConverter.encode(item.saleDate),
|
||||
@@ -512,17 +513,15 @@ class _$ProductDao extends ProductDao {
|
||||
|
||||
final QueryAdapter _queryAdapter;
|
||||
|
||||
final InsertionAdapter<ProductEntity> _productEntityInsertionAdapter;
|
||||
final InsertionAdapter<CanteenSpuEntity> _canteenSpuEntityInsertionAdapter;
|
||||
|
||||
final UpdateAdapter<ProductEntity> _productEntityUpdateAdapter;
|
||||
final UpdateAdapter<CanteenSpuEntity> _canteenSpuEntityUpdateAdapter;
|
||||
|
||||
final DeletionAdapter<ProductEntity> _productEntityDeletionAdapter;
|
||||
final DeletionAdapter<CanteenSpuEntity> _canteenSpuEntityDeletionAdapter;
|
||||
|
||||
@override
|
||||
Future<void> delAllByType(String sysType) async {
|
||||
await _queryAdapter.queryNoReturn(
|
||||
'DELETE FROM product WHERE (?1 = \'-1\' OR sysType = ?1)',
|
||||
arguments: [sysType]);
|
||||
Future<void> delAllByType() async {
|
||||
await _queryAdapter.queryNoReturn('DELETE FROM canteen_spu');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -532,7 +531,7 @@ class _$ProductDao extends ProductDao {
|
||||
String hourType,
|
||||
) async {
|
||||
await _queryAdapter.queryNoReturn(
|
||||
'UPDATE product SET isDefault = ?1 WHERE delFlag = 0 AND serviceUniqueCode = ?2 AND hourType = ?3 AND (sysType = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
'UPDATE canteen_spu SET isDefault = ?1 WHERE delFlag = 0 AND serviceUniqueCode = ?2 AND hourType = ?3 AND (sysType = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
arguments: [_boolConverter.encode(isDefault), uniqueCode, hourType]);
|
||||
}
|
||||
|
||||
@@ -542,51 +541,33 @@ class _$ProductDao extends ProductDao {
|
||||
String hourType,
|
||||
) async {
|
||||
return _queryAdapter.query(
|
||||
'SELECT DISTINCT COUNT(0) FROM product WHERE delFlag = 0 AND (?1 = \'-1\' OR sysType = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?1 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
'SELECT DISTINCT COUNT(0) FROM canteen_spu WHERE delFlag = 0 AND (?1 = \'-1\' OR sysType = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?1 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
mapper: (Map<String, Object?> row) => row.values.first as int,
|
||||
arguments: [sysType, hourType]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProductEntity?> getByCode(String code) async {
|
||||
Future<CanteenSpuEntity?> getByCode(String code) async {
|
||||
return _queryAdapter.query(
|
||||
'SELECT * FROM product WHERE delFlag = 0 AND serviceUniqueCode = ?1',
|
||||
mapper: (Map<String, Object?> row) => ProductEntity(
|
||||
id: row['id'] as int?,
|
||||
serviceUniqueCode: row['serviceUniqueCode'] as String,
|
||||
sysType: _sysTypeConverter.decode(row['sysType'] as String),
|
||||
classifyServiceUniqueCode:
|
||||
row['classifyServiceUniqueCode'] as String,
|
||||
hourType: row['hourType'] == null
|
||||
? null
|
||||
: ProductHourType.values[row['hourType'] as int],
|
||||
saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String),
|
||||
name: row['name'] as String,
|
||||
price: row['price'] as int,
|
||||
image: row['image'] as String?,
|
||||
isDefault: _boolConverter.decode(row['isDefault'] as int),
|
||||
status: row['status'] as int,
|
||||
sort: row['sort'] as int,
|
||||
createTime: _dateTimeConverter.decode(row['createTime'] as String),
|
||||
updateTime: _dateTimeConverter.decode(row['updateTime'] as String),
|
||||
delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
'SELECT * FROM canteen_spu WHERE delFlag = 0 AND serviceUniqueCode = ?1',
|
||||
mapper: (Map<String, Object?> row) => CanteenSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
arguments: [code]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProductEntity>> getAll(
|
||||
Future<List<CanteenSpuEntity>> getAll(
|
||||
String classifyServiceUniqueCode,
|
||||
String hourType,
|
||||
String sysType,
|
||||
) async {
|
||||
return _queryAdapter.queryList(
|
||||
'SELECT product.* FROM product LEFT JOIN classify ON product.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE product.delFlag = 0 AND (?1 = \'-1\' OR product.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR product.sysType = ?3) ORDER BY classify.sort, product.price',
|
||||
mapper: (Map<String, Object?> row) => ProductEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, sysType: _sysTypeConverter.decode(row['sysType'] as String), classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
'SELECT canteen_spu.* FROM canteen_spu LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE canteen_spu.delFlag = 0 AND (?1 = \'-1\' OR canteen_spu.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR canteen_spu.sysType = ?3) ORDER BY classify.sort, canteen_spu.price',
|
||||
mapper: (Map<String, Object?> row) => CanteenSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
arguments: [classifyServiceUniqueCode, hourType, sysType]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProductEntity>> getAllPage(
|
||||
Future<List<CanteenSpuEntity>> getAllPage(
|
||||
String classifyServiceUniqueCode,
|
||||
String hourType,
|
||||
String sysType,
|
||||
@@ -594,8 +575,8 @@ class _$ProductDao extends ProductDao {
|
||||
int offset,
|
||||
) async {
|
||||
return _queryAdapter.queryList(
|
||||
'SELECT product.* FROM product LEFT JOIN classify ON product.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE product.delFlag = 0 AND (?1 = \'-1\' OR product.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || product.hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR product.sysType = ?3) AND (?3 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', product.saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')) ORDER BY classify.sort, classify.id, product.price LIMIT ?4 OFFSET ?5',
|
||||
mapper: (Map<String, Object?> row) => ProductEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, sysType: _sysTypeConverter.decode(row['sysType'] as String), classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
'SELECT canteen_spu.* FROM canteen_spu LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE canteen_spu.delFlag = 0 AND (?1 = \'-1\' OR canteen_spu.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || canteen_spu.hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR canteen_spu.sysType = ?3) AND (?3 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', canteen_spu.saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')) ORDER BY classify.sort, classify.id, canteen_spu.price LIMIT ?4 OFFSET ?5',
|
||||
mapper: (Map<String, Object?> row) => CanteenSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
arguments: [
|
||||
classifyServiceUniqueCode,
|
||||
hourType,
|
||||
@@ -606,37 +587,37 @@ class _$ProductDao extends ProductDao {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProductEntity>> getDefault(
|
||||
Future<List<CanteenSpuEntity>> getDefault(
|
||||
String sysType,
|
||||
String hourType,
|
||||
) async {
|
||||
return _queryAdapter.queryList(
|
||||
'SELECT * FROM product WHERE delFlag = 0 AND isDefault = 1 AND (?1 = \'-1\' OR sysType = ?1) AND (?2 = \'-1\' OR hourType = ?2) AND (?1 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
mapper: (Map<String, Object?> row) => ProductEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, sysType: _sysTypeConverter.decode(row['sysType'] as String), classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
'SELECT * FROM canteen_spu WHERE delFlag = 0 AND isDefault = 1 AND (?1 = \'-1\' OR sysType = ?1) AND (?2 = \'-1\' OR hourType = ?2) AND (?1 = \'CANTEEN\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\'))',
|
||||
mapper: (Map<String, Object?> row) => CanteenSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeEmptyConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)),
|
||||
arguments: [sysType, hourType]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> save(ProductEntity entity) async {
|
||||
await _productEntityInsertionAdapter.insert(
|
||||
Future<void> save(CanteenSpuEntity entity) async {
|
||||
await _canteenSpuEntityInsertionAdapter.insert(
|
||||
entity, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> batchSave(List<ProductEntity> entitys) async {
|
||||
await _productEntityInsertionAdapter.insertList(
|
||||
Future<void> batchSave(List<CanteenSpuEntity> entitys) async {
|
||||
await _canteenSpuEntityInsertionAdapter.insertList(
|
||||
entitys, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> batchEdit(List<ProductEntity> entitys) async {
|
||||
await _productEntityUpdateAdapter.updateList(
|
||||
Future<void> batchEdit(List<CanteenSpuEntity> entitys) async {
|
||||
await _canteenSpuEntityUpdateAdapter.updateList(
|
||||
entitys, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> batchDel(List<ProductEntity> entitys) async {
|
||||
await _productEntityDeletionAdapter.deleteList(entitys);
|
||||
Future<void> batchDel(List<CanteenSpuEntity> entitys) async {
|
||||
await _canteenSpuEntityDeletionAdapter.deleteList(entitys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user