修改购买mixin

This commit is contained in:
dzc committed 2025-03-17 12:29:50 +08:00
1 parent d648272f0e
commit 321ae3378a
11 files changed
+113 -32

No files matched your search

@@ -5,7 +5,7 @@ import 'package:get/get.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
@dao
abstract class ProductDao {
abstract class CanteenSpuDao {
@insert
Future<void> save(CanteenSpuEntity entity);
@@ -18,7 +18,9 @@ abstract class ProductDao {
final database = app.dataBase.database;
final placeholders = List.generate(codes.length, (index) => '?').join(', ');
final sql = '''
UPDATE canteen_spu SET delFlag = 1 WHERE serviceUniqueCode IN ($placeholders)
UPDATE canteen_spu SET delFlag = 1
WHERE
serviceUniqueCode IN ($placeholders)
AND strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', 'now', 'localtime')
''';
return await database.rawUpdate(sql, [...codes]);
@@ -63,21 +65,22 @@ abstract class ProductDao {
FROM canteen_spu
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(',' || hourType || ',', ',' || :hourType || ',') > 0) AND
canteen_spu.delFlag = 0
AND (:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode)
AND (:hourType = '-1' OR INSTR(',' || hourType || ',', ',' || :hourType || ',') > 0)
ORDER BY classify.sort, canteen_spu.price
''')
Future<List<CanteenSpuEntity>> getAll(
String classifyServiceUniqueCode, String hourType);
String classifyServiceUniqueCode,
String hourType,
);
// GROUP BY canteen_spu.serviceUniqueCode
@Query('''
SELECT canteen_spu.*
FROM canteen_spu
LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode
WHERE
canteen_spu.delFlag = 0 AND
canteen_spu.delFlag = 0
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')
@@ -2,5 +2,6 @@ import 'package:floor/floor.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
// supermarket_sku
@dao
abstract class SupermarketSkuDao {}
@@ -2,5 +2,17 @@ import 'package:floor/floor.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
// supermarket_spu
@dao
abstract class SupermarketSpuDao {}
abstract class SupermarketSpuDao {
@Query('''
SELECT supermarket_spu.*
FROM supermarket_spu
LEFT JOIN classify ON supermarket_spu.classifyServiceUniqueCode = classify.serviceUniqueCode
WHERE
supermarket_spu.delFlag = 0
AND (:classifyServiceUniqueCode = '-1' OR supermarket_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode)
ORDER BY classify.sort, supermarket_spu.price
''')
Future<List<SupermarketSpuEntity>> getAll(String classifyServiceUniqueCode);
}
+3 -1
View File
@@ -36,7 +36,9 @@ const typeConverters = <Type>[
@TypeConverters(typeConverters)
abstract class AppDatabase extends FloorDatabase {
OrderDao get getOrderDao;
ProductDao get getProductDao;
CanteenSpuDao get getCanteenSpuDao;
SupermarketSkuDao get getSupermarketSkuDao;
SupermarketSpuDao get getSupermarketSpuDao;
ShopCardDao get getShopCardDao;
ClassifyDao get getClassifyDao;
PrintHistoryDao get getPrintHistoryDao;
+57 -7
View File
@@ -74,7 +74,11 @@ class _$AppDatabase extends AppDatabase {
OrderDao? _getOrderDaoInstance;
ProductDao? _getProductDaoInstance;
CanteenSpuDao? _getCanteenSpuDaoInstance;
SupermarketSkuDao? _getSupermarketSkuDaoInstance;
SupermarketSpuDao? _getSupermarketSpuDaoInstance;
ShopCardDao? _getShopCardDaoInstance;
@@ -142,8 +146,21 @@ class _$AppDatabase extends AppDatabase {
}
@override
ProductDao get getProductDao {
return _getProductDaoInstance ??= _$ProductDao(database, changeListener);
CanteenSpuDao get getCanteenSpuDao {
return _getCanteenSpuDaoInstance ??=
_$CanteenSpuDao(database, changeListener);
}
@override
SupermarketSkuDao get getSupermarketSkuDao {
return _getSupermarketSkuDaoInstance ??=
_$SupermarketSkuDao(database, changeListener);
}
@override
SupermarketSpuDao get getSupermarketSpuDao {
return _getSupermarketSpuDaoInstance ??=
_$SupermarketSpuDao(database, changeListener);
}
@override
@@ -442,8 +459,8 @@ class _$OrderDao extends OrderDao {
}
}
class _$ProductDao extends ProductDao {
_$ProductDao(
class _$CanteenSpuDao extends CanteenSpuDao {
_$CanteenSpuDao(
this.database,
this.changeListener,
) : _queryAdapter = QueryAdapter(database),
@@ -557,7 +574,7 @@ class _$ProductDao extends ProductDao {
String hourType,
) 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 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) 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]);
}
@@ -570,7 +587,7 @@ class _$ProductDao extends ProductDao {
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 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',
'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 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<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, pageSize, offset]);
}
@@ -607,6 +624,39 @@ class _$ProductDao extends ProductDao {
}
}
class _$SupermarketSkuDao extends SupermarketSkuDao {
_$SupermarketSkuDao(
this.database,
this.changeListener,
);
final sqflite.DatabaseExecutor database;
final StreamController<String> changeListener;
}
class _$SupermarketSpuDao extends SupermarketSpuDao {
_$SupermarketSpuDao(
this.database,
this.changeListener,
) : _queryAdapter = QueryAdapter(database);
final sqflite.DatabaseExecutor database;
final StreamController<String> changeListener;
final QueryAdapter _queryAdapter;
@override
Future<List<SupermarketSpuEntity>> getAll(
String classifyServiceUniqueCode) async {
return _queryAdapter.queryList(
'SELECT supermarket_spu.* FROM supermarket_spu LEFT JOIN classify ON supermarket_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE supermarket_spu.delFlag = 0 AND (?1 = \'-1\' OR supermarket_spu.classifyServiceUniqueCode = ?1) ORDER BY classify.sort, supermarket_spu.price',
mapper: (Map<String, Object?> row) => SupermarketSpuEntity(id: row['id'] as int?),
arguments: [classifyServiceUniqueCode]);
}
}
class _$ShopCardDao extends ShopCardDao {
_$ShopCardDao(
this.database,
+2 -2
View File
@@ -179,7 +179,7 @@ abstract class SyncProductTool {
}) async {
final app = Get.find<AppControl>();
final dataBase = app.dataBase;
final productDao = dataBase.getProductDao;
final productDao = dataBase.getCanteenSpuDao;
final productList = await productDao.getAll(
"-1",
"-1",
@@ -225,7 +225,7 @@ abstract class SyncProductTool {
if (ObjectUtil.isEmpty(list)) return;
final app = Get.find<AppControl>();
final dataBase = app.dataBase;
final productDao = dataBase.getProductDao;
final productDao = dataBase.getCanteenSpuDao;
List<CanteenSpuEntity> changeList = [];
for (final v in list) {
CanteenSpuEntity item = CanteenSpuEntity(
@@ -27,8 +27,11 @@ mixin OrderMixin {
// 分类
RxList<ClassifyEntity> classifyList = RxList([]);
// 商品
RxList<CanteenSpuEntity> productList = RxList([]);
// 食堂商品
RxList<CanteenSpuEntity> canteenSpuDao = RxList([]);
// 超市商品
RxList<SupermarketSpuEntity> supermarketSpuDao = RxList([]);
// 总价
RxInt totalPrice = RxInt(0);
@@ -112,10 +115,20 @@ mixin OrderMixin {
// 获取商品
Future<void> getProduct({String classifyCode = "-1"}) async {
final list = await appController.dataBase.getProductDao
.getAll(classifyCode, hourType.value.code);
productList.value = list;
productList.refresh();
if (_sysType == SysType.SUPERMARKET) {
final list = await appController.dataBase.getSupermarketSpuDao.getAll(
classifyCode,
);
supermarketSpuDao.value = list;
supermarketSpuDao.refresh();
} else if (_sysType == SysType.CANTEEN) {
final list = await appController.dataBase.getCanteenSpuDao.getAll(
classifyCode,
hourType.value.code,
);
canteenSpuDao.value = list;
canteenSpuDao.refresh();
}
classifyList.refresh();
}
+1 -1
View File
@@ -247,7 +247,7 @@ class CanteenProductController extends GetxController with OrderMixin {
// 获取默认商品
Future<void> _getDefaultProduct() async {
final sysType = appSetting.sysType.name;
final productDao = appC.dataBase.getProductDao;
final productDao = appC.dataBase.getCanteenSpuDao;
List<CanteenSpuEntity> list = await productDao.getDefault(sysType);
if (ObjectUtil.isEmptyList(list)) return;
for (final CanteenSpuEntity v in list) {
+2 -2
View File
@@ -68,13 +68,13 @@ class CanteenProductPage extends GetView<CanteenProductController> {
itemCount: controller.classifyList.length,
itemBuilder: (context, index) {
if (ObjectUtil.isEmpty(controller.classifyList) ||
ObjectUtil.isEmpty(controller.productList)) {
ObjectUtil.isEmpty(controller.canteenSpuDao)) {
return const SizedBox.shrink();
}
final current = controller.classifyList[index].serviceUniqueCode;
final currentStr = controller.classifyList
.firstWhereOrNull((v) => v.serviceUniqueCode == current);
final currentList = controller.productList
final currentList = controller.canteenSpuDao
.where((i) => i.classifyServiceUniqueCode == current)
.toList();
if (ObjectUtil.isEmpty(currentList)) {
@@ -78,7 +78,7 @@ class ProductManageController extends GetxController {
try {
final app = Get.find<AppControl>();
final sysSetting = await AppSettingTool.getSysSetting();
final productDao = app.dataBase.getProductDao;
final productDao = app.dataBase.getCanteenSpuDao;
final currnetHourType = hourType.code;
String sysType = sysSetting.sysType.name;
final findCount = await productDao.getCount(
@@ -120,7 +120,7 @@ class ProductManageController extends GetxController {
maskType: EasyLoadingMaskType.black,
);
final app = Get.find<AppControl>();
final productDao = app.dataBase.getProductDao;
final productDao = app.dataBase.getCanteenSpuDao;
final editObj = CanteenSpuEntity.fromJson(v.toJson());
editObj.isDefault = !editObj.isDefault;
await productDao.edit(
+2 -2
View File
@@ -99,13 +99,13 @@ class SupermarketOrderPage extends GetView<SupermarketOrderController> {
itemCount: controller.classifyList.length,
itemBuilder: (context, index) {
if (ObjectUtil.isEmpty(controller.classifyList) ||
ObjectUtil.isEmpty(controller.productList)) {
ObjectUtil.isEmpty(controller.canteenSpuDao)) {
return const SizedBox.shrink();
}
final current = controller.classifyList[index].serviceUniqueCode;
final currentStr = controller.classifyList
.firstWhereOrNull((v) => v.serviceUniqueCode == current);
final currentList = controller.productList
final currentList = controller.canteenSpuDao
.where((i) => i.classifyServiceUniqueCode == current)
.toList();
if (ObjectUtil.isEmpty(currentList)) {