feat:食堂sql修改

This commit is contained in:
dzc committed 2025-03-17 12:12:46 +08:00
1 parent fa4bb78f8b
commit d648272f0e
6 files changed
+24 -58

No files matched your search

@@ -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<void> 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<int?> getCount(
String sysType,
String hourType,
);
Future<int?> 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<List<CanteenSpuEntity>> 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<List<CanteenSpuEntity>> 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<List<CanteenSpuEntity>> getDefault(String sysType, String hourType);
Future<List<CanteenSpuEntity>> getDefault(String hourType);
}
+11 -25
View File
@@ -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<int?> getCount(
String sysType,
String hourType,
) async {
Future<int?> 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<String, Object?> row) => row.values.first as int,
arguments: [sysType, hourType]);
arguments: [hourType]);
}
@override
@@ -558,43 +555,32 @@ class _$ProductDao extends ProductDao {
Future<List<CanteenSpuEntity>> 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<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]);
arguments: [classifyServiceUniqueCode, hourType]);
}
@override
Future<List<CanteenSpuEntity>> 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<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,
pageSize,
offset
]);
arguments: [classifyServiceUniqueCode, hourType, pageSize, offset]);
}
@override
Future<List<CanteenSpuEntity>> getDefault(
String sysType,
String hourType,
) async {
Future<List<CanteenSpuEntity>> 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<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]);
arguments: [hourType]);
}
@override
@@ -183,7 +183,6 @@ abstract class SyncProductTool {
final productList = await productDao.getAll(
"-1",
"-1",
"-1",
);
if (ObjectUtil.isEmpty(productList)) {
await _batchAddOrUpdateProduct(
@@ -112,11 +112,8 @@ mixin OrderMixin {
// 获取商品
Future<void> 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();
+1 -4
View File
@@ -248,10 +248,7 @@ class CanteenProductController extends GetxController with OrderMixin {
Future<void> _getDefaultProduct() async {
final sysType = appSetting.sysType.name;
final productDao = appC.dataBase.getProductDao;
List<CanteenSpuEntity> list = await productDao.getDefault(
sysType,
hourType.value.code,
);
List<CanteenSpuEntity> list = await productDao.getDefault(sysType);
if (ObjectUtil.isEmptyList(list)) return;
for (final CanteenSpuEntity v in list) {
final shopCard = shopCardList.firstWhereOrNull((i) {
@@ -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,
);