From 3d2fd3a3f7d0571721b0f894e07c80553fd1e26c Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 10 六月 2026 11:12:05 +0800
Subject: [PATCH] fix(approve): 修复审批流程中的SQL查询和跳转路径问题

---
 src/main/java/com/ruoyi/approve/service/impl/FinReimbursementServiceImpl.java |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 7 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..a3d33f4 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);
@@ -274,6 +274,26 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean delete(List<Long> ids) {
+        if (ids == null || ids.isEmpty()) {
+            throw new ServiceException("鍒犻櫎澶辫触锛岃閫夋嫨瑕佸垹闄ょ殑鏁版嵁");
+        }
+        // 鏌ヨ鎶ラ攢鍗曞叧鑱旂殑瀹℃壒瀹炰緥ID
+        List<FinReimbursement> reimbursements = finReimbursementMapper.selectList(
+                new LambdaQueryWrapper<FinReimbursement>()
+                        .in(FinReimbursement::getId, ids)
+                        .isNotNull(FinReimbursement::getApprovalInstanceId)
+        );
+        List<Long> approvalInstanceIds = reimbursements.stream()
+                .map(FinReimbursement::getApprovalInstanceId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+
+        // 鍒犻櫎鍏宠仈鐨勫鎵硅褰�
+        if (!approvalInstanceIds.isEmpty()) {
+            approvalInstanceService.delete(approvalInstanceIds);
+        }
+
         fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.FILE, RecordTypeEnum.FIN_REIMBURSEMENT, ids);
         //鍏堝垹闄ゆ槑缁�
         finReimbursementDetailMapper.delete(new LambdaQueryWrapper<FinReimbursementDetail>().in(FinReimbursementDetail::getReimbursementId, ids));
@@ -381,7 +401,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) + "瀹℃壒");
@@ -494,15 +514,32 @@
         }
         String title = "鎶ラ攢瀹℃壒";
         String message = "瀹℃壒鍗曞彿 " + instance.getInstanceNo() + " 闇�瑕佹偍瀹℃壒";
-        String jumpPath = "/approvalInstance?id=" + instance.getId();
+        String jumpPath = getJumpPathByBusinessType(instance.getBusinessType(), instance.getId());
         sysNoticeService.simpleNoticeByUser(title, message, approverIds, jumpPath);
     }
 
-    private void resetApprovalFlow(Long approvalInstanceId, Long reimbursementId) {
-        if (approvalInstanceId == null) {
+    private String getJumpPathByBusinessType(Long businessType, Long instanceId) {
+        if (TypeEnums.TRAVEL_REIMBURSEMENT_APPROVAL.getCode().equals(businessType)) {
+            return "/collaborativeApproval/ReimburseManage/travel-reimburse?id=" + instanceId;
+        }
+        if (TypeEnums.EXPENSE_APPROVAL.getCode().equals(businessType)) {
+            return "/collaborativeApproval/ReimburseManage/cost-reimburse?id=" + instanceId;
+        }
+        return "/approvalInstance?id=" + instanceId;
+    }
+
+    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