|
@@ -0,0 +1,417 @@
|
|
|
+package com.sd.business.service.production.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.constant.StatusConstant;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
|
+import com.sd.business.entity.in.dto.InOutStorageDto;
|
|
|
+import com.sd.business.entity.in.emums.InDetailTypeEnum;
|
|
|
+import com.sd.business.entity.in.emums.InOutTypeEnum;
|
|
|
+import com.sd.business.entity.in.emums.OutDetailTypeEnum;
|
|
|
+import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
+import com.sd.business.entity.inventory.po.InventoryFinished;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.order.po.OrderSkuProductionCost;
|
|
|
+import com.sd.business.entity.production.dto.ProductionExceedReceiveDto;
|
|
|
+import com.sd.business.entity.production.dto.ProductionExceedReceiveSelectDto;
|
|
|
+import com.sd.business.entity.production.dto.ProductionExceedReceiveSkuDto;
|
|
|
+import com.sd.business.entity.production.po.ProductionExceedReceive;
|
|
|
+import com.sd.business.entity.production.po.ProductionExceedReceiveSku;
|
|
|
+import com.sd.business.entity.production.vo.ProductionExceedReceiveVo;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
+import com.sd.business.mapper.production.ProductionExceedReceiveMapper;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.in.InOutStorageService;
|
|
|
+import com.sd.business.service.inventory.InventoryFinishedOrderService;
|
|
|
+import com.sd.business.service.inventory.InventoryFinishedService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.business.service.order.OrderService;
|
|
|
+import com.sd.business.service.order.OrderSkuProductionCostService;
|
|
|
+import com.sd.business.service.order.OrderSkuService;
|
|
|
+import com.sd.business.service.production.ProductionExceedReceiveService;
|
|
|
+import com.sd.business.service.production.ProductionExceedReceiveSkuService;
|
|
|
+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 org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 生产超领 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-11-09
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductionExceedReceiveServiceImpl extends ServiceImpl<ProductionExceedReceiveMapper, ProductionExceedReceive> implements ProductionExceedReceiveService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuService orderSkuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecService skuSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InOutStorageService inOutStorageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuProductionCostService orderSkuProductionCostService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionExceedReceiveSkuService productionExceedReceiveSkuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedService inventoryFinishedService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedOrderService inventoryFinishedOrderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ProductionExceedReceiveVo> getPage(ProductionExceedReceiveSelectDto dto) {
|
|
|
+ IWrapper<ProductionExceedReceive> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("per", ProductionExceedReceive::getId);
|
|
|
+ wrapper.eq("per", ProductionExceedReceive::getType, dto.getType());
|
|
|
+ wrapper.like("oi", OrderInfo::getCode, dto.getOrderCode());
|
|
|
+ wrapper.like("oi", OrderInfo::getWlnCode, dto.getOrderWlnCode());
|
|
|
+ Page<ProductionExceedReceiveVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void exceedReceive(ProductionExceedReceiveDto dto) {
|
|
|
+ Long orderId = dto.getOrderId();
|
|
|
+ OrderInfo orderInfo = orderService.getById(orderId);
|
|
|
+ Assert.notNull(orderInfo, "未知订单");
|
|
|
+ Assert.eqTrue(Objects.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey()), "操作失败,请选择生产中的订单");
|
|
|
+
|
|
|
+ // 筛选数量为0的数据
|
|
|
+ List<ProductionExceedReceiveSkuDto> dtoList = dto.getProductionExceedReceiveSkuList();
|
|
|
+ List<ProductionExceedReceiveSkuDto> exceedReceiveSkuList = dtoList.stream()
|
|
|
+ .filter(item -> item.getQuantity() != null
|
|
|
+ && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(exceedReceiveSkuList, "操作失败,订单sku超领明细列表不能为空");
|
|
|
+
|
|
|
+ List<Long> orderSkuIds = exceedReceiveSkuList.stream().map(ProductionExceedReceiveSku::getOrderSkuId).collect(Collectors.toList());
|
|
|
+ Map<Long, OrderSku> orderSkuMap = orderSkuService.byIdsToMap(orderSkuIds);
|
|
|
+ List<Long> bomSpecIds = orderSkuMap.values().stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpec> bomSpecMap = bomSpecService.byIdsToMap(bomSpecIds);
|
|
|
+ Map<Long, BigDecimal> map = exceedReceiveSkuList.stream().collect(Collectors.toMap(
|
|
|
+ item -> orderSkuMap.get(item.getOrderSkuId()).getBomSpecId(),
|
|
|
+ ProductionExceedReceiveSkuDto::getQuantity,
|
|
|
+ BigDecimal::add));
|
|
|
+ boolean result = inventoryService.lockStorage(map, WarehouseConstant.SEMI_FINISHED_PRODUCT);
|
|
|
+ Assert.eqTrue(result, "库存不足,超领失败!");
|
|
|
+
|
|
|
+ // 出入库信息
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = map.keySet().stream().map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item);
|
|
|
+ inOutStorageBom.setQuantity(map.get(item));
|
|
|
+ return inOutStorageBom;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 出库
|
|
|
+ String remark = "订单:" + orderInfo.getCode()
|
|
|
+ + (StrUtil.isBlank(orderInfo.getWlnCode()) ? StringPool.EMPTY : "(" + orderInfo.getWlnCode() + ")");
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.OUT.getKey(),
|
|
|
+ OutDetailTypeEnum.PRODUCTION.getKey(),
|
|
|
+ WarehouseConstant.SEMI_FINISHED_PRODUCT,
|
|
|
+ remark + "超领出库",
|
|
|
+ JSON.parseArray(JSON.toJSONString(inOutStorageBomList), InOutStorageBom.class),
|
|
|
+ StatusConstant.YES);
|
|
|
+ // 入库
|
|
|
+ // 制作损坏入库到生产次品仓,裸垫质量不良入库到采购次品仓
|
|
|
+ Long warehouseId;
|
|
|
+ if (Objects.equals(dto.getType(), 1)) {
|
|
|
+ warehouseId = WarehouseConstant.PRODUCTION_DEFECTIVE;
|
|
|
+ } else {
|
|
|
+ warehouseId = WarehouseConstant.PURCHASE_DEFECTIVE;
|
|
|
+ }
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.IN.getKey(),
|
|
|
+ InDetailTypeEnum.ABANDON.getKey(),
|
|
|
+ warehouseId,
|
|
|
+ remark + "超领报废入库",
|
|
|
+ inOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+ // 人为损坏, 新增订单生产成本的材料成本
|
|
|
+ if (Objects.equals(dto.getType(), 1)) {
|
|
|
+ Map<Long, OrderSkuProductionCost> orderSkuProductionCostMap = orderSkuProductionCostService.mapKEntity(
|
|
|
+ OrderSkuProductionCost::getOrderSkuId,
|
|
|
+ q -> q.eq(OrderSkuProductionCost::getOrderId, orderId)
|
|
|
+ .in(OrderSkuProductionCost::getOrderSkuId, orderSkuIds)
|
|
|
+ );
|
|
|
+ for (ProductionExceedReceiveSkuDto exceedReceiveSkuDto : exceedReceiveSkuList) {
|
|
|
+ OrderSku orderSku = orderSkuMap.get(exceedReceiveSkuDto.getOrderSkuId());
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(orderSku.getBomSpecId());
|
|
|
+ OrderSkuProductionCost orderSkuProductionCost = orderSkuProductionCostMap.get(exceedReceiveSkuDto.getOrderSkuId());
|
|
|
+ // 计算当前sku超领的材料成本
|
|
|
+ BigDecimal materialCost = exceedReceiveSkuDto.getQuantity().multiply(bomSpec.getInternalSellingPrice());
|
|
|
+
|
|
|
+ orderSkuProductionCost.setMaterialCost(orderSkuProductionCost.getMaterialCost().add(materialCost));
|
|
|
+ }
|
|
|
+ // 更新订单生产成本的材料成本
|
|
|
+ orderSkuProductionCostService.updateBatchById(new ArrayList<>(orderSkuProductionCostMap.values()));
|
|
|
+ }
|
|
|
+ // 保存超领数据
|
|
|
+ this.save(dto);
|
|
|
+ List<ProductionExceedReceiveSku> productionExceedReceiveSkuList = exceedReceiveSkuList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setProductionExceedReceiveId(dto.getId());
|
|
|
+ item.setOrderId(dto.getOrderId());
|
|
|
+ item.setExceptionSkuSpecId(item.getSkuSpecId());
|
|
|
+ item.setWarehouseId(warehouseId);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ productionExceedReceiveSkuService.saveBatch(productionExceedReceiveSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void errorExceedReceive(ProductionExceedReceiveDto dto) {
|
|
|
+ Long orderId = dto.getOrderId();
|
|
|
+ OrderInfo orderInfo = orderService.getById(orderId);
|
|
|
+ Assert.notNull(orderInfo, "未知订单");
|
|
|
+ Assert.eqTrue(Objects.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ || Objects.equals(orderInfo.getStatus(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey()),
|
|
|
+ "操作失败,请选择生产中或生产完成的订单");
|
|
|
+
|
|
|
+ List<ProductionExceedReceiveSkuDto> productionCostList = dto.getProductionExceedReceiveSkuList();
|
|
|
+ List<ProductionExceedReceiveSkuDto> exceedReceiveSkuList = productionCostList.stream()
|
|
|
+ .filter(item -> item.getQuantity() != null
|
|
|
+ && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .filter(item -> Objects.nonNull(item.getExceptionSkuSpecId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(exceedReceiveSkuList, "操作失败,订单sku超领明细列表不能为空");
|
|
|
+ Assert.notNull(dto.getProductionExceedReceiveBomList(), "操作失败,超领bom明细列表不能为空");
|
|
|
+
|
|
|
+ List<InOutStorageBom> outStorageBomList = dto.getProductionExceedReceiveBomList().stream()
|
|
|
+ .filter(item -> item.getOutQuantity() != null
|
|
|
+ && item.getOutQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item.getBomSpecId());
|
|
|
+ inOutStorageBom.setQuantity(item.getOutQuantity());
|
|
|
+ return inOutStorageBom;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(outStorageBomList, "操作失败,超领bom明细列表不能为空");
|
|
|
+
|
|
|
+ List<Long> bomSpecIds = outStorageBomList.stream().map(InOutStorageBom::getBomSpecId).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIds);
|
|
|
+
|
|
|
+ // 半成品出库
|
|
|
+ List<InOutStorageBom> semiFinishedProductInOutStorageBomList = outStorageBomList.stream()
|
|
|
+ .filter(item -> Objects.equals(bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId(), 1L))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ String remark = "订单:" + orderInfo.getCode()
|
|
|
+ + (StrUtil.isBlank(orderInfo.getWlnCode()) ? StringPool.EMPTY : "(" + orderInfo.getWlnCode() + ")");
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.OUT.getKey(),
|
|
|
+ OutDetailTypeEnum.PRODUCTION.getKey(),
|
|
|
+ WarehouseConstant.SEMI_FINISHED_PRODUCT,
|
|
|
+ remark + "生产错误超领出库",
|
|
|
+ semiFinishedProductInOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+
|
|
|
+ // 包材出库
|
|
|
+ List<InOutStorageBom> packagingMaterialInOutStorageBomList = outStorageBomList.stream()
|
|
|
+ .filter(item -> !Objects.equals(bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId(), 1L))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.OUT.getKey(),
|
|
|
+ OutDetailTypeEnum.PRODUCTION.getKey(),
|
|
|
+ WarehouseConstant.PACKAGING_MATERIAL,
|
|
|
+ remark + "生产错误超领出库",
|
|
|
+ packagingMaterialInOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+
|
|
|
+ // 入库
|
|
|
+ List<Long> skuSpecIds = exceedReceiveSkuList.stream().map(ProductionExceedReceiveSku::getExceptionSkuSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, SkuSpec> skuSpecMap = skuSpecService.byIdsToMap(skuSpecIds);
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = new ArrayList<>();
|
|
|
+ List<InventoryFinished> inventoryFinishedList = new ArrayList<>();
|
|
|
+ for (ProductionExceedReceiveSkuDto exceedReceiveSkuDto : exceedReceiveSkuList) {
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(exceedReceiveSkuDto.getExceptionSkuSpecId());
|
|
|
+ if (Objects.equals(exceedReceiveSkuDto.getWarehouseId(), WarehouseConstant.PRODUCTION_DEFECTIVE)) {
|
|
|
+ InOutStorageBom inStorageBom = new InOutStorageBom();
|
|
|
+ inStorageBom.setBomSpecId(skuSpec.getBomSpecId());
|
|
|
+ inStorageBom.setQuantity(exceedReceiveSkuDto.getQuantity());
|
|
|
+ inOutStorageBomList.add(inStorageBom);
|
|
|
+ } else {
|
|
|
+ InventoryFinished inventoryFinished = new InventoryFinished();
|
|
|
+ inventoryFinished.setSkuSpecId(skuSpec.getId());
|
|
|
+ inventoryFinished.setQuantity(exceedReceiveSkuDto.getQuantity());
|
|
|
+ inventoryFinishedList.add(inventoryFinished);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!inOutStorageBomList.isEmpty()) {
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.IN.getKey(),
|
|
|
+ InDetailTypeEnum.ABANDON.getKey(),
|
|
|
+ WarehouseConstant.PRODUCTION_DEFECTIVE,
|
|
|
+ remark + "生产错误超领报废入库",
|
|
|
+ inOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+ }
|
|
|
+ if (!inventoryFinishedList.isEmpty()) {
|
|
|
+ List<OrderSku> orderSkuList = inventoryFinishedList.stream().map(item -> {
|
|
|
+ OrderSku orderSku = new OrderSku();
|
|
|
+ orderSku.setSkuSpecId(item.getSkuSpecId());
|
|
|
+ orderSku.setQuantity(item.getQuantity());
|
|
|
+ return orderSku;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 成品入库,并生成明细
|
|
|
+ inventoryFinishedService.inOut(inventoryFinishedList, true);
|
|
|
+ inventoryFinishedOrderService.productionWarehousing(orderSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存超领数据
|
|
|
+ this.save(dto);
|
|
|
+ List<ProductionExceedReceiveSku> productionExceedReceiveSkuList = exceedReceiveSkuList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setProductionExceedReceiveId(dto.getId());
|
|
|
+ item.setOrderId(dto.getOrderId());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ productionExceedReceiveSkuService.saveBatch(productionExceedReceiveSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void unplannedExceedReceive(ProductionExceedReceiveDto dto) {
|
|
|
+ Long orderId = dto.getOrderId();
|
|
|
+ OrderInfo orderInfo = orderService.getById(orderId);
|
|
|
+ Assert.notNull(orderInfo, "未知订单");
|
|
|
+ Assert.eqTrue(Objects.equals(orderInfo.getStatus(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey()), "操作失败,请选择生产完成的订单");
|
|
|
+
|
|
|
+ List<ProductionExceedReceiveSkuDto> productionCostList = dto.getProductionExceedReceiveSkuList();
|
|
|
+ List<ProductionExceedReceiveSkuDto> exceedReceiveSkuList = productionCostList.stream()
|
|
|
+ .filter(item -> item.getQuantity() != null
|
|
|
+ && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(exceedReceiveSkuList, "操作失败,订单sku超领明细列表不能为空");
|
|
|
+ Assert.notNull(dto.getProductionExceedReceiveBomList(), "操作失败,超领bom明细列表不能为空");
|
|
|
+
|
|
|
+ List<InOutStorageBom> outStorageBomList = dto.getProductionExceedReceiveBomList().stream()
|
|
|
+ .filter(item -> item.getOutQuantity() != null
|
|
|
+ && item.getOutQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item.getBomSpecId());
|
|
|
+ inOutStorageBom.setQuantity(item.getOutQuantity());
|
|
|
+ return inOutStorageBom;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(outStorageBomList,"操作失败,超领bom明细列表不能为空");
|
|
|
+
|
|
|
+ List<Long> bomSpecIds = outStorageBomList.stream().map(InOutStorageBom::getBomSpecId).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIds);
|
|
|
+
|
|
|
+ // 半成品出库
|
|
|
+ List<InOutStorageBom> semiFinishedProductInOutStorageBomList = outStorageBomList.stream()
|
|
|
+ .filter(item -> Objects.equals(bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId(), 1L))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ String remark = "订单:" + orderInfo.getCode()
|
|
|
+ + (StrUtil.isBlank(orderInfo.getWlnCode()) ? StringPool.EMPTY : "(" + orderInfo.getWlnCode() + ")");
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.OUT.getKey(),
|
|
|
+ OutDetailTypeEnum.PRODUCTION.getKey(),
|
|
|
+ WarehouseConstant.SEMI_FINISHED_PRODUCT,
|
|
|
+ remark + "计划外超领出库",
|
|
|
+ JSON.parseArray(JSON.toJSONString(semiFinishedProductInOutStorageBomList), InOutStorageBom.class),
|
|
|
+ StatusConstant.NO
|
|
|
+ );
|
|
|
+
|
|
|
+ // 包材出库
|
|
|
+ List<InOutStorageBom> packagingMaterialInOutStorageBomList = outStorageBomList.stream()
|
|
|
+ .filter(item -> !Objects.equals(bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId(), 1L))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.OUT.getKey(),
|
|
|
+ OutDetailTypeEnum.PRODUCTION.getKey(),
|
|
|
+ WarehouseConstant.PACKAGING_MATERIAL,
|
|
|
+ remark + "计划外超领出库",
|
|
|
+ packagingMaterialInOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+
|
|
|
+ // 半成品入库次品仓
|
|
|
+ this.inOutStorageAdd(InOutTypeEnum.IN.getKey(),
|
|
|
+ InDetailTypeEnum.ABANDON.getKey(),
|
|
|
+ WarehouseConstant.PRODUCTION_DEFECTIVE,
|
|
|
+ remark + "计划外超领报废入库",
|
|
|
+ semiFinishedProductInOutStorageBomList,
|
|
|
+ StatusConstant.NO);
|
|
|
+
|
|
|
+ // 保存超领数据
|
|
|
+ this.save(dto);
|
|
|
+ List<ProductionExceedReceiveSku> productionExceedReceiveSkuList = exceedReceiveSkuList.stream()
|
|
|
+ .peek(item -> {
|
|
|
+ item.setProductionExceedReceiveId(dto.getId());
|
|
|
+ item.setOrderId(dto.getOrderId());
|
|
|
+ item.setExceptionSkuSpecId(item.getSkuSpecId());
|
|
|
+ item.setWarehouseId(WarehouseConstant.PRODUCTION_DEFECTIVE);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ productionExceedReceiveSkuService.saveBatch(productionExceedReceiveSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出入库新增
|
|
|
+ * @param type
|
|
|
+ * @param detailType
|
|
|
+ * @param warehouseId
|
|
|
+ * @param remark
|
|
|
+ * @param inOutStorageBomList
|
|
|
+ * @param lockStorage
|
|
|
+ */
|
|
|
+ private void inOutStorageAdd(Integer type, Integer detailType, Long warehouseId, String remark, List<InOutStorageBom> inOutStorageBomList, Integer lockStorage) {
|
|
|
+ if (ObjectUtil.isEmpty(inOutStorageBomList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并相同bom规格出库数量
|
|
|
+ List<InOutStorageBom> list = new ArrayList<>(inOutStorageBomList.stream().collect(Collectors.toMap(
|
|
|
+ InOutStorageBom::getBomSpecId,
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ return v1;
|
|
|
+ })).values());
|
|
|
+
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(type);
|
|
|
+ inOutStorageDto.setDetailType(detailType);
|
|
|
+ inOutStorageDto.setWarehouseId(warehouseId);
|
|
|
+ inOutStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
|
|
|
+ inOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ inOutStorageDto.setRemark(remark);
|
|
|
+ inOutStorageDto.setInOutStorageBomList(list);
|
|
|
+ inOutStorageDto.setLockStorage(lockStorage);
|
|
|
+ inOutStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+}
|