From 47b42159fbe69fb2b4dbc13c75dd45abd00a55ae Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 13 二月 2026 11:10:34 +0800
Subject: [PATCH] fix: 查询日期缺少时分秒
---
src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java | 200 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 195 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
index c7b7ccf..cbef46f 100644
--- a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
+++ b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
@@ -1,25 +1,42 @@
package com.ruoyi.sales.controller;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.framework.web.domain.R;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
+import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
+import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.service.ICommonFileService;
import com.ruoyi.sales.service.ISalesLedgerService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.math.BigDecimal;
-import java.util.List;
+import java.net.URLEncoder;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -31,6 +48,8 @@
@RestController
@RequestMapping("/sales/ledger")
@AllArgsConstructor
+@Api(tags = "閿�鍞彴璐�")
+@Slf4j
public class SalesLedgerController extends BaseController {
private ISalesLedgerService salesLedgerService;
@@ -40,11 +59,64 @@
@Autowired
private InvoiceLedgerMapper invoiceLedgerMapper;
+ @Autowired
+ private ReceiptPaymentMapper receiptPaymentMapper;
+
+ /**
+ * 瀵煎叆閿�鍞彴璐�
+ */
+ @Log(title = "瀵煎叆閿�鍞彴璐�", businessType = BusinessType.INSERT)
+ @PostMapping("/import")
+ @ApiOperation("瀵煎叆閿�鍞彴璐�")
+ public AjaxResult importData(@RequestParam("file")
+ @ApiParam(value = "Excel鏂囦欢", required = true)
+ MultipartFile file) {
+ return salesLedgerService.importData(file);
+ }
+
+ @ApiOperation("瀵煎嚭閿�鍞彴璐︽ā鏉�")
+ @PostMapping("/exportTemplate")
+ public void exportTemplate(HttpServletResponse response) {
+ // 1. 妯℃澘鏂囦欢鍦╮esources/static涓嬬殑璺緞
+ String templatePath = "static/閿�鍞彴璐﹀鍏ユā鏉�.xlsx";
+
+ // 2. 鑾峰彇妯℃澘鏂囦欢鐨勮緭鍏ユ祦
+ try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath)) {
+ if (inputStream == null) {
+ throw new FileNotFoundException("妯℃澘鏂囦欢涓嶅瓨鍦細" + templatePath);
+ }
+
+ // 3. 璁剧疆鍝嶅簲澶达紝瑙﹀彂娴忚鍣ㄤ笅杞�
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("utf-8");
+ String fileName = URLEncoder.encode("閿�鍞彴璐﹀鍏ユā鏉�.xlsx", "utf-8").replaceAll("\\+", "%20");
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
+
+ // 4. 灏嗘ā鏉挎枃浠跺啓鍏ュ搷搴旇緭鍑烘祦
+ try (OutputStream outputStream = response.getOutputStream()) {
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, len);
+ }
+ outputStream.flush();
+ }
+ } catch (IOException e) {
+ log.error("瀵煎嚭閿�鍞彴璐︽ā鏉垮け璐�", e);
+ // 鑻ユā鏉挎枃浠惰鍙栧け璐ワ紝杩斿洖閿欒鎻愮ず
+ try {
+ response.getWriter().write("妯℃澘瀵煎嚭澶辫触锛�" + e.getMessage());
+ } catch (IOException ex) {
+ log.error("鍝嶅簲杈撳嚭閿欒", ex);
+ }
+ }
+ }
+
/**
* 鏌ヨ閿�鍞彴璐﹀垪琛�
*/
@GetMapping("/list")
- public TableDataInfo list(SalesLedgerDto salesLedgerDto) {
+ public TableDataInfo list(Page page, SalesLedgerDto salesLedgerDto) {
startPage();
List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
// 璁$畻宸插紑绁ㄩ噾棰�/鏈紑绁ㄩ噾棰�(宸插~鍐欏彂绁ㄩ噾棰濅负鍑�)
@@ -64,6 +136,7 @@
}
}
}
+
return getDataTable(list);
}
@@ -81,9 +154,29 @@
@Log(title = "閿�鍞彴璐�", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SalesLedgerDto salesLedgerDto) {
- List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
+ Page page = new Page(-1,-1);
+ IPage<SalesLedger> salesLedgerIPage = listPage(page, salesLedgerDto);
ExcelUtil<SalesLedger> util = new ExcelUtil<SalesLedger>(SalesLedger.class);
+ if(salesLedgerIPage == null){
+ util.exportExcel(response, new ArrayList<>(), "閿�鍞彴璐︽暟鎹�");
+ return;
+ }
+ List<SalesLedger> list = salesLedgerIPage.getRecords();
util.exportExcel(response, list, "閿�鍞彴璐︽暟鎹�");
+ }
+
+ /**
+ * 瀵煎嚭寮�绁ㄧ櫥璁板垪琛�
+ */
+ @Log(title = "瀵煎嚭寮�绁ㄧ櫥璁板垪琛�", businessType = BusinessType.EXPORT)
+ @PostMapping("/exportOne")
+ public void exportOne(HttpServletResponse response, SalesLedgerDto salesLedgerDto) {
+ Page page = new Page();
+ page.setCurrent(-1);
+ page.setSize(-1);
+ IPage<SalesLedger> salesLedgerIPage = listPage(page, salesLedgerDto);
+ ExcelUtil<SalesLedger> util = new ExcelUtil<SalesLedger>(SalesLedger.class);
+ util.exportExcel(response, salesLedgerIPage == null ? new ArrayList<>() : salesLedgerIPage.getRecords(), "瀵煎嚭寮�绁ㄧ櫥璁板垪琛�");
}
/**
@@ -156,7 +249,104 @@
* 杩戝崐骞村紑绁�,鍥炴閲戦
*/
@GetMapping("/getAmountHalfYear")
- public AjaxResult getAmountHalfYear() {
- return AjaxResult.success(salesLedgerService.getAmountHalfYear());
+ public AjaxResult getAmountHalfYear(@RequestParam(value = "type",defaultValue = "1") Integer type) {
+ return AjaxResult.success(salesLedgerService.getAmountHalfYear(type));
+ }
+
+ /**
+ * 鏌ヨ閿�鍞彴璐﹀垪琛�
+ */
+ @GetMapping("/listPage")
+ public IPage<SalesLedger> listPage(Page page, SalesLedgerDto salesLedgerDto) {
+ IPage<SalesLedger> iPage = salesLedgerService.selectSalesLedgerListPage(page, salesLedgerDto);
+
+ // 鏌ヨ缁撴灉涓虹┖,鐩存帴杩斿洖
+ if (CollectionUtils.isEmpty(iPage.getRecords())) {
+ return iPage;
+ }
+
+ // 鑾峰彇褰撳墠椤垫墍鏈夊彴璐﹁褰曠殑 ID 闆嗗悎
+ List<Long> salesLedgerIds = iPage.getRecords().stream().map(SalesLedger::getId).collect(Collectors.toList());
+
+ // 鏌ヨ鍙戠エ淇℃伅鐨勫凡寮�绁ㄩ噾棰�
+ List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoicedTotal(salesLedgerIds);
+ if (CollectionUtils.isEmpty(invoiceLedgerDtoList)) {
+ invoiceLedgerDtoList = Collections.emptyList();
+ }
+
+ // 杞崲鍙戠エ鏁版嵁, key 涓哄彴璐D, value 涓鸿鍙拌处鐨勬�诲紑绁ㄩ噾棰�
+ Map<Long, BigDecimal> invoiceTotals = invoiceLedgerDtoList.stream()
+ .filter(dto -> dto.getSalesLedgerId() != null && dto.getInvoiceTotal() != null)
+ .collect(Collectors.toMap(
+ dto -> dto.getSalesLedgerId().longValue(),
+ InvoiceLedgerDto::getInvoiceTotal,
+ BigDecimal::add // 瀛樺湪閲嶅ID鎵ц绱姞
+ ));
+
+ // 鏌ヨ鍥炴/浠樻璁板綍
+ List<ReceiptPayment> receiptPayments = Collections.emptyList();
+ if (!CollectionUtils.isEmpty(salesLedgerIds)) {
+ receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>()
+ .in(ReceiptPayment::getSalesLedgerId, salesLedgerIds));
+ }
+
+ // 杞崲鍥炴鏁版嵁, key 涓哄彴璐D, value 涓鸿鍙拌处鐨勬�诲洖娆鹃噾棰�
+ Map<Long, BigDecimal> receiptTotals = new HashMap<>();
+ if (!CollectionUtils.isEmpty(receiptPayments)) {
+ for (ReceiptPayment receiptPayment : receiptPayments) {
+ if (receiptPayment.getSalesLedgerId() != null && receiptPayment.getReceiptPaymentAmount() != null) {
+ // 濡傛灉 key 瀛樺湪鍒欑浉鍔�,涓嶅瓨鍦ㄥ垯鏀惧叆
+ receiptTotals.merge(receiptPayment.getSalesLedgerId(), receiptPayment.getReceiptPaymentAmount(), BigDecimal::add);
+ }
+ }
+ }
+
+ for (SalesLedger salesLedger : iPage.getRecords()) {
+ Long ledgerId = salesLedger.getId();
+ // 鍚堝悓鎬婚噾棰�
+ BigDecimal contractAmount = salesLedger.getContractAmount() == null ? BigDecimal.ZERO : salesLedger.getContractAmount();
+ // 寮�绁ㄦ�婚鍜屽洖娆炬�婚
+ BigDecimal invoiceTotal = invoiceTotals.getOrDefault(ledgerId, BigDecimal.ZERO);
+ BigDecimal receiptPaymentAmountTotal = receiptTotals.getOrDefault(ledgerId, BigDecimal.ZERO);
+
+ // 鏈紑绁ㄩ噾棰� = 鍚堝悓閲戦 - 宸插紑绁ㄩ噾棰�
+ BigDecimal noInvoiceAmountTotal = contractAmount.subtract(invoiceTotal);
+ if (noInvoiceAmountTotal.compareTo(BigDecimal.ZERO) < 0) {
+ noInvoiceAmountTotal = BigDecimal.ZERO;
+ }
+
+ // 寰呭洖娆鹃噾棰� = 宸插紑绁ㄩ噾棰� - 宸插洖娆鹃噾棰�
+ BigDecimal noReceiptPaymentAmountTotal = invoiceTotal.subtract(receiptPaymentAmountTotal);
+ if (noReceiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) < 0) {
+ noReceiptPaymentAmountTotal = BigDecimal.ZERO;
+ }
+
+ salesLedger.setNoInvoiceAmountTotal(noInvoiceAmountTotal);
+ salesLedger.setInvoiceTotal(invoiceTotal);
+ salesLedger.setReceiptPaymentAmountTotal(receiptPaymentAmountTotal);
+ salesLedger.setNoReceiptAmount(noReceiptPaymentAmountTotal);
+
+ // 濡傛灉宸茬粡鏈夎繃寮�绁ㄦ垨鍥炴鎿嶄綔,鍒欎笉鍏佽缂栬緫
+ boolean hasInvoiceOperation = invoiceTotal.compareTo(BigDecimal.ZERO) > 0;
+ boolean hasReceiptOperation = receiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) > 0;
+ salesLedger.setIsEdit(!(hasInvoiceOperation || hasReceiptOperation));
+ }
+
+ if (ObjectUtils.isNotEmpty(salesLedgerDto.getStatus())) {
+ if (salesLedgerDto.getStatus()) {
+ // 娓呴櫎鎵�鏈夆�滄湭寮�绁ㄩ噾棰濃�濅负 0 鐨勮褰�
+ iPage.getRecords().removeIf(salesLedger ->
+ Objects.equals(salesLedger.getNoInvoiceAmountTotal(), new BigDecimal("0.00")));
+ iPage.setTotal(iPage.getRecords().size());
+ }
+ }
+
+ return iPage;
+ }
+
+ @ApiOperation("鏌ヨ閿�鍞彴璐︽秷鑰楃墿鏂欎俊鎭�")
+ @GetMapping("/getSalesLedgerWithProductsLoss")
+ public R getSalesLedgerWithProductsLoss(Long salesLedgerId) {
+ return R.ok(salesLedgerService.getSalesLedgerWithProductsLoss(salesLedgerId));
}
}
--
Gitblit v1.9.3