feat:离线支持
This commit is contained in:
1 parent
12597ba258
commit
0af163738f
15 files changed
+89
-112
No files matched your search
@@ -47,6 +47,12 @@ abstract class SyncOrderTool {
|
||||
List<Map<String, dynamic>> uploadList = [];
|
||||
for (final OrderEntity v in list) {
|
||||
Map<String, dynamic> item = v.toJson();
|
||||
if (ObjectUtil.isNotEmpty(v.createTime)) {
|
||||
item["createTime"] = DateUtil.formatDate(v.createTime);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(v.payTime)) {
|
||||
item["payTime"] = DateUtil.formatDate(v.payTime!);
|
||||
}
|
||||
if (v.id != null) {
|
||||
final carList = await shopCardDao.findByOrderId(v.id!);
|
||||
if (!ObjectUtil.isEmptyList(carList)) {
|
||||
|
||||
@@ -251,44 +251,21 @@ abstract class SyncProductTool {
|
||||
final app = Get.find<AppControl>();
|
||||
final dataBase = app.dataBase;
|
||||
final productDao = dataBase.getCanteenSpuDao;
|
||||
// 查询当天全部数据
|
||||
final productList = await productDao.getAll(
|
||||
"-1",
|
||||
"-1",
|
||||
dayStr,
|
||||
);
|
||||
if (ObjectUtil.isEmpty(productList)) {
|
||||
await _batchAddOrUpdateCaneenProduct(
|
||||
list: list,
|
||||
isUpdate: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
final apiServiceCodes = list.map((e) => e.spuId.toString()).toSet();
|
||||
final dbServiceCodes = productList.map((e) => e.serviceUniqueCode).toSet();
|
||||
|
||||
final addCodes = apiServiceCodes.difference(dbServiceCodes).toList();
|
||||
final deleteCodes = dbServiceCodes.difference(apiServiceCodes).toList();
|
||||
final updateCodes = apiServiceCodes.intersection(dbServiceCodes).toList();
|
||||
if (ObjectUtil.isNotEmpty(addCodes)) {
|
||||
await _batchAddOrUpdateCaneenProduct(
|
||||
list: _filterCaneenProductListByCodes(list, addCodes),
|
||||
isUpdate: false,
|
||||
);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(deleteCodes)) {
|
||||
await productDao.delByIds(deleteCodes);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(updateCodes)) {
|
||||
await _batchAddOrUpdateCaneenProduct(
|
||||
list: _filterCaneenProductListByCodes(list, updateCodes),
|
||||
isUpdate: true,
|
||||
);
|
||||
}
|
||||
// 删除当天全部数据
|
||||
await productDao.delAllByDay(dayStr);
|
||||
// 插入
|
||||
await _batchAddOrUpdateCaneenProduct(list: list, productList: productList);
|
||||
}
|
||||
|
||||
static Future<void> _batchAddOrUpdateCaneenProduct({
|
||||
required List<ServiceProduct> list,
|
||||
required bool isUpdate,
|
||||
required List<CanteenSpuEntity> productList,
|
||||
}) async {
|
||||
if (ObjectUtil.isEmpty(list)) return;
|
||||
final app = Get.find<AppControl>();
|
||||
@@ -310,36 +287,22 @@ abstract class SyncProductTool {
|
||||
hourType: ProductHourType.values.fromCode(v.hourType),
|
||||
saleDate: v.saleDate ?? DateTime.now(),
|
||||
isDefault: false,
|
||||
delFlag: false,
|
||||
);
|
||||
if (isUpdate) {
|
||||
final saleDateStr = DateUtil.formatDate(item.saleDate);
|
||||
final detail = await productDao.getByCode(
|
||||
item.serviceUniqueCode,
|
||||
saleDateStr,
|
||||
);
|
||||
if (ObjectUtil.isEmpty(detail)) continue;
|
||||
if (detail == item) continue;
|
||||
item.id = detail?.id;
|
||||
if (!ObjectUtil.isEmptyList(productList)) {
|
||||
final targetProduct = productList.firstWhereOrNull((i) =>
|
||||
i.serviceUniqueCode == item.serviceUniqueCode &&
|
||||
i.isDefault == true);
|
||||
if (targetProduct != null) {
|
||||
item.isDefault = true;
|
||||
}
|
||||
}
|
||||
changeList.add(item);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(changeList)) {
|
||||
isUpdate
|
||||
? await productDao.batchEdit(changeList)
|
||||
: await productDao.batchSave(changeList);
|
||||
await productDao.batchSave(changeList);
|
||||
}
|
||||
}
|
||||
|
||||
static List<ServiceProduct> _filterCaneenProductListByCodes(
|
||||
List<ServiceProduct> sourceList,
|
||||
List<String> codes,
|
||||
) {
|
||||
return sourceList
|
||||
.where((item) => codes.contains(item.spuId.toString()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// 同步食堂商品 spu end
|
||||
// **************************************************************************
|
||||
|
||||
Reference in new issue
Block a user