From 360f96ffb62a0ba418c0de0a4a5b5f537912872e Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 26 五月 2025 14:05:08 +0800
Subject: [PATCH] 首页数据
---
src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java | 266 ++++++++++++++++++++-----
src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java | 14 +
src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java | 9
src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java | 12 +
src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java | 3
src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java | 8
src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java | 17 -
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 127 +++++++++++-
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java | 37 +++
src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java | 3
src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java | 44 ++-
src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java | 13 +
12 files changed, 446 insertions(+), 107 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java b/src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java
index b8f233d..6ba3a59 100644
--- a/src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java
+++ b/src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java
@@ -1,5 +1,7 @@
package com.ruoyi.purchase.controller;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
@@ -13,17 +15,17 @@
import org.springframework.web.bind.annotation.*;
import java.util.List;
+import java.util.Map;
/**
* 浠樻鐧昏Controller
- *
+ *
* @author ruoyi
* @date 2025-05-15
*/
@RestController
@RequestMapping("/purchase/paymentRegistration")
-public class PaymentRegistrationController extends BaseController
-{
+public class PaymentRegistrationController extends BaseController {
@Autowired
private IPaymentRegistrationService paymentRegistrationService;
@@ -32,8 +34,7 @@
*/
// @PreAuthorize("@ss.hasPermi('system:registration:list')")
@GetMapping("/list")
- public TableDataInfo list(PaymentRegistrationDto paymentRegistrationDto)
- {
+ public TableDataInfo list(PaymentRegistrationDto paymentRegistrationDto) {
startPage();
List<PaymentRegistrationDto> list = paymentRegistrationService.selectPaymentRegistrationList(paymentRegistrationDto);
return getDataTable(list);
@@ -55,8 +56,7 @@
* 鑾峰彇浠樻鐧昏璇︾粏淇℃伅
*/
@GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(paymentRegistrationService.selectPaymentRegistrationById(id));
}
@@ -65,8 +65,7 @@
*/
@Log(title = "浠樻鐧昏", businessType = BusinessType.INSERT)
@PostMapping
- public AjaxResult add(@RequestBody PaymentRegistration paymentRegistration)
- {
+ public AjaxResult add(@RequestBody PaymentRegistration paymentRegistration) {
return toAjax(paymentRegistrationService.insertPaymentRegistration(paymentRegistration));
}
@@ -75,8 +74,7 @@
*/
@Log(title = "浠樻鐧昏", businessType = BusinessType.UPDATE)
@PutMapping
- public AjaxResult edit(@RequestBody PaymentRegistration paymentRegistration)
- {
+ public AjaxResult edit(@RequestBody PaymentRegistration paymentRegistration) {
return toAjax(paymentRegistrationService.updatePaymentRegistration(paymentRegistration));
}
@@ -84,9 +82,8 @@
* 鍒犻櫎浠樻鐧昏
*/
@Log(title = "浠樻鐧昏", businessType = BusinessType.DELETE)
- @DeleteMapping("/del")
- public AjaxResult remove(@RequestBody Long[] ids)
- {
+ @DeleteMapping("/del")
+ public AjaxResult remove(@RequestBody Long[] ids) {
return toAjax(paymentRegistrationService.deletePaymentRegistrationByIds(ids));
}
@@ -94,8 +91,7 @@
* 鑾峰彇浠樻鐧昏璇︾粏淇℃伅
*/
@GetMapping(value = "/byPurchaseId/{id}")
- public AjaxResult getPurchaseInfo(@PathVariable("id") Long id)
- {
+ public AjaxResult getPurchaseInfo(@PathVariable("id") Long id) {
return success(paymentRegistrationService.selectPaymentRegistrationByPurchaseId(id));
}
@@ -103,8 +99,18 @@
* 鑾峰彇浠樻鐧昏璇︾粏淇℃伅
*/
@GetMapping(value = "/paymentLedgerList")
- public AjaxResult paymentLedgerList(PaymentLedgerDto paymentLedgerDto)
- {
- return success(paymentRegistrationService.selectPaymentLedgerList(paymentLedgerDto));
+ public AjaxResult paymentLedgerList(PaymentLedgerDto paymentLedgerDto, Page page,
+ Integer detailPageNum,
+ Integer detailPageSize) {
+ IPage<Map<String, Object>> mapIPage = paymentRegistrationService.selectPaymentLedgerList(paymentLedgerDto, page, detailPageNum, detailPageSize);
+ return success(mapIPage);
+ }
+
+ /**
+ * 鑾峰彇鏈湀搴斾粯淇℃伅
+ */
+ @GetMapping(value = "/paymentMonthList")
+ public AjaxResult paymentMonthList() {
+ return success(paymentRegistrationService.paymentMonthList());
}
}
diff --git a/src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java b/src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java
index cbf484f..ec1244b 100644
--- a/src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java
+++ b/src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java
@@ -1,10 +1,13 @@
package com.ruoyi.purchase.service;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.purchase.dto.PaymentLedgerDto;
import com.ruoyi.purchase.dto.PaymentRegistrationDto;
import com.ruoyi.purchase.pojo.PaymentRegistration;
+import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@@ -63,5 +66,9 @@
*/
PaymentRegistration selectPaymentRegistrationByPurchaseId(Long purchaseId);
- List<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto);
+ IPage<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto, Page page,
+ Integer detailPageNum,
+ Integer detailPageSize);
+
+ Map<String, BigDecimal> paymentMonthList();
}
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..667df89 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -2,7 +2,9 @@
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;
@@ -27,6 +29,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;
@@ -176,8 +180,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 +193,223 @@
}
});
- 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());
- // 搴斾粯閲戦
+ // 搴斾粯閲戦璁$畻
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)
+ ).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)
+ .map(BigDecimal::new)
+ .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));
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;
}
+
+ // 鎵归噺鏌ヨ閲囪喘鍙拌处锛堝綋鏈堬級
+ 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);
+ }
}
diff --git a/src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java b/src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java
index 6549c3b..3078365 100644
--- a/src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java
+++ b/src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java
@@ -76,10 +76,10 @@
@GetMapping("/getReceiptAmount")
public AjaxResult getReceiptAmount() {
try {
- BigDecimal amount = receiptPaymentService.getReceiptAmount();
- return AjaxResult.success(amount != null ? amount : BigDecimal.ZERO);
+ BigDecimal receiptAmount = receiptPaymentService.getReceiptAmount();
+ return AjaxResult.success(receiptAmount != null ? receiptAmount : BigDecimal.ZERO);
} catch (Exception e) {
- return AjaxResult.error("鑾峰彇鍚堝悓閲戦澶辫触锛�" + e.getMessage());
+ return AjaxResult.error("鑾峰彇鍥炴閲戦澶辫触锛�" + e.getMessage());
}
}
@@ -103,4 +103,12 @@
public AjaxResult invoiceInfo (Integer id) {
return AjaxResult.success(receiptPaymentService.invoiceInfo(id));
}
+
+ /**
+ * 鏈湀搴旀敹,鍥炴閲戦
+ */
+ @GetMapping("/getAmountMouth")
+ public AjaxResult getAmountMouth() {
+ return AjaxResult.success(receiptPaymentService.getAmountMouth());
+ }
}
diff --git a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
index d21a2dd..a85c360 100644
--- a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
+++ b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
@@ -112,8 +112,8 @@
@GetMapping("/getContractAmount")
public AjaxResult getContractAmount() {
try {
- BigDecimal amount = salesLedgerService.getContractAmount();
- return AjaxResult.success(amount != null ? amount : BigDecimal.ZERO);
+ BigDecimal contractAmount = salesLedgerService.getContractAmount();
+ return AjaxResult.success(contractAmount != null ? contractAmount : BigDecimal.ZERO);
} catch (Exception e) {
return AjaxResult.error("鑾峰彇鍚堝悓閲戦澶辫触锛�" + e.getMessage());
}
@@ -126,4 +126,12 @@
public AjaxResult getTopFiveList() {
return AjaxResult.success(salesLedgerService.getTopFiveList());
}
+
+ /**
+ * 杩戝崐骞村紑绁�,鍥炴閲戦
+ */
+ @GetMapping("/getAmountHalfYear")
+ public AjaxResult getAmountHalfYear() {
+ return AjaxResult.success(salesLedgerService.getAmountHalfYear());
+ }
}
diff --git a/src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java b/src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java
new file mode 100644
index 0000000..155fc5f
--- /dev/null
+++ b/src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java
@@ -0,0 +1,13 @@
+package com.ruoyi.sales.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class MonthlyAmountDto {
+
+ private String month;
+ private BigDecimal invoiceAmount; // 寮�绁ㄩ噾棰�
+ private BigDecimal receiptAmount; // 鍥炴閲戦
+}
diff --git a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
index 8656614..f0d8353 100644
--- a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
+++ b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
@@ -1,9 +1,13 @@
package com.ruoyi.sales.mapper;
-import java.util.List;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.ruoyi.sales.pojo.SalesLedger;
import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
/**
@@ -21,4 +25,6 @@
List<Integer> selectSequencesByDate(@Param("datePart") String datePart);
List getSalesNo();
+
+ <T> BigDecimal selectSum(LambdaQueryWrapper<T> wrapper, SFunction<T, BigDecimal> column);
}
diff --git a/src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java b/src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java
index 4f736c7..0c8bcad 100644
--- a/src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java
+++ b/src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java
@@ -1,6 +1,7 @@
package com.ruoyi.sales.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.pojo.SalesLedger;
@@ -28,4 +29,6 @@
BigDecimal getContractAmount();
List getTopFiveList();
+
+ List<MonthlyAmountDto> getAmountHalfYear();
}
diff --git a/src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java b/src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java
index c77cb8d..dbb85ce 100644
--- a/src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java
+++ b/src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java
@@ -8,6 +8,7 @@
import java.math.BigDecimal;
import java.util.List;
+import java.util.Map;
public interface ReceiptPaymentService {
@@ -63,4 +64,6 @@
* @return
*/
InvoiceLedgerDto invoiceInfo(Integer id);
+
+ Map<String,BigDecimal> getAmountMouth();
}
diff --git a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
index 8d40b1c..696f72e 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
@@ -13,11 +13,8 @@
import com.ruoyi.sales.mapper.InvoiceLedgerFileMapper;
import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
-import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.pojo.InvoiceLedger;
import com.ruoyi.sales.pojo.InvoiceLedgerFile;
-import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
-import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.service.InvoiceLedgerService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
@@ -33,7 +30,6 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -258,13 +254,12 @@
// 鎵ц鏌ヨ骞惰绠楁�诲拰
List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(queryWrapper);
-// BigDecimal totalContractAmount = invoiceLedgers.stream()
-// .map(InvoiceLedger::getInvoiceAmount)
-// .filter(Objects::nonNull)
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
-//
-// return totalContractAmount;
- return null;
+ BigDecimal totalContractAmount = invoiceLedgers.stream()
+ .map(InvoiceLedger::getInvoiceTotal)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ return totalContractAmount;
}
/**
diff --git a/src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
index 7ee2762..16cc5e9 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
@@ -7,7 +7,9 @@
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.ReceiptPaymentDto;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.ReceiptPayment;
+import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.service.ReceiptPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -17,7 +19,9 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
@Service
@@ -25,6 +29,9 @@
@Autowired
private ReceiptPaymentMapper receiptPaymentMapper;
+
+ @Autowired
+ private SalesLedgerMapper salesLedgerMapper;
/**
* 鍥炴鐧昏鏂板
@@ -140,4 +147,34 @@
public InvoiceLedgerDto invoiceInfo(Integer id) {
return receiptPaymentMapper.invoiceInfo(id);
}
+
+ @Override
+ public Map<String,BigDecimal> getAmountMouth() {
+ List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(null);
+ BigDecimal contractAmount = salesLedgers.stream().map(SalesLedger::getContractAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ LocalDate now = LocalDate.now();
+ YearMonth currentMonth = YearMonth.from(now);
+
+ // 鍒涘缓LambdaQueryWrapper
+ LambdaQueryWrapper<ReceiptPayment> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.ge(ReceiptPayment::getReceiptPaymentDate, currentMonth.atDay(1).atStartOfDay()) // 澶т簬绛変簬鏈湀绗竴澶�
+ .lt(ReceiptPayment::getReceiptPaymentDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // 灏忎簬涓嬫湀绗竴澶�
+
+ // 鎵ц鏌ヨ骞惰绠楁�诲拰
+ List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(queryWrapper);
+
+ BigDecimal receiveAmount = receiptPayments.stream()
+ .map(ReceiptPayment::getReceiptPaymentAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ // 鏋勫缓缁撴灉
+ Map<String, BigDecimal> result = new HashMap<>();
+ result.put("receiveAmount", receiveAmount);
+ result.put("contractAmount", contractAmount);
+ return result;
+ }
}
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index c20172e..1b33c06 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,7 +1,6 @@
package com.ruoyi.sales.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -12,15 +11,10 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
+import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
-import com.ruoyi.sales.mapper.CommonFileMapper;
-import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
-import com.ruoyi.sales.mapper.SalesLedgerMapper;
-import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
-import com.ruoyi.sales.pojo.CommonFile;
-import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
-import com.ruoyi.sales.pojo.SalesLedger;
-import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.sales.mapper.*;
+import com.ruoyi.sales.pojo.*;
import com.ruoyi.sales.service.ISalesLedgerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -32,7 +26,6 @@
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.ObjectUtils;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -70,6 +63,10 @@
private final CommonFileMapper commonFileMapper;
private final TempFileMapper tempFileMapper;
+
+ private final ReceiptPaymentMapper receiptPaymentMapper;
+
+ private final InvoiceLedgerMapper invoiceLedgerMapper;
@Autowired
private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
@@ -159,8 +156,114 @@
@Override
public List getTopFiveList() {
-
- return null;
+ // 鏌ヨ鍘熷鏁版嵁
+ LambdaQueryWrapper<SalesLedger> queryWrapper = Wrappers.lambdaQuery();
+ queryWrapper.select(SalesLedger::getCustomerId,
+ SalesLedger::getCustomerName,
+ SalesLedger::getContractAmount)
+ .orderByDesc(SalesLedger::getContractAmount);
+ List<SalesLedger> records = salesLedgerMapper.selectList(queryWrapper);
+
+ // 鎸夊鎴稩D鍒嗙粍骞惰仛鍚堥噾棰�
+ Map<Long, GroupedCustomer> groupedMap = new LinkedHashMap<>(); // 浣跨敤LinkedHashMap淇濇寔鎺掑簭
+ for (SalesLedger record : records) {
+ groupedMap.computeIfAbsent(record.getCustomerId(),
+ k -> new GroupedCustomer(record.getCustomerId(), record.getCustomerName()))
+ .addAmount(record.getContractAmount());
+ }
+
+ // 杞崲涓虹粨鏋滃垪琛ㄥ苟鍙栧墠5
+ return groupedMap.values().stream()
+ .sorted(Comparator.comparing(GroupedCustomer::getTotalAmount).reversed())
+ .limit(5)
+ .map(customer -> {
+ Map<String, Object> result = new HashMap<>();
+ result.put("customerId", customer.getCustomerId());
+ result.put("customerName", customer.getCustomerName());
+ result.put("totalAmount", customer.getTotalAmount());
+ return result;
+ })
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<MonthlyAmountDto> getAmountHalfYear() {
+ LocalDate now = LocalDate.now();
+ YearMonth currentMonth = YearMonth.from(now);
+
+ List<MonthlyAmountDto> monthlyAmounts = new ArrayList<>();
+
+ for (int i = 0; i < 6; i++) {
+ YearMonth targetMonth = currentMonth.minusMonths(i);
+ LocalDate firstDayOfMonth = targetMonth.atDay(1);
+ LocalDate firstDayOfNextMonth = targetMonth.plusMonths(1).atDay(1);
+
+ LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
+ LocalDateTime startOfNextMonth = firstDayOfNextMonth.atStartOfDay();
+
+ LambdaQueryWrapper<ReceiptPayment> receiptPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ receiptPaymentLambdaQueryWrapper.ge(ReceiptPayment::getCreateTime, startOfMonth)
+ .lt(ReceiptPayment::getCreateTime, startOfNextMonth);
+
+ LambdaQueryWrapper<InvoiceLedger> invoiceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ invoiceLedgerLambdaQueryWrapper.ge(InvoiceLedger::getCreateTime, startOfMonth)
+ .lt(InvoiceLedger::getCreateTime, startOfNextMonth);
+
+ // 鑾峰彇鍥炴閲戦
+ List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(receiptPaymentLambdaQueryWrapper);
+ //寮�绁ㄩ噾棰�
+ List<InvoiceLedger> invoiceLedgerList = invoiceLedgerMapper.selectList(invoiceLedgerLambdaQueryWrapper);
+
+ // 浣跨敤 Stream 姹傚拰
+ BigDecimal invoiceAmount = invoiceLedgerList.stream()
+ .map(InvoiceLedger::getInvoiceTotal)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ BigDecimal receiptAmount = receiptPaymentList.stream()
+ .map(ReceiptPayment::getReceiptPaymentAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ MonthlyAmountDto monthlyAmount = new MonthlyAmountDto();
+ monthlyAmount.setMonth(targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
+ monthlyAmount.setInvoiceAmount(invoiceAmount);
+ monthlyAmount.setReceiptAmount(receiptAmount);
+
+ monthlyAmounts.add(monthlyAmount);
+ }
+
+ return monthlyAmounts;
+ }
+
+ // 鍐呴儴绫荤敤浜庡瓨鍌ㄨ仛鍚堢粨鏋�
+ private static class GroupedCustomer {
+ private final Long customerId;
+ private final String customerName;
+ private BigDecimal totalAmount = BigDecimal.ZERO;
+
+ public GroupedCustomer(Long customerId, String customerName) {
+ this.customerId = customerId;
+ this.customerName = customerName;
+ }
+
+ public void addAmount(BigDecimal amount) {
+ if (amount != null) {
+ this.totalAmount = this.totalAmount.add(amount);
+ }
+ }
+
+ public Long getCustomerId() {
+ return customerId;
+ }
+
+ public String getCustomerName() {
+ return customerName;
+ }
+
+ public BigDecimal getTotalAmount() {
+ return totalAmount;
+ }
}
/**
--
Gitblit v1.9.3