feat:超市数据库

This commit is contained in:
dzc committed 2025-03-17 12:07:11 +08:00
1 parent 9a98ac8e1c
commit fa4bb78f8b
25 files changed
+307 -185

No files matched your search

+2 -2
View File
@@ -34,7 +34,7 @@ abstract class ProductApi {
dynamic pa,
) async {
final res = await HttpManage().dio.get(
"/supermarket-classify",
"/supermarket/supermarketCategory/simpleAll",
queryParameters: pa,
);
if (res.data == null) return null;
@@ -46,7 +46,7 @@ abstract class ProductApi {
/// 超市商品
static Future<List<ServiceProduct>?> supermarketProduct(dynamic pa) async {
final res = await HttpManage().dio.get(
"/supermarket-product",
"supermarket/supermarketSpu/ad/selectListAll",
queryParameters: pa,
);
if (res.data == null) return null;
@@ -7,10 +7,10 @@ import 'package:pj_supermarket_cloud/common/index.dart';
@dao
abstract class ProductDao {
@insert
Future<void> save(ProductEntity entity);
Future<void> save(CanteenSpuEntity entity);
@insert
Future<void> batchSave(List<ProductEntity> entitys);
Future<void> batchSave(List<CanteenSpuEntity> entitys);
Future<int> delByIds(List<String> codes) async {
if (ObjectUtil.isEmptyList(codes)) return -1;
@@ -18,26 +18,22 @@ abstract class ProductDao {
final database = app.dataBase.database;
final placeholders = List.generate(codes.length, (index) => '?').join(', ');
final sql = '''
UPDATE product SET delFlag = 1 WHERE serviceUniqueCode IN ($placeholders)
UPDATE canteen_spu SET delFlag = 1 WHERE serviceUniqueCode IN ($placeholders)
AND (sysType = 'CANTEEN' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime'))
''';
return await database.rawUpdate(sql, [...codes]);
}
@Query('''
DELETE FROM product
WHERE
(:sysType = '-1' OR sysType = :sysType)
DELETE FROM canteen_spu
''')
Future<void> delAllByType(
String sysType,
);
Future<void> delAllByType();
@delete
Future<void> batchDel(List<ProductEntity> entitys);
Future<void> batchDel(List<CanteenSpuEntity> entitys);
@Query("""
UPDATE product SET isDefault = :isDefault
UPDATE canteen_spu SET isDefault = :isDefault
WHERE
delFlag = 0
AND serviceUniqueCode = :uniqueCode AND hourType = :hourType
@@ -46,10 +42,10 @@ abstract class ProductDao {
Future<void> edit(bool isDefault, String uniqueCode, String hourType);
@update
Future<void> batchEdit(List<ProductEntity> entitys);
Future<void> batchEdit(List<CanteenSpuEntity> entitys);
@Query("""
SELECT DISTINCT COUNT(0) FROM product
SELECT DISTINCT COUNT(0) FROM canteen_spu
WHERE
delFlag = 0
AND (:sysType = '-1' OR sysType = :sysType)
@@ -62,42 +58,42 @@ abstract class ProductDao {
);
@Query('''
SELECT * FROM product WHERE delFlag = 0 AND serviceUniqueCode = :code
SELECT * FROM canteen_spu WHERE delFlag = 0 AND serviceUniqueCode = :code
''')
Future<ProductEntity?> getByCode(String code);
Future<CanteenSpuEntity?> getByCode(String code);
@Query('''
SELECT product.*
FROM product
LEFT JOIN classify ON product.classifyServiceUniqueCode = classify.serviceUniqueCode
SELECT canteen_spu.*
FROM canteen_spu
LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode
WHERE
product.delFlag = 0 AND
(:classifyServiceUniqueCode = '-1' OR product.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND
canteen_spu.delFlag = 0 AND
(:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND
(:hourType = '-1' OR INSTR(',' || hourType || ',', ',' || :hourType || ',') > 0) AND
(:sysType = '-1' OR product.sysType = :sysType)
ORDER BY classify.sort, product.price
(:sysType = '-1' OR canteen_spu.sysType = :sysType)
ORDER BY classify.sort, canteen_spu.price
''')
Future<List<ProductEntity>> getAll(
Future<List<CanteenSpuEntity>> getAll(
String classifyServiceUniqueCode,
String hourType,
String sysType,
);
// GROUP BY product.serviceUniqueCode
// GROUP BY canteen_spu.serviceUniqueCode
@Query('''
SELECT product.*
FROM product
LEFT JOIN classify ON product.classifyServiceUniqueCode = classify.serviceUniqueCode
SELECT canteen_spu.*
FROM canteen_spu
LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode
WHERE
product.delFlag = 0 AND
(:classifyServiceUniqueCode = '-1' OR product.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND
(:hourType = '-1' OR INSTR(',' || product.hourType || ',', ',' || :hourType || ',') > 0) AND
(:sysType = '-1' OR product.sysType = :sysType) AND
(:sysType = 'CANTEEN' OR strftime('%Y-%m-%d', product.saleDate) = strftime('%Y-%m-%d', 'now', 'localtime'))
ORDER BY classify.sort, classify.id, product.price
canteen_spu.delFlag = 0 AND
(:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND
(:hourType = '-1' OR INSTR(',' || canteen_spu.hourType || ',', ',' || :hourType || ',') > 0) AND
(:sysType = '-1' OR canteen_spu.sysType = :sysType) AND
(:sysType = '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 :pageSize OFFSET :offset
''')
Future<List<ProductEntity>> getAllPage(
Future<List<CanteenSpuEntity>> getAllPage(
String classifyServiceUniqueCode,
String hourType,
String sysType,
@@ -106,7 +102,7 @@ abstract class ProductDao {
);
@Query('''
SELECT * FROM product
SELECT * FROM canteen_spu
WHERE
delFlag = 0
AND isDefault = 1
@@ -114,5 +110,5 @@ abstract class ProductDao {
AND (:hourType = '-1' OR hourType = :hourType)
AND (:sysType = 'CANTEEN' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime'))
''')
Future<List<ProductEntity>> getDefault(String sysType, String hourType);
Future<List<CanteenSpuEntity>> getDefault(String sysType, String hourType);
}
@@ -0,0 +1,6 @@
import 'package:floor/floor.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
@dao
abstract class SupermarketSkuDao {}
@@ -0,0 +1,6 @@
import 'package:floor/floor.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
@dao
abstract class SupermarketSpuDao {}
+3 -1
View File
@@ -9,7 +9,9 @@ part 'database.g.dart';
const entities = <Type>[
OrderEntity,
ProductEntity,
CanteenSpuEntity,
SupermarketSkuEntity,
SupermarketSpuEntity,
ShopCardEntity,
ClassifyEntity,
PrintHistoryEntity,
+41 -60
View File
@@ -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);
}
}
@@ -4,11 +4,11 @@ import 'package:json_annotation/json_annotation.dart';
import 'package:pj_supermarket_cloud/common/models/index.dart';
part 'product_entity.g.dart';
part 'canteen_spu_entity.g.dart';
@JsonSerializable()
@Entity(tableName: "product")
class ProductEntity extends Equatable {
@Entity(tableName: "canteen_spu")
class CanteenSpuEntity extends Equatable {
/// 自增ID
@PrimaryKey(autoGenerate: true)
int? id;
@@ -16,9 +16,6 @@ class ProductEntity extends Equatable {
/// 服务端唯一标识
String serviceUniqueCode;
/// 平台类型
SysType sysType;
/// 分类 serviceID
String classifyServiceUniqueCode;
@@ -55,10 +52,9 @@ class ProductEntity extends Equatable {
/// 是否删除
bool delFlag;
ProductEntity({
CanteenSpuEntity({
this.id,
required this.serviceUniqueCode,
required this.sysType,
required this.classifyServiceUniqueCode,
this.hourType,
this.saleDate,
@@ -73,15 +69,14 @@ class ProductEntity extends Equatable {
required this.delFlag,
});
factory ProductEntity.fromJson(Map<String, dynamic> json) =>
_$ProductEntityFromJson(json);
factory CanteenSpuEntity.fromJson(Map<String, dynamic> json) =>
_$CanteenSpuEntityFromJson(json);
Map<String, dynamic> toJson() => _$ProductEntityToJson(this);
Map<String, dynamic> toJson() => _$CanteenSpuEntityToJson(this);
@override
List<Object?> get props => [
serviceUniqueCode,
sysType,
classifyServiceUniqueCode,
hourType,
name,
@@ -1,16 +1,15 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'product_entity.dart';
part of 'canteen_spu_entity.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
ProductEntity _$ProductEntityFromJson(Map<String, dynamic> json) =>
ProductEntity(
CanteenSpuEntity _$CanteenSpuEntityFromJson(Map<String, dynamic> json) =>
CanteenSpuEntity(
id: (json['id'] as num?)?.toInt(),
serviceUniqueCode: json['serviceUniqueCode'] as String,
sysType: $enumDecode(_$SysTypeEnumMap, json['sysType']),
classifyServiceUniqueCode: json['classifyServiceUniqueCode'] as String,
hourType: $enumDecodeNullable(_$ProductHourTypeEnumMap, json['hourType']),
saleDate: json['saleDate'] == null
@@ -27,11 +26,10 @@ ProductEntity _$ProductEntityFromJson(Map<String, dynamic> json) =>
delFlag: json['delFlag'] as bool,
);
Map<String, dynamic> _$ProductEntityToJson(ProductEntity instance) =>
Map<String, dynamic> _$CanteenSpuEntityToJson(CanteenSpuEntity instance) =>
<String, dynamic>{
'id': instance.id,
'serviceUniqueCode': instance.serviceUniqueCode,
'sysType': _$SysTypeEnumMap[instance.sysType]!,
'classifyServiceUniqueCode': instance.classifyServiceUniqueCode,
'hourType': _$ProductHourTypeEnumMap[instance.hourType],
'saleDate': instance.saleDate?.toIso8601String(),
@@ -46,11 +44,6 @@ Map<String, dynamic> _$ProductEntityToJson(ProductEntity instance) =>
'delFlag': instance.delFlag,
};
const _$SysTypeEnumMap = {
SysType.SUPERMARKET: 'SUPERMARKET',
SysType.CANTEEN: 'CANTEEN',
};
const _$ProductHourTypeEnumMap = {
ProductHourType.TOTAL: 'TOTAL',
ProductHourType.MORNING: 'MORNING',
@@ -0,0 +1,21 @@
import 'package:floor/floor.dart';
import 'package:json_annotation/json_annotation.dart';
part 'supermarket_sku_entity.g.dart';
@JsonSerializable()
@Entity(tableName: "supermarket_sku")
class SupermarketSkuEntity {
/// 自增ID
@PrimaryKey(autoGenerate: true)
int? id;
SupermarketSkuEntity({
this.id,
});
factory SupermarketSkuEntity.fromJson(Map<String, dynamic> json) =>
_$SupermarketSkuEntityFromJson(json);
Map<String, dynamic> toJson() => _$SupermarketSkuEntityToJson(this);
}
@@ -0,0 +1,19 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'supermarket_sku_entity.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
SupermarketSkuEntity _$SupermarketSkuEntityFromJson(
Map<String, dynamic> json) =>
SupermarketSkuEntity(
id: (json['id'] as num?)?.toInt(),
);
Map<String, dynamic> _$SupermarketSkuEntityToJson(
SupermarketSkuEntity instance) =>
<String, dynamic>{
'id': instance.id,
};
@@ -0,0 +1,21 @@
import 'package:floor/floor.dart';
import 'package:json_annotation/json_annotation.dart';
part 'supermarket_spu_entity.g.dart';
@JsonSerializable()
@Entity(tableName: "supermarket_spu")
class SupermarketSpuEntity {
/// 自增ID
@PrimaryKey(autoGenerate: true)
int? id;
SupermarketSpuEntity({
this.id,
});
factory SupermarketSpuEntity.fromJson(Map<String, dynamic> json) =>
_$SupermarketSpuEntityFromJson(json);
Map<String, dynamic> toJson() => _$SupermarketSpuEntityToJson(this);
}
@@ -0,0 +1,19 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'supermarket_spu_entity.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
SupermarketSpuEntity _$SupermarketSpuEntityFromJson(
Map<String, dynamic> json) =>
SupermarketSpuEntity(
id: (json['id'] as num?)?.toInt(),
);
Map<String, dynamic> _$SupermarketSpuEntityToJson(
SupermarketSpuEntity instance) =>
<String, dynamic>{
'id': instance.id,
};
+6 -2
View File
@@ -8,16 +8,20 @@ export './database/dao/classify_dao.dart';
export './database/dao/face_dao.dart';
export './database/dao/order_dao.dart';
export './database/dao/print_history_dao.dart';
export './database/dao/product_dao.dart';
export './database/dao/canteen_spu_dao.dart';
export './database/dao/setting_dao.dart';
export './database/dao/shop_card_dao.dart';
export './database/dao/supermarket_sku_dao.dart';
export './database/dao/supermarket_spu_dao.dart';
export './database/dao/user_dao.dart';
export './database/entity/classify_entity.dart';
export './database/entity/face_entity.dart';
export './database/entity/order_entity.dart';
export './database/entity/print_history_entity.dart';
export './database/entity/product_entity.dart';
export './database/entity/canteen_spu_entity.dart';
export './database/entity/setting_entity.dart';
export './database/entity/shop_card_entity.dart';
export './database/entity/supermarket_sku_entity.dart';
export './database/entity/supermarket_spu_entity.dart';
export './database/entity/user_entity.dart';
+2 -3
View File
@@ -227,13 +227,12 @@ abstract class SyncProductTool {
final app = Get.find<AppControl>();
final dataBase = app.dataBase;
final productDao = dataBase.getProductDao;
List<ProductEntity> changeList = [];
List<CanteenSpuEntity> changeList = [];
for (final v in list) {
ProductEntity item = ProductEntity(
CanteenSpuEntity item = CanteenSpuEntity(
serviceUniqueCode: sysType == SysType.CANTEEN
? v.spuId.toString()
: v.spuId.toString(),
sysType: sysType,
classifyServiceUniqueCode:
v.categoryId != null ? v.categoryId.toString() : "-1",
name: v.name!,
+1 -1
View File
@@ -12,5 +12,5 @@ Widget appBack(
return FIcon(
FAssets.icons.chevronLeft,
size: theme.typography.xl4.fontSize,
).alignLeft().width(height).onTap(() => onTap());
).center().width(height).height(height).onTap(() => onTap());
}
-1
View File
@@ -1,4 +1,3 @@
import 'package:common_utils/common_utils.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:forui/forui.dart';
@@ -28,10 +28,7 @@ mixin OrderMixin {
RxList<ClassifyEntity> classifyList = RxList([]);
// 商品
RxList<ProductEntity> productList = RxList([]);
// 商品分类ids
RxList<String> productClassifyList = RxList([]);
RxList<CanteenSpuEntity> productList = RxList([]);
// 总价
RxInt totalPrice = RxInt(0);
@@ -96,7 +93,6 @@ mixin OrderMixin {
_sysType.name,
hourType.value.code,
);
productClassifyList.value = list.map((v) => v.serviceUniqueCode).toList();
list.insert(
0,
ClassifyEntity(
@@ -123,7 +119,7 @@ mixin OrderMixin {
);
productList.value = list;
productList.refresh();
productClassifyList.refresh();
classifyList.refresh();
}
// 创建本地订单
+26 -13
View File
@@ -160,20 +160,33 @@ Widget orderRowClassify(
.map((v) {
final target = classifyList[currentTabIndex];
final active = target.id == v.id;
return FButton(
style: active ? FButtonStyle.primary : FButtonStyle.secondary,
label: Text(
v.name,
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.typography.xl.copyWith(
return Text(
v.name,
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.typography.xl2.copyWith(
height: 1,
color: active
? theme.colorScheme.background
: theme.colorScheme.primary,
),
)
.center()
.width(180.w)
.height(60.h)
.decorated(
color: active
? theme.colorScheme.secondary
: theme.colorScheme.primary,
),
).center().width(120.w),
onPress: () {
? theme.colorScheme.primary
: theme.colorScheme.background,
border: Border.all(
color: theme.colorScheme.primary,
width: 1,
),
borderRadius: theme.style.borderRadius / 2,
)
.onTap(
() {
final index = classifyList.indexWhere((i) => i.id == v.id);
onChange(index);
},
@@ -22,7 +22,7 @@ class SteelyardController extends GetxController {
final app = Get.find<AppControl>();
// 称重商品
Rxn<ProductEntity?> _widgetProduct = Rxn(null);
Rxn<CanteenSpuEntity?> _widgetProduct = Rxn(null);
// 重量
RxDouble widget = RxDouble(0);
@@ -65,7 +65,7 @@ class SteelyardController extends GetxController {
}
// 打开称重
bool open(ProductEntity current) {
bool open(CanteenSpuEntity current) {
final isOpen = _openSerial();
if (!isOpen) {
_closeStatus();
+3 -3
View File
@@ -121,7 +121,7 @@ class CanteenProductController extends GetxController with OrderMixin {
}
// 点击商品
void doProduct(ProductEntity current) async {
void doProduct(CanteenSpuEntity current) async {
final target = shopCardList.firstWhereOrNull((e) {
return e.productServiceUniqueCode == current.serviceUniqueCode;
});
@@ -248,12 +248,12 @@ class CanteenProductController extends GetxController with OrderMixin {
Future<void> _getDefaultProduct() async {
final sysType = appSetting.sysType.name;
final productDao = appC.dataBase.getProductDao;
List<ProductEntity> list = await productDao.getDefault(
List<CanteenSpuEntity> list = await productDao.getDefault(
sysType,
hourType.value.code,
);
if (ObjectUtil.isEmptyList(list)) return;
for (final ProductEntity v in list) {
for (final CanteenSpuEntity v in list) {
final shopCard = shopCardList.firstWhereOrNull((i) {
return int.tryParse(i.productServiceUniqueCode) == v.id;
});
+37 -20
View File
@@ -17,21 +17,39 @@ class CanteenProductPage extends GetView<CanteenProductController> {
final context = Get.context!;
final theme = FTheme.of(context);
return <Widget>[
appBack(
context,
height: headerHeight,
onTap: () => Get.offAndToNamed(RouteNames.panel),
),
Obx(
() => orderRowClassify(
<Widget>[
appBack(
context,
classifyList: controller.classifyList,
currentTabIndex: controller.currentTabIndex,
onChange: (tabIndex) => controller.doTab(tabIndex),
height: headerHeight,
onTap: () => Get.offAndToNamed(RouteNames.panel),
),
).scrollable(scrollDirection: Axis.horizontal).expanded(),
appRadioHourTypeDialog(context, controller.hourTypeC).width(300.w),
].toRow();
Obx(
() => orderRowClassify(
context,
classifyList: controller.classifyList,
currentTabIndex: controller.currentTabIndex,
onChange: (tabIndex) => controller.doTab(tabIndex),
),
).scrollable(scrollDirection: Axis.horizontal).expanded(),
appRadioHourTypeDialog(context, controller.hourTypeC).width(300.w),
].toRow(),
FDivider(
style: theme.dividerStyles.horizontalStyle.copyWith(
padding: EdgeInsets.zero,
),
),
].toColumn().decorated(
color: theme.colorScheme.background,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
offset: const Offset(0, 2),
blurRadius: 6,
spreadRadius: 0,
),
],
);
;
}
// 商品
@@ -47,13 +65,13 @@ class CanteenProductPage extends GetView<CanteenProductController> {
return Obx(
() => ListView.builder(
padding: EdgeInsets.zero,
itemCount: controller.productClassifyList.length,
itemCount: controller.classifyList.length,
itemBuilder: (context, index) {
if (ObjectUtil.isEmpty(controller.productClassifyList) ||
if (ObjectUtil.isEmpty(controller.classifyList) ||
ObjectUtil.isEmpty(controller.productList)) {
return const SizedBox.shrink();
}
final current = controller.productClassifyList[index];
final current = controller.classifyList[index].serviceUniqueCode;
final currentStr = controller.classifyList
.firstWhereOrNull((v) => v.serviceUniqueCode == current);
final currentList = controller.productList
@@ -79,7 +97,7 @@ class CanteenProductPage extends GetView<CanteenProductController> {
/// 商品项
Widget _buildProductItem(
BuildContext context, {
required List<ProductEntity> productList,
required List<CanteenSpuEntity> productList,
required double productSpacing,
required Size productSize,
String? title = "",
@@ -212,6 +230,7 @@ class CanteenProductPage extends GetView<CanteenProductController> {
final width = context.width;
final theme = FTheme.of(context);
return <Widget>[
SizedBox(width: 15.w),
_buildProduct().expanded(),
SizedBox(width: 15.w),
_buildUser().width(width * 0.25).decorated(
@@ -232,9 +251,7 @@ class CanteenProductPage extends GetView<CanteenProductController> {
id: "canteen_product",
builder: (_) {
return FScaffold(
header: _buildHeader(height.h)
.height(height.h)
.padding(vertical: 30.h, horizontal: 10.w),
header: _buildHeader(height.h).height(height.h).paddingVertical(30.h),
content: _buildView(),
contentPad: true,
resizeToAvoidBottomInset: false,
+1 -1
View File
@@ -22,7 +22,7 @@ class FaceManageController extends GetxController {
RxInt pageSize = RxInt(15);
final TextEditingController usernameC = TextEditingController();
final usernameC = TextEditingController();
late StreamSubscription mqUpdateListen;
@@ -10,7 +10,7 @@ import 'package:pj_supermarket_cloud/common/index.dart';
class ProductManageController extends GetxController {
static const _tag = "商品管理 Controller";
RxList<ProductEntity> productList = <ProductEntity>[].obs;
RxList<CanteenSpuEntity> productList = <CanteenSpuEntity>[].obs;
ProductHourType hourType = ProductHourType.MORNING;
@@ -110,7 +110,7 @@ class ProductManageController extends GetxController {
}
// 切换是否默认
Future<void> trigger(ProductEntity v) async {
Future<void> trigger(CanteenSpuEntity v) async {
try {
final isSure = await appMessageDialog(
Get.context!,
@@ -123,7 +123,7 @@ class ProductManageController extends GetxController {
);
final app = Get.find<AppControl>();
final productDao = app.dataBase.getProductDao;
final editObj = ProductEntity.fromJson(v.toJson());
final editObj = CanteenSpuEntity.fromJson(v.toJson());
editObj.isDefault = !editObj.isDefault;
await productDao.edit(
editObj.isDefault,
@@ -1,4 +1,5 @@
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_subscreen_plugin/flutter_subscreen_plugin.dart';
import 'package:get/get.dart';
@@ -12,6 +13,8 @@ class SupermarketOrderController extends GetxController with OrderMixin {
final appC = Get.find<AppControl>();
final selfCodeC = TextEditingController();
late SysSetting appSetting;
RxInt currentPage = RxInt(1);
@@ -43,6 +46,7 @@ class SupermarketOrderController extends GetxController with OrderMixin {
// 读卡器
appC.serialCardManage.readerClose();
appC.serialCardManage.close();
selfCodeC.dispose();
}
Future<void> _initState() async {
@@ -54,6 +58,7 @@ class SupermarketOrderController extends GetxController with OrderMixin {
// 打开副屏
SubScreenPlugin.sendMsgToViceScreen(SubScreenAction.jumpSubPage.name);
// 组件初始化
hourType.value = ProductHourType.TOTAL;
sysType = SysType.SUPERMARKET;
_listenPayTypeSelectCallback();
// 获取分类和商品
+38 -8
View File
@@ -33,7 +33,38 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
onChange: (tabIndex) => controller.doTab(tabIndex),
),
).scrollable(scrollDirection: Axis.horizontal).expanded(),
].toRow();
<Widget>[
FTextField(
controller: controller.selfCodeC,
hint: '请输入自编码',
maxLines: 1,
).width(300.w),
SizedBox(width: 10.w),
FButton(
prefix: FIcon(
FAssets.icons.search,
size: theme.typography.base.fontSize,
),
label: Text(
'搜索',
style: theme.typography.base.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () => controller.doPage(),
),
].toRow().padding(horizontal: 10.w),
].toRow(crossAxisAlignment: CrossAxisAlignment.center).decorated(
color: theme.colorScheme.background,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
offset: const Offset(0, 2),
blurRadius: 6,
spreadRadius: 0,
),
],
);
}
// **************************************************************************
@@ -46,7 +77,7 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
Widget _buildProductItem(
BuildContext context, {
required List<ProductEntity> productList,
required List<CanteenSpuEntity> productList,
required double productSpacing,
required Size productSize,
String? title = "",
@@ -65,13 +96,13 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
double itemHeight = (maxHeight - (runSpacing + 30) * 3) / 3;
return ListView.builder(
padding: EdgeInsets.zero,
itemCount: controller.productClassifyList.length,
itemCount: controller.classifyList.length,
itemBuilder: (context, index) {
if (ObjectUtil.isEmpty(controller.productClassifyList) ||
if (ObjectUtil.isEmpty(controller.classifyList) ||
ObjectUtil.isEmpty(controller.productList)) {
return const SizedBox.shrink();
}
final current = controller.productClassifyList[index];
final current = controller.classifyList[index].serviceUniqueCode;
final currentStr = controller.classifyList
.firstWhereOrNull((v) => v.serviceUniqueCode == current);
final currentList = controller.productList
@@ -188,6 +219,7 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
final width = context.width;
final theme = FTheme.of(context);
return <Widget>[
SizedBox(width: 15.w),
_buildProductArea().expanded(),
SizedBox(width: 15.w),
_buildUser().width(width * 0.25).decorated(
@@ -208,9 +240,7 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
id: "supermarket_order",
builder: (_) {
return FScaffold(
header: _buildHeader(height.h)
.height(height.h)
.padding(vertical: 30.h, horizontal: 10.w),
header: _buildHeader(height.h).height(height.h).paddingVertical(30.h),
content: _buildView(context),
contentPad: true,
resizeToAvoidBottomInset: false,