feat:超市实体
This commit is contained in:
1 parent
321ae3378a
commit
c0fbf652fb
16 files changed
+640
-80
No files matched your search
@@ -43,15 +43,25 @@ abstract class ProductApi {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// 超市商品
|
||||
static Future<List<ServiceProduct>?> supermarketProduct(dynamic pa) async {
|
||||
final res = await HttpManage().dio.get(
|
||||
/// 超市 spu
|
||||
static Future<List<ServiceSupermarketSpuPage>?> supermarketSpu(
|
||||
dynamic pa) async {
|
||||
final res = await HttpManage().dio.post(
|
||||
"supermarket/supermarketSpu/ad/selectListAll",
|
||||
queryParameters: pa,
|
||||
);
|
||||
if (res.data == null) return null;
|
||||
return res.data
|
||||
?.map<ServiceProduct>((e) => ServiceProduct.fromJson(e))
|
||||
.toList();
|
||||
return res.data?.map((e) => ServiceSupermarketSpuPage.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
/// 超市 spu 详情
|
||||
static Future<List<ServiceSupermarketSkuPage>?> supermarketSupDetial(
|
||||
dynamic pa) async {
|
||||
final res = await HttpManage().dio.get(
|
||||
"supermarket/supermarketSpu/ad/SpuDetails",
|
||||
queryParameters: pa,
|
||||
);
|
||||
if (res.data == null) return null;
|
||||
return res.data?.map((e) => ServiceSupermarketSkuPage.fromJson(e)).toList();
|
||||
}
|
||||
}
|
||||
@@ -92,3 +92,251 @@ class ServiceProduct {
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceProductToJson(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// 超市 spu start
|
||||
// **************************************************************************
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSpu {
|
||||
/// id
|
||||
String? id;
|
||||
|
||||
/// 货号
|
||||
String? productCode;
|
||||
|
||||
/// 商品名称
|
||||
String? productName;
|
||||
|
||||
/// 单位
|
||||
String? unit;
|
||||
|
||||
/// 规格
|
||||
String? spec;
|
||||
|
||||
/// 商品分类编号
|
||||
String? categoryId;
|
||||
|
||||
/// 商品封面图
|
||||
String? picUrl;
|
||||
|
||||
/// 剩余库存
|
||||
String? stock;
|
||||
|
||||
/// 商品性质(字典)
|
||||
String? productNature;
|
||||
|
||||
/// 零售价
|
||||
String? retailPrice;
|
||||
|
||||
/// 促销价
|
||||
int? promotionPrice;
|
||||
|
||||
/// 销量
|
||||
int? salesCount;
|
||||
|
||||
ServiceSupermarketSpu({
|
||||
this.id,
|
||||
this.productCode,
|
||||
this.productName,
|
||||
this.unit,
|
||||
this.spec,
|
||||
this.categoryId,
|
||||
this.picUrl,
|
||||
this.stock,
|
||||
this.productNature,
|
||||
this.retailPrice,
|
||||
this.promotionPrice,
|
||||
this.salesCount,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSpu.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSpuFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSpuToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSpuPage extends ServicePageBase {
|
||||
List<ServiceSupermarketSpu>? records;
|
||||
|
||||
ServiceSupermarketSpuPage({
|
||||
this.records,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSpuPage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSpuPageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSpuPageToJson(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// 超市 spu end
|
||||
// **************************************************************************
|
||||
|
||||
// **************************************************************************
|
||||
// 超市 sku start
|
||||
// **************************************************************************
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSku {
|
||||
/// 商品 SPU 编号,自增
|
||||
String? id;
|
||||
|
||||
/// 货号
|
||||
String? productCode;
|
||||
|
||||
/// 商品名称
|
||||
String? productName;
|
||||
|
||||
/// 商品分类编号
|
||||
String? categoryId;
|
||||
|
||||
/// 商品封面图
|
||||
String? picUrl;
|
||||
|
||||
/// 剩余库存
|
||||
double? stock;
|
||||
|
||||
/// 商户编号
|
||||
String? merchantId;
|
||||
|
||||
/// 产地
|
||||
String? origin;
|
||||
|
||||
/// 商品性质(字典)
|
||||
String? productNature;
|
||||
|
||||
/// 品牌id
|
||||
String? brandId;
|
||||
|
||||
/// 货商id
|
||||
String? supplierId;
|
||||
|
||||
/// 销量
|
||||
int? salesCount;
|
||||
|
||||
/// 辅助条码集合
|
||||
List<ServiceSupermarketSkuCode>? supermarketAuxiliaryCodeEntityList;
|
||||
|
||||
/// 包装对象集合
|
||||
List<ServiceSupermarketSkuPackage>? supermarketUnitEntityList;
|
||||
|
||||
ServiceSupermarketSku({
|
||||
this.id,
|
||||
this.productCode,
|
||||
this.productName,
|
||||
this.categoryId,
|
||||
this.picUrl,
|
||||
this.stock,
|
||||
this.merchantId,
|
||||
this.origin,
|
||||
this.productNature,
|
||||
this.brandId,
|
||||
this.supplierId,
|
||||
this.salesCount,
|
||||
this.supermarketAuxiliaryCodeEntityList,
|
||||
this.supermarketUnitEntityList,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSku.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSkuFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSkuToJson(this);
|
||||
}
|
||||
|
||||
// 辅助条码
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSkuCode {
|
||||
/// 辅助条码id
|
||||
String? id;
|
||||
|
||||
/// spu Id
|
||||
String? spuId;
|
||||
|
||||
/// 包装单位id
|
||||
String? unitId;
|
||||
|
||||
/// 条码
|
||||
String? barCode;
|
||||
|
||||
ServiceSupermarketSkuCode({
|
||||
this.id,
|
||||
this.spuId,
|
||||
this.unitId,
|
||||
this.barCode,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSkuCode.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSkuCodeFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSkuCodeToJson(this);
|
||||
}
|
||||
|
||||
// 包装单位
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSkuPackage {
|
||||
/// 包装单位id
|
||||
String? id;
|
||||
|
||||
/// spu id
|
||||
String? spuId;
|
||||
|
||||
/// 条码
|
||||
String? barCode;
|
||||
|
||||
/// 规格
|
||||
String? spec;
|
||||
|
||||
/// 单位
|
||||
String? unit;
|
||||
|
||||
/// 状态(0正常,1停销)
|
||||
int? status;
|
||||
|
||||
/// 内装数量
|
||||
int? packageNum;
|
||||
|
||||
/// 进价/单位分
|
||||
int? purchasePrice;
|
||||
|
||||
/// 零售价/单位分
|
||||
int? retailPrice;
|
||||
|
||||
/// 促销价
|
||||
int? promotionPrice;
|
||||
|
||||
ServiceSupermarketSkuPackage({
|
||||
this.id,
|
||||
this.spuId,
|
||||
this.barCode,
|
||||
this.spec,
|
||||
this.unit,
|
||||
this.status,
|
||||
this.packageNum,
|
||||
this.purchasePrice,
|
||||
this.retailPrice,
|
||||
this.promotionPrice,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSkuPackage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSkuPackageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSkuPackageToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ServiceSupermarketSkuPage extends ServicePageBase {
|
||||
List<ServiceSupermarketSku>? records;
|
||||
|
||||
ServiceSupermarketSkuPage({
|
||||
this.records,
|
||||
});
|
||||
|
||||
factory ServiceSupermarketSkuPage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceSupermarketSkuPageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServiceSupermarketSkuPageToJson(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// 超市 sku end
|
||||
// **************************************************************************
|
||||
@@ -56,3 +56,178 @@ Map<String, dynamic> _$ServiceProductToJson(ServiceProduct instance) =>
|
||||
'categoryType': instance.categoryType,
|
||||
'saleDate': instance.saleDate?.toIso8601String(),
|
||||
};
|
||||
|
||||
ServiceSupermarketSpu _$ServiceSupermarketSpuFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSpu(
|
||||
id: json['id'] as String?,
|
||||
productCode: json['productCode'] as String?,
|
||||
productName: json['productName'] as String?,
|
||||
unit: json['unit'] as String?,
|
||||
spec: json['spec'] as String?,
|
||||
categoryId: json['categoryId'] as String?,
|
||||
picUrl: json['picUrl'] as String?,
|
||||
stock: json['stock'] as String?,
|
||||
productNature: json['productNature'] as String?,
|
||||
retailPrice: json['retailPrice'] as String?,
|
||||
promotionPrice: (json['promotionPrice'] as num?)?.toInt(),
|
||||
salesCount: (json['salesCount'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSpuToJson(
|
||||
ServiceSupermarketSpu instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'productCode': instance.productCode,
|
||||
'productName': instance.productName,
|
||||
'unit': instance.unit,
|
||||
'spec': instance.spec,
|
||||
'categoryId': instance.categoryId,
|
||||
'picUrl': instance.picUrl,
|
||||
'stock': instance.stock,
|
||||
'productNature': instance.productNature,
|
||||
'retailPrice': instance.retailPrice,
|
||||
'promotionPrice': instance.promotionPrice,
|
||||
'salesCount': instance.salesCount,
|
||||
};
|
||||
|
||||
ServiceSupermarketSpuPage _$ServiceSupermarketSpuPageFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSpuPage(
|
||||
records: (json['records'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) => ServiceSupermarketSpu.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
)
|
||||
..current = (json['current'] as num).toInt()
|
||||
..pages = (json['pages'] as num).toInt()
|
||||
..size = (json['size'] as num).toInt()
|
||||
..total = (json['total'] as num).toInt();
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSpuPageToJson(
|
||||
ServiceSupermarketSpuPage instance) =>
|
||||
<String, dynamic>{
|
||||
'current': instance.current,
|
||||
'pages': instance.pages,
|
||||
'size': instance.size,
|
||||
'total': instance.total,
|
||||
'records': instance.records,
|
||||
};
|
||||
|
||||
ServiceSupermarketSku _$ServiceSupermarketSkuFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSku(
|
||||
id: json['id'] as String?,
|
||||
productCode: json['productCode'] as String?,
|
||||
productName: json['productName'] as String?,
|
||||
categoryId: json['categoryId'] as String?,
|
||||
picUrl: json['picUrl'] as String?,
|
||||
stock: (json['stock'] as num?)?.toDouble(),
|
||||
merchantId: json['merchantId'] as String?,
|
||||
origin: json['origin'] as String?,
|
||||
productNature: json['productNature'] as String?,
|
||||
brandId: json['brandId'] as String?,
|
||||
supplierId: json['supplierId'] as String?,
|
||||
salesCount: (json['salesCount'] as num?)?.toInt(),
|
||||
supermarketAuxiliaryCodeEntityList:
|
||||
(json['supermarketAuxiliaryCodeEntityList'] as List<dynamic>?)
|
||||
?.map((e) =>
|
||||
ServiceSupermarketSkuCode.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
supermarketUnitEntityList: (json['supermarketUnitEntityList']
|
||||
as List<dynamic>?)
|
||||
?.map((e) =>
|
||||
ServiceSupermarketSkuPackage.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSkuToJson(
|
||||
ServiceSupermarketSku instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'productCode': instance.productCode,
|
||||
'productName': instance.productName,
|
||||
'categoryId': instance.categoryId,
|
||||
'picUrl': instance.picUrl,
|
||||
'stock': instance.stock,
|
||||
'merchantId': instance.merchantId,
|
||||
'origin': instance.origin,
|
||||
'productNature': instance.productNature,
|
||||
'brandId': instance.brandId,
|
||||
'supplierId': instance.supplierId,
|
||||
'salesCount': instance.salesCount,
|
||||
'supermarketAuxiliaryCodeEntityList':
|
||||
instance.supermarketAuxiliaryCodeEntityList,
|
||||
'supermarketUnitEntityList': instance.supermarketUnitEntityList,
|
||||
};
|
||||
|
||||
ServiceSupermarketSkuCode _$ServiceSupermarketSkuCodeFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSkuCode(
|
||||
id: json['id'] as String?,
|
||||
spuId: json['spuId'] as String?,
|
||||
unitId: json['unitId'] as String?,
|
||||
barCode: json['barCode'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSkuCodeToJson(
|
||||
ServiceSupermarketSkuCode instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'spuId': instance.spuId,
|
||||
'unitId': instance.unitId,
|
||||
'barCode': instance.barCode,
|
||||
};
|
||||
|
||||
ServiceSupermarketSkuPackage _$ServiceSupermarketSkuPackageFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSkuPackage(
|
||||
id: json['id'] as String?,
|
||||
spuId: json['spuId'] as String?,
|
||||
barCode: json['barCode'] as String?,
|
||||
spec: json['spec'] as String?,
|
||||
unit: json['unit'] as String?,
|
||||
status: (json['status'] as num?)?.toInt(),
|
||||
packageNum: (json['packageNum'] as num?)?.toInt(),
|
||||
purchasePrice: (json['purchasePrice'] as num?)?.toInt(),
|
||||
retailPrice: (json['retailPrice'] as num?)?.toInt(),
|
||||
promotionPrice: (json['promotionPrice'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSkuPackageToJson(
|
||||
ServiceSupermarketSkuPackage instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'spuId': instance.spuId,
|
||||
'barCode': instance.barCode,
|
||||
'spec': instance.spec,
|
||||
'unit': instance.unit,
|
||||
'status': instance.status,
|
||||
'packageNum': instance.packageNum,
|
||||
'purchasePrice': instance.purchasePrice,
|
||||
'retailPrice': instance.retailPrice,
|
||||
'promotionPrice': instance.promotionPrice,
|
||||
};
|
||||
|
||||
ServiceSupermarketSkuPage _$ServiceSupermarketSkuPageFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ServiceSupermarketSkuPage(
|
||||
records: (json['records'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) => ServiceSupermarketSku.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
)
|
||||
..current = (json['current'] as num).toInt()
|
||||
..pages = (json['pages'] as num).toInt()
|
||||
..size = (json['size'] as num).toInt()
|
||||
..total = (json['total'] as num).toInt();
|
||||
|
||||
Map<String, dynamic> _$ServiceSupermarketSkuPageToJson(
|
||||
ServiceSupermarketSkuPage instance) =>
|
||||
<String, dynamic>{
|
||||
'current': instance.current,
|
||||
'pages': instance.pages,
|
||||
'size': instance.size,
|
||||
'total': instance.total,
|
||||
'records': instance.records,
|
||||
};
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
@@ -1,14 +1,33 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
abstract class AppSettingTool {
|
||||
static const String _tag = "app配置工具";
|
||||
|
||||
static const String _settingKey = "setting";
|
||||
|
||||
// 自定义缓存管理器
|
||||
static final CacheManager _settingCache = CacheManager(
|
||||
Config(
|
||||
'setting_cache',
|
||||
stalePeriod: const Duration(days: 7),
|
||||
maxNrOfCacheObjects: 10,
|
||||
),
|
||||
);
|
||||
|
||||
static Future<SettingEntity> _getSetting() async {
|
||||
// 尝试从缓存获取
|
||||
final fileInfo = await _settingCache.getFileFromCache(_settingKey);
|
||||
if (fileInfo != null) {
|
||||
final content = await fileInfo.file.readAsString();
|
||||
return SettingEntity.fromJson(json.decode(content));
|
||||
}
|
||||
final app = Get.find<AppControl>();
|
||||
final settingDao = app.dataBase.getSettingDao;
|
||||
final setting = await settingDao.get();
|
||||
@@ -64,9 +83,12 @@ abstract class AppSettingTool {
|
||||
canteenExtraPriceConfig.toJson(),
|
||||
);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(userJson)) {}
|
||||
if (ObjectUtil.isNotEmpty(canteenExtraPriceConfig)) {}
|
||||
await settingDao.edit(setting);
|
||||
await _settingCache.putFile(
|
||||
'setting',
|
||||
Uint8List.fromList(utf8.encode(json.encode(setting.toJson()))),
|
||||
fileExtension: 'json',
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ abstract class SyncProductTool {
|
||||
apiList?.forEach((v) => v.saleDate = dayStr);
|
||||
}
|
||||
} else if (sysType == SysType.SUPERMARKET) {
|
||||
apiList = await ProductApi.supermarketProduct(null);
|
||||
apiList = await ProductApi.supermarketSpu(null);
|
||||
}
|
||||
if (apiList == null) return;
|
||||
if (ObjectUtil.isEmptyList(apiList)) {
|
||||
|
||||
@@ -193,5 +193,5 @@ Widget orderRowClassify(
|
||||
);
|
||||
})
|
||||
.toList()
|
||||
.toRowSpace(space: 20.w);
|
||||
.toRowSpace(space: 10.w);
|
||||
}
|
||||
@@ -17,28 +17,21 @@ class CanteenProductPage extends GetView<CanteenProductController> {
|
||||
final context = Get.context!;
|
||||
final theme = FTheme.of(context);
|
||||
return <Widget>[
|
||||
<Widget>[
|
||||
appBack(
|
||||
context,
|
||||
height: headerHeight,
|
||||
onTap: () => Get.offAndToNamed(RouteNames.panel),
|
||||
),
|
||||
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,
|
||||
),
|
||||
appBack(
|
||||
context,
|
||||
height: headerHeight,
|
||||
onTap: () => Get.offAndToNamed(RouteNames.panel),
|
||||
),
|
||||
].toColumn().decorated(
|
||||
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().decorated(
|
||||
color: theme.colorScheme.background,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
@@ -49,7 +42,6 @@ class CanteenProductPage extends GetView<CanteenProductController> {
|
||||
),
|
||||
],
|
||||
);
|
||||
;
|
||||
}
|
||||
|
||||
// 商品
|
||||
|
||||
@@ -118,8 +118,6 @@ class SettingPage extends GetView<SettingController> {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return settingProduct(context);
|
||||
default:
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -101,12 +101,12 @@ class FaceManageController extends GetxController {
|
||||
getFaceList();
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
currentPage.value = 1;
|
||||
getFaceList();
|
||||
// 重新生成人脸模型
|
||||
await AppFaceTool.removeFace(sampleId: "-1");
|
||||
await AppFaceTool.faceRegister(forceRegister: true);
|
||||
} finally {
|
||||
currentPage.value = 1;
|
||||
Toast.success(msg: "同步成功");
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:forui/forui.dart';
|
||||
@@ -10,14 +9,22 @@ import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
class ProductManageController extends GetxController {
|
||||
static const _tag = "商品管理 Controller";
|
||||
|
||||
RxList<CanteenSpuEntity> productList = <CanteenSpuEntity>[].obs;
|
||||
AppControl appC = Get.find<AppControl>();
|
||||
|
||||
late SysSetting sysSetting;
|
||||
|
||||
Rx<SysType> sysType = SysType.CANTEEN.obs;
|
||||
|
||||
// 食堂商品
|
||||
RxList<CanteenSpuEntity> canteenSpuList = <CanteenSpuEntity>[].obs;
|
||||
|
||||
// 超市商品
|
||||
final supermarketSpuList = <SupermarketSpuEntity>[].obs;
|
||||
|
||||
ProductHourType hourType = ProductHourType.MORNING;
|
||||
|
||||
RxInt currentPage = RxInt(1);
|
||||
|
||||
RxInt totalPage = RxInt(0);
|
||||
|
||||
RxInt pageSize = RxInt(24);
|
||||
|
||||
final hourTypeC = FRadioSelectGroupController<String>(
|
||||
@@ -26,8 +33,10 @@ class ProductManageController extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
await initData();
|
||||
super.onInit();
|
||||
sysSetting = await AppSettingTool.getSysSetting();
|
||||
sysType.value = sysSetting.sysType;
|
||||
await getProductList();
|
||||
hourTypeC.addValueListener((v) async {
|
||||
final currentHourType = ProductHourType.values.fromCode(
|
||||
v.first,
|
||||
@@ -44,13 +53,6 @@ class ProductManageController extends GetxController {
|
||||
hourTypeC.dispose();
|
||||
}
|
||||
|
||||
Future<void> initData() async {
|
||||
await getProductList();
|
||||
if (ObjectUtil.isEmptyList(productList)) {
|
||||
getProductList();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新商品和分类
|
||||
Future<void> updateProductAndClassify() async {
|
||||
EasyLoading.show(
|
||||
@@ -76,22 +78,35 @@ class ProductManageController extends GetxController {
|
||||
);
|
||||
}
|
||||
try {
|
||||
final app = Get.find<AppControl>();
|
||||
final sysSetting = await AppSettingTool.getSysSetting();
|
||||
final productDao = app.dataBase.getCanteenSpuDao;
|
||||
final currnetHourType = hourType.code;
|
||||
String sysType = sysSetting.sysType.name;
|
||||
final findCount = await productDao.getCount(
|
||||
currnetHourType,
|
||||
);
|
||||
if (findCount != null) totalPage.value = findCount;
|
||||
final list = await productDao.getAllPage(
|
||||
"-1",
|
||||
currnetHourType,
|
||||
pageSize.value,
|
||||
(currentPage.value - 1) * pageSize.value,
|
||||
);
|
||||
productList.value = list;
|
||||
SysType sysType = sysSetting.sysType;
|
||||
|
||||
if (sysType == SysType.SUPERMARKET) {
|
||||
// 超市
|
||||
final supermarketSpuDao = appC.dataBase.getSupermarketSpuDao;
|
||||
final findCount = await supermarketSpuDao.getCount();
|
||||
totalPage.value = findCount ?? 0;
|
||||
final list = await supermarketSpuDao.getAllPage(
|
||||
"-1",
|
||||
pageSize.value,
|
||||
(currentPage.value - 1) * pageSize.value,
|
||||
);
|
||||
supermarketSpuList.value = list;
|
||||
} else if (sysType == SysType.CANTEEN) {
|
||||
// 食堂
|
||||
final productDao = appC.dataBase.getCanteenSpuDao;
|
||||
final findCount = await productDao.getCount(
|
||||
currnetHourType,
|
||||
);
|
||||
totalPage.value = findCount ?? 0;
|
||||
final list = await productDao.getAllPage(
|
||||
"-1",
|
||||
currnetHourType,
|
||||
pageSize.value,
|
||||
(currentPage.value - 1) * pageSize.value,
|
||||
);
|
||||
canteenSpuList.value = list;
|
||||
}
|
||||
} finally {
|
||||
if (isLoading) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
@@ -119,8 +134,7 @@ class ProductManageController extends GetxController {
|
||||
status: '设置中...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final app = Get.find<AppControl>();
|
||||
final productDao = app.dataBase.getCanteenSpuDao;
|
||||
final productDao = appC.dataBase.getCanteenSpuDao;
|
||||
final editObj = CanteenSpuEntity.fromJson(v.toJson());
|
||||
editObj.isDefault = !editObj.isDefault;
|
||||
await productDao.edit(
|
||||
@@ -135,16 +149,20 @@ class ProductManageController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 搜索条件
|
||||
Widget buildSearch(BuildContext context) {
|
||||
// 搜索条件
|
||||
Widget _buildSearch(BuildContext context) {
|
||||
final theme = FTheme.of(context);
|
||||
final productC = Get.find<ProductManageController>();
|
||||
return <Widget>[
|
||||
<Widget>[
|
||||
appRadioHourTypeDialog(
|
||||
context,
|
||||
productC.hourTypeC,
|
||||
).width(300.w),
|
||||
Obx(
|
||||
() => appRadioHourTypeDialog(
|
||||
context,
|
||||
productC.hourTypeC,
|
||||
).offstage(
|
||||
offstage: productC.sysType.value != SysType.CANTEEN,
|
||||
),
|
||||
).width(300.w)
|
||||
].toRow().expanded(),
|
||||
FButton(
|
||||
prefix: FIcon(
|
||||
@@ -172,8 +190,8 @@ Widget buildSearch(BuildContext context) {
|
||||
].toRow();
|
||||
}
|
||||
|
||||
/// 列表
|
||||
Widget buildList(BuildContext context) {
|
||||
// 食堂列表
|
||||
Widget _buildCanteenList(BuildContext context) {
|
||||
final theme = FTheme.of(context);
|
||||
final productC = Get.find<ProductManageController>();
|
||||
return Obx(
|
||||
@@ -184,9 +202,9 @@ Widget buildList(BuildContext context) {
|
||||
crossAxisSpacing: 10.w,
|
||||
childAspectRatio: 0.7,
|
||||
),
|
||||
itemCount: productC.productList.length,
|
||||
itemCount: productC.canteenSpuList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final v = productC.productList[index];
|
||||
final v = productC.canteenSpuList[index];
|
||||
return FCard(
|
||||
style: theme.cardStyle.copyWith(
|
||||
contentStyle: theme.cardStyle.contentStyle.copyWith(
|
||||
@@ -212,13 +230,24 @@ Widget buildList(BuildContext context) {
|
||||
);
|
||||
}
|
||||
|
||||
// 超市列表
|
||||
Widget _buildSupermarketList(BuildContext context) {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
Widget settingProduct(BuildContext context) {
|
||||
final productC = Get.put<ProductManageController>(
|
||||
ProductManageController(),
|
||||
);
|
||||
return <Widget>[
|
||||
buildSearch(context),
|
||||
buildList(context).expanded(),
|
||||
_buildSearch(context),
|
||||
Obx(
|
||||
() => Visibility(
|
||||
visible: productC.sysType.value == SysType.CANTEEN,
|
||||
replacement: _buildSupermarketList(context),
|
||||
child: _buildCanteenList(context),
|
||||
),
|
||||
).expanded(),
|
||||
Obx(
|
||||
() => appPage(
|
||||
context,
|
||||
|
||||
+1
-1
@@ -436,7 +436,7 @@ packages:
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_cache_manager:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_cache_manager
|
||||
sha256: "400b6592f16a4409a7f2bb929a9a7e38c72cceb8ffb99ee57bbf2cb2cecf8386"
|
||||
|
||||
@@ -48,6 +48,8 @@ dependencies:
|
||||
# 数据库
|
||||
sqflite: 2.4.1
|
||||
floor: 1.4.2
|
||||
# 缓存
|
||||
flutter_cache_manager: ^3.4.1
|
||||
# json序列化
|
||||
json_annotation: ^4.9.0
|
||||
# 外部路径获取
|
||||
|
||||
Reference in new issue
Block a user