|
@@ -30,9 +30,11 @@ import com.sd.business.entity.sku.bo.SkuSpecBo;
|
|
import com.sd.business.entity.sku.dto.SkuSpecDto;
|
|
import com.sd.business.entity.sku.dto.SkuSpecDto;
|
|
import com.sd.business.entity.sku.dto.SkuSpecImportDataDto;
|
|
import com.sd.business.entity.sku.dto.SkuSpecImportDataDto;
|
|
import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
|
|
import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
|
|
|
|
+import com.sd.business.entity.sku.dto.SkuSpecSelectImportDto;
|
|
import com.sd.business.entity.sku.po.Sku;
|
|
import com.sd.business.entity.sku.po.Sku;
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
import com.sd.business.entity.sku.po.SkuSpecLink;
|
|
import com.sd.business.entity.sku.po.SkuSpecLink;
|
|
|
|
+import com.sd.business.entity.sku.vo.SkuSpecLinkVo;
|
|
import com.sd.business.entity.sku.vo.SkuSpecVo;
|
|
import com.sd.business.entity.sku.vo.SkuSpecVo;
|
|
import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
import com.sd.business.mapper.sku.SkuSpecMapper;
|
|
import com.sd.business.mapper.sku.SkuSpecMapper;
|
|
@@ -625,4 +627,95 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
return skuSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toSet());
|
|
return skuSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toSet());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<SkuSpecVo> getSkuSpecListFromImport(List<SkuSpecSelectImportDto> list) {
|
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> skuSpecCodes = list.stream().map(SkuSpecSelectImportDto::getSkuSpecCode).collect(Collectors.toList());
|
|
|
|
+ List<SkuSpec> skuSpecList = this.list(q -> q.in(SkuSpec::getCode, skuSpecCodes));
|
|
|
|
+ if (ObjectUtil.isEmpty(skuSpecList)) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+ List<SkuSpecVo> skuSpecVoList = BeanUtil.copyToList(skuSpecList, SkuSpecVo.class);
|
|
|
|
+
|
|
|
|
+ // sku规格关联
|
|
|
|
+ List<Long> skuSpecIds = skuSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = skuSpecLinkService.list(q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds));
|
|
|
|
+
|
|
|
|
+ // sku规格关联map
|
|
|
|
+ Map<Long, Map<Integer, List<SkuSpecLink>>> map = skuSpecLinkList.stream().collect(
|
|
|
|
+ Collectors.groupingBy(SkuSpecLink::getSkuSpecId, Collectors.groupingBy(SkuSpecLink::getType)));
|
|
|
|
+
|
|
|
|
+ // bom规格id列表
|
|
|
|
+ List<Long> skuBomSpecIds = skuSpecList.stream().map(SkuSpec::getBomSpecId).filter(ObjectUtil::isNotNull).collect(Collectors.toList());
|
|
|
|
+ List<Long> bomSpecIdList = new ArrayList<>();
|
|
|
|
+ bomSpecIdList.addAll(skuBomSpecIds);
|
|
|
|
+ bomSpecIdList.addAll(skuSpecLinkList.stream().map(SkuSpecLink::getBomSpecId).collect(Collectors.toList()));
|
|
|
|
+ Map<Long, BomSpec> bomSpecMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ if (!bomSpecIdList.isEmpty()) {
|
|
|
|
+ bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 库存列表
|
|
|
|
+ Map<Long, BigDecimal> inventoryMap = inventoryService.mapKV(Inventory::getBomSpecId, Inventory::getQuantity, q -> q
|
|
|
|
+ .in(Inventory::getBomSpecId, skuBomSpecIds)
|
|
|
|
+ .in(Inventory::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT, WarehouseConstant.PACKAGING_MATERIAL));
|
|
|
|
+
|
|
|
|
+ for (SkuSpecVo item : skuSpecVoList) {
|
|
|
|
+
|
|
|
|
+ // 赋值主材bom名称
|
|
|
|
+ Long bomSpecId = item.getBomSpecId();
|
|
|
|
+ if (bomSpecId != null) {
|
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(bomSpecId);
|
|
|
|
+ if (bomSpec != null) {
|
|
|
|
+ item.setBomSpecCode(bomSpec.getCode());
|
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 包材,快递包装
|
|
|
|
+ Map<Integer, List<SkuSpecLink>> typeSkuSpecLinkMap = map.get(item.getId());
|
|
|
|
+ if (typeSkuSpecLinkMap == null) {
|
|
|
|
+ item.setPackagingMaterialList(Collections.emptyList());
|
|
|
|
+ item.setExpressPackingList(Collections.emptyList());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 赋值包材
|
|
|
|
+ List<SkuSpecLinkVo> packagingMaterialList = createSkuSpecLinkVoList(typeSkuSpecLinkMap.get(1), bomSpecMap);
|
|
|
|
+ item.setPackagingMaterialList(packagingMaterialList);
|
|
|
|
+
|
|
|
|
+ // 赋值快递包装
|
|
|
|
+ List<SkuSpecLinkVo> expressPackingList = createSkuSpecLinkVoList(typeSkuSpecLinkMap.get(2), bomSpecMap);
|
|
|
|
+ item.setExpressPackingList(expressPackingList);
|
|
|
|
+
|
|
|
|
+ // 赋值库存数量
|
|
|
|
+ item.setInventoryQuantity(inventoryMap.getOrDefault(item.getBomSpecId(), BigDecimal.ZERO));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return skuSpecVoList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建sku规格关联
|
|
|
|
+ */
|
|
|
|
+ private List<SkuSpecLinkVo> createSkuSpecLinkVoList(List<SkuSpecLink> skuSpecLinkList, Map<Long, BomSpec> bomSpecMap) {
|
|
|
|
+ if (ObjectUtil.isEmpty(skuSpecLinkList)) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return skuSpecLinkList.stream().map(item -> {
|
|
|
|
+ SkuSpecLinkVo skuSpecLinkVo = BeanUtil.toBean(item, SkuSpecLinkVo.class);
|
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(item.getBomSpecId());
|
|
|
|
+ if (bomSpec != null) {
|
|
|
|
+ skuSpecLinkVo.setName(bomSpec.getName());
|
|
|
|
+ skuSpecLinkVo.setInternalSellingPrice(bomSpec.getInternalSellingPrice());
|
|
|
|
+ }
|
|
|
|
+ return skuSpecLinkVo;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|