From b5f919e8cc4301b71ff6b12de93f7aefc823ca6d Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期二, 21 十月 2025 09:55:02 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java | 406 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 338 insertions(+), 68 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
index 2d78a62..30e838f 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -2,13 +2,16 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.SupplierManageMapper;
import com.ruoyi.basic.pojo.SupplierManage;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.purchase.dto.PaymentHistoryRecordVo;
import com.ruoyi.purchase.dto.PaymentLedgerDto;
import com.ruoyi.purchase.dto.PaymentRegistrationDto;
import com.ruoyi.purchase.mapper.*;
@@ -27,6 +30,8 @@
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
@@ -42,8 +47,6 @@
private PaymentRegistrationMapper paymentRegistrationMapper;
private PurchaseLedgerMapper purchaseLedgerMapper;
-
- private InvoicePurchaseMapper invoicePurchaseMapper;
private SalesLedgerMapper salesLedgerMapper;
@@ -79,7 +82,8 @@
List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
.eq("ticket_registration_id", registrationDto.getTicketRegistrationId()));
BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
- registrationDto.setUnPaymentAmount(registrationDto.getInvoiceAmount().subtract(total));
+ BigDecimal invoiceAmount = (null != registrationDto.getInvoiceAmount())? registrationDto.getInvoiceAmount() : BigDecimal.ZERO;
+ registrationDto.setUnPaymentAmount(invoiceAmount.subtract(total));
}
return list;
}
@@ -95,11 +99,12 @@
PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(paymentRegistration.getPurchaseLedgerId());
SalesLedger salesLedger = salesLedgerMapper.selectOne(new QueryWrapper<SalesLedger>().
eq("sales_contract_no", purchaseLedger.getSalesContractNo()));
- if (salesLedger == null) {
- throw new RuntimeException("鍏宠仈閿�鍞悎鍚屽彿涓嶅瓨鍦�");
+// if (salesLedger == null) {
+// throw new RuntimeException("鍏宠仈閿�鍞悎鍚屽彿涓嶅瓨鍦�");
+// }
+ if (salesLedger != null) {
+ paymentRegistration.setSaleLedgerId(salesLedger.getId());
}
-
- paymentRegistration.setSaleLedgerId(salesLedger.getId());
paymentRegistration.setSupplierId(purchaseLedger.getSupplierId());
TicketRegistration tr = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getId, paymentRegistration.getTicketRegistrationId()));
@@ -117,8 +122,8 @@
}
LoginUser loginUser = SecurityUtils.getLoginUser();
- Integer tenantId = loginUser.getTenantId();
- paymentRegistration.setTenantId(tenantId.longValue());
+ Long tenantId = loginUser.getTenantId();
+ paymentRegistration.setTenantId(tenantId);
paymentRegistration.setRegistrantId(loginUser.getUserId());
paymentRegistration.setCreateTime(DateUtils.getNowDate());
paymentRegistration.setUpdateTime(DateUtils.getNowDate());
@@ -133,7 +138,9 @@
*/
@Override
public int updatePaymentRegistration(PaymentRegistration paymentRegistration) {
- TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
+ PaymentRegistration paymentRegistration1 = paymentRegistrationMapper.selectById(paymentRegistration.getId());
+
+ TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()==null?paymentRegistration1.getTicketRegistrationId():paymentRegistration.getTicketRegistrationId());
List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
.eq("ticket_registration_id", paymentRegistration.getTicketRegistrationId()).ne("id", paymentRegistration.getId()));
@@ -176,8 +183,11 @@
}
@Override
- public List<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto) {
- List<Map<String, Object>> result = new ArrayList<>();
+ public IPage<Map<String, Object>> selectPaymentLedgerList(
+ PaymentLedgerDto paymentLedgerDto,
+ Page page,
+ Integer detailPageNum,
+ Integer detailPageSize) {
LambdaQueryWrapper<SupplierManage> queryWrapper = new LambdaQueryWrapper<>();
Optional.ofNullable(paymentLedgerDto)
.ifPresent(dto -> {
@@ -186,80 +196,340 @@
}
});
- List<SupplierManage> supplierManages = supplierManageMapper.selectList(queryWrapper);
+ IPage<SupplierManage> supplierPage = supplierManageMapper.selectPage(page, queryWrapper);
+ List<SupplierManage> supplierManages = supplierPage.getRecords();
+
+ IPage<Map<String, Object>> resultPage = new Page<>(page.getCurrent(), page.getSize(), supplierPage.getTotal());
+ List<Map<String, Object>> result = new ArrayList<>();
for (SupplierManage supplierManage : supplierManages) {
Map<String, Object> res = new HashMap<>();
res.put("supplierName", supplierManage.getSupplierName());
+ res.put("supplierId", supplierManage.getId());
- // 搴斾粯閲戦
+ // 搴斾粯閲戦璁$畻
BigDecimal payableAmount = BigDecimal.ZERO;
- List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId()));
- if (purchaseLedgers != null && purchaseLedgers.size() > 0) {
- List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>()
- .in("sales_ledger_id", purchaseLedgers.stream().map(PurchaseLedger::getId).collect(Collectors.toList())));
- // 搴斾粯閲戦
- payableAmount = salesLedgerProducts.stream().map(SalesLedgerProduct::getTaxInclusiveTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+ List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(
+ new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId())
+ );
+ List<SalesLedgerProduct> salesLedgerProducts = purchaseLedgers.stream()
+ .filter(Objects::nonNull)
+ .map(PurchaseLedger::getId)
+ .filter(Objects::nonNull)
+ .flatMap(id -> salesLedgerProductMapper.selectList(
+ new QueryWrapper<SalesLedgerProduct>().eq("sales_ledger_id", id).eq("type",2)
+ ).stream())
+ .collect(Collectors.toList());
+ payableAmount = salesLedgerProducts.stream()
+ .map(SalesLedgerProduct::getTaxInclusiveTotalPrice)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
- }
+ // 鏉ョエ閲戦璁$畻
+ List<TicketRegistration> ticketRegistrations = purchaseLedgers.stream()
+ .map(PurchaseLedger::getId)
+ .filter(Objects::nonNull)
+ .map(id -> ticketRegistrationMapper.selectList(
+ new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id)
+ ))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ BigDecimal invoiceAmount = ticketRegistrations.stream()
+ .map(TicketRegistration::getInvoiceAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal invoiceAmount = BigDecimal.ZERO;
- List<TicketRegistration> ticketRegistrations = Collections.emptyList();
+ // 浠樻璁板綍鍙婅鎯呭垎椤�
+ List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(
+ new QueryWrapper<PaymentRegistration>().eq("supplier_id", supplierManage.getId())
+ );
+ BigDecimal paymentAmount = paymentRegistrations.stream()
+ .map(PaymentRegistration::getCurrentPaymentAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
- // 澧炲姞绌哄�兼鏌ワ紝閬垮厤NullPointerException
- if (CollectionUtils.isNotEmpty(purchaseLedgers)) {
- Long[] ids = purchaseLedgers.stream()
- .map(PurchaseLedger::getId)
- .toArray(Long[]::new);
+ // 璇︽儏鍒嗛〉澶勭悊
+ detailPageNum = detailPageNum != null ? detailPageNum : 1;
+ detailPageSize = detailPageSize != null ? detailPageSize : paymentRegistrations.size(); // 榛樿鏄剧ず鍏ㄩ儴
+ int totalDetails = paymentRegistrations.size();
+ int start = (detailPageNum - 1) * detailPageSize;
+ int end = Math.min(start + detailPageSize, totalDetails);
+ List<PaymentRegistration> pagedDetails = paymentRegistrations.subList(start, end);
- // 妫�鏌ユ暟缁勬槸鍚︽湁鍏冪礌
- if (ids.length > 0) {
- ticketRegistrations = ticketRegistrationMapper.selectList(
- new LambdaQueryWrapper<TicketRegistration>()
- .in(TicketRegistration::getPurchaseLedgerId, ids)
- );
- }
- }
- if (ticketRegistrations != null && ticketRegistrations.size() > 0) {
- // 鏉ョエ閲戦
- invoiceAmount = ticketRegistrations.stream().map(TicketRegistration::getInvoiceAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
- }
- // 浠樻閲戦
- List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
- .eq("supplier_id", supplierManage.getId()));
+ // 鏋勫缓璇︽儏鍒楄〃
+ List<Map<String, Object>> details = pagedDetails.stream()
+ .filter(Objects::nonNull)
+ .map(pr -> {
+ Map<String, Object> detail = new HashMap<>();
+ detail.put("paymentAmount", pr.getCurrentPaymentAmount());
- BigDecimal paymentAmount = BigDecimal.ZERO;
- if (paymentRegistrations != null && paymentRegistrations.size() > 0) {
- paymentAmount = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
- }
+ // 鎵归噺鏌ヨ TicketRegistration锛堥伩鍏� N+1锛�
+ TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(pr.getTicketRegistrationId());
+ if (ticketRegistration != null) {
+ detail.put("payableAmount", ticketRegistration.getInvoiceAmount());
+ BigDecimal voteCount = productRecordMapper.selectList(
+ new LambdaQueryWrapper<ProductRecord>().eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId())
+ ).stream()
+ .map(ProductRecord::getTicketsNum)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ detail.put("voteCount", voteCount);
+ }
+ // 鏃ユ湡鏍煎紡鍖栵紙寤鸿浣跨敤 LocalDateTime锛�
+ if (pr.getPaymentDate() != null) {
+ detail.put("paymentDate", new SimpleDateFormat("yyyy-MM-dd").format(pr.getPaymentDate()));
+ }
+ return detail;
+ })
+ .collect(Collectors.toList());
+
+ // 灏佽璇︽儏鍒嗛〉鍏冩暟鎹�
+ Map<String, Object> detailPagination = new HashMap<>();
+ detailPagination.put("total", totalDetails);
+ detailPagination.put("pageNum", detailPageNum);
+ detailPagination.put("pageSize", detailPageSize);
+ detailPagination.put("pages", (int) Math.ceil((double) totalDetails / detailPageSize));
+
+ // 搴斾粯閲戦閫昏緫涓嶉噰鐢ㄥ悎鍚岄噾棰濇敼鎴� 鍙戠エ閲戦鍑忎粯娆鹃噾棰�
+ payableAmount = invoiceAmount.subtract(paymentAmount);
res.put("invoiceAmount", invoiceAmount);
res.put("payableAmount", payableAmount);
res.put("paymentAmount", paymentAmount);
-
- // 璇︽儏
- List<Map<String, Object>> details = new ArrayList<>();
- for (PaymentRegistration paymentRegistration : paymentRegistrations) {
- Map<String, Object> detail = new HashMap<>();
- detail.put("paymentAmount", paymentRegistration.getCurrentPaymentAmount()); // 浠樻閲戦
- TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
- detail.put("payableAmount", ticketRegistration.getInvoiceAmount()); // 搴斾粯閲戦
- BigDecimal voteCount = productRecordMapper.selectList(
- new LambdaQueryWrapper<ProductRecord>()
- .eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId()))
- .stream()
- .map(ProductRecord::getTicketsNum)
- .map(BigDecimal::new)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- detail.put("voteCount", voteCount); // 绁ㄦ暟
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String formattedDate = sdf.format(paymentRegistration.getPaymentDate());
- detail.put("paymentDate", formattedDate); // 鍙戠敓鏃堕棿
- details.add(detail);
- }
res.put("details", details);
+ res.put("detailPagination", detailPagination); // 娣诲姞璇︽儏鍒嗛〉淇℃伅
result.add(res);
}
+
+ resultPage.setRecords(result);
+ return resultPage;
+ }
+
+ @Override
+ public Map<String, BigDecimal> paymentMonthList() {
+
+ // 鏌ヨ渚涘簲鍟嗗垪琛�
+ List<SupplierManage> suppliers = supplierManageMapper.selectList(null);
+ if (CollectionUtils.isEmpty(suppliers)) {
+ Map<String, BigDecimal> result = new HashMap<>();
+ result.put("payableAmount", BigDecimal.ZERO);
+ result.put("paymentAmount", BigDecimal.ZERO);
+ return result;
+ }
+
+ // 鎻愬彇鎵�鏈変緵搴斿晢ID
+ List<Long> supplierIds = suppliers.stream()
+ .map(SupplierManage::getId) // 鍏堣幏鍙朓nteger绫诲瀷鐨処D
+ .filter(Objects::nonNull) // 杩囨护鎺夊彲鑳界殑null鍊�
+ .map(Integer::longValue) // 灏咺nteger杞崲涓篖ong
+ .collect(Collectors.toList());
+
+ // 鑾峰彇褰撴湀鐨勫紑濮嬪拰缁撴潫鏃ユ湡
+ YearMonth currentMonth = YearMonth.now();
+ LocalDate startDate = currentMonth.atDay(1);
+ LocalDate endDate = currentMonth.atEndOfMonth();
+
+ // 鎵归噺鏌ヨ閲囪喘鍙拌处锛堝綋鏈堬級
+ Map<Long, List<PurchaseLedger>> purchaseLedgerMap = batchQueryPurchaseLedgers(supplierIds, startDate, endDate);
+
+ // 鎵归噺鏌ヨ閿�鍞彴璐︿骇鍝�
+ Map<Long, List<SalesLedgerProduct>> salesLedgerProductMap = batchQuerySalesLedgerProducts(purchaseLedgerMap);
+
+ // 鎵归噺鏌ヨ浠樻璁板綍锛堝綋鏈堬級
+ Map<Long, List<PaymentRegistration>> paymentRegistrationMap = batchQueryPaymentRegistrations(supplierIds, startDate, endDate);
+
+ // 璁$畻搴斾粯閲戦鍜屼粯娆鹃噾棰�
+ BigDecimal totalPayableAmount = calculateTotalPayableAmount(purchaseLedgerMap, salesLedgerProductMap);
+ BigDecimal totalPaymentAmount = calculateTotalPaymentAmount(paymentRegistrationMap);
+
+ // 鏋勫缓缁撴灉
+ Map<String, BigDecimal> result = new HashMap<>();
+ result.put("payableAmount", totalPayableAmount);
+ result.put("paymentAmount", totalPaymentAmount);
return result;
}
+
+ /**
+ * 鏌ヨ浠樻鐧昏鍒楄〃
+ *
+ * @param paymentRegistrationDto 浠樻鐧昏
+ * @return 浠樻鐧昏闆嗗悎
+ */
+ @Override
+ public List<PaymentRegistrationDto> paymentHistoryList(PaymentRegistrationDto paymentRegistrationDto) {
+ return paymentRegistrationMapper.paymentHistoryList(paymentRegistrationDto);
+ }
+
+ /**
+ * 鏌ヨ渚涘簲鍟嗗線鏉ヨ褰�
+ * @param supplierId
+ * @return
+ */
+ @Override
+ public List<PaymentHistoryRecordVo> getPaymentRecordList(Long supplierId) {
+ List<PaymentHistoryRecordVo> paymentRecordList = paymentRegistrationMapper.getPaymentRecordList(supplierId);
+ List<PaymentHistoryRecordVo> result = new ArrayList<>();
+ List<PaymentHistoryRecordVo> newResult = new ArrayList<>();
+ // 搴斾粯鎬婚噾棰濋噾棰濊绠�
+ BigDecimal amountTotal = BigDecimal.ZERO;
+ if(CollectionUtils.isNotEmpty(paymentRecordList)) {
+ Map<LocalDate, List<PaymentHistoryRecordVo>> dateListMap = paymentRecordList.stream().collect(
+ Collectors.groupingBy(
+ PaymentHistoryRecordVo::getHappenTime,
+ LinkedHashMap::new,
+ Collectors.toList()
+ )
+ );
+ for (LocalDate localDate : dateListMap.keySet()) {
+ BigDecimal currentPaymentAmount = BigDecimal.ZERO;
+ BigDecimal invoiceAmount = BigDecimal.ZERO;
+ BigDecimal currentDateTotal = BigDecimal.ZERO;
+ List<PaymentHistoryRecordVo> paymentHistoryRecordVos = dateListMap.get(localDate);
+ // 璁$畻褰撳ぉ姹囨鏁�
+ currentPaymentAmount = paymentHistoryRecordVos.stream()
+ .filter(item ->item.getType() == 0)
+ .map(PaymentHistoryRecordVo::getCurrentPaymentAmount)
+ .reduce(BigDecimal.ZERO,BigDecimal::add);
+ // 璁$畻浠婂ぉ鏉ョエ鏁�
+ invoiceAmount = paymentHistoryRecordVos.stream()
+ .filter(item ->item.getType() == 1)
+ .map(PaymentHistoryRecordVo::getInvoiceAmount)
+ .reduce(BigDecimal.ZERO,BigDecimal::add);
+ // 璁$畻褰撴棩姹囨��
+ currentDateTotal = currentDateTotal.add(invoiceAmount).subtract(currentPaymentAmount);
+ PaymentHistoryRecordVo paymentHistoryRecordVo = new PaymentHistoryRecordVo();
+ paymentHistoryRecordVo.setHappenTime(localDate);
+ paymentHistoryRecordVo.setCurrentPaymentAmount(currentPaymentAmount);
+ paymentHistoryRecordVo.setInvoiceAmount(invoiceAmount);
+ amountTotal = paymentHistoryRecordVo.getInvoiceAmount().subtract(paymentHistoryRecordVo.getCurrentPaymentAmount());
+ paymentHistoryRecordVo.setPayableAmount(amountTotal);
+ result.add(paymentHistoryRecordVo);
+ }
+
+
+ for (int i = 0; i < result.size(); i++) {
+ PaymentHistoryRecordVo paymentHistoryRecordVo = result.get(i);
+ if (i == 0) {
+ paymentHistoryRecordVo.setPayableAmount(paymentHistoryRecordVo.getInvoiceAmount().subtract(paymentHistoryRecordVo.getCurrentPaymentAmount()));
+ }else {
+ PaymentHistoryRecordVo paymentHistoryRecordVo1 = result.get(i-1);
+ paymentHistoryRecordVo.setPayableAmount(paymentHistoryRecordVo1.getPayableAmount()
+ .add(paymentHistoryRecordVo.getInvoiceAmount()).subtract(paymentHistoryRecordVo.getCurrentPaymentAmount()));
+ }
+ newResult.add(paymentHistoryRecordVo);
+ }
+ }
+ return newResult;
+ }
+
+ /**
+ * 鏌ヨ浠樻鐧昏鍒楄〃鍒嗛〉
+ *
+ * @param paymentRegistrationDto 浠樻鐧昏
+ * @return 浠樻鐧昏闆嗗悎
+ */
+ @Override
+ public IPage<PaymentRegistrationDto> paymentHistoryListPage(Page page, PaymentRegistrationDto paymentRegistrationDto) {
+ return paymentRegistrationMapper.paymentHistoryListPage(page, paymentRegistrationDto);
+ }
+
+ @Override
+ public Boolean delete(Long[] ids) {
+ for (Long id : ids) {
+ List<ProductRecord> productRecords = productRecordMapper.selectList(new QueryWrapper<ProductRecord>().lambda().eq(ProductRecord::getTicketRegistrationId, id));
+ for (ProductRecord productRecord : productRecords) {
+ SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(productRecord.getSaleLedgerProjectId());
+ salesLedgerProduct.setTicketsNum(salesLedgerProduct.getTicketsNum().subtract(productRecord.getTicketsNum()));
+ salesLedgerProduct.setTicketsAmount(salesLedgerProduct.getTicketsAmount().subtract(productRecord.getTicketsAmount()));
+ salesLedgerProduct.setFutureTickets(salesLedgerProduct.getFutureTickets().add(productRecord.getTicketsNum()));
+ salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getFutureTicketsAmount().add(productRecord.getTicketsAmount()));
+ salesLedgerProductMapper.updateById(salesLedgerProduct);
+ }
+ ticketRegistrationMapper.delete(new QueryWrapper<TicketRegistration>().lambda().eq(TicketRegistration::getId, id));
+ productRecordMapper.delete(new QueryWrapper<ProductRecord>().lambda().eq(ProductRecord::getTicketRegistrationId, id));
+ }
+ return true;
+ }
+
+ @Override
+ public int delPaymentRegistration(Long id) {
+// PaymentRegistration paymentRegistration = paymentRegistrationMapper.selectById(id);
+// TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
+// if (ticketRegistration != null) {
+// ticketRegistration.setPaymentAmountTotal(ticketRegistration.getPaymentAmountTotal().subtract(paymentRegistration.getCurrentPaymentAmount()));
+// ticketRegistration.setUnPaymentAmountTotal(ticketRegistration.getUnPaymentAmountTotal().add(paymentRegistration.getCurrentPaymentAmount()));
+// ticketRegistrationMapper.updateById(ticketRegistration);
+// }
+
+ return paymentRegistrationMapper.deleteById(id);
+ }
+
+ // 鎵归噺鏌ヨ閲囪喘鍙拌处锛堝綋鏈堬級
+ private Map<Long, List<PurchaseLedger>> batchQueryPurchaseLedgers(List<Long> supplierIds, LocalDate startDate, LocalDate endDate) {
+ LambdaQueryWrapper<PurchaseLedger> query = new LambdaQueryWrapper<>();
+ query.in(PurchaseLedger::getSupplierId, supplierIds)
+ .ge(PurchaseLedger::getCreatedAt, startDate)
+ .le(PurchaseLedger::getCreatedAt, endDate);
+ List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(query);
+
+ return purchaseLedgers.stream()
+ .filter(pl -> pl.getSupplierId() != null)
+ .collect(Collectors.groupingBy(PurchaseLedger::getSupplierId));
+ }
+
+ // 鎵归噺鏌ヨ閿�鍞彴璐︿骇鍝�
+ private Map<Long, List<SalesLedgerProduct>> batchQuerySalesLedgerProducts(Map<Long, List<PurchaseLedger>> purchaseLedgerMap) {
+ // 鎻愬彇鎵�鏈夐噰璐彴璐D
+ List<Long> purchaseLedgerIds = purchaseLedgerMap.values().stream()
+ .flatMap(Collection::stream)
+ .map(PurchaseLedger::getId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ if (purchaseLedgerIds.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ LambdaQueryWrapper<SalesLedgerProduct> query = new LambdaQueryWrapper<>();
+ query.in(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerIds);
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(query);
+
+ return products.stream()
+ .filter(slp -> slp.getSalesLedgerId() != null)
+ .collect(Collectors.groupingBy(SalesLedgerProduct::getSalesLedgerId));
+ }
+
+ // 鎵归噺鏌ヨ浠樻璁板綍锛堝綋鏈堬級
+ private Map<Long, List<PaymentRegistration>> batchQueryPaymentRegistrations(List<Long> supplierIds, LocalDate startDate, LocalDate endDate) {
+ LambdaQueryWrapper<PaymentRegistration> query = new LambdaQueryWrapper<>();
+ query.in(PaymentRegistration::getSupplierId, supplierIds)
+ .ge(PaymentRegistration::getPaymentDate, startDate)
+ .le(PaymentRegistration::getPaymentDate, endDate);
+ List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(query);
+
+ return paymentRegistrations.stream()
+ .filter(pr -> pr.getSupplierId() != null)
+ .collect(Collectors.groupingBy(PaymentRegistration::getSupplierId));
+ }
+
+ // 璁$畻鎬诲簲浠橀噾棰�
+ private BigDecimal calculateTotalPayableAmount(Map<Long, List<PurchaseLedger>> purchaseLedgerMap,
+ Map<Long, List<SalesLedgerProduct>> salesLedgerProductMap) {
+ return purchaseLedgerMap.values().stream()
+ .flatMap(Collection::stream)
+ .map(pl -> salesLedgerProductMap.getOrDefault(pl.getId(), Collections.emptyList()))
+ .flatMap(Collection::stream)
+ .map(SalesLedgerProduct::getTaxInclusiveTotalPrice)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+
+ // 璁$畻鎬讳粯娆鹃噾棰�
+ private BigDecimal calculateTotalPaymentAmount(Map<Long, List<PaymentRegistration>> paymentRegistrationMap) {
+ return paymentRegistrationMap.values().stream()
+ .flatMap(Collection::stream)
+ .map(PaymentRegistration::getCurrentPaymentAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
}
--
Gitblit v1.9.3