| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | |
| | | if (existing != null) { |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AWARD_SUPPLIER_EXISTS); |
| | | } |
| | | // 校验投标记录:必须属于该项目、未被撤标、且供应商一致 |
| | | SrmTenderBidDO bid = tenderBidMapper.selectById(createReqVO.getBidId()); |
| | | if (bid == null) { |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.BID_NOT_EXISTS); |
| | | } |
| | | if (!bid.getTenderProjectId().equals(createReqVO.getTenderProjectId())) { |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AWARD_BID_NOT_IN_PROJECT); |
| | | } |
| | | if (BidStatusEnum.WITHDRAWN.getCode().equals(bid.getBidStatus())) { |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AWARD_BID_WITHDRAWN); |
| | | } |
| | | if (!bid.getSupplierId().equals(createReqVO.getSupplierId())) { |
| | | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AWARD_SUPPLIER_NOT_MATCH_BID); |
| | | } |
| | | SrmBidAwardDO award = BeanUtils.toBean(createReqVO, SrmBidAwardDO.class); |
| | | award.setAwardStatus(AwardStatusEnum.PENDING_APPROVAL.getCode()); |
| | | award.setAwardTime(LocalDateTime.now()); |
| | | bidAwardMapper.insert(award); |
| | | |
| | | // 更新投标状态为中标 |
| | | SrmTenderBidDO bid = tenderBidMapper.selectById(createReqVO.getBidId()); |
| | | if (bid != null) { |
| | | bid.setBidStatus(BidStatusEnum.WIN.getCode()); |
| | | tenderBidMapper.updateById(bid); |
| | | } |
| | | bid.setBidStatus(BidStatusEnum.WIN.getCode()); |
| | | tenderBidMapper.updateById(bid); |
| | | |
| | | return award.getId(); |
| | | } |
| | |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemList(productIds).getCheckedData() |
| | | .stream().collect(Collectors.toMap(MdmItemRespDTO::getId, Function.identity())); |
| | | |
| | | // 6. 构建订单项 |
| | | // 6. 构建订单项(报价为总价,需除以数量得到单价) |
| | | BigDecimal totalQuoteAmount = quotes.stream() |
| | | .map(SrmSupplierQuoteDO::getQuotePrice) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal awardAmount = award.getAwardAmount() != null ? award.getAwardAmount() : totalQuoteAmount; |
| | | BigDecimal ratio = totalQuoteAmount.compareTo(BigDecimal.ZERO) > 0 |
| | | ? awardAmount.divide(totalQuoteAmount, 8, RoundingMode.HALF_UP) |
| | | : BigDecimal.ONE; |
| | | |
| | | List<ErpPurchaseOrderCreateReqDTO.Item> orderItems = new ArrayList<>(); |
| | | for (SrmTenderMaterialDO material : materials) { |
| | | SrmSupplierQuoteDO quote = quoteMap.get(material.getId()); |
| | |
| | | if (mdmItem == null) { |
| | | continue; |
| | | } |
| | | BigDecimal materialTotal = quote.getQuotePrice().multiply(ratio); |
| | | BigDecimal unitPrice = materialTotal.divide(material.getQuantity(), 4, RoundingMode.HALF_UP); |
| | | ErpPurchaseOrderCreateReqDTO.Item item = new ErpPurchaseOrderCreateReqDTO.Item(); |
| | | item.setProductId(material.getProductId()); |
| | | item.setProductUnitId(mdmItem.getUnitMeasureId()); |
| | | item.setProductPrice(quote.getQuotePrice()); |
| | | item.setProductPrice(unitPrice); |
| | | item.setCount(material.getQuantity()); |
| | | item.setTaxPercent(quote.getTaxRate()); |
| | | item.setRemark("招标编号: " + award.getAwardNo()); |