diff --git a/lib/common/services/database/dao/canteen_spu_dao.dart b/lib/common/services/database/dao/canteen_spu_dao.dart index 6cc7fe5..308767f 100644 --- a/lib/common/services/database/dao/canteen_spu_dao.dart +++ b/lib/common/services/database/dao/canteen_spu_dao.dart @@ -19,7 +19,7 @@ abstract class ProductDao { final placeholders = List.generate(codes.length, (index) => '?').join(', '); final sql = ''' 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')) + AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime') '''; return await database.rawUpdate(sql, [...codes]); } @@ -37,7 +37,7 @@ abstract class ProductDao { WHERE delFlag = 0 AND serviceUniqueCode = :uniqueCode AND hourType = :hourType - AND (sysType = 'CANTEEN' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime')) + AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime') """) Future edit(bool isDefault, String uniqueCode, String hourType); @@ -48,14 +48,10 @@ abstract class ProductDao { SELECT DISTINCT COUNT(0) FROM canteen_spu WHERE delFlag = 0 - AND (:sysType = '-1' OR sysType = :sysType) AND (:hourType = '-1' OR INSTR(',' || hourType || ',', ',' || :hourType || ',') > 0) - AND (:sysType = 'CANTEEN' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime')) + AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime') """) - Future getCount( - String sysType, - String hourType, - ); + Future getCount(String hourType); @Query(''' SELECT * FROM canteen_spu WHERE delFlag = 0 AND serviceUniqueCode = :code @@ -70,14 +66,10 @@ abstract class ProductDao { canteen_spu.delFlag = 0 AND (:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND (:hourType = '-1' OR INSTR(',' || hourType || ',', ',' || :hourType || ',') > 0) AND - (:sysType = '-1' OR canteen_spu.sysType = :sysType) ORDER BY classify.sort, canteen_spu.price ''') Future> getAll( - String classifyServiceUniqueCode, - String hourType, - String sysType, - ); + String classifyServiceUniqueCode, String hourType); // GROUP BY canteen_spu.serviceUniqueCode @Query(''' @@ -86,17 +78,15 @@ abstract class ProductDao { LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE 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')) + AND (:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) + AND (:hourType = '-1' OR INSTR(',' || canteen_spu.hourType || ',', ',' || :hourType || ',') > 0) + AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime') ORDER BY classify.sort, classify.id, canteen_spu.price LIMIT :pageSize OFFSET :offset ''') Future> getAllPage( String classifyServiceUniqueCode, String hourType, - String sysType, int pageSize, int offset, ); @@ -106,9 +96,8 @@ abstract class ProductDao { WHERE delFlag = 0 AND isDefault = 1 - AND (:sysType = '-1' OR sysType = :sysType) AND (:hourType = '-1' OR hourType = :hourType) - AND (:sysType = 'CANTEEN' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime')) + AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime') ''') - Future> getDefault(String sysType, String hourType); + Future> getDefault(String hourType); } diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index bad8aad..c06cb79 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -531,19 +531,16 @@ class _$ProductDao extends ProductDao { String hourType, ) async { await _queryAdapter.queryNoReturn( - '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\'))', + 'UPDATE canteen_spu SET isDefault = ?1 WHERE delFlag = 0 AND serviceUniqueCode = ?2 AND hourType = ?3 AND strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')', arguments: [_boolConverter.encode(isDefault), uniqueCode, hourType]); } @override - Future getCount( - String sysType, - String hourType, - ) async { + Future getCount(String hourType) async { return _queryAdapter.query( - '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\'))', + 'SELECT DISTINCT COUNT(0) FROM canteen_spu WHERE delFlag = 0 AND (?1 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?1 || \',\') > 0) AND strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')', mapper: (Map row) => row.values.first as int, - arguments: [sysType, hourType]); + arguments: [hourType]); } @override @@ -558,43 +555,32 @@ class _$ProductDao extends ProductDao { Future> getAll( String classifyServiceUniqueCode, String hourType, - String sysType, ) async { return _queryAdapter.queryList( - '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', + '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 ORDER BY classify.sort, canteen_spu.price', mapper: (Map 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]); + arguments: [classifyServiceUniqueCode, hourType]); } @override Future> getAllPage( String classifyServiceUniqueCode, String hourType, - String sysType, int pageSize, int offset, ) async { return _queryAdapter.queryList( - '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', + 'SELECT canteen_spu.* FROM canteen_spu LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE canteen_spu.delFlag = 0 AND AND (?1 = \'-1\' OR canteen_spu.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || canteen_spu.hourType || \',\', \',\' || ?2 || \',\') > 0) AND strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\') ORDER BY classify.sort, classify.id, canteen_spu.price LIMIT ?3 OFFSET ?4', mapper: (Map 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, - pageSize, - offset - ]); + arguments: [classifyServiceUniqueCode, hourType, pageSize, offset]); } @override - Future> getDefault( - String sysType, - String hourType, - ) async { + Future> getDefault(String hourType) async { return _queryAdapter.queryList( - '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\'))', + 'SELECT * FROM canteen_spu WHERE delFlag = 0 AND isDefault = 1 AND (?1 = \'-1\' OR hourType = ?1) AND strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')', mapper: (Map 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]); + arguments: [hourType]); } @override diff --git a/lib/common/utils/sync/sync_product_tool.dart b/lib/common/utils/sync/sync_product_tool.dart index a847df6..a437967 100644 --- a/lib/common/utils/sync/sync_product_tool.dart +++ b/lib/common/utils/sync/sync_product_tool.dart @@ -183,7 +183,6 @@ abstract class SyncProductTool { final productList = await productDao.getAll( "-1", "-1", - "-1", ); if (ObjectUtil.isEmpty(productList)) { await _batchAddOrUpdateProduct( diff --git a/lib/common/widgets/order/mixin/order_mixin.dart b/lib/common/widgets/order/mixin/order_mixin.dart index 5b7a795..24402b0 100644 --- a/lib/common/widgets/order/mixin/order_mixin.dart +++ b/lib/common/widgets/order/mixin/order_mixin.dart @@ -112,11 +112,8 @@ mixin OrderMixin { // 获取商品 Future getProduct({String classifyCode = "-1"}) async { - final list = await appController.dataBase.getProductDao.getAll( - classifyCode, - hourType.value.code, - _sysType.name, - ); + final list = await appController.dataBase.getProductDao + .getAll(classifyCode, hourType.value.code); productList.value = list; productList.refresh(); classifyList.refresh(); diff --git a/lib/pages/canteen_product/controller.dart b/lib/pages/canteen_product/controller.dart index 8008046..676a7d0 100644 --- a/lib/pages/canteen_product/controller.dart +++ b/lib/pages/canteen_product/controller.dart @@ -248,10 +248,7 @@ class CanteenProductController extends GetxController with OrderMixin { Future _getDefaultProduct() async { final sysType = appSetting.sysType.name; final productDao = appC.dataBase.getProductDao; - List list = await productDao.getDefault( - sysType, - hourType.value.code, - ); + List list = await productDao.getDefault(sysType); if (ObjectUtil.isEmptyList(list)) return; for (final CanteenSpuEntity v in list) { final shopCard = shopCardList.firstWhereOrNull((i) { diff --git a/lib/pages/setting/widgets/setting_product.dart b/lib/pages/setting/widgets/setting_product.dart index c70e8c5..cbc78cf 100644 --- a/lib/pages/setting/widgets/setting_product.dart +++ b/lib/pages/setting/widgets/setting_product.dart @@ -82,14 +82,12 @@ class ProductManageController extends GetxController { final currnetHourType = hourType.code; String sysType = sysSetting.sysType.name; final findCount = await productDao.getCount( - sysType, currnetHourType, ); if (findCount != null) totalPage.value = findCount; final list = await productDao.getAllPage( "-1", currnetHourType, - sysType, pageSize.value, (currentPage.value - 1) * pageSize.value, );