|
@@ -5,16 +5,23 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.sku.dto.SkuSpecDto;
|
|
|
import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
import com.sd.business.entity.sku.vo.SkuSpecVo;
|
|
|
+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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
@@ -33,6 +40,11 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> implements SkuSpecService {
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
|
|
|
@Override
|
|
|
public Page<SkuSpecVo> getPage(SkuSpecSelectDto dto) {
|
|
@@ -82,4 +94,32 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
return list.stream().collect(Collectors.toMap(BomSpecBo::getBomSpecId, Function.identity()));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public BigDecimal getSkuInventoryQuantity(Long id) {
|
|
|
+ SkuSpec skuSpec = this.getById(id);
|
|
|
+ if (skuSpec == null) {
|
|
|
+ throw new ServiceException("没有找到sku信息");
|
|
|
+ }
|
|
|
+ Long bomSpecId = skuSpec.getBomSpecId();
|
|
|
+ if (ObjectUtil.isEmpty(bomSpecId)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = this.getBomSpecBoByIdList(Collections.singleton(bomSpecId));
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ throw new ServiceException("未知bom规格id:" + bomSpecId);
|
|
|
+ }
|
|
|
+ Long warehouseId;
|
|
|
+ // 主材
|
|
|
+ if (ObjectUtil.equals(bomSpecBo.getClassifyParentId(), 1L)) {
|
|
|
+ warehouseId = WarehouseConstant.SEMI_FINISHED_PRODUCT;
|
|
|
+ } else {
|
|
|
+ warehouseId = WarehouseConstant.PACKAGING_MATERIAL;
|
|
|
+ }
|
|
|
+ Inventory inventory = inventoryService.getOne(q -> q
|
|
|
+ .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
+ .eq(Inventory::getBomSpecId, bomSpecId));
|
|
|
+ return inventory == null ? BigDecimal.ZERO : inventory.getQuantity();
|
|
|
+ }
|
|
|
+
|
|
|
}
|