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,6 +15,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; /** * 仿¬¾ç»è®°Controller @@ -22,8 +25,7 @@ */ @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)); } @@ -85,8 +83,7 @@ */ @Log(title = "仿¬¾ç»è®°", businessType = BusinessType.DELETE) @DeleteMapping("/del") public AjaxResult remove(@RequestBody Long[] ids) { 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()); } } 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(); } 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); } BigDecimal invoiceAmount = BigDecimal.ZERO; List<TicketRegistration> ticketRegistrations = Collections.emptyList(); // å¢å ç©ºå¼æ£æ¥ï¼é¿å NullPointerException if (CollectionUtils.isNotEmpty(purchaseLedgers)) { Long[] ids = purchaseLedgers.stream() .map(PurchaseLedger::getId) .toArray(Long[]::new); // æ£æ¥æ°ç»æ¯å¦æå ç´ if (ids.length > 0) { ticketRegistrations = ticketRegistrationMapper.selectList( new LambdaQueryWrapper<TicketRegistration>() .in(TicketRegistration::getPurchaseLedgerId, ids) List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList( new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId()) ); } } 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<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); BigDecimal paymentAmount = BigDecimal.ZERO; if (paymentRegistrations != null && paymentRegistrations.size() > 0) { paymentAmount = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).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); // 仿¬¾è®°å½å详æ å页 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); // 详æ å页å¤ç 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); // æå»ºè¯¦æ å表 List<Map<String, Object>> details = pagedDetails.stream() .filter(Objects::nonNull) .map(pr -> { Map<String, Object> detail = new HashMap<>(); detail.put("paymentAmount", pr.getCurrentPaymentAmount()); // æ¹éæ¥è¯¢ 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) // å è·åIntegerç±»åçID .filter(Objects::nonNull) // è¿æ»¤æå¯è½çnullå¼ .map(Integer::longValue) // å°Integer转æ¢ä¸ºLong .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) { // æåææéè´å°è´¦ID 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); } } 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()); } } 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()); } } 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; // 忬¾éé¢ } 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); } 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(); } 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(); } 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; } /** 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; } } 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() { // æ¥è¯¢åå§æ°æ® LambdaQueryWrapper<SalesLedger> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.select(SalesLedger::getCustomerId, SalesLedger::getCustomerName, SalesLedger::getContractAmount) .orderByDesc(SalesLedger::getContractAmount); List<SalesLedger> records = salesLedgerMapper.selectList(queryWrapper); return null; // æå®¢æ·IDåç»å¹¶èåéé¢ 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; } } /**