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 | 349 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 301 insertions(+), 48 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
index 1f871d6..cbef46f 100644
--- a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
+++ b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
@@ -1,49 +1,151 @@
package com.ruoyi.sales.controller;
-import java.util.List;
-import javax.servlet.http.HttpServletResponse;
-
+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.sales.pojo.SalesLedger;
-import com.ruoyi.sales.service.ISalesLedgerService;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
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.net.URLEncoder;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 閿�鍞彴璐ontroller
- *
+ *
* @author ruoyi
* @date 2025-05-08
*/
@RestController
@RequestMapping("/sales/ledger")
-public class SalesLedgerController extends BaseController
-{
- @Autowired
+@AllArgsConstructor
+@Api(tags = "閿�鍞彴璐�")
+@Slf4j
+public class SalesLedgerController extends BaseController {
+
private ISalesLedgerService salesLedgerService;
+
+ private ICommonFileService commonFileService;
+
+ @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(SalesLedger salesLedger)
- {
+ public TableDataInfo list(Page page, SalesLedgerDto salesLedgerDto) {
startPage();
- List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedger);
+ List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
+ // 璁$畻宸插紑绁ㄩ噾棰�/鏈紑绁ㄩ噾棰�(宸插~鍐欏彂绁ㄩ噾棰濅负鍑�)
+ if(CollectionUtils.isEmpty(list)){
+ return getDataTable(list);
+ }
+ List<Long> salesLedgerIds = list.stream().map(SalesLedger::getId).collect(Collectors.toList());
+ List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoicedTotal(salesLedgerIds);
+ if(CollectionUtils.isEmpty(invoiceLedgerDtoList)){
+ return getDataTable(list);
+ }
+ for (SalesLedger salesLedger : list) {
+ for (InvoiceLedgerDto invoiceLedgerDto : invoiceLedgerDtoList) {
+ if (salesLedger.getId().intValue() == invoiceLedgerDto.getSalesLedgerId()) {
+ BigDecimal noInvoiceAmountTotal = salesLedger.getContractAmount().subtract(invoiceLedgerDto.getInvoiceTotal());
+ salesLedger.setNoInvoiceAmountTotal(noInvoiceAmountTotal);
+ }
+ }
+ }
+
return getDataTable(list);
+ }
+
+ /**
+ * 鏌ヨ閿�鍞彴璐﹀拰浜у搧鐖跺瓙鍒楄〃
+ */
+ @GetMapping("/getSalesLedgerWithProducts")
+ public SalesLedgerDto getSalesLedgerWithProducts(SalesLedgerDto salesLedgerDto) {
+ return salesLedgerService.getSalesLedgerWithProducts(salesLedgerDto);
}
/**
@@ -51,49 +153,200 @@
*/
@Log(title = "閿�鍞彴璐�", businessType = BusinessType.EXPORT)
@PostMapping("/export")
- public void export(HttpServletResponse response, SalesLedger salesLedger)
- {
- List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedger);
+ public void export(HttpServletResponse response, SalesLedgerDto 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, "閿�鍞彴璐︽暟鎹�");
}
/**
- * 鑾峰彇閿�鍞彴璐﹁缁嗕俊鎭�
+ * 瀵煎嚭寮�绁ㄧ櫥璁板垪琛�
*/
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return success(salesLedgerService.selectSalesLedgerById(id));
+ @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(), "瀵煎嚭寮�绁ㄧ櫥璁板垪琛�");
}
/**
- * 鏂板閿�鍞彴璐�
+ * 鏂板淇敼閿�鍞彴璐�
*/
@Log(title = "閿�鍞彴璐�", businessType = BusinessType.INSERT)
- @PostMapping ("/insertSalesLedger")
- public AjaxResult add(@RequestBody SalesLedger salesLedger)
- {
- return toAjax(salesLedgerService.insertSalesLedger(salesLedger));
- }
-
- /**
- * 淇敼閿�鍞彴璐�
- */
- @Log(title = "閿�鍞彴璐�", businessType = BusinessType.UPDATE)
- @PostMapping ("/updateSalesLedger")
- public AjaxResult edit(@RequestBody SalesLedger salesLedger)
- {
- return toAjax(salesLedgerService.updateSalesLedger(salesLedger));
+ @PostMapping("/addOrUpdateSalesLedger")
+ public AjaxResult add(@RequestBody SalesLedgerDto salesLedgerDto) {
+ return toAjax(salesLedgerService.addOrUpdateSalesLedger(salesLedgerDto));
}
/**
* 鍒犻櫎閿�鍞彴璐�
*/
@Log(title = "閿�鍞彴璐�", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
+ @DeleteMapping("/delLedger")
+ public AjaxResult remove(@RequestBody Long[] ids) {
+ if (ids == null || ids.length == 0) {
+ return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+ }
return toAjax(salesLedgerService.deleteSalesLedgerByIds(ids));
}
+
+ /**
+ * 鏌ヨ閿�鍞彴璐︿笉鍒嗛〉
+ *
+ * @param salesLedgerDto
+ * @return
+ */
+ @GetMapping("/listNoPage")
+ public AjaxResult listNoPage(SalesLedgerDto salesLedgerDto) {
+ List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
+ return AjaxResult.success(list);
+ }
+
+ /**
+ * 閿�鍞彴璐﹂檮浠跺垹闄�
+ */
+ @Log(title = "閿�鍞彴璐﹂檮浠跺垹闄�", businessType = BusinessType.DELETE)
+ @DeleteMapping("/delLedgerFile")
+ public AjaxResult delLedgerFile(@RequestBody Long[] ids) {
+ if (ids == null || ids.length == 0) {
+ return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+ }
+ return toAjax(commonFileService.deleteSalesLedgerByIds(ids));
+ }
+
+ /**
+ * 鏈湀閿�鍞悎鍚岄噾棰�
+ */
+ @GetMapping("/getContractAmount")
+ public AjaxResult getContractAmount() {
+ try {
+ BigDecimal contractAmount = salesLedgerService.getContractAmount();
+ return AjaxResult.success(contractAmount != null ? contractAmount : BigDecimal.ZERO);
+ } catch (Exception e) {
+ return AjaxResult.error("鑾峰彇鍚堝悓閲戦澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 瀹㈡埛鍚堝悓閲戦TOP5缁熻
+ */
+ @GetMapping("/getTopFiveList")
+ public AjaxResult getTopFiveList() {
+ return AjaxResult.success(salesLedgerService.getTopFiveList());
+ }
+
+ /**
+ * 杩戝崐骞村紑绁�,鍥炴閲戦
+ */
+ @GetMapping("/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