feat:超市实体

This commit is contained in:
dzc committed 2025-03-17 15:45:50 +08:00
1 parent 321ae3378a
commit c0fbf652fb
16 files changed
+640 -80

No files matched your search

@@ -15,4 +15,27 @@ abstract class SupermarketSpuDao {
ORDER BY classify.sort, supermarket_spu.price
''')
Future<List<SupermarketSpuEntity>> getAll(String classifyServiceUniqueCode);
@Query("""
SELECT DISTINCT COUNT(0) FROM canteen_spu
WHERE
delFlag = 0
""")
Future<int?> getCount();
@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
LIMIT :pageSize OFFSET :offset
''')
Future<List<SupermarketSpuEntity>> getAllPage(
String classifyServiceUniqueCode,
int pageSize,
int offset,
);
}
+21 -2
View File
@@ -120,7 +120,7 @@ class _$AppDatabase extends AppDatabase {
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)');
'CREATE TABLE IF NOT EXISTS `supermarket_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `price` 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 `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(
@@ -652,9 +652,28 @@ class _$SupermarketSpuDao extends SupermarketSpuDao {
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?),
mapper: (Map<String, Object?> row) => SupermarketSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, price: row['price'] 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]);
}
@override
Future<int?> getCount() async {
return _queryAdapter.query(
'SELECT DISTINCT COUNT(0) FROM canteen_spu WHERE delFlag = 0',
mapper: (Map<String, Object?> row) => row.values.first as int);
}
@override
Future<List<SupermarketSpuEntity>> getAllPage(
String classifyServiceUniqueCode,
int pageSize,
int offset,
) 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 LIMIT ?2 OFFSET ?3',
mapper: (Map<String, Object?> row) => SupermarketSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, price: row['price'] 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, pageSize, offset]);
}
}
class _$ShopCardDao extends ShopCardDao {
@@ -10,8 +10,36 @@ class SupermarketSpuEntity {
@PrimaryKey(autoGenerate: true)
int? id;
/// 服务端唯一标识
String serviceUniqueCode;
/// 分类 serviceID
String classifyServiceUniqueCode;
/// 商品价格(分)
int price;
/// 排序 倒序排列
int sort;
/// 创建时间
DateTime createTime;
/// 同步时间
DateTime updateTime;
/// 是否删除
bool delFlag;
SupermarketSpuEntity({
this.id,
required this.serviceUniqueCode,
required this.classifyServiceUniqueCode,
required this.price,
required this.sort,
required this.createTime,
required this.updateTime,
required this.delFlag,
});
factory SupermarketSpuEntity.fromJson(Map<String, dynamic> json) =>
@@ -10,10 +10,24 @@ SupermarketSpuEntity _$SupermarketSpuEntityFromJson(
Map<String, dynamic> json) =>
SupermarketSpuEntity(
id: (json['id'] as num?)?.toInt(),
serviceUniqueCode: json['serviceUniqueCode'] as String,
classifyServiceUniqueCode: json['classifyServiceUniqueCode'] as String,
price: (json['price'] as num).toInt(),
sort: (json['sort'] as num).toInt(),
createTime: DateTime.parse(json['createTime'] as String),
updateTime: DateTime.parse(json['updateTime'] as String),
delFlag: json['delFlag'] as bool,
);
Map<String, dynamic> _$SupermarketSpuEntityToJson(
SupermarketSpuEntity instance) =>
<String, dynamic>{
'id': instance.id,
'serviceUniqueCode': instance.serviceUniqueCode,
'classifyServiceUniqueCode': instance.classifyServiceUniqueCode,
'price': instance.price,
'sort': instance.sort,
'createTime': instance.createTime.toIso8601String(),
'updateTime': instance.updateTime.toIso8601String(),
'delFlag': instance.delFlag,
};