From 8beb176e14312b8e7ca43a25f8ec1386157502f9 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 28 五月 2026 14:40:42 +0800
Subject: [PATCH] feat:采购批量审核-质检-入库

---
 src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java b/src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java
index a69bb76..305ea9d 100644
--- a/src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java
+++ b/src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java
@@ -76,7 +76,7 @@
         String billStatus = validateAddParam(finReimbursementDto);
 
         // 鐢熸垚鎶ラ攢鍗曞彿
-        String billNo = OrderUtils.countTodayByCreateTime(finReimbursementMapper, "BXD", "bill_no");
+        String billNo = OrderUtils.countTodayByCreateTime(finReimbursementMapper, "BXD", "bill_no", finReimbursementDto.getCreateTime() != null ? finReimbursementDto.getCreateTime() : LocalDateTime.now());
         List<FinReimbursementDetail> details = finReimbursementDto.getDetails();
         BigDecimal totalAmount = details.stream()
                 .map(FinReimbursementDetail::getAmount)
@@ -199,7 +199,7 @@
             }
         }
 
-        resetApprovalFlow(existing.getApprovalInstanceId(), reimbursementId);
+        resetApprovalFlow(existing, reimbursementId);
         if (BILL_STATUS_IN_APPROVAL.equals(billStatus)) {
             reimbursement.setApprovalInstanceId(null);
             startApproval(reimbursement, finReimbursementDto);
@@ -381,7 +381,7 @@
     private void startApproval(FinReimbursement reimbursement, FinReimbursementDto finReimbursementDto) {
         Long businessType = resolveBusinessType(finReimbursementDto.getReimbursementType());
         ApprovalInstanceDto approvalInstanceDto = new ApprovalInstanceDto();
-        approvalInstanceDto.setInstanceNo(OrderUtils.countTodayByCreateTime(approvalInstanceMapper, "SP", "instance_no"));
+        approvalInstanceDto.setInstanceNo(OrderUtils.countTodayByCreateTime(approvalInstanceMapper, "SP", "instance_no", approvalInstanceDto.getCreateTime() != null ? approvalInstanceDto.getCreateTime() : LocalDateTime.now()));
         approvalInstanceDto.setBusinessId(reimbursement.getId());
         approvalInstanceDto.setTemplateId(null);
         approvalInstanceDto.setTemplateName(TypeEnums.getLabelByValue(businessType) + "瀹℃壒");
@@ -498,11 +498,18 @@
         sysNoticeService.simpleNoticeByUser(title, message, approverIds, jumpPath);
     }
 
-    private void resetApprovalFlow(Long approvalInstanceId, Long reimbursementId) {
-        if (approvalInstanceId == null) {
+    private void resetApprovalFlow(FinReimbursement existing, Long reimbursementId) {
+        if (existing == null || existing.getApprovalInstanceId() == null) {
             return;
         }
-        approvalInstanceService.delete(Collections.singletonList(approvalInstanceId));
+        Long approvalInstanceId = existing.getApprovalInstanceId();
+        if (!"REJECTED".equals(existing.getBillStatus())) {
+            approvalInstanceService.delete(Collections.singletonList(approvalInstanceId));
+        }
+        clearApprovalBinding(reimbursementId);
+    }
+
+    private void clearApprovalBinding(Long reimbursementId) {
         int rows = finReimbursementMapper.update(
                 null,
                 Wrappers.<FinReimbursement>lambdaUpdate()

--
Gitblit v1.9.3