From b1b1c6b65cef9a4f6d9f3d7b09a31b40535ef63a Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 27 一月 2026 10:17:10 +0800
Subject: [PATCH] yys 优化采购审批模块
---
src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java | 127 ++++++++++++++++++++++++++++-------------
1 files changed, 86 insertions(+), 41 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java b/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
index 378a9c3..2358caf 100644
--- a/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
+++ b/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
@@ -11,19 +11,30 @@
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.purchase.dto.PurchaseLedgerDto;
+import com.ruoyi.purchase.mapper.PurchaseLedgerTemplateMapper;
+import com.ruoyi.purchase.mapper.SalesLedgerProductTemplateMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
+import com.ruoyi.purchase.pojo.PurchaseLedgerTemplate;
+import com.ruoyi.purchase.pojo.SalesLedgerProductTemplate;
import com.ruoyi.purchase.service.IPurchaseLedgerService;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
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.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.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -37,12 +48,68 @@
@RestController
@RequestMapping("/purchase/ledger")
@AllArgsConstructor
-@Api(tags = "111")
+@Api(tags = "閲囪喘鍙拌处")
+@Slf4j
public class PurchaseLedgerController extends BaseController {
private IPurchaseLedgerService purchaseLedgerService;
private ISalesLedgerService salesLedgerService;
private ISalesLedgerProductService salesLedgerProductService;
+
+ private PurchaseLedgerTemplateMapper purchaseLedgerTemplateMapper;
+
+ private SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper;
+
+
+ /**
+ * 瀵煎叆閲囪喘鍙拌处
+ */
+ @Log(title = "瀵煎叆閲囪喘鍙拌处", businessType = BusinessType.INSERT)
+ @PostMapping("/import")
+ @ApiOperation("瀵煎叆閲囪喘鍙拌处")
+ public AjaxResult importData(@RequestParam("file")
+ @ApiParam(value = "Excel鏂囦欢", required = true)
+ MultipartFile file) {
+ return purchaseLedgerService.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);
+ }
+ }
+ }
/**
* 鏌ヨ閲囪喘鍙拌处鍒楄〃
@@ -84,34 +151,24 @@
*/
@Log(title = "閲囪喘鍙拌处", businessType = BusinessType.INSERT)
@PostMapping("/addOrEditPurchase")
- public AjaxResult addOrEditPurchase(@RequestBody PurchaseLedgerDto purchaseLedgerDto) throws IOException {
+ public AjaxResult addOrEditPurchase(@RequestBody PurchaseLedgerDto purchaseLedgerDto) throws Exception {
return toAjax(purchaseLedgerService.addOrEditPurchase(purchaseLedgerDto));
}
- /**
- * 鏂板閲囪喘妯℃澘
- */
- @PostMapping("/addPurchaseTemplate")
- public AjaxResult addPurchaseTemplate(@RequestBody PurchaseLedgerDto purchaseLedgerDto) throws IOException {
- return toAjax(purchaseLedgerService.addPurchaseTemplate(purchaseLedgerDto));
- }
+
/**
* 鏌ヨ閲囪喘妯℃澘
*/
- @ApiOperation("/2222")
+ @ApiOperation("/鏌ヨ閲囪喘妯℃澘")
@GetMapping("/getPurchaseTemplateList")
public AjaxResult getPurchaseTemplateList() {
- PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto();
- purchaseLedgerDto.setApprovalStatus(3);
- IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerService.selectPurchaseLedgerListPage(new Page(1, -1), purchaseLedgerDto);
- List<PurchaseLedgerDto> purchaseLedgers = purchaseLedgerDtoIPage.getRecords();
-
+ List<PurchaseLedgerTemplate> purchaseLedgers = purchaseLedgerTemplateMapper.selectList(null);
purchaseLedgers.forEach(purchaseLedgerDto1 -> {
- LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerDto1.getId())
- .eq(SalesLedgerProduct::getType, 2);
- List<SalesLedgerProduct> list = salesLedgerProductService.list(queryWrapper);
+ LambdaQueryWrapper<SalesLedgerProductTemplate> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(SalesLedgerProductTemplate::getSalesLedgerId, purchaseLedgerDto1.getId())
+ .eq(SalesLedgerProductTemplate::getType, 2);
+ List<SalesLedgerProductTemplate> list = salesLedgerProductTemplateMapper.selectList(queryWrapper);
if (!list.isEmpty()) {
- purchaseLedgerDto1.setProductData(list);
+ purchaseLedgerDto1.setProductList(list);
}
});
return AjaxResult.success(purchaseLedgers);
@@ -129,6 +186,14 @@
@GetMapping("/getPurchaseById")
public PurchaseLedgerDto getPurchaseById(PurchaseLedgerDto purchaseLedgerDto) {
return purchaseLedgerService.getPurchaseById(purchaseLedgerDto);
+ }
+
+ /**
+ * 鏌ヨ閲囪喘鍙拌处鍜屼骇鍝佺埗瀛愬垪琛�
+ */
+ @GetMapping("/getPurchaseByCode")
+ public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) {
+ return purchaseLedgerService.getPurchaseByCode(purchaseLedgerDto);
}
/**
@@ -194,27 +259,7 @@
*/
@GetMapping("/listPage")
public AjaxResult listPage(Page page, PurchaseLedgerDto purchaseLedger) {
- IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = Optional.ofNullable(
- purchaseLedgerService.selectPurchaseLedgerListPage(page, purchaseLedger)
- ).orElse(new Page<>());
-
- // 澶勭悊null
- Optional.ofNullable(purchaseLedgerDtoIPage.getRecords())
- .filter(CollectionUtils::isNotEmpty)
- .ifPresent(records -> {
- // 杩囨护approvalStatus=3鐨勮褰�
- records.removeIf(dto -> dto != null && dto.getApprovalStatus() == 3);
- // 淇鏈敹浠樻閲戦
- records.forEach(dto -> {
- if (dto == null) return;
- BigDecimal unReceiptAmt = Optional.ofNullable(dto.getUnReceiptPaymentAmount()).orElse(BigDecimal.ZERO);
- if (unReceiptAmt.compareTo(BigDecimal.ZERO) == 0) {
- dto.setUnReceiptPaymentAmount(Optional.ofNullable(dto.getContractAmount()).orElse(BigDecimal.ZERO));
- }
- });
- });
-
- return AjaxResult.success(purchaseLedgerDtoIPage);
+ return AjaxResult.success(purchaseLedgerService.selectPurchaseLedgerListPage(page, purchaseLedger));
}
@ApiOperation("鐢熸垚閲囪喘搴忓垪鍙�")
--
Gitblit v1.9.3