|
@@ -1,11 +1,21 @@
|
|
|
package com.sd.business.service.sku.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
import com.sd.business.mapper.sku.SkuSpecMapper;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
+import com.sd.framework.util.Assert;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -18,4 +28,42 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> implements SkuSpecService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal getSkuInventoryQuantity(Long id) {
|
|
|
+ // 获取sku信息
|
|
|
+ SkuSpec skuSpec = this.getById(id);
|
|
|
+ Assert.notNull(skuSpec, "没有找到sku信息");
|
|
|
+
|
|
|
+ // 获取bom规格id
|
|
|
+ Long bomSpecId = skuSpec.getBomSpecId();
|
|
|
+ if (ObjectUtil.isEmpty(bomSpecId)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取bom规格信息
|
|
|
+ BomSpecBo bomSpecBo = bomSpecService.getBomSpecBo(bomSpecId);
|
|
|
+ Assert.notNull(bomSpecBo, "未知bom规格id:" + bomSpecId);
|
|
|
+
|
|
|
+ // 获取库存仓库id
|
|
|
+ Long warehouseId = ObjectUtil.equals(bomSpecBo.getClassifyParentId(), 1L) ?
|
|
|
+ WarehouseConstant.SEMI_FINISHED_PRODUCT : WarehouseConstant.PACKAGING_MATERIAL;
|
|
|
+
|
|
|
+ // 查询库存
|
|
|
+ Inventory inventory = inventoryService.getOne(q -> q
|
|
|
+ .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
+ .eq(Inventory::getBomSpecId, bomSpecId));
|
|
|
+
|
|
|
+ if (inventory == null) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ObjectUtil.defaultIfNull(inventory.getQuantity(), BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
}
|