|
@@ -201,12 +201,18 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
if (ObjectUtil.isEmpty(list)) {
|
|
|
throw new ServiceException("sku规格信息不能为空");
|
|
|
}
|
|
|
+ // 获取sku数据
|
|
|
List<String> skuSpecCodes = list.stream().map(SkuSpecImportDataDto::getSkuSpecCode).collect(Collectors.toList());
|
|
|
Map<String, SkuSpec> skuSpecMap = this.mapKEntity(SkuSpec::getCode, q -> q.in(SkuSpec::getCode, skuSpecCodes));
|
|
|
List<ArtworkLibrary> artworkLibraryList = artworkLibraryService.list();
|
|
|
List<BomSpec> bomSpecList = bomSpecService.list();
|
|
|
Map<String, BomSpec> bomSpecMap = bomSpecList.stream().collect(Collectors.toMap(BomSpec::getCode, item -> item, (v1, v2) -> v2));
|
|
|
- List<SkuSpecLink> skuSpecLinkList = new ArrayList<>();
|
|
|
+ // 获取所有sku的包材数据
|
|
|
+ List<Long> skuSpecIds = skuSpecMap.values().stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<SkuSpecLink>> oldLinkMap = skuSpecLinkService.mapKGroup(SkuSpecLink::getSkuSpecId, q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds));
|
|
|
+
|
|
|
+ List<SkuSpecLink> addLinkList = new ArrayList<>();
|
|
|
+ List<SkuSpecLink> removeLinkList = new ArrayList<>();
|
|
|
|
|
|
for (SkuSpecImportDataDto dto : list) {
|
|
|
SkuSpec skuSpec = skuSpecMap.get(dto.getSkuSpecCode());
|
|
@@ -267,9 +273,20 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
bomSpecCodes.add(dto.getPackagingBomSpecCode_9());
|
|
|
bomSpecCodes.add(dto.getPackagingBomSpecCode_10());
|
|
|
bomSpecCodes.removeAll(Collections.singleton(null));
|
|
|
+
|
|
|
+ List<SkuSpecLink> linkList = oldLinkMap.getOrDefault(skuSpec.getId(), Collections.emptyList());
|
|
|
+
|
|
|
for (String bomSpecCode : bomSpecCodes) {
|
|
|
BomSpec packagingBomSpec = bomSpecMap.get(bomSpecCode);
|
|
|
if (packagingBomSpec != null) {
|
|
|
+ // 判断是否已经存在该包材,存在踢出需要删除的集合
|
|
|
+ SkuSpecLink link = linkList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getBomSpecId(), packagingBomSpec.getId()))
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (link != null) {
|
|
|
+ linkList.remove(link);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
SkuSpecLink skuSpecLink = new SkuSpecLink();
|
|
|
skuSpecLink.setSkuId(skuSpec.getSkuId());
|
|
|
skuSpecLink.setSkuSpecId(skuSpec.getId());
|
|
@@ -277,28 +294,41 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
skuSpecLink.setDepartmentId(0L);
|
|
|
skuSpecLink.setType(1);
|
|
|
skuSpecLink.setQuantity(BigDecimal.ONE);
|
|
|
- skuSpecLinkList.add(skuSpecLink);
|
|
|
+ addLinkList.add(skuSpecLink);
|
|
|
}
|
|
|
}
|
|
|
// 保存快递包材
|
|
|
BomSpec deliveryMaterialsBomSpec = bomSpecMap.get(dto.getDeliveryMaterialsBomSpecCode());
|
|
|
if (deliveryMaterialsBomSpec != null) {
|
|
|
- SkuSpecLink skuSpecLink = new SkuSpecLink();
|
|
|
- skuSpecLink.setSkuId(skuSpec.getSkuId());
|
|
|
- skuSpecLink.setSkuSpecId(skuSpec.getId());
|
|
|
- skuSpecLink.setBomSpecId(deliveryMaterialsBomSpec.getId());
|
|
|
- skuSpecLink.setDepartmentId(0L);
|
|
|
- skuSpecLink.setType(2);
|
|
|
- skuSpecLink.setQuantity(BigDecimal.ONE);
|
|
|
- skuSpecLinkList.add(skuSpecLink);
|
|
|
+ // 判断是否已经存在该包材,存在踢出需要删除的集合
|
|
|
+ SkuSpecLink link = linkList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getBomSpecId(), deliveryMaterialsBomSpec.getId()))
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (link != null) {
|
|
|
+ linkList.remove(link);
|
|
|
+ } else {
|
|
|
+ SkuSpecLink skuSpecLink = new SkuSpecLink();
|
|
|
+ skuSpecLink.setSkuId(skuSpec.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(skuSpec.getId());
|
|
|
+ skuSpecLink.setBomSpecId(deliveryMaterialsBomSpec.getId());
|
|
|
+ skuSpecLink.setDepartmentId(0L);
|
|
|
+ skuSpecLink.setType(2);
|
|
|
+ skuSpecLink.setQuantity(BigDecimal.ONE);
|
|
|
+ addLinkList.add(skuSpecLink);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 添加需要删除包材数据
|
|
|
+ removeLinkList.addAll(linkList);
|
|
|
}
|
|
|
|
|
|
this.updateBatchById(skuSpecMap.values());
|
|
|
- if (!skuSpecLinkList.isEmpty()) {
|
|
|
- List<Long> skuSpecIds = skuSpecLinkList.stream().map(SkuSpecLink::getSkuSpecId).distinct().collect(Collectors.toList());
|
|
|
- skuSpecLinkService.remove(q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds));
|
|
|
- skuSpecLinkService.saveBatch(skuSpecLinkList);
|
|
|
+ if (!removeLinkList.isEmpty()) {
|
|
|
+ List<Long> removeLinkIds = removeLinkList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ skuSpecLinkService.remove(q -> q.in(BaseIdPo::getId, removeLinkIds));
|
|
|
+ }
|
|
|
+ if (!addLinkList.isEmpty()) {
|
|
|
+ skuSpecLinkService.saveBatch(addLinkList);
|
|
|
}
|
|
|
}
|
|
|
|