|
@@ -15,6 +15,7 @@ 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.Inventory;
|
|
|
+import com.sd.business.entity.inventory.po.InventoryFinishedOrder;
|
|
|
import com.sd.business.entity.order.enums.OrderClassifyEnum;
|
|
|
import com.sd.business.entity.order.enums.OrderExceptionTypeEnum;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
@@ -33,6 +34,7 @@ import com.sd.business.service.bom.BomClassifyService;
|
|
|
import com.sd.business.service.bom.BomService;
|
|
|
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.OrderPackageBomService;
|
|
@@ -100,6 +102,9 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
@Autowired
|
|
|
private OrderPackageBomService orderPackageBomService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedOrderService inventoryFinishedOrderService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<UncompletedVo> uncompletedList(StockPreparationDto dto) {
|
|
|
|
|
@@ -308,6 +313,12 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
.set(OrderSku::getStockPreparationTime, stockPreparationTime)
|
|
|
.set(OrderSku::getStockPreparationStatus, StatusConstant.YES));
|
|
|
|
|
|
+ // 成品库出库
|
|
|
+ if (Objects.equals(dto.getOrderStockType(), 1)) {
|
|
|
+ orderFinishedDelivery(list);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 订单出库
|
|
|
orderDelivery(list, dto);
|
|
|
|
|
@@ -361,6 +372,39 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void orderFinishedDelivery(List<StockPreparationVo> list) {
|
|
|
+ // 成品出库
|
|
|
+ List<Long> orderIdList = list.stream().map(StockPreparationVo::getOrderId).distinct().collect(Collectors.toList());
|
|
|
+ inventoryFinishedService.noSourceSaleOutOfWarehouse(orderIdList);
|
|
|
+
|
|
|
+ // 生产工单
|
|
|
+ List<ProductionWorkOrder> productionWorkOrderList = new ArrayList<>();
|
|
|
+ Map<Long, List<StockPreparationVo>> map = list.stream().collect(Collectors.groupingBy(StockPreparationVo::getOrderId));
|
|
|
+ Map<Long, List<OrderSku>> orderSkuMap = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList))
|
|
|
+ .stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
|
|
|
+ map.forEach((orderId, stockPreparationVoList) -> {
|
|
|
+ StockPreparationVo stockPreparationVo = stockPreparationVoList.get(0);
|
|
|
+ String orderCode = stockPreparationVo.getOrderCode();
|
|
|
+ String orderWlnCode = stockPreparationVo.getOrderWlnCode();
|
|
|
+ addWorkOrder(orderId, ObjectUtil.defaultIfNull(orderWlnCode, orderCode),
|
|
|
+ orderSkuMap.getOrDefault(orderId, Collections.emptyList()), productionWorkOrderList);
|
|
|
+ });
|
|
|
+
|
|
|
+ skuSpecService.attributeAssign(productionWorkOrderList, ProductionWorkOrder::getSkuSpecId,
|
|
|
+ (item, skuSpec) -> item.setMachinedPanel(skuSpec.getMachinedPanel()));
|
|
|
+
|
|
|
+ // 直接完成生产任务
|
|
|
+ productionWorkOrderList.forEach(item -> {
|
|
|
+ item.setStatus(3);
|
|
|
+ item.setCompleteTime(new Date());
|
|
|
+ });
|
|
|
+
|
|
|
+ orderService.update(q -> q
|
|
|
+ .in(BaseIdPo::getId, orderIdList)
|
|
|
+ .set(OrderInfo::getStatus, OrderStatusEnum.COMPLETION_PRODUCTION.getKey()));
|
|
|
+ productionWorkOrderService.saveBatch(productionWorkOrderList);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<PackageBomVo> getPackageBomList(List<Long> orderSkuIdList) {
|
|
|
|
|
@@ -398,6 +442,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
public List<OutBomVo> outBomList(StockPreparationDto dto) {
|
|
|
Long outDepartmentId = dto.getOutDepartmentId();
|
|
|
Assert.notNull(outDepartmentId, "出库事业部id不能为空");
|
|
|
+ dto.setOrderStockType(0);
|
|
|
|
|
|
// 订单sku列表
|
|
|
IWrapper<StockPreparationVo> wrapper = getWrapper(dto);
|
|
@@ -530,6 +575,92 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<OutSkuVo> outSkuList(StockPreparationDto dto) {
|
|
|
+ Long outDepartmentId = dto.getOutDepartmentId();
|
|
|
+ Assert.notNull(outDepartmentId, "出库事业部id不能为空");
|
|
|
+ dto.setOrderStockType(1);
|
|
|
+
|
|
|
+ // 订单sku列表
|
|
|
+ IWrapper<StockPreparationVo> wrapper = getWrapper(dto);
|
|
|
+ List<StockPreparationVo> stockPreparationVoList = stockPreparationMapper.uncompletedList(wrapper);
|
|
|
+
|
|
|
+ if (stockPreparationVoList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> orderIdList = stockPreparationVoList.stream().map(StockPreparationVo::getOrderId).distinct().collect(Collectors.toList());
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
|
|
|
+
|
|
|
+ Map<Long, OutSkuVo> map = orderSkuList.stream()
|
|
|
+ .map(item -> {
|
|
|
+ OutSkuVo outSkuVo = new OutSkuVo();
|
|
|
+ outSkuVo.setSkuSpecId(item.getSkuSpecId());
|
|
|
+ outSkuVo.setOutQuantity(item.getQuantity());
|
|
|
+ return outSkuVo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OutSkuVo::getSkuSpecId,
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setOutQuantity(v1.getOutQuantity().add(v2.getOutQuantity()));
|
|
|
+ return v1;
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ List<OutSkuVo> outBomVoList = new ArrayList<>(map.values());
|
|
|
+
|
|
|
+ Map<Long, SkuSpec> skuSpecMap = skuSpecService.byIdsToMap(map.keySet());
|
|
|
+ // 查询成品库存
|
|
|
+ List<InventoryFinishedOrder> list = inventoryFinishedOrderService.list(
|
|
|
+ q -> q.in(InventoryFinishedOrder::getSkuSpecId, map.keySet())
|
|
|
+ .eq(InventoryFinishedOrder::getStatus, 1)
|
|
|
+ .isNull(InventoryFinishedOrder::getOrderInfoId));
|
|
|
+ Map<Long, BigDecimal> inventoryMap = list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ InventoryFinishedOrder::getSkuSpecId,
|
|
|
+ InventoryFinishedOrder::getExistingQuantity,
|
|
|
+ BigDecimal::add)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 赋值
|
|
|
+ for (OutSkuVo outSkuVo : outBomVoList) {
|
|
|
+ Long skuSpecId = outSkuVo.getSkuSpecId();
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(skuSpecId);
|
|
|
+ outSkuVo.setSkuSpecCode(skuSpec.getCode());
|
|
|
+ outSkuVo.setSkuSpecName(skuSpec.getName());
|
|
|
+ outSkuVo.setWarehouseId(WarehouseConstant.FINISHED_PRODUCT);
|
|
|
+ outSkuVo.setWarehouseName("成品仓");
|
|
|
+ outSkuVo.setInventoryQuantity(inventoryMap.getOrDefault(skuSpecId, BigDecimal.ZERO));
|
|
|
+ }
|
|
|
+
|
|
|
+ return outBomVoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal uncompletedListTotal(StockPreparationDto dto) {
|
|
|
+ IWrapper<StockPreparationVo> wrapper = IWrapper.getWrapper();
|
|
|
+ wrapper.eq("oi", OrderInfo::getStatus, OrderStatusEnum.STOCK_PREPARATION.getKey());
|
|
|
+ wrapper.eq("oi", OrderInfo::getExceptionType, OrderExceptionTypeEnum.NORMAL.getKey().toString());
|
|
|
+ wrapper.eq("os", OrderSku::getStockPreparationStatus, StatusConstant.NO);
|
|
|
+ wrapper.and(q -> q
|
|
|
+ .ge("oi", OrderInfo::getWlnStatus, 2)
|
|
|
+ .or().eq("oi", OrderInfo::getSource, 1));
|
|
|
+ wrapper.and(q -> q
|
|
|
+ .and(r -> r.isNull("oi.flow_id").isNull("oi.flow_status"))
|
|
|
+ .or(r -> r.eq("oi", OrderInfo::getFlowStatus, FlowStatusEnum.PASS.getKey())));
|
|
|
+ wrapper.eq("oi", OrderInfo::getStockType, dto.getOrderStockType());
|
|
|
+ // 不计算委外订单主材数量
|
|
|
+ wrapper.ne("oi", OrderInfo::getType, 2);
|
|
|
+ List<StockPreparationVo> stockPreparationVoList = stockPreparationMapper.uncompletedList(wrapper);
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(stockPreparationVoList)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ return stockPreparationVoList.stream().map(StockPreparationVo::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取wrapper
|
|
|
*/
|
|
@@ -551,6 +682,8 @@ public class StockPreparationServiceImpl implements StockPreparationService {
|
|
|
.and(r -> r.isNull("oi.flow_id").isNull("oi.flow_status"))
|
|
|
.or(r -> r.eq("oi", OrderInfo::getFlowStatus, FlowStatusEnum.PASS.getKey())));
|
|
|
|
|
|
+ wrapper.eq("oi", OrderInfo::getStockType, dto.getOrderStockType());
|
|
|
+
|
|
|
return wrapper;
|
|
|
}
|
|
|
|