2 Säilykkeet f68025092b ... 2bec0e2c65

Tekijä SHA1 Viesti Päivämäärä
  25057 2bec0e2c65 2025/12/29新版 3 kuukautta sitten
  25057 47fe6f1e87 2025/12/27 3 kuukautta sitten
28 muutettua tiedostoa jossa 595 lisäystä ja 356 poistoa
  1. 1 2
      pom.xml
  2. 27 0
      src/main/java/com/loan/system/config/MapNullKeySerializer.java
  3. 1 9
      src/main/java/com/loan/system/controller/wechat/EsignController.java
  4. 7 11
      src/main/java/com/loan/system/controller/wechat/LoanController.java
  5. 10 6
      src/main/java/com/loan/system/controller/wechat/OssFileController.java
  6. 7 7
      src/main/java/com/loan/system/controller/wechat/UserController.java
  7. 11 8
      src/main/java/com/loan/system/domain/dto/CompleteMultipartUploadDTO.java
  8. 6 5
      src/main/java/com/loan/system/domain/enums/StepPropertyEnum.java
  9. 3 0
      src/main/java/com/loan/system/domain/vo/CaseAndUserVO.java
  10. 1 1
      src/main/java/com/loan/system/repository/ClearDetailRepository.java
  11. 3 0
      src/main/java/com/loan/system/repository/ContractDisbursementRepository.java
  12. 5 0
      src/main/java/com/loan/system/repository/ContractRepository.java
  13. 3 0
      src/main/java/com/loan/system/repository/CustomerRepository.java
  14. 1 0
      src/main/java/com/loan/system/repository/UserRepository.java
  15. 2 0
      src/main/java/com/loan/system/service/ContractDisbursementService.java
  16. 3 0
      src/main/java/com/loan/system/service/ContractService.java
  17. 2 0
      src/main/java/com/loan/system/service/CustomerService.java
  18. 10 5
      src/main/java/com/loan/system/service/Impl/ClearDetailServiceImpl.java
  19. 5 0
      src/main/java/com/loan/system/service/Impl/ContractDisbursementServiceImpl.java
  20. 7 0
      src/main/java/com/loan/system/service/Impl/ContractServiceImpl.java
  21. 5 0
      src/main/java/com/loan/system/service/Impl/CustomerServiceImpl.java
  22. 98 37
      src/main/java/com/loan/system/service/Impl/DisbursementServiceImpl.java
  23. 207 164
      src/main/java/com/loan/system/service/Impl/LoanServiceImpl.java
  24. 146 88
      src/main/java/com/loan/system/service/Impl/OssService.java
  25. 3 1
      src/main/java/com/loan/system/service/Impl/RepaymentServiceImpl.java
  26. 14 7
      src/main/java/com/loan/system/service/Impl/UserServiceImpl.java
  27. 2 0
      src/main/java/com/loan/system/service/LoanService.java
  28. 5 5
      src/main/resources/application-prod.yaml

+ 1 - 2
pom.xml

@@ -324,8 +324,6 @@
             <groupId>esign-cn</groupId>
             <artifactId>paas-sdk</artifactId>
             <version>3.1.4</version>
-            <scope>system</scope>
-            <systemPath>${project.basedir}/lib/paas-sdk-3.1.4.jar</systemPath>
         </dependency>
         <!--
         备用方案:如果Maven仓库无法访问,取消下面注释并注释上面的依赖
@@ -376,6 +374,7 @@
                 </configuration>
             </plugin>
 
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>

+ 27 - 0
src/main/java/com/loan/system/config/MapNullKeySerializer.java

@@ -0,0 +1,27 @@
+package com.loan.system.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class MapNullKeySerializer extends JsonSerializer<Map<?, ?>> {
+    @Override
+    public void serialize(Map<?, ?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+        if (value == null) {
+            gen.writeNull();
+            return;
+        }
+
+        gen.writeStartObject();
+        for (Map.Entry<?, ?> entry : value.entrySet()) {
+            Object key = entry.getKey();
+            if (key != null) {
+                gen.writeObjectField(key.toString(), entry.getValue());
+            }
+        }
+        gen.writeEndObject();
+    }
+}

+ 1 - 9
src/main/java/com/loan/system/controller/wechat/EsignController.java

@@ -1,18 +1,10 @@
 package com.loan.system.controller.wechat;
 
-import cn.hutool.core.bean.BeanUtil;
-import com.loan.system.config.FileUploadConfig;
+
 import com.loan.system.domain.dto.EsignCreateFlowDTO;
 import com.loan.system.domain.dto.EsignFillTemplateDTO;
 import com.loan.system.domain.dto.EsignTemplateFillDTO;
-import com.loan.system.domain.entity.Contract;
-import com.loan.system.domain.entity.Document;
-import com.loan.system.domain.enums.ContractEnum;
-import com.loan.system.domain.pojo.ContractInformation;
 import com.loan.system.domain.pojo.Result;
-import com.loan.system.domain.vo.CustomerVO;
-import com.loan.system.domain.vo.EsignFlowVO;
-import com.loan.system.domain.vo.LoanCaseSimpleVO;
 import com.loan.system.service.*;
 import com.loan.system.utils.EsignContractUtil;
 import com.loan.system.utils.ResultUtil;

+ 7 - 11
src/main/java/com/loan/system/controller/wechat/LoanController.java

@@ -1,6 +1,7 @@
 package com.loan.system.controller.wechat;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
 import com.loan.system.context.BaseContext;
 import com.loan.system.domain.dto.*;
 import com.loan.system.domain.entity.*;
@@ -133,7 +134,7 @@ public class LoanController {
 
 
     @GetMapping("/all/{key}")
-    @ApiOperation("按客户关键字查询业务(所有)")//x
+    @ApiOperation("按客户关键字查询业务(所有)")
     @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
     public Result findAllLoanCaseByKey(@PathVariable String key, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
         List<Customer> customers = customerService.getAllCustomerByKey(key, false);
@@ -147,17 +148,12 @@ public class LoanController {
     }
 
     @GetMapping("/dealing/{key}")
-    @ApiOperation("按客户关键字查询业务")//x
+    @ApiOperation("按客户关键字查询业务")
     @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
-    public Result findLoanCaseByKey(@PathVariable String key, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
-        List<Customer> customers = customerService.getAllCustomerByKey(key, false);
-        List<Long> customerIds = new ArrayList<>();
-        for (Customer customer : customers)
-            customerIds.add(customer.getId());
-
-        List<LoanCaseVO> loanCases = loanService.findLoanCaseByCustomerIds(customerIds, pageNum, pageSize, DecisionEnum.PROCESS.getMsg(), false);
-
-        return ResultUtil.success("success", loanCases);
+    public Result findLoanCaseByKey(@PathVariable String key ,@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {//key为业务编号或客户姓名
+       if (key == null || StrUtil.isBlank( key))
+           return ResultUtil.success("success");
+        return ResultUtil.success("success", loanService.listLoanCaseByKeyAndIsComplete(key,DecisionEnum.PROCESS.getMsg(),pageNum,pageSize));
     }
 
     @GetMapping("/dealing/currentUser/{userId}")

+ 10 - 6
src/main/java/com/loan/system/controller/wechat/OssFileController.java

@@ -11,6 +11,7 @@ import com.loan.system.service.Impl.OssService;
 import com.loan.system.utils.ResultUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.ObjectUtils;
@@ -26,6 +27,7 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 
+@Slf4j
 @RestController
 @RequestMapping("/wechat/file")
 @Api(tags = "OSS文件处理接口")
@@ -53,7 +55,7 @@ public class OssFileController {
                 break;
 
             if (value != 0) {
-                System.out.println("删除文件" + id);
+                log.info("删除文件: {}", id);
                 fileService.deleteFileById(id);
                 // 从OSS删除文件
                 ossService.deleteFile(document.getFileName());
@@ -149,7 +151,7 @@ public class OssFileController {
             return;
         }
 
-        System.out.println("文件获取成功: " + fileName + ", 大小: " + ossObject.getObjectMetadata().getContentLength());
+        log.info("文件获取成功: {}, 大小: {}", fileName, ossObject.getObjectMetadata().getContentLength());
 
         response.setContentType(ossObject.getObjectMetadata().getContentType());
         response.setHeader("Content-Disposition",
@@ -230,7 +232,7 @@ public class OssFileController {
         }
     }
     
-    /** 初始化分块上传 */
+    /** 1.初始化分块上传 */
     @PostMapping("/multipart/init/{caseId}/{type}")
     @ApiOperation("初始化分块上传")
     public Result initMultipartUpload(@PathVariable("caseId") Long caseId,
@@ -257,7 +259,7 @@ public class OssFileController {
         return ResultUtil.success("初始化成功", result);
     }
     
-    /** 上传分块 */
+    /** 2.上传分块 */
     @PostMapping("/multipart/upload")
     @ApiOperation("上传分块")
     public Result uploadPart(@RequestParam String fileName,
@@ -282,7 +284,7 @@ public class OssFileController {
         return ResultUtil.success("分块上传成功", result);
     }
     
-    /** 完成分块上传 */
+    /** 3.完成分块上传 */
     @PostMapping("/multipart/complete/{caseId}/{type}")
     @ApiOperation("完成分块上传")
     public Result completeMultipartUpload(@PathVariable("caseId") Long caseId,
@@ -300,7 +302,7 @@ public class OssFileController {
                     break;
 
                 if (value != 0) {
-                    System.out.println("删除文件" + id);
+                    log.info("删除文件{}", id);
                     fileService.deleteFileById(id);
                     // 从OSS删除文件
                     ossService.deleteFile(document.getFileName());
@@ -311,7 +313,9 @@ public class OssFileController {
         // 将DTO列表转换为PartETag列表
         List<PartETag> partETags = new ArrayList<>();
         if (request.getPartETagsList() != null) {
+            log.info("partETagsList: {}", request.getPartETagsList());
             for (CompleteMultipartUploadDTO.PartETagDTO partETagDTO : request.getPartETagsList()) {
+                log.info("partETagDTO: {}", partETagDTO);
                 partETags.add(new PartETag(partETagDTO.getPartNumber(), partETagDTO.getETag()));
             }
         }

+ 7 - 7
src/main/java/com/loan/system/controller/wechat/UserController.java

@@ -258,12 +258,12 @@ public class UserController {//包含内部人员、外部人员
             throw new DescribeException(ExceptionEnum.INPUT_ERROR);
         return ResultUtil.success("success", userService.listSales(stepCode));
     }
-    @GetMapping("/finances")
-    @ApiOperation("查询所有财务")
-    @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','BACK_OFFICE')")
-    public Result findAllFinances(){
-
-        return ResultUtil.success("success", userService.findAllFinances());
-    }
+//    @GetMapping("/finances")
+//    @ApiOperation("查询所有财务")
+//    @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','BACK_OFFICE')")
+//    public Result findAllFinances(){
+//
+//        return ResultUtil.success("success", userService.findAllFinances());
+//    }
 
 }

+ 11 - 8
src/main/java/com/loan/system/domain/dto/CompleteMultipartUploadDTO.java

@@ -1,5 +1,6 @@
 package com.loan.system.domain.dto;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -16,14 +17,14 @@ import java.util.Map;
 @NoArgsConstructor
 @AllArgsConstructor
 public class CompleteMultipartUploadDTO implements Serializable {
-    private String fileName;
-    private String uploadId;
-    private String randomUUID;
-    private String ext;
-    private String originalName;
-    private Long fileSize;
-    private Map<String, String> isDelete;
-    private List<PartETagDTO> partETagsList;
+    private String fileName;//1.
+    private String uploadId;//1.
+    private String randomUUID;//1.
+    private String ext;//1.
+    private String originalName;//前端可给定
+    private Long fileSize;//文件总大小
+    private Map<String, String> isDelete;//删除的文件
+    private List<PartETagDTO> partETagsList;//2.分块
     
     /**
      * 分块ETag DTO
@@ -33,6 +34,8 @@ public class CompleteMultipartUploadDTO implements Serializable {
     @AllArgsConstructor
     public static class PartETagDTO implements Serializable {
         private Integer partNumber;
+
+        @JsonProperty("eTag")
         private String eTag;
     }
 }

+ 6 - 5
src/main/java/com/loan/system/domain/enums/StepPropertyEnum.java

@@ -50,8 +50,8 @@ public enum StepPropertyEnum {
     REPAY_PARENT(571, "回款环节", true),
     REPAY_START(572, "回款申报", false),
     REPAY_APPROVAL(573, "回款派单", false),
-//    FINANCE_CHECK(574, "财务核算", false),
-    BALANCE_REPAY(575, "回款操作", false),
+    BALANCE_REPAY(574, "回款操作", false),
+    AUTO_REPAY(575, "主动回款", false),
     FINANCE_CONFIRM(576, "财务确认", false),
     REPAYMENT_COMPLETE(577, "完成回款", false),
     CASE_COMPLETE(578, "业务终结", false),
@@ -244,12 +244,13 @@ public enum StepPropertyEnum {
                 Arrays.asList(),
                 Arrays.asList(),//回款25
                 Arrays.asList(27),
-                Arrays.asList(28),
-                Arrays.asList(29),
+                Arrays.asList(28,29),
+                Arrays.asList(30),
                 Arrays.asList(30),
                 Arrays.asList(31),
                 Arrays.asList(32),
-                Arrays.asList()
+                Arrays.asList(33),
+                 Arrays.asList()
         ));
 
         return list;

+ 3 - 0
src/main/java/com/loan/system/domain/vo/CaseAndUserVO.java

@@ -1,5 +1,7 @@
 package com.loan.system.domain.vo;
 
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.loan.system.config.MapNullKeySerializer;
 import com.loan.system.domain.entity.User;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -13,5 +15,6 @@ import java.util.Map;
 @NoArgsConstructor
 public class CaseAndUserVO {
     List<UserVO> users;//所有业务员
+    @JsonSerialize(using = MapNullKeySerializer.class)
     Map<Long,List<LoanCaseVO>> caseUsers;//每个业务对应的业务员
 }

+ 1 - 1
src/main/java/com/loan/system/repository/ClearDetailRepository.java

@@ -16,6 +16,6 @@ public interface ClearDetailRepository extends JpaRepository<ClearDetail, Long>
 
     @Modifying
     @Transactional
-    @Query("update ClearDetail c set c.currentAmount = ?1 where c.id = ?2")
+    @Query("update ClearDetail c set c.currentInterest = ?1 where c.id = ?2")
     void updateCurrentAmountById(Double currentAmount, Long id);
 }

+ 3 - 0
src/main/java/com/loan/system/repository/ContractDisbursementRepository.java

@@ -16,4 +16,7 @@ public interface ContractDisbursementRepository extends JpaRepository<ContractDi
     @Transactional
     @Query("delete from ContractDisbursement c where c.disbursementRecordId = ?1 and c.isPlan = ?2")
     void deleteByRecordId(Long id , Boolean isPlan);
+
+    @Query("select c from ContractDisbursement c where c.caseId = ?1 and c.isPlan = ?2 and c.isDelete = ?3")
+    List<ContractDisbursement> findByCaseIdAndIsPlanAndIsDelete(Long caseId, boolean b, boolean b1);
 }

+ 5 - 0
src/main/java/com/loan/system/repository/ContractRepository.java

@@ -105,4 +105,9 @@ public interface ContractRepository extends JpaRepository<Contract,Long> {
 
     @Query("select c.id from Contract c where c.caseId = ?1 and c.isDelete = ?2")
     List<Long> findIdsByCaseIdAndIsDelete(Long caseId, boolean b);
+
+    @Transactional
+    @Modifying
+    @Query("update Contract c set c.actualAmount = ?2 where c.id = ?1")
+    void updateActualAmountById(Long key, Double value);
 }

+ 3 - 0
src/main/java/com/loan/system/repository/CustomerRepository.java

@@ -93,4 +93,7 @@ public interface CustomerRepository extends JpaRepository<Customer,Long> {
     @Modifying
     @Query("update Customer c set c.isDelete = ?1 where c.id = ?2")
     void updateIsDeleteById(boolean b, Long otherId1);
+
+    @Query("select c from Customer c where c.name = ?1 and c.isDelete = ?2")
+    List<Customer> findByNameAndIsDelete(String name, Boolean isDelete);
 }

+ 1 - 0
src/main/java/com/loan/system/repository/UserRepository.java

@@ -1,6 +1,7 @@
 package com.loan.system.repository;
 
 import com.loan.system.domain.dto.UserDTO;
+import com.loan.system.domain.entity.Customer;
 import com.loan.system.domain.entity.User;
 import com.loan.system.domain.vo.UserVO;
 import org.springframework.data.domain.Page;

+ 2 - 0
src/main/java/com/loan/system/service/ContractDisbursementService.java

@@ -12,4 +12,6 @@ public interface ContractDisbursementService {
     List<ContractDisbursement> findByRecordIdAndIsPlan(Long recordId,Boolean isPlan);
 
     void deleteByRecordId(Long id, Boolean isPlan);
+
+    List<ContractDisbursement> findByCaseIdAndIsPlan(Long caseId, boolean b);
 }

+ 3 - 0
src/main/java/com/loan/system/service/ContractService.java

@@ -11,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.Map;
 
 public interface ContractService {
     Contract saveContract(ContractDTO contract);
@@ -57,4 +58,6 @@ public interface ContractService {
     void updateClearedStatusById(Long contractId, String msg);
 
     List<Long> findIdsByCaseId(Long caseId);
+
+    void updateActualAmountByIds(Map<Long, Double> contractIdAndAmount);
 }

+ 2 - 0
src/main/java/com/loan/system/service/CustomerService.java

@@ -51,6 +51,8 @@ public interface CustomerService {
 
     void deleteById(Long otherId1);
 
+    List<Customer> findByCustomerNameAndIsDelete(String customerName, boolean b);
+
     //Controller
 
 }

+ 10 - 5
src/main/java/com/loan/system/service/Impl/ClearDetailServiceImpl.java

@@ -9,6 +9,7 @@ import com.loan.system.domain.vo.ClearDetailVO;
 import com.loan.system.repository.ClearDetailRepository;
 import com.loan.system.service.ClearDetailService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
@@ -21,6 +22,7 @@ import java.util.Map;
 
 @Service
 @RequiredArgsConstructor
+@Slf4j
 public class ClearDetailServiceImpl implements ClearDetailService {
     
     private final ClearDetailRepository clearDetailRepository;
@@ -92,22 +94,25 @@ public class ClearDetailServiceImpl implements ClearDetailService {
                     continue;
 
                 if(interestAmount > gap){
-                    detail.put(clearDetail.getId(), clearDetail.getCurrentAmount() + gap);
+                    detail.put(clearDetail.getId(), clearDetail.getCurrentInterest() + gap);
                     interestAmount -= gap;
                 }else {
-                    detail.put(clearDetail.getId(), clearDetail.getCurrentAmount() + interestAmount);
+                    detail.put(clearDetail.getId(), clearDetail.getCurrentInterest() + interestAmount);
                     interestAmount = 0.0;
                 }
+
             }
         }
 
-        Iterator<Map.Entry<Long, Double>> iterator1 = contractIdAndInterestAmount.entrySet().iterator();
+        Iterator<Map.Entry<Long, Double>> iterator1 = detail.entrySet().iterator();
         while (iterator1.hasNext()) {
             Map.Entry<Long, Double> entry = iterator1.next();
             Long id = entry.getKey();
-            Double currentAmount = entry.getValue();
+            Double currentInterest = entry.getValue();
+
+            log.info("更新合同ID:" + id + "金额:" + currentInterest);
 
-            clearDetailRepository.updateCurrentAmountById(currentAmount, id);
+            clearDetailRepository.updateCurrentAmountById(currentInterest, id);
         }
 
     }

+ 5 - 0
src/main/java/com/loan/system/service/Impl/ContractDisbursementServiceImpl.java

@@ -51,4 +51,9 @@ public class ContractDisbursementServiceImpl implements ContractDisbursementServ
     public void deleteByRecordId(Long id, Boolean isPlan) {
         contractDisbursementRepository.deleteByRecordId(id,isPlan);
     }
+
+    @Override
+    public List<ContractDisbursement> findByCaseIdAndIsPlan(Long caseId, boolean b) {
+        return contractDisbursementRepository.findByCaseIdAndIsPlanAndIsDelete(caseId,b, false);
+    }
 }

+ 7 - 0
src/main/java/com/loan/system/service/Impl/ContractServiceImpl.java

@@ -287,5 +287,12 @@ public class ContractServiceImpl implements ContractService {
         return contractRepository.findIdsByCaseIdAndIsDelete(caseId, false);
     }
 
+    @Override
+    public void updateActualAmountByIds(Map<Long, Double> contractIdAndAmount) {
+        for (Map.Entry<Long, Double> entry : contractIdAndAmount.entrySet()){
+            contractRepository.updateActualAmountById(entry.getKey(),entry.getValue());
+        }
+    }
+
 
 }

+ 5 - 0
src/main/java/com/loan/system/service/Impl/CustomerServiceImpl.java

@@ -140,4 +140,9 @@ public class CustomerServiceImpl implements CustomerService {
     public void deleteById(Long otherId1) {
         customerRepository.updateIsDeleteById(true,otherId1);
     }
+
+    @Override
+    public List<Customer> findByCustomerNameAndIsDelete(String customerName, boolean b) {
+        return customerRepository.findByNameAndIsDelete(customerName,b);
+    }
 }

+ 98 - 37
src/main/java/com/loan/system/service/Impl/DisbursementServiceImpl.java

@@ -10,6 +10,7 @@ import com.loan.system.domain.entity.*;
 import com.loan.system.domain.enums.*;
 import com.loan.system.domain.pojo.DateAndAmountPOJO;
 import com.loan.system.domain.vo.*;
+import com.loan.system.exception.DescribeException;
 import com.loan.system.repository.DisbursementRepository;
 import com.loan.system.service.*;
 import com.loan.system.utils.RedisData;
@@ -43,6 +44,7 @@ public class DisbursementServiceImpl implements DisbursementService {
     private final UserService userService;
     private final ContractDisbursementService contractDisbursementService;
     private final LocationDatumService locationDatumService;
+    private final ContractService contractService;
 
     @Override
     public DisbursementVO addDisbursement(DisbursementDTO disbursementDTO) {
@@ -131,10 +133,23 @@ public class DisbursementServiceImpl implements DisbursementService {
     public void addDisbursementPlan(DisbursementDTO disbursementDTO) {
         Long id = disbursementDTO.getId();
         if (id > 0) {
+            Disbursement disbursement = disbursementRepository.findByIdAndIsDelete(id, false);
+            ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(disbursement.getApprovalId());
+            if(approvalRecord ==null || approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))
+                throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
+
             updateDisbursementByCaseId(disbursementDTO);
             //删除记录
             contractDisbursementService.deleteByRecordId(id, true);
         } else {
+            List<Disbursement> disbursements = disbursementRepository.findDisbursementsByCaseId(disbursementDTO.getCaseId(), false);
+            if(!ObjectUtils.isEmpty(disbursements)){
+                Disbursement disbursement = disbursements.get(disbursements.size()-1);
+
+                ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(disbursement.getApprovalId());
+                if (approvalRecord == null || !approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))
+                    throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
+            }
             DisbursementVO disbursementVO = addDisbursement(disbursementDTO);
             id = disbursementVO.getId();
         }
@@ -224,13 +239,25 @@ public class DisbursementServiceImpl implements DisbursementService {
         if (recordId > 0) {
             //审批意见为通过,无法修改
             DisbursementRecord record = disbursementRecordService.findRecordById(recordId);
-            if (record != null){
+            if (record != null) {
+                String approvalIds = record.getApprovalIds();
+                ApprovalRecord approvalRecord = null;
+                if (approvalIds != null && !approvalIds.isEmpty()) {
+                    String[] split = approvalIds.split(",");
+                    if (split.length > 0)
+                        approvalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
+                }
 
-                //            ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(record.getApprovalId());
-//            ApprovalRecord financeApprovalRecord = approvalService.findByIdAndIsDelete(record.getFinanceApprovalId());
-//            if ((ObjectUtils.isEmpty(approvalRecord) || approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))&&
-//                    (ObjectUtils.isEmpty(financeApprovalRecord) || financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))
-//                throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
+                String financeApprovalIds = record.getFinanceApprovalIds();
+                ApprovalRecord financeApprovalRecord = null;
+                if (financeApprovalIds != null && !financeApprovalIds.isEmpty()) {
+                    String[] split = financeApprovalIds.split(",");
+                    if (split.length > 0)
+                        financeApprovalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
+                }
+                if ((ObjectUtils.isEmpty(approvalRecord) || approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())) &&
+                        (ObjectUtils.isEmpty(financeApprovalRecord) || financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))
+                    throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
             }
 
             disbursementRecordService.updateRecordById(disbursementRecordDTO);
@@ -238,15 +265,29 @@ public class DisbursementServiceImpl implements DisbursementService {
             contractDisbursementService.deleteByRecordId(recordId, false);
         } else {
             //无法新增
-//            List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
-//            if (!records.isEmpty()) {
-//                DisbursementRecord record = records.get(records.size() - 1);
-//                ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(record.getApprovalId());
-//                ApprovalRecord financeApprovalRecord = approvalService.findByIdAndIsDelete(record.getFinanceApprovalId());
-//                if ((ObjectUtils.isEmpty(approvalRecord) || !approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))&&
-//                        (ObjectUtils.isEmpty(financeApprovalRecord) || !financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))//未审批通过
-//                    throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
-//            }
+            List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
+            if (!records.isEmpty()) {
+                for (DisbursementRecord record : records){
+                    String approvalIds = record.getApprovalIds();
+                    ApprovalRecord approvalRecord = null;
+                    if (approvalIds != null && !approvalIds.isEmpty()) {
+                        String[] split = approvalIds.split(",");
+                        if (split.length > 0)
+                            approvalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
+                    }
+
+                    String financeApprovalIds = record.getFinanceApprovalIds();
+                    ApprovalRecord financeApprovalRecord = null;
+                    if (financeApprovalIds != null && !financeApprovalIds.isEmpty()) {
+                        String[] split = financeApprovalIds.split(",");
+                        if (split.length > 0)
+                            financeApprovalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
+                    }
+                    if ((ObjectUtils.isEmpty(approvalRecord) || !approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())) &&
+                            (ObjectUtils.isEmpty(financeApprovalRecord) || !financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))//未审批通过
+                        throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
+                }
+            }
 
             DisbursementRecord disbursementRecord = disbursementRecordService.addDisbursementRecord(disbursementRecordDTO);
             recordId = disbursementRecord.getId();
@@ -257,12 +298,12 @@ public class DisbursementServiceImpl implements DisbursementService {
         contractDisbursementService.addContractDisbursement(contractAndAmount, recordId, false);
 
         //添加当票信息
-        pawnTicketService.addPawnTicket(disbursementStartDTO.getContractAndPawn(),recordId,disbursementRecordDTO.getCreateTime(),caseId);
+        pawnTicketService.addPawnTicket(disbursementStartDTO.getContractAndPawn(), recordId, disbursementRecordDTO.getCreateTime(), caseId);
         new RedisData(redisTemplate).deleteApprovalByKey(caseId, StepPropertyEnum.DISBURSE_START.getLabel(), StepPropertyEnum.DISBURSE_START.getCode());
 
         //修改状态
         stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.DISBURSE_START.getCode(), BaseContext.getCurrentId(), caseId);
-        if (isComplete)
+        if (isComplete || disburseIsComplete(caseId))
             stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.DISBURSE_START.getCode(), caseId);
         stepService.tryStartStep(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
 
@@ -280,6 +321,17 @@ public class DisbursementServiceImpl implements DisbursementService {
 
     }
 
+    private boolean disburseIsComplete(Long caseId) {
+        List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
+        Double totalAmount = 0.0;
+        for (DisbursementRecord record : records)
+            totalAmount += record.getAmount();
+        LoanCaseSimpleVO l = loanService.findLoanCaseSimpleByIdAndIsDelete(caseId, false);
+
+        return Math.abs(totalAmount - l.getTotalLoanAmount())<Double.MIN_VALUE;
+
+    }
+
     @Override
     public void disbursementApproval(ApprovalRecordDTO approvalRecordDTO, String decision) {
         Long caseId = approvalRecordDTO.getCaseId();
@@ -290,7 +342,7 @@ public class DisbursementServiceImpl implements DisbursementService {
         DisbursementRecord record = disbursementRecordService.findRecordById(approvalRecordDTO.getRecordId());
         DisbursementRecordDTO disbursementRecordDTO = new DisbursementRecordDTO();
         disbursementRecordDTO.setId(record.getId());
-        String approvalIds  = record.getApprovalIds()== null ? approvalRecord.getId().toString() : record.getApprovalIds() + "," + approvalRecord.getId();
+        String approvalIds = record.getApprovalIds() == null ? approvalRecord.getId().toString() : record.getApprovalIds() + "," + approvalRecord.getId();
         disbursementRecordDTO.setApprovalIds(approvalIds);
         disbursementRecordService.updateRecordById(disbursementRecordDTO);
 
@@ -349,8 +401,8 @@ public class DisbursementServiceImpl implements DisbursementService {
         //设置说明
         RedisData redisData = new RedisData(redisTemplate);
         Long version = redisData.getVersion(StepPropertyEnum.DISBURSE_CONFIRM.getCode());
-        disbursementRecordService.updateCommentsByIds(BaseContext.getCurrentId(),comment,version,ids);
-        redisData.setVersion(version+1,StepPropertyEnum.DISBURSE_CONFIRM.getCode());
+        disbursementRecordService.updateCommentsByIds(BaseContext.getCurrentId(), comment, version, ids);
+        redisData.setVersion(version + 1, StepPropertyEnum.DISBURSE_CONFIRM.getCode());
 
         boolean flag = true;
         List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
@@ -375,8 +427,8 @@ public class DisbursementServiceImpl implements DisbursementService {
     public DisbursementDetailVO getAllDetails(Long caseId) {
         DisbursementDetailVO disbursementDetailVO = getLoanCaseAndCustomerByCaseId(caseId);
         //填充
-        Map<Long , UserVO> userVOMap1=new HashMap<>();
-        Map<Long , UserVO> userVOMap2=new HashMap<>();
+        Map<Long, UserVO> userVOMap1 = new HashMap<>();
+        Map<Long, UserVO> userVOMap2 = new HashMap<>();
         if (!ObjectUtils.isEmpty(disbursementDetailVO)) {
             //1.List<DisbursementVO> disbursementPlans;
             List<Disbursement> plans = disbursementRepository.findDisbursementsByCaseId(caseId, false);
@@ -388,7 +440,7 @@ public class DisbursementServiceImpl implements DisbursementService {
                     disbursementVO.setOperatorUser(BeanUtil.copyProperties(user, UserVO.class));
                 disbursementVO.setLocationDatum(locationDatumService.findById(plan.getLocationId()));
                 ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(plan.getApprovalId());
-                if (approvalRecord != null){
+                if (approvalRecord != null) {
                     ApprovalRecordVO approvalRecordVO = BeanUtil.copyProperties(approvalRecord, ApprovalRecordVO.class);
                     User approver = userService.findByIdAndIsDelete(approvalRecord.getApproverId());
                     if (approver != null)
@@ -396,16 +448,16 @@ public class DisbursementServiceImpl implements DisbursementService {
                     disbursementVO.setApprovalRecordVO(approvalRecordVO);
                 }
                 User user1 = userService.findByIdAndIsDelete(plan.getMainUserId());
-                if (user1 != null){
+                if (user1 != null) {
                     UserVO u = BeanUtil.copyProperties(user1, UserVO.class);
                     disbursementVO.setMainUser(u);
-                    userVOMap1.put(plan.getId(),u);
+                    userVOMap1.put(plan.getId(), u);
                 }
                 User user2 = userService.findByIdAndIsDelete(plan.getAssistUserId());
-                if (user2 != null){
+                if (user2 != null) {
                     UserVO u = BeanUtil.copyProperties(user2, UserVO.class);
                     disbursementVO.setAssistUser(u);
-                    userVOMap2.put(plan.getId(),u);
+                    userVOMap2.put(plan.getId(), u);
                 }
 
                 List<ContractDisbursement> contractDisbursements = contractDisbursementService.findByRecordIdAndIsPlan(plan.getId(), true);
@@ -495,28 +547,28 @@ public class DisbursementServiceImpl implements DisbursementService {
                 result.computeIfAbsent(contractDisbursement.getContractId(), k -> new ArrayList<>()).add(dateAndAmountPOJO);
             }
         }
-        
+
         // 对结果进行处理,将同一id中日期相同的金额进行累加
         Map<Long, List<DateAndAmountPOJO>> processedResult = new HashMap<>();
         for (Map.Entry<Long, List<DateAndAmountPOJO>> entry : result.entrySet()) {
             Long contractId = entry.getKey();
             List<DateAndAmountPOJO> originalList = entry.getValue();
             Map<String, Double> dateAmountMap = new HashMap<>();
-            
+
             // 按日期累加金额
             for (DateAndAmountPOJO item : originalList) {
                 String dateOnly = formatDateTimeToDate(item.getDate());
                 dateAmountMap.merge(dateOnly, item.getAmount(), Double::sum);
             }
-            
+
             // 重建列表,保留完整日期时间格式但按日期聚合
             List<DateAndAmountPOJO> processedList = new ArrayList<>();
             for (DateAndAmountPOJO originalItem : originalList) {
                 String dateOnly = formatDateTimeToDate(originalItem.getDate());
                 // 只对每个唯一日期添加一次,避免重复
                 boolean exists = processedList.stream()
-                    .anyMatch(pojo -> formatDateTimeToDate(pojo.getDate()).equals(dateOnly));
-                
+                        .anyMatch(pojo -> formatDateTimeToDate(pojo.getDate()).equals(dateOnly));
+
                 if (!exists) {
                     DateAndAmountPOJO newItem = new DateAndAmountPOJO();
                     newItem.setDate(originalItem.getDate()); // 保留原始日期时间格式
@@ -533,6 +585,7 @@ public class DisbursementServiceImpl implements DisbursementService {
 
     /**
      * 将日期时间格式转换为日期格式
+     *
      * @param dateTimeStr 原始日期时间字符串 (yyyy-MM-dd HH:mm:ss)
      * @return 格式化后的日期字符串 (yyyy-MM-dd)
      */
@@ -561,7 +614,7 @@ public class DisbursementServiceImpl implements DisbursementService {
         DisbursementRecord record = disbursementRecordService.findRecordById(approvalRecordDTO.getRecordId());
         DisbursementRecordDTO disbursementRecordDTO = new DisbursementRecordDTO();
         disbursementRecordDTO.setId(record.getId());
-        String approvalIds  = record.getFinanceApprovalIds()== null ? approvalRecord.getId().toString() : record.getFinanceApprovalIds() + "," + approvalRecord.getId();
+        String approvalIds = record.getFinanceApprovalIds() == null ? approvalRecord.getId().toString() : record.getFinanceApprovalIds() + "," + approvalRecord.getId();
         disbursementRecordDTO.setFinanceApprovalIds(approvalIds);
         disbursementRecordService.updateRecordById(disbursementRecordDTO);
 
@@ -569,6 +622,14 @@ public class DisbursementServiceImpl implements DisbursementService {
         stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.FINANCE_DISBURSE.getCode(), BaseContext.getCurrentId(), caseId);
 
         if (decision.equals(DecisionEnum.PASS.getMsg())) {
+            //修改当前合同的出款金额
+            List<ContractDisbursement> contractDisbursements = contractDisbursementService.findByCaseIdAndIsPlan(caseId, false);
+            Map<Long, Double> contractIdAndAmount = new HashMap<>();
+            for (ContractDisbursement contractDisbursement : contractDisbursements) {
+                contractIdAndAmount.merge(contractDisbursement.getContractId(), contractDisbursement.getAmount(), Double::sum);
+            }
+            contractService.updateActualAmountByIds(contractIdAndAmount);
+
             StepVO step = stepService.findByStepCodeAndCaseId(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
             if (ApprovalIsCompleted(caseId, StepPropertyEnum.FINANCE_DISBURSE.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
                 stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.FINANCE_DISBURSE.getCode(), caseId);
@@ -597,8 +658,8 @@ public class DisbursementServiceImpl implements DisbursementService {
         List<Long> approvals = new ArrayList<>();
         if (stepCode.equals(StepPropertyEnum.DISBURSE_AUDIT.getCode())) {
             List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
-            for(DisbursementRecord record : records){
-                if(record.getApprovalIds() != null && !record.getApprovalIds().isEmpty()){
+            for (DisbursementRecord record : records) {
+                if (record.getApprovalIds() != null && !record.getApprovalIds().isEmpty()) {
                     String[] split = record.getApprovalIds().split(",");
                     if (split.length > 0)
                         approvals.add(Long.parseLong(split[split.length - 1]));
@@ -609,8 +670,8 @@ public class DisbursementServiceImpl implements DisbursementService {
                 return false;
         } else if (stepCode.equals(StepPropertyEnum.FINANCE_DISBURSE.getCode())) {
             List<DisbursementRecord> records = disbursementRecordService.findRecordByCaseId(caseId);
-            for(DisbursementRecord record : records){
-                if(record.getFinanceApprovalIds() != null && !record.getFinanceApprovalIds().isEmpty()){
+            for (DisbursementRecord record : records) {
+                if (record.getFinanceApprovalIds() != null && !record.getFinanceApprovalIds().isEmpty()) {
                     String[] split = record.getFinanceApprovalIds().split(",");
                     if (split.length > 0)
                         approvals.add(Long.parseLong(split[split.length - 1]));

+ 207 - 164
src/main/java/com/loan/system/service/Impl/LoanServiceImpl.java

@@ -53,9 +53,9 @@ public class LoanServiceImpl implements LoanService {
     private final WxService wxService;
 
     @Override
-    public List<LoanCaseVO> findLoanCaseByIsComplete(Integer pageNum,Integer pageSize,String isComplete, boolean isDelete) {
+    public List<LoanCaseVO> findLoanCaseByIsComplete(Integer pageNum, Integer pageSize, String isComplete, boolean isDelete) {
         Pageable pageable = PageRequest.of(pageNum, pageSize);
-        Page<LoanCase> loanCases = loanRepository.findByIsCompleteAndIsDelete(isComplete, isDelete,pageable);
+        Page<LoanCase> loanCases = loanRepository.findByIsCompleteAndIsDelete(isComplete, isDelete, pageable);
 
         return getLoanCaseVO(loanCases.getContent());
     }
@@ -65,28 +65,25 @@ public class LoanServiceImpl implements LoanService {
         LoanCase loanCase = new LoanCase();
         loanCase.setCustomerId(customerId);
         loanCase.setIsComplete(DecisionEnum.PROCESS.getMsg());
-        loanCase.setCreateTime(LocalDateTime.now()
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-        loanCase.setUpdateTime(LocalDateTime.now()
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        loanCase.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        loanCase.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
         loanCase.setIsDelete(false);
 
         return BeanUtil.copyProperties(loanRepository.save(loanCase), LoanCaseVO.class);
     }
 
     @Override
-    public void updateLoanCaseById(LoanCaseDTO loanCaseDTO,Long customerId1,Long customerId2,  Long caseId) {
+    public void updateLoanCaseById(LoanCaseDTO loanCaseDTO, Long customerId1, Long customerId2, Long caseId) {
         LoanCase loanCase = BeanUtil.copyProperties(loanCaseDTO, LoanCase.class);
         loanCase.setOtherId1(customerId1);
         loanCase.setOtherId2(customerId2);
 
         loanCase.setIsComplete(DecisionEnum.PROCESS.getMsg());
-        loanCase.setUpdateTime(LocalDateTime.now()
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        loanCase.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
 
 
-        loanRepository.updateLoanCaseById(loanCase,caseId);
-        loanRepository.updateCustomersById(customerId1,customerId2,caseId);
+        loanRepository.updateLoanCaseById(loanCase, caseId);
+        loanRepository.updateCustomersById(customerId1, customerId2, caseId);
     }
 
     @Override
@@ -95,18 +92,17 @@ public class LoanServiceImpl implements LoanService {
         LoanCase loanCase = loanRepository.findLoanCaseById(caseId, false);
         LoanCaseVO loanCaseVO = BeanUtil.copyProperties(loanCase, LoanCaseVO.class);
         //2.获取客户信息
-        loanCaseVO.setCustomer(customerService.findByCustomerIdAndIsDelete(loanCase.getCustomerId(),false));
+        loanCaseVO.setCustomer(customerService.findByCustomerIdAndIsDelete(loanCase.getCustomerId(), false));
         //3.获取合同信息
         RedisData redisData = new RedisData(stringRedisTemplate);
         List<Contract> contracts = redisData.getContracts(caseId);
         List<ContractVO> contractVOS = new ArrayList<>();
-        if(ObjectUtils.isEmpty(contracts))
-            contractVOS = contractService.findContractByCaseId(caseId);
-        else{
-            for (Contract contract : contracts){
+        if (ObjectUtils.isEmpty(contracts)) contractVOS = contractService.findContractByCaseId(caseId);
+        else {
+            for (Contract contract : contracts) {
                 ContractVO contractVO = BeanUtil.copyProperties(contract, ContractVO.class);
                 Customer customer = customerService.findByIdAndIsDelete(contract.getCustomerId());
-                contractVO.setCustomerName(customer != null?customer.getName():"");
+                contractVO.setCustomerName(customer != null ? customer.getName() : "");
 
                 contractVOS.add(contractVO);
             }
@@ -114,23 +110,22 @@ public class LoanServiceImpl implements LoanService {
         loanCaseVO.setContracts(contractVOS);
         //4.获取押品信息
         List<CollateralVO> collaterals = redisData.getCollaterals(caseId);
-        if(ObjectUtils.isEmpty(collaterals))
-            collaterals = collateralService.findByCaseId(caseId);
+        if (ObjectUtils.isEmpty(collaterals)) collaterals = collateralService.findByCaseId(caseId);
         loanCaseVO.setCollateral(collaterals);
         //5.获取合同押品关联信息
-        List<ContractAndCollateral> contractAndCollaterals =redisData.getContractAndCollateral(caseId);
+        List<ContractAndCollateral> contractAndCollaterals = redisData.getContractAndCollateral(caseId);
         if (ObjectUtils.isEmpty(contractAndCollaterals))
             contractAndCollaterals = contractAndCollateralService.findContractAndCollateralByCaseId(caseId);
-        List<Map<Long,List<Long>>> relations = new ArrayList<>();
+        List<Map<Long, List<Long>>> relations = new ArrayList<>();
 
-        Map<Long,List<Long>> relation = new java.util.HashMap<>();
+        Map<Long, List<Long>> relation = new java.util.HashMap<>();
         List<Long> collateralIds = new ArrayList<>();
-        int j=0;
-        for(int i=0; i < contractAndCollaterals.size() && j < contractVOS.size(); i++) {
+        int j = 0;
+        for (int i = 0; i < contractAndCollaterals.size() && j < contractVOS.size(); i++) {
             if (contractAndCollaterals.get(i).getContractId().equals(contractVOS.get(j).getId())) {
                 collateralIds.add(contractAndCollaterals.get(i).getCollateralId());
-            }else {
-                relation.put(contractVOS.get(j).getId(),collateralIds);
+            } else {
+                relation.put(contractVOS.get(j).getId(), collateralIds);
                 relations.add(relation);
                 j++;
                 relation = new java.util.HashMap<>();
@@ -139,19 +134,17 @@ public class LoanServiceImpl implements LoanService {
                 loanCaseVO.setCollateralAndContract(relations);
             }
         }
-        if(j < contractVOS.size()){
-            relation.put(contractVOS.get(j).getId(),collateralIds);
+        if (j < contractVOS.size()) {
+            relation.put(contractVOS.get(j).getId(), collateralIds);
             relations.add(relation);
             loanCaseVO.setCollateralAndContract(relations);
         }
 
         //5.获取其它客户信息
-        CustomerVO customerOther1 = customerService.findByCustomerIdAndIsDelete(loanCase.getOtherId1(),false);
-        if(!ObjectUtils.isEmpty(customerOther1))
-            loanCaseVO.setCustomers1(customerOther1);
+        CustomerVO customerOther1 = customerService.findByCustomerIdAndIsDelete(loanCase.getOtherId1(), false);
+        if (!ObjectUtils.isEmpty(customerOther1)) loanCaseVO.setCustomers1(customerOther1);
         CustomerVO customerOther2 = customerService.findByCustomerIdAndIsDelete(loanCase.getOtherId2(), false);
-        if(!ObjectUtils.isEmpty(customerOther2))
-            loanCaseVO.setCustomers2(customerOther2);
+        if (!ObjectUtils.isEmpty(customerOther2)) loanCaseVO.setCustomers2(customerOther2);
 
         //6.获取附件信息
         loanCaseVO.setDocuments(BeanUtil.copyToList(documentService.findByCaseId(caseId), DocumentVO.class));
@@ -160,7 +153,7 @@ public class LoanServiceImpl implements LoanService {
         loanCaseVO.setRecommender(BeanUtil.copyProperties(recommender.getRecommenderById(loanCase.getRecommenderId()), BizRecommenderVO.class));
 
         //8.获取驳回意见
-        loanCaseVO.setRejectComment(redisData.getRejectApprovalRecord(caseId,StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),StepPropertyEnum.BUSINESS_ACCEPT.getCode()));
+        loanCaseVO.setRejectComment(redisData.getRejectApprovalRecord(caseId, StepPropertyEnum.BUSINESS_ACCEPT.getLabel(), StepPropertyEnum.BUSINESS_ACCEPT.getCode()));
 
         return loanCaseVO;
     }
@@ -171,17 +164,18 @@ public class LoanServiceImpl implements LoanService {
     }
 
     @Override
-    public void updateUpdatetimeByIdAndIsDeleted(Long id,boolean isDelete){
-        loanRepository.updateUpdatetimeByIdAndIsDeleted(id,false, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+    public void updateUpdatetimeByIdAndIsDeleted(Long id, boolean isDelete) {
+        loanRepository.updateUpdatetimeByIdAndIsDeleted(id, false, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
     }
+
     @Override
-    public void logic_delete(Long id){
+    public void logic_delete(Long id) {
         loanRepository.logic_delete(id, true, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
     }
 
     @Override
     public LoanCaseSimpleVO findLoanCaseSimpleByIdAndIsDelete(Long caseId, boolean isDelete) {
-        return BeanUtil.copyProperties(loanRepository.findLoanCaseById(caseId, isDelete),LoanCaseSimpleVO.class);
+        return BeanUtil.copyProperties(loanRepository.findLoanCaseById(caseId, isDelete), LoanCaseSimpleVO.class);
     }
 
     @Override
@@ -190,7 +184,7 @@ public class LoanServiceImpl implements LoanService {
     }
 
     @Override
-    public List<LoanCaseVO> findLoanCaseByCustomerIds(List<Long> customerIds, Integer pageNum, Integer pageSize,String isComplete, boolean isDelete) {
+    public List<LoanCaseVO> findLoanCaseByCustomerIds(List<Long> customerIds, Integer pageNum, Integer pageSize, String isComplete, boolean isDelete) {
         Pageable pageable = PageRequest.of(pageNum, pageSize);
         Page<LoanCase> page = loanRepository.findLoanCaseByCustomerIds(customerIds, pageable, isComplete, isDelete);
 
@@ -200,7 +194,7 @@ public class LoanServiceImpl implements LoanService {
     @Override
     public List<LoanCaseVO> findLoanCaseByCustomerIds(List<Long> customerIds, Integer pageNum, Integer pageSize, boolean isDelete) {
         Pageable pageable = PageRequest.of(pageNum, pageSize);
-        Page<LoanCase> page = loanRepository.findLoanCaseByCustomerIds(customerIds, pageable,isDelete);
+        Page<LoanCase> page = loanRepository.findLoanCaseByCustomerIds(customerIds, pageable, isDelete);
 
         return getLoanCaseVO(page.getContent());
     }
@@ -208,7 +202,7 @@ public class LoanServiceImpl implements LoanService {
 
     @Override
     public List<Long> findIdsByIsComplete(String isComplete, boolean isDelete) {
-        return loanRepository.findIdsByIsCompleteAndIsDelete(isComplete,isDelete);
+        return loanRepository.findIdsByIsCompleteAndIsDelete(isComplete, isDelete);
     }
 
     @Override
@@ -222,18 +216,18 @@ public class LoanServiceImpl implements LoanService {
     @Override
     public void updateIsCompleteByCaseId(String msg, Long caseId) {
         String updateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-        loanRepository.updateIsCompleteByCaseId(msg, caseId,updateTime);
+        loanRepository.updateIsCompleteByCaseId(msg, caseId, updateTime);
     }
 
     @Override
     public List<LoanCaseSimpleVO> findLoanCaseSimpleByIsComplete(String msg) {
-        return BeanUtil.copyToList(loanRepository.findLoanSimpleByIsCompleteAndIsDelete(msg,false),LoanCaseSimpleVO.class);
+        return BeanUtil.copyToList(loanRepository.findLoanSimpleByIsCompleteAndIsDelete(msg, false), LoanCaseSimpleVO.class);
     }
 
     @Override
     public List<LoanCaseVO> findLoanCaseAll(Integer pageNum, Integer pageSize, boolean isDelete) {
         Pageable pageable = PageRequest.of(pageNum, pageSize);
-        Page<LoanCase> page = loanRepository.findByIsDelete(isDelete,pageable);
+        Page<LoanCase> page = loanRepository.findByIsDelete(isDelete, pageable);
 
         return getLoanCaseVO(page.getContent());
     }
@@ -252,26 +246,25 @@ public class LoanServiceImpl implements LoanService {
         List<LoanCase> complete = loanRepository.findLoanCaseBetweenRangeAndIsDeleteAndComplete(begin, end, DecisionEnum.COMPLETE.getMsg(), false);
         List<LoanCase> process = loanRepository.findLoanCaseBetweenRangeAndIsDeleteAndProcess(end, DecisionEnum.PROCESS.getMsg(), false);
         //合并两个列表
-        List<LoanCase> allLoanCases = Stream.concat(complete.stream(), process.stream())
-                .collect(Collectors.toList());
+        List<LoanCase> allLoanCases = Stream.concat(complete.stream(), process.stream()).collect(Collectors.toList());
         return BeanUtil.copyToList(allLoanCases, LoanCaseSimpleVO.class);
     }
 
     @Override
     public List<LoanCaseVO> listLoanCaseByIsComplete(String isComplete) {
-        return getLoanCaseVO(loanRepository.listLoanCaseByIsCompleteAndIsDelete(isComplete,false));
+        return getLoanCaseVO(loanRepository.listLoanCaseByIsCompleteAndIsDelete(isComplete, false));
     }
 
-//TODO:controller使用
+    //TODO:controller使用
     @Override
     public List<LoanCaseVO> listLoanCaseByStepCode(Integer stepCode) {
         //根据角色返回业务列表,业务员返回全部未完成、审批员与财务员仅展示未审批或未财务审批的人物
-        List<Long> loanCaseIds = loanRepository.findIdsByIsCompleteAndIsDelete(DecisionEnum.PROCESS.getMsg(),false);
+        List<Long> loanCaseIds = loanRepository.findIdsByIsCompleteAndIsDelete(DecisionEnum.PROCESS.getMsg(), false);
         List<Long> ids = new ArrayList<>();
-        List<StepVO> currentSteps=new ArrayList<>();
+        List<StepVO> currentSteps = new ArrayList<>();
         List<LoanCaseVO> loanCaseVOS = new ArrayList<>();
 
-        for(Long caseId : loanCaseIds){
+        for (Long caseId : loanCaseIds) {
             List<StepVO> steps = stepService.getStepByCaseId(caseId);
 
             StepVO processStep = null;//受理环节
@@ -281,39 +274,38 @@ public class LoanServiceImpl implements LoanService {
             StepVO pushStep2 = null;
             boolean flag = false;
             for (StepVO step : steps) {
-                if (step.getParentCode()==0 )
-                    continue;
+                if (step.getParentCode() == 0) continue;
 
                 //同一用户只能以一个角色处理同一单业务:如果当前环节是第二个角色处理过该单业务,则跳过(true)
 //                flag=stepService.hasRolesInCase(caseId,BaseContext.getCurrentId(),step.getCode());
 
                 //只保存正在处理的
-                Step parent = stepService.findStepByCodeAndCaseId(step.getParentCode(),caseId);
-                if (step.getStatus().equals(StepEnum.PROCESS.getMsg())&&parent.getCode().equals(stepCode)&&!flag) {
-                    if (step.getCode().equals(StepPropertyEnum.CASE_COMPLETE.getCode())){//仅显示结清(回款完成)的”业务终结“环节
+                Step parent = stepService.findStepByCodeAndCaseId(step.getParentCode(), caseId);
+                if (step.getStatus().equals(StepEnum.PROCESS.getMsg()) && parent.getCode().equals(stepCode) && !flag) {
+                    if (step.getCode().equals(StepPropertyEnum.CASE_COMPLETE.getCode())) {//仅显示结清(回款完成)的”业务终结“环节
                         Step step1 = stepService.findStepByCodeAndCaseId(StepPropertyEnum.BALANCE_REPAY.getCode(), caseId);
-                        if (step1!=null && step1.getStatus().equals(StepEnum.COMPLETED.getMsg())){
+                        if (step1 != null && step1.getStatus().equals(StepEnum.COMPLETED.getMsg())) {
                             currentSteps.add(step);
                             ids.add(step.getCaseId());
                         }
-                    }else{
+                    } else {
                         currentSteps.add(step);
                         ids.add(step.getCaseId());
                     }
                 }
 
                 //业务受理环节显示未审批的业务
-                if (stepCode.equals(StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode())){
-                    if(step.getCode().equals(StepPropertyEnum.BUSINESS_ACCEPT.getCode())&&step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
+                if (stepCode.equals(StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode())) {
+                    if (step.getCode().equals(StepPropertyEnum.BUSINESS_ACCEPT.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
                         processStep = step;
 //                    if(step.getCode().equals(StepPropertyEnum.PRE_TRIAL.getCode())&&!step.getStatus().equals(StepEnum.UNSTART.getMsg()))
 //                        preTrialStep = step;
-                    if (!step.getStatus().equals(StepEnum.COMPLETED.getMsg())&&step.getCode().equals(StepPropertyEnum.APPROVAL.getCode())){
-                       if (processStep!=null){
-                           currentSteps.add( processStep);
-                           ids.add(processStep.getCaseId());
-                           processStep = null;
-                       }
+                    if (!step.getStatus().equals(StepEnum.COMPLETED.getMsg()) && step.getCode().equals(StepPropertyEnum.APPROVAL.getCode())) {
+                        if (processStep != null) {
+                            currentSteps.add(processStep);
+                            ids.add(processStep.getCaseId());
+                            processStep = null;
+                        }
 //                       if (preTrialStep!=null){
 //                           currentSteps.add(preTrialStep);
 //                           ids.add(preTrialStep.getCaseId());
@@ -323,15 +315,15 @@ public class LoanServiceImpl implements LoanService {
                 }
 
                 //保留取证至回款前
-                if(stepCode.equals(StepPropertyEnum.COLLATERAL_RECEIVE.getCode())){
-                    if(step.getCode().equals(StepPropertyEnum.PLAN_SUBMISSION.getCode())&&step.getStatus().equals(StepEnum.COMPLETED.getMsg())&&step.getUserId1()!=null)
+                if (stepCode.equals(StepPropertyEnum.COLLATERAL_RECEIVE.getCode())) {
+                    if (step.getCode().equals(StepPropertyEnum.PLAN_SUBMISSION.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()) && step.getUserId1() != null)
                         receiveStep = step;
 
 //                    if(step.getCode().equals(StepPropertyEnum.CHANNEL_PUSH.getCode())&&step.getStatus().equals(StepEnum.COMPLETED.getMsg())&&step.getUserId1()!=null)
 //                        pushStep1 = step;
 
-                    if (step.getCode().equals(StepPropertyEnum.APPROVAL_ASSIGNMENT_2.getCode())&&step.getStatus().equals(StepEnum.UNSTART.getMsg())){
-                        if (receiveStep!=null){
+                    if (step.getCode().equals(StepPropertyEnum.APPROVAL_ASSIGNMENT_2.getCode()) && step.getStatus().equals(StepEnum.UNSTART.getMsg())) {
+                        if (receiveStep != null) {
                             currentSteps.add(receiveStep);
                             ids.add(receiveStep.getCaseId());
                             receiveStep = null;
@@ -346,27 +338,26 @@ public class LoanServiceImpl implements LoanService {
                 }
 
                 //保留取证
-                if(stepCode.equals(StepPropertyEnum.COLLATERAL_DELIVERY.getCode())){
-                    if(step.getCode().equals(StepPropertyEnum.PLAN_SUBMISSION_2.getCode())&&step.getStatus().equals(StepEnum.COMPLETED.getMsg())&&step.getUserId1()!=null)
+                if (stepCode.equals(StepPropertyEnum.COLLATERAL_DELIVERY.getCode())) {
+                    if (step.getCode().equals(StepPropertyEnum.PLAN_SUBMISSION_2.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()) && step.getUserId1() != null)
                         receiveStep = step;
 
 //                    if(step.getCode().equals(StepPropertyEnum.CHANNEL_PUSH_2.getCode())&&step.getStatus().equals(StepEnum.COMPLETED.getMsg())&&step.getUserId1()!=null)
 //                        pushStep2 = step;
 
-                    if (step.getCode().equals(StepPropertyEnum.REPAY_APPROVAL.getCode())){
-                        if (receiveStep!=null){
-                            if(step.getStatus().equals(StepEnum.COMPLETED.getMsg())){
+                    if (step.getCode().equals(StepPropertyEnum.REPAY_APPROVAL.getCode())) {
+                        if (receiveStep != null) {
+                            if (step.getStatus().equals(StepEnum.COMPLETED.getMsg())) {
                                 // 解析字符串为LocalDateTime
-                                LocalDateTime competeTime = LocalDateTime.parse(step.getUpdateTime(),
-                                        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).plusDays(7);
+                                LocalDateTime competeTime = LocalDateTime.parse(step.getUpdateTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).plusDays(7);
                                 //保留至指派后七天
-                                if (LocalDateTime.now().isBefore(competeTime)){
+                                if (LocalDateTime.now().isBefore(competeTime)) {
                                     System.out.println(LocalDateTime.now());
                                     currentSteps.add(receiveStep);
                                     ids.add(receiveStep.getCaseId());
                                     receiveStep = null;
                                 }
-                            }else {
+                            } else {
                                 //未完成前也需要保存
                                 currentSteps.add(receiveStep);
                                 ids.add(receiveStep.getCaseId());
@@ -401,21 +392,21 @@ public class LoanServiceImpl implements LoanService {
             }
 
         }
-        for( int i = 0; i < ids.size(); i++){
+        for (int i = 0; i < ids.size(); i++) {
             LoanCase loanCase = loanRepository.findLoanCaseById(ids.get(i), false);
 
             Long customerId = loanCase.getCustomerId();
-            CustomerVO customer = customerService.findByCustomerIdAndIsDelete(customerId,false);
+            CustomerVO customer = customerService.findByCustomerIdAndIsDelete(customerId, false);
             LoanCaseVO loanCaseVO = BeanUtil.copyProperties(loanCase, LoanCaseVO.class);
             loanCaseVO.setCustomer(customer);
 //            Long userId=stepService.findByStepNameAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), loanCase.getId()).getUserId1();
 //            loanCaseVO.setUserName(userService.findByIdAndIsDelete(userId).getUsername());
-            StepVO stepVO =currentSteps.get( i);
-            if (stepVO.getCode().equals(StepPropertyEnum.BUSINESS_ACCEPT.getCode())&& stepVO.getStatus().equals(StepEnum.COMPLETED.getMsg()))
+            StepVO stepVO = currentSteps.get(i);
+            if (stepVO.getCode().equals(StepPropertyEnum.BUSINESS_ACCEPT.getCode()) && stepVO.getStatus().equals(StepEnum.COMPLETED.getMsg()))
                 stepVO.setStepName("预审状态");
             loanCaseVO.setStep(currentSteps.get(i));
             User user = userService.findByIdAndIsDelete(currentSteps.get(i).getUserId1());
-            if (user!=null){
+            if (user != null) {
                 loanCaseVO.setUserName(user.getRealName());
             }
 
@@ -432,86 +423,85 @@ public class LoanServiceImpl implements LoanService {
         //创建流程
 //        stepService.addStepByCaseId(loanCase.getId());
         List<List<Integer>> seq = StepPropertyEnum.seqList();
-        stepService.addStepByCaseIdAndSequences(loanCase.getId(),seq);
+        stepService.addStepByCaseIdAndSequences(loanCase.getId(), seq);
         //设置当前处理人
-        stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ADD.getCode(),BaseContext.getCurrentId(),loanCase.getId());
-        stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.BUSINESS_ADD.getCode(),loanCase.getId());
-        stepService.tryStartStep(StepPropertyEnum.BUSINESS_ADD.getCode(),loanCase.getId());
+        stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ADD.getCode(), BaseContext.getCurrentId(), loanCase.getId());
+        stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.BUSINESS_ADD.getCode(), loanCase.getId());
+        stepService.tryStartStep(StepPropertyEnum.BUSINESS_ADD.getCode(), loanCase.getId());
 
         return loanCase;
     }
 
     @Override
-    public void saveLoanCase(LoanCaseDTO loanCaseDTO, Long caseId, Boolean isComplete,Boolean isSkip) {
+    public void saveLoanCase(LoanCaseDTO loanCaseDTO, Long caseId, Boolean isComplete, Boolean isSkip) {
         //1.补充业务信息
         LoanCaseSimpleVO loanCaseSimple = findLoanCaseSimpleByIdAndIsDelete(caseId, false);
         Long otherId1 = loanCaseSimple.getOtherId1();//上次状态的借款人id
         Long otherId2 = loanCaseSimple.getOtherId2();
 
         //设置旧-新id的映射关系
-        Map<Long,Long> customerIdMap = new HashMap<>();
-        customerIdMap.put(loanCaseDTO.getCustomer().getId(),loanCaseDTO.getCustomer().getId());
+        Map<Long, Long> customerIdMap = new HashMap<>();
+        customerIdMap.put(loanCaseDTO.getCustomer().getId(), loanCaseDTO.getCustomer().getId());
         //个数不变或新增
         CustomerDTO customers1 = loanCaseDTO.getCustomers1();
         Long customerId1 = null;
-        if(customers1 != null && customers1.getId()!=null){//对于其它借款人,有数据则传入后端
+        if (customers1 != null && customers1.getId() != null) {//对于其它借款人,有数据则传入后端
             customerId1 = customers1.getId();
             //id<0新增,否则更新
-            if (customers1.getId()<0){
+            if (customers1.getId() < 0) {
                 Customer customer = BeanUtil.copyProperties(customers1, Customer.class);
                 customer.setIsRegister(false);
                 Customer customer1 = customerService.addCustomer(customer);
                 customerId1 = customer1.getId();
-            }else {
-                customerService.updateUserById(customers1,customers1.getId());
+            } else {
+                customerService.updateUserById(customers1, customers1.getId());
             }
-            customerIdMap.put(customers1.getId(),customerId1);
+            customerIdMap.put(customers1.getId(), customerId1);
         }
 
         CustomerDTO customers2 = loanCaseDTO.getCustomers2();
         Long customerId2 = null;
-        if(customers2 != null && customers2.getId()!=null){//对于其它借款人,有数据则传入后端
+        if (customers2 != null && customers2.getId() != null) {//对于其它借款人,有数据则传入后端
             customerId2 = customers2.getId();
             //id<0新增,否则更新
-            if (customers2.getId()<0){
+            if (customers2.getId() < 0) {
                 Customer customer = BeanUtil.copyProperties(customers2, Customer.class);
                 customer.setIsRegister(false);
                 Customer customer2 = customerService.addCustomer(customer);
                 customerId2 = customer2.getId();
-            }else {
-                customerService.updateUserById(customers2,customers2.getId());
+            } else {
+                customerService.updateUserById(customers2, customers2.getId());
             }
-            customerIdMap.put(customers2.getId(),customerId2);
+            customerIdMap.put(customers2.getId(), customerId2);
         }
         //个数减少
-        if(otherId1 != null && customerId1 == null){
+        if (otherId1 != null && customerId1 == null) {
             customerService.deleteById(otherId1);
         }
-        if (customerId2 ==null && otherId2 != null){
+        if (customerId2 == null && otherId2 != null) {
             customerService.deleteById(otherId2);
         }
 
-        updateLoanCaseById(loanCaseDTO,customerId1,customerId2,caseId);
+        updateLoanCaseById(loanCaseDTO, customerId1, customerId2, caseId);
 
         //2.修改客户信息
         CustomerDTO customerDTO = loanCaseDTO.getCustomer();
-        customerService.updateUserById(customerDTO,customerDTO.getId());
+        customerService.updateUserById(customerDTO, customerDTO.getId());
 
-        for(ContractDTO contractDTO :loanCaseDTO.getContracts()){
+        for (ContractDTO contractDTO : loanCaseDTO.getContracts()) {
             Long customerId = contractDTO.getCustomerId();
 
             if (customerIdMap.get(customerId) != null)//由-1变为实际
                 contractDTO.setCustomerId(customerIdMap.get(customerId));
-            else
-                contractDTO.setCustomerId(null);
+            else contractDTO.setCustomerId(null);
         }
 
         RedisData redisData = new RedisData(stringRedisTemplate);
         redisData.delete(caseId);
-        if(!isComplete){//TODO:利用redis保存草稿信息
-            redisData.setLoanCase(caseId,loanCaseDTO);
+        if (!isComplete) {//TODO:利用redis保存草稿信息
+            redisData.setLoanCase(caseId, loanCaseDTO);
 
-        }else {
+        } else {
             /*
             //TODO:提交后才真正保存到数据库,并删除原有的草稿
             因为后续驳回会修改,所以是如果有数据则修改,无数据则新增
@@ -519,13 +509,13 @@ public class LoanServiceImpl implements LoanService {
             //3.设置合同(若存在则修改)
             contractService.deleteAllByCaseId(caseId);
             List<Contract> contracts = new ArrayList<>();
-            for (ContractDTO contractDTO : loanCaseDTO.getContracts()){
+            for (ContractDTO contractDTO : loanCaseDTO.getContracts()) {
                 Long contractId = contractDTO.getId();
-                if(contractId != null && contractService.existsById(contractId)){
+                if (contractId != null && contractService.existsById(contractId)) {
                     //修改合同
-                    contractService.updateContractById(contractId,contractDTO,false);
-                    contracts.add(BeanUtil.copyProperties(contractDTO,Contract.class));
-                }else {
+                    contractService.updateContractById(contractId, contractDTO, false);
+                    contracts.add(BeanUtil.copyProperties(contractDTO, Contract.class));
+                } else {
                     //新增合同(若为负数,表示不存在)
                     Contract contract = contractService.saveContract(contractDTO);
                     contracts.add(contract);
@@ -535,12 +525,12 @@ public class LoanServiceImpl implements LoanService {
             //4.设置押品
             collateralService.deleteAllByCaseId(caseId);
             List<Long> collateralIds = new ArrayList<>();
-            for(CollateralDTO collateralDTO : loanCaseDTO.getCollateral()){
+            for (CollateralDTO collateralDTO : loanCaseDTO.getCollateral()) {
                 Long collateralId = collateralDTO.getId();
-                if(collateralId != null && collateralService.existsById(collateralId)){
+                if (collateralId != null && collateralService.existsById(collateralId)) {
                     //修改押品
-                    collateralService.updateCollateralById(collateralId,collateralDTO,false);
-                }else {
+                    collateralService.updateCollateralById(collateralId, collateralDTO, false);
+                } else {
                     //新增押品
                     Collateral collateral = collateralService.saveCollateral(collateralDTO);
                     collateralId = collateral.getId();
@@ -561,7 +551,7 @@ public class LoanServiceImpl implements LoanService {
 
             Map<Integer, List<Integer>> contractSeqAndCollateralSeq = loanCaseDTO.getContractSeqAndCollateralSeq();
             Iterator<Map.Entry<Integer, List<Integer>>> iterator = contractSeqAndCollateralSeq.entrySet().iterator();
-            contractAndCollateralService.addBatch(iterator,contracts,collateralIds,caseId);
+            contractAndCollateralService.addBatch(iterator, contracts, collateralIds, caseId);
 
 //            //6.添加其它客户
 //            customerService.deleteIsRegisterByCaseId(false,caseId);
@@ -579,25 +569,24 @@ public class LoanServiceImpl implements LoanService {
 //                    customerOtherService.addCustomers(loanCaseDTO.getCustomers2());
 //            }
         }
-        stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ACCEPT.getCode(),BaseContext.getCurrentId(),caseId);
+        stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), BaseContext.getCurrentId(), caseId);
         //7.设置阶段负责人与状态(如果第一个人是辅办人员,那第二个人必须是主办)
-        if(isComplete){
-            redisData.deleteApprovalByKey(caseId,StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),StepPropertyEnum.BUSINESS_ACCEPT.getCode());
-            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getCode(),caseId);
-            stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ACCEPT.getCode(),BaseContext.getCurrentId(),caseId);
+        if (isComplete) {
+            redisData.deleteApprovalByKey(caseId, StepPropertyEnum.BUSINESS_ACCEPT.getLabel(), StepPropertyEnum.BUSINESS_ACCEPT.getCode());
+            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.BUSINESS_ACCEPT.getCode(), caseId);
+            stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), BaseContext.getCurrentId(), caseId);
             //设置当阶段为完成,下阶段为开始
-            stepService.tryStartStep(StepPropertyEnum.BUSINESS_ACCEPT.getCode(),caseId);
+            stepService.tryStartStep(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), caseId);
 
             //TODO:8.微信推送预审通过消息和通知下一环节
-            List<User> users =new ArrayList<>();
+            List<User> users = new ArrayList<>();
             String stepName = "待处理环节为:";
-            if (isSkip){
+            if (isSkip) {
                 users = userService.findByRoleAndIsDelete(Arrays.asList(RoleEnum.APPROVER.getMsg()), false);
                 stepName = stepName.concat(StepPropertyEnum.APPROVAL.getLabel());
-            }
-            else{
-                users = userService.findByRoleAndIsDelete(Arrays.asList(RoleEnum.ASSIST_SALES.getMsg(),RoleEnum.LEAD_SALES.getMsg()), false);
+            } else {
+                users = userService.findByRoleAndIsDelete(Arrays.asList(RoleEnum.ASSIST_SALES.getMsg(), RoleEnum.LEAD_SALES.getMsg()), false);
                 stepName = stepName.concat(StepPropertyEnum.PRE_TRIAL.getLabel());
             }
             TemplateMessage message = new TemplateMessage();
@@ -607,11 +596,9 @@ public class LoanServiceImpl implements LoanService {
             data.put("amount4", Collections.singletonMap("value", String.valueOf(loanCaseDTO.getTotalLoanAmount())));
             data.put("things5", Collections.singletonMap("value", stepName));
             message.setData(data);
-            for (User user : users){
-                if (user.getId() .equals(BaseContext.getCurrentId()))
-                    continue;
-                if (user.getOpenid() != null)
-                    wxService.sendTemplateMessage(user.getOpenid(),message);
+            for (User user : users) {
+                if (user.getId().equals(BaseContext.getCurrentId())) continue;
+                if (user.getOpenid() != null) wxService.sendTemplateMessage(user.getOpenid(), message);
             }
 
 
@@ -619,32 +606,32 @@ public class LoanServiceImpl implements LoanService {
     }
 
     @Override
-    public void loanCaseComplete(Long caseId, Boolean isCancel,Map<String,String> pawnList) {
-        if(!isCancel){
-            updateIsCompleteByCaseId(DecisionEnum.COMPLETE.getMsg(),caseId);
+    public void loanCaseComplete(Long caseId, Boolean isCancel, Map<String, String> pawnList) {
+        if (!isCancel) {
+            updateIsCompleteByCaseId(DecisionEnum.COMPLETE.getMsg(), caseId);
 
             //保存当票信息
             Iterator<Map.Entry<String, String>> iterator = pawnList.entrySet().iterator();
-            while (iterator.hasNext()){
+            while (iterator.hasNext()) {
                 Map.Entry<String, String> entry = iterator.next();
                 String pawnTicketNo = entry.getKey();
                 String redeemTicketNo = entry.getValue();
-                if (redeemTicketNo != null && !redeemTicketNo.trim().isEmpty()){
-                    pawnTicketService.updateRedeemTicketNoByPawnTicketNo(redeemTicketNo,pawnTicketNo);
+                if (redeemTicketNo != null && !redeemTicketNo.trim().isEmpty()) {
+                    pawnTicketService.updateRedeemTicketNoByPawnTicketNo(redeemTicketNo, pawnTicketNo);
                 }
             }
 
-            stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.CASE_COMPLETE.getCode(),BaseContext.getCurrentId(), caseId);
-            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.CASE_COMPLETE.getCode(),caseId);
+            stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.CASE_COMPLETE.getCode(), BaseContext.getCurrentId(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.REPAY_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.CASE_COMPLETE.getCode(), caseId);
 
-            stepService.tryStartStep(StepPropertyEnum.CASE_COMPLETE.getCode(),caseId);
-        }else{
-            updateIsCompleteByCaseId(DecisionEnum.PROCESS.getMsg(),caseId);
+            stepService.tryStartStep(StepPropertyEnum.CASE_COMPLETE.getCode(), caseId);
+        } else {
+            updateIsCompleteByCaseId(DecisionEnum.PROCESS.getMsg(), caseId);
 
             stepService.deleteUserRecordByCaseIdAndStepCode(StepPropertyEnum.CASE_COMPLETE.getCode(), caseId);
-            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.REPAY_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.CASE_COMPLETE.getCode(),caseId);
+            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.REPAY_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.CASE_COMPLETE.getCode(), caseId);
             stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.CASE_ARCHIVE.getCode(), caseId);
 
         }
@@ -653,41 +640,97 @@ public class LoanServiceImpl implements LoanService {
     @Override
     public void cancelLoanCase(Long caseId) {
         //撤回业务状态
-        if (stepService.findStepByCodeAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(),caseId).getStatus().equals(StepEnum.COMPLETED.getMsg())){
-            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getCode(),caseId);
+        if (stepService.findStepByCodeAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), caseId).getStatus().equals(StepEnum.COMPLETED.getMsg())) {
+            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.BUSINESS_ACCEPT.getCode(), caseId);
 
             //撤回预审状态
-            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL.getCode(),caseId);
+            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.PRE_TRIAL_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.PRE_TRIAL.getCode(), caseId);
 
-            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL_PARENT.getCode(),caseId);
-            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL.getCode(),caseId);
+            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.APPROVAL_PARENT.getCode(), caseId);
+            stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.APPROVAL.getCode(), caseId);
         }
     }
 
+    @Override
+    public List<LoanCaseVO> listLoanCaseByKeyAndIsComplete(String keyRaw, String msg,Integer pageNum, Integer pageSize) {
+        // 2. 判断能否被解析成 Long
+        String key = keyRaw.trim();
+        boolean isLongKey = false;
+        try {
+            Long.parseLong(key);   // 不会溢出就认为是 Long
+            isLongKey = true;
+        } catch (NumberFormatException ignore) {
+            // 不是纯数字,按字符串处理
+        }
+
+        // 3. 分支调用
+        if (isLongKey) {
+            // 按 Long 型主键搜索
+            Long id = Long.valueOf(key);
+            LoanCase loanCase = loanRepository.findLoanCaseById(id, false);
+            if (loanCase != null)
+                return getLoanCaseVO2(Collections.singletonList(loanCase));
+            return null;
+        } else {
+            // 按字符串模糊搜索
+            List<Customer> customers = customerService.findByCustomerNameAndIsDelete(key, false);
+            if (customers != null ){
+                List<Long> customerIds = customers.stream().map(Customer::getId).collect(Collectors.toList());
+                Pageable pageable = PageRequest.of(pageNum, pageSize);
+                Page<LoanCase> loanCases = loanRepository.findLoanCaseByCustomerIds(customerIds, pageable, false);
+                return getLoanCaseVO2(loanCases.getContent());
+            }
+            return null;
+
+        }
+    }
 
     private List<LoanCaseVO> getLoanCaseVO(List<LoanCase> loanCases) {
         List<LoanCaseVO> loanCaseVO = new ArrayList<>();
         for (LoanCase loanCase1 : loanCases) {
             Long customerId = loanCase1.getCustomerId();
-            CustomerVO customer = customerService.findByCustomerIdAndIsDelete(customerId,false);
+            CustomerVO customer = customerService.findByCustomerIdAndIsDelete(customerId, false);
             LoanCaseVO loanCaseVO1 = BeanUtil.copyProperties(loanCase1, LoanCaseVO.class);
             loanCaseVO1.setCustomer(customer);
-            Long userId=stepService.findByStepCodeAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), loanCase1.getId()).getUserId1();
+            Long userId = stepService.findByStepCodeAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), loanCase1.getId()).getUserId1();
             User user = userService.findByIdAndIsDelete(userId);
-            if (user != null)
-                loanCaseVO1.setUserName(user.getRealName());
+            if (user != null) loanCaseVO1.setUserName(user.getRealName());
 
             List<StepVO> steps = stepService.getStepByCaseId(loanCase1.getId());
             loanCaseVO1.setSteps(steps);
             for (StepVO stepVO : steps)
-                if (stepVO.getParentCode() !=0 && stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())){
+                if (stepVO.getParentCode() != 0 && stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) {
                     loanCaseVO1.setStep(stepVO);
                     break;
                 }
 
 
+            loanCaseVO.add(loanCaseVO1);
+        }
+        return loanCaseVO;
+    }
+
+    private List<LoanCaseVO> getLoanCaseVO2(List<LoanCase> loanCases) {
+        List<LoanCaseVO> loanCaseVO = new ArrayList<>();
+        for (LoanCase loanCase1 : loanCases) {
+            Long customerId = loanCase1.getCustomerId();
+            CustomerVO customer = customerService.findByCustomerIdAndIsDelete(customerId, false);
+            LoanCaseVO loanCaseVO1 = BeanUtil.copyProperties(loanCase1, LoanCaseVO.class);
+            loanCaseVO1.setCustomer(customer);
+            Long userId = stepService.findByStepCodeAndCaseId(StepPropertyEnum.BUSINESS_ACCEPT.getCode(), loanCase1.getId()).getUserId1();
+            User user = userService.findByIdAndIsDelete(userId);
+            if (user != null) loanCaseVO1.setUserName(user.getRealName());
+
+            List<StepVO> steps = stepService.getStepByCaseId(loanCase1.getId());
+            List<StepVO> processStep = new ArrayList<>();
+            for (StepVO stepVO : steps)
+                if (stepVO.getParentCode() != 0 && stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) {
+                    processStep.add(stepVO);
+                }
+            loanCaseVO1.setSteps(processStep);
+
             loanCaseVO.add(loanCaseVO1);
         }
         return loanCaseVO;

+ 146 - 88
src/main/java/com/loan/system/service/Impl/OssService.java

@@ -4,14 +4,17 @@ import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSException;
 import com.aliyun.oss.model.*;
 import com.loan.system.config.OssConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+@Slf4j
 @Service
 public class OssService {
 
@@ -39,17 +42,17 @@ public class OssService {
             // 返回文件访问URL
             return getObjectUrl(fileName);
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException, which means your request made it to OSS, "
-                    + "but was rejected with an error response for some reason.");
-            System.out.println("Error Message:" + oe.getErrorMessage());
-            System.out.println("Error Code:" + oe.getErrorCode());
-            System.out.println("Request ID:" + oe.getRequestId());
-            System.out.println("Host ID:" + oe.getHostId());
+            log.error("Caught an OSSException, which means your request made it to OSS, " +
+                    "but was rejected with an error response for some reason.");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException, which means the client encountered "
-                    + "a serious internal problem while trying to communicate with OSS, "
-                    + "such as not being able to access the network.");
-            System.out.println("Error Message:" + ce.getMessage());
+            log.error("Caught an ClientException, which means the client encountered " +
+                    "a serious internal problem while trying to communicate with OSS, " +
+                    "such as not being able to access the network.");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return null;
     }
@@ -64,17 +67,17 @@ public class OssService {
             // 删除文件
             ossClient.deleteObject(ossConfig.getBucketName(), fileName);
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException, which means your request made it to OSS, "
-                    + "but was rejected with an error response for some reason.");
-            System.out.println("Error Message:" + oe.getErrorMessage());
-            System.out.println("Error Code:" + oe.getErrorCode());
-            System.out.println("Request ID:" + oe.getRequestId());
-            System.out.println("Host ID:" + oe.getHostId());
+            log.error("Caught an OSSException, which means your request made it to OSS, " +
+                    "but was rejected with an error response for some reason.");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException, which means the client encountered "
-                    + "a serious internal problem while trying to communicate with OSS, "
-                    + "such as not being able to access the network.");
-            System.out.println("Error Message:" + ce.getMessage());
+            log.error("Caught an ClientException, which means the client encountered " +
+                    "a serious internal problem while trying to communicate with OSS, " +
+                    "such as not being able to access the network.");
+            log.error("Error Message: {}", ce.getMessage());
         }
     }
 
@@ -105,17 +108,17 @@ public class OssService {
             OSSObject ossObject = ossClient.getObject(ossConfig.getBucketName(), fileName);
             return ossObject;
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException, which means your request made it to OSS, "
-                    + "but was rejected with an error response for some reason.");
-            System.out.println("Error Message:" + oe.getErrorMessage());
-            System.out.println("Error Code:" + oe.getErrorCode());
-            System.out.println("Request ID:" + oe.getRequestId());
-            System.out.println("Host ID:" + oe.getHostId());
+            log.error("Caught an OSSException, which means your request made it to OSS, " +
+                    "but was rejected with an error response for some reason.");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException, which means the client encountered "
-                    + "a serious internal problem while trying to communicate with OSS, "
-                    + "such as not being able to access the network.");
-            System.out.println("Error Message:" + ce.getMessage());
+            log.error("Caught an ClientException, which means the client encountered " +
+                    "a serious internal problem while trying to communicate with OSS, " +
+                    "such as not being able to access the network.");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return null;
     }
@@ -140,17 +143,17 @@ public class OssService {
             // 设置版本控制
             ossClient.setBucketVersioning(request);
             
-            System.out.println("Successfully enabled versioning for bucket: " + ossConfig.getBucketName());
+            log.info("Successfully enabled versioning for bucket: {}", ossConfig.getBucketName());
             return true;
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when enabling versioning:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when enabling versioning:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when enabling versioning:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when enabling versioning:");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return false;
     }
@@ -175,17 +178,17 @@ public class OssService {
             // 设置版本控制
             ossClient.setBucketVersioning(request);
             
-            System.out.println("Successfully disabled versioning for bucket: " + ossConfig.getBucketName());
+            log.info("Successfully disabled versioning for bucket: {}", ossConfig.getBucketName());
             return true;
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when disabling versioning:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when disabling versioning:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when disabling versioning:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when disabling versioning:");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return false;
     }
@@ -203,17 +206,17 @@ public class OssService {
             );
             
             String status = configuration.getStatus();
-            System.out.println("Bucket versioning status: " + status);
+            log.info("Bucket versioning status: {}", status);
             return status;
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when getting versioning status:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when getting versioning status:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when getting versioning status:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when getting versioning status:");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return null;
     }
@@ -253,17 +256,21 @@ public class OssService {
             
             // 返回上传ID
             String uploadId = result.getUploadId();
-            System.out.println("Initiated multipart upload, uploadId: " + uploadId);
+            if (uploadId != null) {
+                log.info("Initiated multipart upload, uploadId: {}", uploadId);
+            } else {
+                log.warn("Initiated multipart upload, but uploadId is null");
+            }
             return uploadId;
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when initiating multipart upload:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when initiating multipart upload:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when initiating multipart upload:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when initiating multipart upload:");
+            log.error("Error Message: {}", ce.getMessage());
         }
         return null;
     }
@@ -295,17 +302,32 @@ public class OssService {
             
             // 返回分块ETag
             PartETag partETag = uploadPartResult.getPartETag();
-            System.out.println("Uploaded part " + partNumber + ", ETag: " + partETag.getETag());
-            return partETag;
+            if (partETag != null && partETag.getETag() != null) {
+                log.info("Uploaded part {} successfully, ETag: {}", partNumber, partETag.getETag());
+                return partETag;
+            } else {
+                // 添加详细的诊断信息
+                log.error("Uploaded part {} failed, partETag is null or ETag is null", partNumber);
+                log.error("UploadPartResult: {}", uploadPartResult);
+                log.error("PartETag object: {}", partETag);
+                if (partETag != null) {
+                    log.error("PartETag partNumber: {}", partETag.getPartNumber());
+                    log.error("PartETag ETag: {}", partETag.getETag());
+                }
+                
+                // 如果partETag或其ETag为null,可能表示上传失败,返回null
+                return null;
+            }
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when uploading part " + partNumber + ":");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when uploading part {}:", partNumber);
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when uploading part " + partNumber + ":");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when uploading part {}:", partNumber);
+            log.error("Error Message: {}", ce.getMessage());
+            ce.printStackTrace();
         }
         return null;
     }
@@ -320,31 +342,67 @@ public class OssService {
      */
     public String completeMultipartUpload(String fileName, String uploadId, List<PartETag> partETags) {
         try {
+            // 验证partETags列表,确保没有null值或ETag为null的项
+            if (partETags == null || partETags.isEmpty()) {
+                log.error("PartETags list is null or empty");
+                return null;
+            }
+            
+            // 过滤掉ETag为null的PartETag对象
+            List<PartETag> validPartETags = new ArrayList<>();
+            for (int i = 0; i < partETags.size(); i++) {
+                PartETag partETag = partETags.get(i);
+                if (partETag == null) {
+                    log.error("PartETag at index {} is null", i);
+                    continue;
+                }
+                if (partETag.getETag() == null) {
+                    log.error("PartETag at index {} has null ETag, partNumber: {}", i, partETag.getPartNumber());
+                    continue;
+                }
+                validPartETags.add(partETag);
+            }
+            
+            if (validPartETags.isEmpty()) {
+                log.error("No valid PartETags found, all have null ETags");
+                return null;
+            }
+            
+            if (validPartETags.size() != partETags.size()) {
+                log.warn("Filtered out {} invalid PartETags from {} total", 
+                         partETags.size() - validPartETags.size(), partETags.size());
+            }
+            
             // 创建完成分块上传请求
             CompleteMultipartUploadRequest completeMultipartUploadRequest = 
                     new CompleteMultipartUploadRequest(
                             ossConfig.getBucketName(), 
                             fileName, 
                             uploadId, 
-                            partETags);
+                            validPartETags);
             
             // 完成分块上传
             CompleteMultipartUploadResult result = ossClient.completeMultipartUpload(
                     completeMultipartUploadRequest);
             
-            System.out.println("Completed multipart upload, ETag: " + result.getETag());
+            if (result != null && result.getETag() != null) {
+                log.info("Completed multipart upload, ETag: {}", result.getETag());
+            } else {
+                log.warn("Completed multipart upload, but ETag is null");
+            }
             
             // 返回文件访问URL
             return getObjectUrl(fileName);
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when completing multipart upload:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when completing multipart upload:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when completing multipart upload:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when completing multipart upload:");
+            log.error("Error Message: {}", ce.getMessage());
+            ce.printStackTrace();
         }
         return null;
     }
@@ -367,16 +425,16 @@ public class OssService {
             // 取消分块上传
             ossClient.abortMultipartUpload(abortMultipartUploadRequest);
             
-            System.out.println("Aborted multipart upload, uploadId: " + uploadId);
+            log.info("Aborted multipart upload, uploadId: {}", uploadId);
         } catch (OSSException oe) {
-            System.out.println("Caught an OSSException when aborting multipart upload:");
-            System.out.println("Error Message: " + oe.getErrorMessage());
-            System.out.println("Error Code: " + oe.getErrorCode());
-            System.out.println("Request ID: " + oe.getRequestId());
-            System.out.println("Host ID: " + oe.getHostId());
+            log.error("Caught an OSSException when aborting multipart upload:");
+            log.error("Error Message: {}", oe.getErrorMessage());
+            log.error("Error Code: {}", oe.getErrorCode());
+            log.error("Request ID: {}", oe.getRequestId());
+            log.error("Host ID: {}", oe.getHostId());
         } catch (Exception ce) {
-            System.out.println("Caught an ClientException when aborting multipart upload:");
-            System.out.println("Error Message: " + ce.getMessage());
+            log.error("Caught an ClientException when aborting multipart upload:");
+            log.error("Error Message: {}", ce.getMessage());
         }
     }
 }

+ 3 - 1
src/main/java/com/loan/system/service/Impl/RepaymentServiceImpl.java

@@ -530,8 +530,10 @@ public class RepaymentServiceImpl implements RepaymentService {
         //TODO:添加结清记录
         clearDetailService.addClearDetailByList(repaymentRecordDTO.getClearDetailList());
         //TODO:更新费息情况
-        if(repaymentRecordDTO.getInterestAmount()>Double.MIN_VALUE)
+        if(repaymentRecordDTO.getInterestAmount()>Double.MIN_VALUE){
+            log.info("更新合同费息");
             clearDetailService.updateInterestsByCaseId(repaymentRecordDTO.getContractIdAndInterestAmount(),caseId);
+        }
 
         //添加完记录后,查看利息是否结清
         contractIsCleared(repaymentId, repaymentRecordDTO.getClearInterest());

+ 14 - 7
src/main/java/com/loan/system/service/Impl/UserServiceImpl.java

@@ -227,7 +227,8 @@ public class UserServiceImpl implements UserService {
             for (Contract contract : contracts) {
                 Long financeId = contract.getFinanceUserId();
                 System.out.println("financeId = " + financeId);
-                if (financeId != null && contract.getInterestAmount() < Double.MIN_VALUE) {
+                // 修复:确保financeId不为null,同时修正利息金额判断逻辑
+                if (financeId != null && Math.abs(contract.getInterestAmount()) > 0.0001) { // 使用一个小的阈值来避免浮点数精度问题
                     userAndCases
                             .computeIfAbsent(financeId, k -> new ArrayList<>())  // key 为空就 new ArrayList
                             .add(loanCaseVO);
@@ -266,9 +267,12 @@ public class UserServiceImpl implements UserService {
             StepVO stepVO = stepService.findByStepCodeAndCaseId(stepCode, caseId);
             if ((stepCode.equals(StepPropertyEnum.DISBURSE_START.getCode()) || stepCode.equals(StepPropertyEnum.BALANCE_REPAY.getCode()))
                     && stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) {
-                userAndCases
-                        .computeIfAbsent(stepVO.getUserId1(), k -> new ArrayList<>())  // key 为空就 new ArrayList
-                        .add(loanCaseVO);
+                Long userId = stepVO.getUserId1();
+                if (userId != null) { // 修复:确保userId不为null
+                    userAndCases
+                            .computeIfAbsent(userId, k -> new ArrayList<>())  // key 为空就 new ArrayList
+                            .add(loanCaseVO);
+                }
 
             } else if ((stepCode.equals(StepPropertyEnum.EVIDENCE_CONFIRMATION.getCode()) || stepCode.equals(StepPropertyEnum.DELIVERY_CONFIRMATION.getCode()))
                     && stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) {
@@ -282,9 +286,12 @@ public class UserServiceImpl implements UserService {
                             DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).plusDays(2);
 
                     if (collateralPlan.getStatus().equals(DecisionEnum.WAITING_EXECUTION.getMsg()) && LocalDateTime.now().isBefore(competeTime)) {
-                        userAndCases
-                                .computeIfAbsent(collateralPlan.getOperatorId(), k -> new ArrayList<>())  // key 为空就 new ArrayList
-                                .add(loanCaseVO);
+                        Long operatorId = collateralPlan.getOperatorId();
+                        if (operatorId != null) { // 修复:确保operatorId不为null
+                            userAndCases
+                                    .computeIfAbsent(operatorId, k -> new ArrayList<>())  // key 为空就 new ArrayList
+                                    .add(loanCaseVO);
+                        }
                     }
 
                 }

+ 2 - 0
src/main/java/com/loan/system/service/LoanService.java

@@ -59,4 +59,6 @@ public interface LoanService {
     void loanCaseComplete(Long caseId, Boolean isCancel, Map<String,String> pawnList);
 
     void cancelLoanCase(Long caseId);
+
+    List<LoanCaseVO> listLoanCaseByKeyAndIsComplete(String key, String msg,Integer pageNum, Integer pageSize);
 }

+ 5 - 5
src/main/resources/application-prod.yaml

@@ -62,11 +62,11 @@ system:
     appid: wxb7f7a8e73e064953
     secret: 7946aadbe147d95981e740799f0a1d3c
   esign:
-    # ==================== 生产环境配置(正式环境) ====================
-    app-id: your-production-app-id  # 生产环境应用ID(正式用,需要在e签宝开放平台申请
-    app-secret: your-production-app-secret  # 生产环境应用密钥(正式用)
-    api-url: https://smlopenapi.esign.cn  # 生产环境API地址(正式环境,与沙箱地址相同
-    project-id: your-production-project-id  # 生产环境项目ID(可为空)
+    # ==================== 沙箱环境配置(当前使用) ====================
+    app-id: 7439093682  # 沙箱环境应用ID(测试用
+    app-secret: da96bb269786338c156050cfa23eba4f  # 沙箱环境应用密钥(测试用)
+    api-url: https://smlopenapi.esign.cn  # 沙箱环境API地址(测试环境
+    project-id: your-project-id  # 沙箱环境项目ID(可为空)
     enabled: true  # 是否启用e签宝
     
     # ==================== 沙箱环境配置(测试环境,已注释) ====================