| | |
| | | award.setBidId(bidId); |
| | | award.setAwardNo("SMP" + System.currentTimeMillis()); |
| | | award.setAwardStatus(AwardStatusEnum.AWARDED.getCode()); |
| | | award.setAwardAmount(bid.getBidTotalAmount()); |
| | | // 投标金额为空时,回退到该投标下所有报价之和,避免 award_amount 为空导致入库失败 |
| | | award.setAwardAmount(resolveAwardAmount(bidId, bid.getBidTotalAmount())); |
| | | award.setAwardTime(LocalDateTime.now()); |
| | | award.setApprovalTime(LocalDateTime.now()); |
| | | bidAwardMapper.insert(award); |
| | |
| | | // 6. 更新项目状态 |
| | | project.setTenderStatus(TenderStatusEnum.CONFIRMED.getCode()); |
| | | tenderProjectMapper.updateById(project); |
| | | } |
| | | |
| | | /** |
| | | * 解析中标金额:投标金额为空时,汇总该投标下所有报价 |
| | | */ |
| | | private BigDecimal resolveAwardAmount(Long bidId, BigDecimal bidTotalAmount) { |
| | | if (bidTotalAmount != null) { |
| | | return bidTotalAmount; |
| | | } |
| | | List<SrmSupplierQuoteDO> quotes = supplierQuoteMapper.selectListByBidId(bidId); |
| | | return quotes.stream() |
| | | .map(SrmSupplierQuoteDO::getQuotePrice) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | |
| | | /** |
| | |
| | | // 计算价格 |
| | | BigDecimal totalQuoteAmount = quotes.stream() |
| | | .map(SrmSupplierQuoteDO::getQuotePrice) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal awardAmount = award.getAwardAmount() != null ? award.getAwardAmount() : totalQuoteAmount; |
| | | BigDecimal ratio = totalQuoteAmount.compareTo(BigDecimal.ZERO) > 0 |
| | |
| | | if (quote == null) { |
| | | continue; |
| | | } |
| | | BigDecimal quotePrice = quote.getQuotePrice(); |
| | | if (quotePrice == null) { |
| | | continue; |
| | | } |
| | | BigDecimal quantity = material.getQuantity(); |
| | | if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | MdmItemRespDTO mdmItem = itemMap.get(material.getProductId()); |
| | | if (mdmItem == null) { |
| | | continue; |
| | | } |
| | | BigDecimal materialTotal = quote.getQuotePrice().multiply(ratio); |
| | | BigDecimal unitPrice = materialTotal.divide(material.getQuantity(), 4, RoundingMode.HALF_UP); |
| | | BigDecimal materialTotal = quotePrice.multiply(ratio); |
| | | BigDecimal unitPrice = materialTotal.divide(quantity, 4, RoundingMode.HALF_UP); |
| | | ErpPurchaseOrderCreateReqDTO.Item item = new ErpPurchaseOrderCreateReqDTO.Item(); |
| | | item.setProductId(material.getProductId()); |
| | | item.setProductUnitId(mdmItem.getUnitMeasureId()); |
| | | item.setProductPrice(unitPrice); |
| | | item.setCount(material.getQuantity()); |
| | | item.setCount(quantity); |
| | | item.setTaxPercent(quote.getTaxRate()); |
| | | item.setRemark("定标编号: " + award.getAwardNo()); |
| | | orderItems.add(item); |