| | |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesQuotationMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.mapper.StockOutRecordSalesLedgerMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesQuotation; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.StockOutRecordSalesLedger; |
| | | import com.ruoyi.stock.mapper.StockOutRecordMapper; |
| | | import com.ruoyi.stock.pojo.StockOutRecord; |
| | | import dev.langchain4j.agent.tool.P; |
| | |
| | | private final ShippingInfoMapper shippingInfoMapper; |
| | | private final AccountSalesCollectionMapper accountSalesCollectionMapper; |
| | | private final StockOutRecordMapper stockOutRecordMapper; |
| | | private final StockOutRecordSalesLedgerMapper stockOutRecordSalesLedgerMapper; |
| | | private final AiSessionUserContext aiSessionUserContext; |
| | | |
| | | public SalesAgentTools(CustomerMapper customerMapper, |
| | |
| | | ShippingInfoMapper shippingInfoMapper, |
| | | AccountSalesCollectionMapper accountSalesCollectionMapper, |
| | | StockOutRecordMapper stockOutRecordMapper, |
| | | StockOutRecordSalesLedgerMapper stockOutRecordSalesLedgerMapper, |
| | | AiSessionUserContext aiSessionUserContext) { |
| | | this.customerMapper = customerMapper; |
| | | this.salesLedgerMapper = salesLedgerMapper; |
| | |
| | | this.shippingInfoMapper = shippingInfoMapper; |
| | | this.accountSalesCollectionMapper = accountSalesCollectionMapper; |
| | | this.stockOutRecordMapper = stockOutRecordMapper; |
| | | this.stockOutRecordSalesLedgerMapper = stockOutRecordSalesLedgerMapper; |
| | | this.aiSessionUserContext = aiSessionUserContext; |
| | | } |
| | | |
| | |
| | | result.put(entry.getKey(), ledgerIds); |
| | | } |
| | | } |
| | | mergeOilOutBindingLedgerIds(collections, result); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 油品出库的收款单不存出库单 id,存的是绑定行 id(一个出库单可能按客户拆给多个台账)。 |
| | | * 绑定行上直接带 sales_ledger_id,不需要再经 shipping_info 中转。 |
| | | */ |
| | | private void mergeOilOutBindingLedgerIds(List<AccountSalesCollection> collections, Map<Integer, Set<Long>> result) { |
| | | Map<Integer, List<Long>> bindingIdsByCollection = new HashMap<>(); |
| | | Set<Long> allBindingIds = new HashSet<>(); |
| | | for (AccountSalesCollection collection : collections) { |
| | | if (collection.getId() == null) { |
| | | continue; |
| | | } |
| | | List<Long> bindingIds = parseLongIds(collection.getStockOutBindingIds()); |
| | | if (bindingIds.isEmpty()) { |
| | | continue; |
| | | } |
| | | bindingIdsByCollection.put(collection.getId(), bindingIds); |
| | | allBindingIds.addAll(bindingIds); |
| | | } |
| | | if (allBindingIds.isEmpty()) { |
| | | return; |
| | | } |
| | | Map<Long, Long> ledgerIdByBindingId = defaultList(stockOutRecordSalesLedgerMapper.selectByIds(allBindingIds)).stream() |
| | | .filter(item -> item.getId() != null && item.getSalesLedgerId() != null) |
| | | .collect(Collectors.toMap(StockOutRecordSalesLedger::getId, StockOutRecordSalesLedger::getSalesLedgerId, (a, b) -> a)); |
| | | |
| | | for (Map.Entry<Integer, List<Long>> entry : bindingIdsByCollection.entrySet()) { |
| | | Set<Long> ledgerIds = result.computeIfAbsent(entry.getKey(), key -> new LinkedHashSet<>()); |
| | | for (Long bindingId : entry.getValue()) { |
| | | Long ledgerId = ledgerIdByBindingId.get(bindingId); |
| | | if (ledgerId != null) { |
| | | ledgerIds.add(ledgerId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean isSalesOutboundRecord(StockOutRecord stockOutRecord) { |
| | | if (stockOutRecord == null || !StringUtils.hasText(stockOutRecord.getRecordType())) { |
| | | return false; |