|
@@ -1,27 +1,52 @@
|
|
|
package com.fjhx.mes.service;
|
|
|
|
|
|
import com.fjhx.mes.entity.production.po.ProductionOrder;
|
|
|
+import com.fjhx.mes.entity.production.po.ProductionOrderDetail;
|
|
|
+import com.fjhx.mes.service.production.ProduceOrderDetailService;
|
|
|
import com.fjhx.mes.service.production.ProduceOrderService;
|
|
|
+import com.fjhx.sale.entity.contract.dto.ContractOutboundInfoDto;
|
|
|
+import com.fjhx.sale.entity.contract.dto.ContractOutboundRecordsDto;
|
|
|
+import com.fjhx.sale.entity.contract.po.ContractOutboundRecords;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
+import com.fjhx.sale.entity.contract.vo.ContractOutboundRecordsVo;
|
|
|
import com.fjhx.sale.entity.contract.vo.ContractProductVo;
|
|
|
+import com.fjhx.sale.service.contract.ContractOutboundRecordsService;
|
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
+import com.fjhx.sale.service.contract.ContractService;
|
|
|
+import com.fjhx.wms.entity.stock.emums.JournalType;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWait;
|
|
|
import com.fjhx.wms.service.WmsService;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitService;
|
|
|
import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class WmsServiceImpl implements WmsService {
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
+ private ContractService contractService;
|
|
|
+ @Resource
|
|
|
private ContractProductService contractProductService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ProduceOrderService produceOrderService;
|
|
|
+ @Resource
|
|
|
+ private ProduceOrderDetailService produceOrderDetailService;
|
|
|
+ @Resource
|
|
|
+ private ContractOutboundRecordsService outboundRecordsService;
|
|
|
+ @Resource
|
|
|
+ private StockWaitService stockWaitService;
|
|
|
|
|
|
@Override
|
|
|
public void updateProdStatus(List<Long> cpIds, Long prodOrderId) {
|
|
@@ -41,4 +66,59 @@ public class WmsServiceImpl implements WmsService {
|
|
|
.set(BasePo::getUpdateTime, new Date())
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完工入库调用销售出库
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saleOutboundByOrderId(Long orderId) {
|
|
|
+ ProductionOrder orderById = produceOrderService.getById(orderId);
|
|
|
+ List<ProductionOrderDetail> list = produceOrderDetailService.list(q -> q.eq(ProductionOrderDetail::getProduceOrderId, orderId));
|
|
|
+
|
|
|
+ long count = stockWaitService.count(q -> q
|
|
|
+ .eq(StockWait::getProdOrderId, orderId)
|
|
|
+ .eq(StockWait::getBusinessType, JournalType.COMPLETION_IN.getDetailType())
|
|
|
+ .ne(StockWait::getStatus, 2)
|
|
|
+ );
|
|
|
+ //订单生产完成,完工入库全部入库
|
|
|
+ if (orderById.getProduceStatus() < 2 || count != 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> cpIds = list.stream().map(ProductionOrderDetail::getContractDetailId).distinct().collect(Collectors.toList());
|
|
|
+ List<ContractOutboundRecordsVo> outRecordsList = outboundRecordsService.getList(IWrapper.getWrapper()
|
|
|
+ .in("cor.contract_product_id", cpIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ //获取已出库数量
|
|
|
+ Map<Long, BigDecimal> outRecordsMap = outRecordsList.stream()
|
|
|
+ .collect(Collectors.groupingBy(ContractOutboundRecords::getContractProductId,
|
|
|
+ Collectors.mapping(ContractOutboundRecords::getQuantity, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)))
|
|
|
+ );
|
|
|
+
|
|
|
+ List<ContractOutboundRecordsDto> outboundRecordList = new ArrayList<>();
|
|
|
+ for (ProductionOrderDetail task : list) {
|
|
|
+ //已出库数量
|
|
|
+ BigDecimal outQuantity = outRecordsMap.get(task.getContractDetailId());
|
|
|
+
|
|
|
+ BigDecimal subtract = task.getQuantity().subtract(outQuantity);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ContractOutboundRecordsDto recordsDto = new ContractOutboundRecordsDto();
|
|
|
+ recordsDto.setContractProductId(task.getContractDetailId());
|
|
|
+ recordsDto.setQuantity(subtract);
|
|
|
+ outboundRecordList.add(recordsDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ ContractOutboundInfoDto dto = new ContractOutboundInfoDto();
|
|
|
+ dto.setContractId(orderById.getContractId());
|
|
|
+ dto.setOutboundRecordList(outboundRecordList);
|
|
|
+ contractService.saleOutbound(dto);
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("自动出货出错:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|