feat:本地商品bug
This commit is contained in:
1 parent
32341ef253
commit
1f50f737b1
11 files changed
+152
-92
No files matched your search
@@ -163,21 +163,34 @@ abstract class SyncProductTool {
|
||||
await _batchUpdateCaneenProduct(list: canteenList);
|
||||
} else if (sysType == SysType.SUPERMARKET) {
|
||||
// 超市
|
||||
final app = Get.find<AppControl>();
|
||||
final dataBase = app.dataBase;
|
||||
final supermarketSpuDao = dataBase.getSupermarketSpuDao;
|
||||
final supermarketSkuDao = dataBase.getSupermarketSkuDao;
|
||||
final supermarketCodeDao = dataBase.getSupermarketCodeDao;
|
||||
int currentPage = 1;
|
||||
Set<String> serviceCodes = {};
|
||||
while (true) {
|
||||
final pa = {
|
||||
"current": currentPage,
|
||||
"size": 50,
|
||||
};
|
||||
final supermarket = await ProductApi.supermarketSpu(
|
||||
pa,
|
||||
final pa = {"current": currentPage, "size": 50};
|
||||
final supermarket = await ProductApi.supermarketSpu(pa);
|
||||
if (supermarket == null) break;
|
||||
if (ObjectUtil.isEmptyList(supermarket.records)) break;
|
||||
final ids = await _batchUpdateSupermarketProduct(
|
||||
list: supermarket.records!,
|
||||
);
|
||||
if (supermarket == null ||
|
||||
ObjectUtil.isEmptyList(supermarket.records)) {
|
||||
break;
|
||||
}
|
||||
currentPage += 1;
|
||||
await _batchUpdateSupermarketProduct(list: supermarket.records!);
|
||||
serviceCodes.addAll(ids);
|
||||
}
|
||||
// 处理删除
|
||||
final productList = await supermarketSpuDao.getAll(
|
||||
"-1",
|
||||
);
|
||||
final dbCodes = productList.map((e) => e.serviceUniqueCode).toSet();
|
||||
final deleteCodes = dbCodes.difference(serviceCodes).toList();
|
||||
if (ObjectUtil.isNotEmpty(deleteCodes)) {
|
||||
await supermarketSpuDao.delByIds(deleteCodes);
|
||||
await supermarketSkuDao.delBySpuIds(deleteCodes);
|
||||
await supermarketCodeDao.delBySpuIds(deleteCodes);
|
||||
}
|
||||
}
|
||||
// 更新同步时间
|
||||
@@ -299,7 +312,7 @@ abstract class SyncProductTool {
|
||||
// 同步食堂商品 spu start
|
||||
// **************************************************************************
|
||||
|
||||
static Future<void> _batchUpdateSupermarketProduct({
|
||||
static Future<List<String>> _batchUpdateSupermarketProduct({
|
||||
required List<ServiceSupermarketSpu> list,
|
||||
}) async {
|
||||
final app = Get.find<AppControl>();
|
||||
@@ -314,13 +327,12 @@ abstract class SyncProductTool {
|
||||
isUpdate: false,
|
||||
);
|
||||
await _batchAddOrUpdateSupermarketSpuAndCode(list);
|
||||
return;
|
||||
return list.map((e) => e.id.toString()).toSet().toList();
|
||||
}
|
||||
final apiServiceCodes = list.map((e) => e.id.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 _batchAddOrUpdateSupermarketProduct(
|
||||
@@ -328,9 +340,6 @@ abstract class SyncProductTool {
|
||||
isUpdate: false,
|
||||
);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(deleteCodes)) {
|
||||
await supermarketSpuDao.delByIds(deleteCodes);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(updateCodes)) {
|
||||
await _batchAddOrUpdateSupermarketProduct(
|
||||
list: _filterCaneenSupermarketByCodes(list, updateCodes),
|
||||
@@ -338,6 +347,7 @@ abstract class SyncProductTool {
|
||||
);
|
||||
}
|
||||
await _batchAddOrUpdateSupermarketSpuAndCode(list);
|
||||
return apiServiceCodes.toList();
|
||||
}
|
||||
|
||||
static Future<void> _batchAddOrUpdateSupermarketProduct({
|
||||
@@ -354,13 +364,13 @@ abstract class SyncProductTool {
|
||||
serviceUniqueCode: v.id ?? "-1",
|
||||
classifyServiceUniqueCode: v.categoryId ?? "-1",
|
||||
productCode: v.productCode ?? "-1",
|
||||
productName: v.productCode ?? "",
|
||||
productName: v.productName ?? "",
|
||||
productNature: ProductNature.values.fromCode(v.productNature) ??
|
||||
ProductNature.DEFAULT,
|
||||
barCode: "",
|
||||
packageNum: 0,
|
||||
unit: v.productCode ?? "",
|
||||
spec: v.productCode ?? "",
|
||||
unit: v.unit ?? "",
|
||||
spec: v.spec ?? "",
|
||||
picUrl: v.picUrl ?? "",
|
||||
stock: v.stock ?? 0,
|
||||
salesCount:
|
||||
|
||||
Reference in new issue
Block a user