package com.loan.system.controller.wechat; import cn.hutool.core.bean.BeanUtil; import com.loan.system.context.BaseContext; import com.loan.system.domain.dto.*; import com.loan.system.domain.entity.*; import com.loan.system.domain.enums.*; import com.loan.system.domain.pojo.Result; import com.loan.system.domain.vo.*; import com.loan.system.exception.DescribeException; import com.loan.system.repository.ContractSeqRepository; import com.loan.system.service.*; import com.loan.system.service.DisbursementRecordService; import com.loan.system.utils.ResultUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import net.bytebuddy.dynamic.scaffold.MethodRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; import static com.loan.system.domain.enums.ExceptionEnum.*; import static com.loan.system.utils.ValidUtil.isAllFieldsNull; @RestController @RequestMapping("/wechat/repayment") @Api(tags = "还款接口") public class RepaymentController { @Autowired private DisbursementService disbursementService; @Autowired private StepService stepService; @Autowired private ContractService contractService; @Autowired private ContractRepaymentService contractRepaymentService; @Autowired private RepaymentService repaymentService; @Autowired private RepaymentRecordService repaymentRecordService; @Autowired private LoanService loanService; @GetMapping("/{caseId}/repayDetails") @ApiOperation("显示回款详情")//与loanContraller的方法一致,但为了规范 @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')") public Result findLoanCaseDetails(@PathVariable("caseId")Long caseId){ if(!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_START.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO) || stepVO.getStatus().equals(StepEnum.UNSTART.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); return ResultUtil.success("success",repaymentService.getDetails(caseId, StepPropertyEnum.REPAY_START.getLabel())); } @PostMapping("/{id}") @ApiOperation(value = "启动回款") @PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')") public Result addDisbursement(@RequestBody RepaymentRecordDTO repaymentRecordDTO, @RequestParam Long caseId, @PathVariable("id") Long recordId) { if(ObjectUtils.isEmpty(repaymentRecordDTO)||isAllFieldsNull(repaymentRecordDTO)) throw new DescribeException(INPUT_ERROR); System.out.println(repaymentRecordDTO); if(caseId == null ||!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_START.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO) || !stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false); if(ObjectUtils.isEmpty(repayment)){ Repayment rep = new Repayment(); rep.setCaseId(caseId); rep.setStartUserId(BaseContext.getCurrentId()); rep.setTotalAmount(disbursementService.getDisbursementByCaseId(caseId).getPlannedAmount()); repayment=repaymentService.addRepayment(rep); } RepaymentRecord record =new RepaymentRecord(); //上报计划(-1表示当前为新增) if(recordId <= 0){ List repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false); if(!repaymentRecords.isEmpty()){ record = repaymentRecords.get(repaymentRecords.size()-1); if(record.getApprovalDecision()==null || !record.getApprovalDecision().equals(DecisionEnum.PASS.getMsg())) throw new DescribeException(REPAYMENT_HAS_BEEN_REJECTED); } RepaymentRecord repaymentRecord = repaymentRecordService.addRepaymentRecord(repaymentRecordDTO, repayment.getId()); recordId = repaymentRecord.getId(); } else{ //审批意见为通过,无法修改 record = repaymentRecordService.findByIdAndIsDelete(recordId); if(record.getApprovalDecision()==null || record.getApprovalDecision().equals(DecisionEnum.PASS.getMsg())) throw new DescribeException(REPAYMENT_HAS_COMPLETED); repaymentRecordService.updateRepaymentRecordById(repaymentRecordDTO,recordId); //获取合同回款 List Ids = contractRepaymentService.findByRepaymentRecordIdAndIsDelete(recordId); contractRepaymentService.deleteByIds(Ids); } //创建新关联关系 Iterator> iterator = repaymentRecordDTO.getContractIdAndAmount().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); Long contractId = entry.getKey(); double amount = entry.getValue(); contractRepaymentService.addContractRepayment(recordId,contractId,caseId,amount,record.getRepayTime()); } //修改状态 if(isCleared(caseId,StepPropertyEnum.REPAY_START.getLabel())){ //若结清,则回款完成 stepService.updateStatusByCaseId( StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_START.getLabel(), caseId); } stepService.tryStartStep(StepPropertyEnum.REPAY_START.getLabel(),caseId); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); return ResultUtil.success("success"); } @GetMapping("/{caseId}/approvalDetails") @ApiOperation("显示审批详情")//与loanContraller的方法一致,但为了规范 @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')") public Result findLoanCaseDetails2(@PathVariable("caseId")Long caseId){ if (caseId == null ||!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); return ResultUtil.success("success",repaymentService.getDetails(caseId, StepPropertyEnum.REPAY_APPROVAL.getLabel())); } //TODO:在回款记录添加审批记录,且每次审批完之后才能再回款 @PostMapping("/approval/pass") @ApiOperation(value = "回款审批") @PreAuthorize("@pms.hasRole('APPROVER')") public Result repaymentApproval(@RequestBody RepaymentApprovalDTO approvalDTO,@RequestParam Long chargeId) { if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null||approvalDTO.getRecordId() == null) throw new DescribeException(INPUT_ERROR); if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId())) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); Long caseId = approvalDTO.getCaseId(); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId); if(!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); //填写审批意见 repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.PASS.getMsg(),BaseContext.getCurrentId(),approvalDTO.getRecordId()); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); //修改状态 stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId); //TODO:更新结清状态(因为是一审一批,只有通过的时候才结清状态,不通过则不结清,保证了结清时的总金额为审批通过的) contractIsCleared(repaymentService.findByCaseIdAndIsDelete(caseId,false).getId(),chargeId); if(isCleared(caseId,StepPropertyEnum.REPAY_APPROVAL.getLabel())) stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_APPROVAL.getLabel(), caseId); stepService.tryStartStep(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId); return ResultUtil.success("success"); } @PostMapping("/approval/reject") @ApiOperation(value = "回款审批驳回") @PreAuthorize("@pms.hasRole('APPROVER')") public Result repaymentCancel(@RequestBody RepaymentApprovalDTO approvalDTO) { if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null||approvalDTO.getRecordId() == null) throw new DescribeException(INPUT_ERROR); if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId())) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); Long caseId = approvalDTO.getCaseId(); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId); if(stepVO.getStatus().equals(StepEnum.COMPLETED.getMsg())) throw new DescribeException(ExceptionEnum.STEP_HAS_COMPLETEED); //填写驳回意见 repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.REJECT.getMsg(),BaseContext.getCurrentId(),approvalDTO.getRecordId()); //修改负责人 stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId); stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.REPAY_START.getLabel(), caseId); stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(), StepPropertyEnum.REPAY_APPROVAL.getLabel(), caseId); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); return ResultUtil.success("success"); } //TODO:用于判断总的金额是否结清 private Boolean isCleared(Long caseId,String stepName){ Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false); //获取回款记录 List repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false); Double totalAmount = repaymentService.findByCaseIdAndIsDelete(caseId, false).getTotalAmount(); Double currentAmount= 0.0; for (RepaymentRecord repaymentRecord : repaymentRecords) if(stepName.equals(StepPropertyEnum.REPAY_APPROVAL.getLabel())){ if(repaymentRecord.getApprovalDecision()!=null && repaymentRecord.getApprovalDecision().equals(DecisionEnum.PASS.getMsg()) && !repaymentRecord.getIsInterest())//审批、财务环节显示审批通过后的总额 currentAmount += repaymentRecord.getAmount(); }else if(stepName.equals(StepPropertyEnum.REPAY_START.getLabel())){ if( !repaymentRecord.getIsInterest())//审批、财务环节显示审批通过后的总额 currentAmount += repaymentRecord.getAmount(); } return Math.abs(totalAmount-currentAmount)< Double.MIN_VALUE; } /*TODO:更新合同结清状态 * 1.根据recordId查合同关联表, * 2.查出每个合同id对应的回款金额 * 3.若回款金额与借款金额相同,则结清 * */ private void contractIsCleared(Long repaymentId,Long chargeId) { //1. List repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsDelete(repaymentId, false); List recordIds= repaymentRecords.stream().map(RepaymentRecord::getId).collect(Collectors.toList()); List contractRepayments = contractRepaymentService.findByRepaymentRecordIdsAndIsDelete(recordIds); //2. List contractIds = contractRepayments.stream().map(ContractRepayment::getContractId).collect(Collectors.toList()); for(Long contractId:contractIds){ double amount = 0.0; for (ContractRepayment contractRepayment:contractRepayments){ RepaymentRecord repaymentRecord = repaymentRecordService.findByIdAndIsDelete(contractRepayment.getRepaymentRecordId()); if(!repaymentRecord.getIsInterest() && contractRepayment.getContractId().equals(contractId)) amount += contractRepayment.getAmount(); } System.out.println("amount:"+amount); //3. if(Math.abs(amount-contractService.findContractById(contractId).getContractAmount())< Double.MIN_VALUE) contractService.updateRepayById(true,0.0,chargeId,contractId,false); } } @GetMapping("/financeDetails") @ApiOperation("显示财务核算详情")//与loanContraller的方法一致,但为了规范 @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')") public Result findLoanCaseDetails3(@RequestParam Long caseId){ if (caseId == null ||!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); return ResultUtil.success("success",repaymentService.getDetails(caseId,StepPropertyEnum.FINANCE_CHECK.getLabel())); } @PostMapping("/financeCheck/{caseId}") @ApiOperation(value = "财务核算") @PreAuthorize("@pms.hasRole('FINANCE')") public Result financeDisbursement( @PathVariable Long caseId,@RequestParam Double interest,@RequestParam Long contractId) { if(caseId==null||!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.FINANCE_CHECK.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); Contract contract = contractService.findContractById(contractId); if(!contract.getIsCleared()) throw new DescribeException(FUND_NOT_CLEAR); if(contract.getFinanceUserId()!=null && !contract.getFinanceUserId().equals(BaseContext.getCurrentId())) throw new DescribeException(STEP_USER_NOT_EXPECTED); //修改合同信息 contractService.updateRepayById(true,interest,BaseContext.getCurrentId(),contractId,false); //修改状态 stepService.updateUserByCaseId(StepPropertyEnum.FINANCE_CHECK.getLabel(), BaseContext.getCurrentId(), caseId); boolean flag = true; List contractByCaseId = contractService.findContractByCaseId2(caseId); for (Contract contract2 : contractByCaseId) if (contract2.getFinanceUserId()== null){ flag = false; break; } if (flag)//如果全部合同都有财务人员,则表示全部核算完成 stepService.updateStatusByCaseId( StepEnum.COMPLETED.getMsg(),StepPropertyEnum.FINANCE_CHECK.getLabel(),caseId); stepService.tryStartStep(StepPropertyEnum.FINANCE_CHECK.getLabel(),caseId); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); return ResultUtil.success("success"); } @GetMapping("/balanceDetails") @ApiOperation("显示费息回款详情")//与loanContraller的方法一致,但为了规范 @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')") public Result findLoanCaseDetails4(@RequestParam Long caseId){ if (caseId == null ||!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); return ResultUtil.success("success",repaymentService.getDetails(caseId,StepPropertyEnum.BALANCE_REPAY.getLabel())); } @PostMapping("/balanceRepay") @ApiOperation(value = "费息回款") @PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')") public Result balanceRepay(@RequestParam Long caseId , @RequestBody RepaymentRecordDTO repaymentRecordDTO ) { if(ObjectUtils.isEmpty(repaymentRecordDTO)||caseId==null) throw new DescribeException(INPUT_ERROR); if(!loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.BALANCE_REPAY.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); // Long currentId = stepVO.getUserId1(); // if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){ // throw new DescribeException(STEP_USER_NOT_EXPECTED); // } //添加回款记录 repaymentRecordDTO.setIsInterest( true); RepaymentRecord record = repaymentRecordService.addRepaymentRecord(repaymentRecordDTO, repaymentService.findByCaseIdAndIsDelete(caseId, false).getId()); //创建新关联关系 Iterator> iterator = repaymentRecordDTO.getContractIdAndAmount().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); Long contractId = entry.getKey(); double amount = entry.getValue(); contractRepaymentService.addContractRepayment(record.getId(),contractId,caseId,amount,record.getRepayTime()); } //TODO:添加赎当号码 stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.BALANCE_REPAY.getLabel(), BaseContext.getCurrentId(), caseId); if(interestIsCleared(repaymentService.findByCaseIdAndIsDelete(caseId, false).getId()))//当全部的合同的费息都完成时才结束环节 stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.BALANCE_REPAY.getLabel(),caseId); stepService.tryStartStep(StepPropertyEnum.BALANCE_REPAY.getLabel(),caseId); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); return ResultUtil.success("success"); } /*TODO:更新合同费息结清状态 * 1.根据recordId查合同关联表, * 2.查出每个合同id对应的回款金额 * 3.若全部合同的回款金额与费息相同,则结清 * */ private Boolean interestIsCleared(Long repaymentId) { //1. List repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsInterestAndIsDelete(repaymentId, false); List recordIds= repaymentRecords.stream().map(RepaymentRecord::getId).collect(Collectors.toList()); List contractRepayments = contractRepaymentService.findByRepaymentRecordIdsAndIsDelete(recordIds); //2. List contractIds = contractRepayments.stream().map(ContractRepayment::getContractId).collect(Collectors.toList()); for(Long contractId:contractIds){ double amount = 0.0; for (ContractRepayment contractRepayment:contractRepayments){ RepaymentRecord record = repaymentRecordService.findByIdAndIsDelete(contractRepayment.getRepaymentRecordId()); if(contractRepayment.getContractId().equals(contractId)&&record.getIsInterest()) amount += contractRepayment.getAmount(); } //3. if(Math.abs(amount-contractService.findContractById(contractId).getInterestAmount())> Double.MIN_VALUE) return false; } return true; } @PostMapping("/financeConfirm") @ApiOperation(value = "财务确认") @PreAuthorize("@pms.hasRole('FINANCE')") public Result financeConfirm(@RequestParam List recordIds,@RequestParam Long caseId) {//TODO:一下子可以确认多笔 if(caseId==null || !loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.FINANCE_CONFIRM.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); // Long currentId = stepVO.getUserId1(); // if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){ // throw new DescribeException(STEP_USER_NOT_EXPECTED); // } for(Long recordId:recordIds){ repaymentRecordService.updateApprovalById("",DecisionEnum.PASS.getMsg(),BaseContext.getCurrentId(),recordId); } stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.FINANCE_CONFIRM.getLabel(), BaseContext.getCurrentId(), caseId); if(interestIsCleared(repaymentService.findByCaseIdAndIsDelete(caseId, false).getId())){ stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.FINANCE_CONFIRM.getLabel(),caseId); // loanService.updateIsCompleteByCaseId(DecisionEnum.COMPLETE.getMsg(),caseId); } stepService.tryStartStep(StepPropertyEnum.FINANCE_CONFIRM.getLabel(),caseId); //TODO:微信推送预审通过消息和通知下一环节 // SysMessage message = new SysMessage(); // message.setMobile(null); // message.setUserRole(""); // message.setMessageTitle(""); // message.setMessageContent(""); // message.setStepName(""); // message.setRelatedId(loanCase.getId()); // message.setRelatedType(""); // messageService.addMessage(message); // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage()); return ResultUtil.success("success"); } @PostMapping("/repayComplete") @ApiOperation(value = "回款完成") @PreAuthorize("@pms.hasAnyRoles('APPROVAL')") public Result repayComplete(@RequestParam Long caseId) { if(caseId==null || !loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAYMENT_COMPLETE.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); StepVO stepVO1 = stepService.findByStepNameAndCaseId(StepPropertyEnum.FINANCE_CONFIRM.getLabel(), caseId); if(ObjectUtils.isEmpty(stepVO1)||!stepVO1.getStatus().equals(StepEnum.COMPLETED.getMsg())) throw new DescribeException(PRE_STEP_NOT_COMPLETE); List steps = stepService.getStepByCaseId(caseId); for(StepVO step:steps){ if(!step.getStatus().equals(StepEnum.COMPLETED.getMsg())) throw new DescribeException(STEP_EXIST_NOT_COMPLETE); } //更新回款单 repaymentService.updateStatusByCaseId(DecisionEnum.REPAYMENT_COMPLETE.getMsg(),caseId); stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.REPAYMENT_COMPLETE.getLabel(),BaseContext.getCurrentId(), caseId); //stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_PARENT.getLabel(),caseId); stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAYMENT_COMPLETE.getLabel(),caseId); stepService.tryStartStep(StepPropertyEnum.REPAYMENT_COMPLETE.getLabel(),caseId); return ResultUtil.success("success"); } @PostMapping("/caseComplete") @ApiOperation(value = "业务完成") @PreAuthorize("@pms.hasAnyRoles('BACK_OFFICE')") public Result loanCaseComplete(@RequestParam Long caseId) { if(caseId==null || !loanService.existsByIdAndIsDelete(caseId)) throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST); StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.CASE_COMPLETE.getLabel(),caseId); if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg())) throw new DescribeException(STEP_HAS_NOT_PROCESS); StepVO stepVO1 = stepService.findByStepNameAndCaseId(StepPropertyEnum.FINANCE_CONFIRM.getLabel(), caseId); if(ObjectUtils.isEmpty(stepVO1)||!stepVO1.getStatus().equals(StepEnum.COMPLETED.getMsg())) throw new DescribeException(PRE_STEP_NOT_COMPLETE); //设置业务状态 loanService.updateIsCompleteByCaseId(DecisionEnum.COMPLETE.getMsg(),caseId); stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.CASE_COMPLETE.getLabel(),BaseContext.getCurrentId(), caseId); stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_PARENT.getLabel(),caseId); stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.CASE_COMPLETE.getLabel(),caseId); stepService.tryStartStep(StepPropertyEnum.CASE_COMPLETE.getLabel(),caseId); return ResultUtil.success("success"); } //TODO:因为现在是一审一批,所以仅最后一笔金额可能是未通过 // private Boolean isCleared(Long caseId,String stepName){ // Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false); // //获取回款记录 // List repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false); // Double totalAmount = repaymentService.findByCaseIdAndIsDelete(caseId, false).getTotalAmount(); // // Double currentAmount= 0.0; // if(stepName.equals(StepPropertyEnum.REPAY_START.getLabel())){ // //不计算最后一次,因为最后一次一定未审批 // totalAmount-= repaymentRecords.get(repaymentRecords.size()-1).getAmount(); // for (int i=0;i