From 849648e82e5dec96f9f30fcc9c9bd799268b1f4c Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期四, 09 四月 2026 10:40:44 +0800
Subject: [PATCH] 新增资金流水导入
---
service/src/main/java/com/ruoyi/cwgl/controller/PayableBillManagementController.java | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 205 insertions(+), 0 deletions(-)
diff --git a/service/src/main/java/com/ruoyi/cwgl/controller/PayableBillManagementController.java b/service/src/main/java/com/ruoyi/cwgl/controller/PayableBillManagementController.java
index 2916ee3..69a406a 100644
--- a/service/src/main/java/com/ruoyi/cwgl/controller/PayableBillManagementController.java
+++ b/service/src/main/java/com/ruoyi/cwgl/controller/PayableBillManagementController.java
@@ -1,6 +1,9 @@
package com.ruoyi.cwgl.controller;
+import java.util.Date;
import java.util.List;
+
+import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -16,8 +19,20 @@
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Objects;
+import com.ruoyi.cwgl.domain.InvoiceManage;
import com.ruoyi.cwgl.domain.PayableBillManagement;
+import com.ruoyi.cwgl.domain.PayableBillManagementLog;
+import com.ruoyi.cwgl.domain.PayableInvoiceBusiness;
+import com.ruoyi.cwgl.domain.dto.BillAuditDto;
+import com.ruoyi.cwgl.domain.dto.PayableAuditLog;
+import com.ruoyi.cwgl.service.IInvoiceManageService;
+import com.ruoyi.cwgl.service.IPayableBillManagementLogService;
import com.ruoyi.cwgl.service.IPayableBillManagementService;
+import com.ruoyi.cwgl.service.IPayableInvoiceBusinessService;
+import com.ruoyi.cwgl.service.ITmsAuditLogPushService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@@ -33,6 +48,18 @@
{
@Autowired
private IPayableBillManagementService payableBillManagementService;
+
+ @Autowired
+ private IInvoiceManageService invoiceManageService;
+
+ @Autowired
+ private IPayableInvoiceBusinessService payableInvoiceBusinessService;
+
+ @Autowired
+ private ITmsAuditLogPushService tmsAuditLogPushService;
+
+ @Autowired
+ private IPayableBillManagementLogService payableBillManagementLogService;
@@ -105,4 +132,182 @@
{
return toAjax(payableBillManagementService.deletePayableBillManagementByIds(ids));
}
+
+ /**
+ * 浣滃簾搴斾粯璐﹀崟绠$悊璁板綍
+ */
+ @PreAuthorize("@ss.hasPermi('cwgl:payableBillManagement:void')")
+ @Log(title = "搴斾粯璐﹀崟绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping("/void/{id}")
+ public AjaxResult voidPayableBill(@PathVariable("id") Integer id)
+ {
+ return toAjax(payableBillManagementService.voidPayableBillManagement(id));
+ }
+
+ /**
+ * 搴斾粯璐﹀崟鐢宠寮�绁�
+ * @param invoiceManage 鍙戠エ绠$悊瀵硅薄
+ * @param id 搴斾粯璐﹀崟ID
+ * @return 缁撴灉
+ */
+ @PreAuthorize("@ss.hasPermi('cwgl:payableBillManagement:invoice')")
+ @Log(title = "搴斾粯璐﹀崟绠$悊", businessType = BusinessType.OTHER)
+ @PostMapping("/invoice/{id}")
+ public AjaxResult applyPayableInvoice(@RequestBody InvoiceManage invoiceManage, @PathVariable("id") Integer id)
+ {
+ return invoiceManageService.applyPayableInvoice(invoiceManage, id);
+ }
+
+ /**
+ * 鏌ヨ搴斾粯璐﹀崟宸插紑绁ㄩ噾棰�
+ * @param id 搴斾粯璐﹀崟ID
+ * @return 宸插紑绁ㄩ噾棰�
+ */
+ @PreAuthorize("@ss.hasPermi('cwgl:payableBillManagement:query')")
+ @GetMapping("/invoice/amount/{id}")
+ public AjaxResult getPayableInvoicedAmount(@PathVariable("id") Integer id)
+ {
+ // 鏌ヨpayable_invoice_business琛ㄤ腑status涓�1鐨勮褰�
+ PayableInvoiceBusiness query = new PayableInvoiceBusiness();
+ query.setHeadId(id);
+ query.setStatus(1);
+ List<PayableInvoiceBusiness> invoices = payableInvoiceBusinessService.selectPayableInvoiceBusinessList(query);
+
+ // 璁$畻宸插紑绁ㄩ噾棰�
+ BigDecimal invoicedAmount = invoices.stream()
+ .map(PayableInvoiceBusiness::getInvoicingAmount)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ return AjaxResult.success(invoicedAmount);
+ }
+
+ /**
+ * 搴斾粯璐﹀崟瀹℃牳鎺ュ彛
+ * @param billAuditDto 瀹℃牳鏁版嵁浼犺緭瀵硅薄
+ * @return 瀹℃牳缁撴灉
+ */
+ @PreAuthorize("@ss.hasPermi('cwgl:payableBillManagement:audit')")
+ @Log(title = "搴斾粯璐﹀崟绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping("/audit")
+ public AjaxResult auditPayableBill(@RequestBody BillAuditDto billAuditDto) {
+ try {
+ // 1. 鏌ヨ搴斾粯璐﹀崟
+ PayableBillManagement bill = payableBillManagementService.selectPayableBillManagementById(billAuditDto.getBillId());
+ if (bill == null) {
+ return AjaxResult.error("搴斾粯璐﹀崟涓嶅瓨鍦紝ID锛�" + billAuditDto.getBillId());
+ }
+
+ // 2. 璁板綍瀹℃牳鍓嶇姸鎬�
+ Integer beforeAuditStatus = bill.getAuditStatus();
+
+ // 3. 鏇存柊瀹℃牳鐘舵��
+ bill.setAuditStatus(billAuditDto.getAuditResult());
+ bill.setUpdateTime(new java.util.Date());
+ bill.setUpdateBy(getUsername());
+
+ // 4. 鏇存柊璐﹀崟
+ int rows = payableBillManagementService.updatePayableBillManagement(bill);
+ if (rows <= 0) {
+ return AjaxResult.error("鏇存柊搴斾粯璐﹀崟瀹℃牳鐘舵�佸け璐�");
+ }
+
+ // 5. 璁板綍瀹℃牳鏃ュ織
+ savePayableAuditLog(billAuditDto, bill, beforeAuditStatus);
+
+ // 6. 濡傛灉鏉ユ簮绯荤粺鏄疶MS锛屾帹閫佸鏍告棩蹇楀埌TMS
+ if (tmsAuditLogPushService.isPayableBillFromTms(bill.getSystemNo())) {
+ try {
+ PayableAuditLog auditLog = createPayableAuditLog(billAuditDto, bill);
+ tmsAuditLogPushService.pushPayableAuditLog(auditLog);
+ } catch (Exception e) {
+ logger.error("鎺ㄩ�佸簲浠樿处鍗曞鏍告棩蹇楀埌TMS澶辫触锛岃处鍗旾D锛歿}", bill.getId(), e);
+ // 鎺ㄩ�佸け璐ヤ笉褰卞搷涓绘祦绋嬶紝鍙褰曟棩蹇�
+ }
+ }
+
+ return AjaxResult.success("搴斾粯璐﹀崟瀹℃牳鎴愬姛");
+
+ } catch (Exception e) {
+ return AjaxResult.error("搴斾粯璐﹀崟瀹℃牳澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 淇濆瓨搴斾粯璐﹀崟瀹℃牳鏃ュ織
+ */
+ private void savePayableAuditLog(BillAuditDto billAuditDto, PayableBillManagement bill, Integer beforeAuditStatus) {
+ try {
+ PayableBillManagementLog log = new PayableBillManagementLog();
+ log.setBillId(bill.getId());
+ log.setSourceSystemId(bill.getSourceSystemId()); // 璁剧疆鏉ユ簮绯荤粺ID
+ log.setCreateBy(getUsername());
+ log.setCreateTime(new Date());
+
+ // 鏋勫缓鎿嶄綔璇存槑
+ String operation = String.format("搴斾粯璐﹀崟瀹℃牳 - 璐﹀崟缂栧彿锛�%s锛屽鏍稿墠鐘舵�侊細%s锛屽鏍哥粨鏋滐細%s锛屽鏍告剰瑙侊細%s",
+ bill.getSystemNo(),
+ getAuditStatusText(beforeAuditStatus),
+ getAuditResultText(billAuditDto.getAuditResult()),
+ billAuditDto.getAuditComment() != null ? billAuditDto.getAuditComment() : "鏃�");
+ log.setOperation(operation);
+
+ // 淇濆瓨鍒版暟鎹簱
+ payableBillManagementLogService.insertPayableBillManagementLog(log);
+
+ logger.info("搴斾粯璐﹀崟瀹℃牳鏃ュ織淇濆瓨鎴愬姛 - 璐﹀崟ID锛歿}锛屾潵婧愮郴缁烮D锛歿}", bill.getId(), bill.getSourceSystemId());
+
+ } catch (Exception e) {
+ logger.error("淇濆瓨搴斾粯璐﹀崟瀹℃牳鏃ュ織澶辫触锛岃处鍗旾D锛歿}", bill.getId(), e);
+ // 鏃ュ織淇濆瓨澶辫触涓嶅奖鍝嶄富娴佺▼锛屽彧璁板綍閿欒鏃ュ織
+ }
+ }
+
+ /**
+ * 鑾峰彇瀹℃牳鐘舵�佹枃鏈�
+ */
+ private String getAuditStatusText(Integer auditStatus) {
+ switch (auditStatus) {
+ case 0: return "寰呭鏍�";
+ case 1: return "瀹℃牳閫氳繃";
+ case 2: return "瀹℃牳椹冲洖";
+ default: return "鏈煡鐘舵��";
+ }
+ }
+
+ /**
+ * 鑾峰彇瀹℃牳缁撴灉鏂囨湰
+ */
+ private String getAuditResultText(Integer auditResult) {
+ switch (auditResult) {
+ case 1: return "閫氳繃";
+ case 2: return "椹冲洖";
+ default: return "鏈煡缁撴灉";
+ }
+ }
+
+ /**
+ * 鍒涘缓搴斾粯璐﹀崟瀹℃牳鏃ュ織瀵硅薄
+ */
+ private PayableAuditLog createPayableAuditLog(BillAuditDto billAuditDto, PayableBillManagement bill) {
+ PayableAuditLog auditLog = new PayableAuditLog();
+ auditLog.setHeadId(bill.getSourceSystemId());
+ auditLog.setCreateBy(getUsername());
+ auditLog.setCreateTime(new Date());
+
+ String opertion = "";
+ if (billAuditDto.getAuditResult() != null&& billAuditDto.getAuditResult().equals(1)) {
+ opertion = "瀹℃牳閫氳繃";
+ if (StringUtils.isNotEmpty(billAuditDto.getAuditComment())){
+ opertion += ",瀹℃牳鎰忚 :" + billAuditDto.getAuditComment();
+ }
+ }else {
+ opertion = "瀹℃牳椹冲洖";
+ if (StringUtils.isNotEmpty(billAuditDto.getAuditComment())){
+ opertion += ",瀹℃牳鎰忚:" + billAuditDto.getAuditComment();
+ }
+ } auditLog.setOperation(opertion);
+
+ return auditLog;
+ }
}
--
Gitblit v1.8.0