| | |
| | | import cn.iocoder.yudao.module.srm.enums.BidStatusEnum; |
| | | import cn.iocoder.yudao.module.srm.enums.ErrorCodeConstants; |
| | | import cn.iocoder.yudao.module.srm.enums.TenderStatusEnum; |
| | | import cn.iocoder.yudao.module.srm.service.apply.SrmSupplierApplyService; |
| | | import com.mzt.logapi.starter.annotation.LogRecord; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Resource |
| | | private ErpPurchaseOrderApi erpPurchaseOrderApi; |
| | | |
| | | @Resource |
| | | private SrmSupplierApplyService supplierApplyService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AWARD_SUPPLIER_NOT_SYNCED); |
| | | } |
| | | |
| | | // 供应商未准入则自动准入并通过,保证采购订单流程可用 |
| | | supplierApplyService.ensureSupplierApproved(srmSupplier.getId()); |
| | | |
| | | // 3. 查招标物料列表 |
| | | List<SrmTenderMaterialDO> materials = tenderMaterialMapper |
| | | .selectListByTenderProjectId(award.getTenderProjectId()); |
| | |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemList(productIds).getCheckedData() |
| | | .stream().collect(Collectors.toMap(MdmItemRespDTO::getId, Function.identity())); |
| | | |
| | | // 6. 构建订单项(报价为总价,需除以数量得到单价) |
| | | BigDecimal totalQuoteAmount = quotes.stream() |
| | | .map(SrmSupplierQuoteDO::getQuotePrice) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 6. 构建订单项(报价为“单价”口径:行金额 = 报价单价 × 数量; |
| | | // 定标金额与报价合计不一致时按行金额比例分摊,订单行单价仍取报价单价) |
| | | BigDecimal totalQuoteAmount = BigDecimal.ZERO; |
| | | for (SrmTenderMaterialDO material : materials) { |
| | | SrmSupplierQuoteDO quote = quoteMap.get(material.getId()); |
| | | BigDecimal quantity = material.getQuantity(); |
| | | if (quote == null || quote.getQuotePrice() == null |
| | | || quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | totalQuoteAmount = totalQuoteAmount.add(quote.getQuotePrice().multiply(quantity)); |
| | | } |
| | | BigDecimal awardAmount = award.getAwardAmount() != null ? award.getAwardAmount() : totalQuoteAmount; |
| | | BigDecimal ratio = totalQuoteAmount.compareTo(BigDecimal.ZERO) > 0 |
| | | ? awardAmount.divide(totalQuoteAmount, 8, RoundingMode.HALF_UP) |
| | |
| | | List<ErpPurchaseOrderCreateReqDTO.Item> orderItems = new ArrayList<>(); |
| | | for (SrmTenderMaterialDO material : materials) { |
| | | SrmSupplierQuoteDO quote = quoteMap.get(material.getId()); |
| | | if (quote == null) { |
| | | if (quote == null || quote.getQuotePrice() == 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 unitPrice = quote.getQuotePrice().multiply(ratio).setScale(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); |