|
@@ -1,15 +1,14 @@
|
|
|
package com.loan.system.controller.wechat;
|
|
package com.loan.system.controller.wechat;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.loan.system.context.BaseContext;
|
|
import com.loan.system.context.BaseContext;
|
|
|
import com.loan.system.domain.dto.*;
|
|
import com.loan.system.domain.dto.*;
|
|
|
-import com.loan.system.domain.entity.ApprovalRecord;
|
|
|
|
|
-import com.loan.system.domain.entity.Disbursement;
|
|
|
|
|
-import com.loan.system.domain.entity.Repayment;
|
|
|
|
|
-import com.loan.system.domain.entity.RepaymentRecord;
|
|
|
|
|
|
|
+import com.loan.system.domain.entity.*;
|
|
|
import com.loan.system.domain.enums.*;
|
|
import com.loan.system.domain.enums.*;
|
|
|
import com.loan.system.domain.pojo.Result;
|
|
import com.loan.system.domain.pojo.Result;
|
|
|
import com.loan.system.domain.vo.*;
|
|
import com.loan.system.domain.vo.*;
|
|
|
import com.loan.system.exception.DescribeException;
|
|
import com.loan.system.exception.DescribeException;
|
|
|
|
|
+import com.loan.system.repository.ContractSeqRepository;
|
|
|
import com.loan.system.service.*;
|
|
import com.loan.system.service.*;
|
|
|
import com.loan.system.service.DisbursementRecordService;
|
|
import com.loan.system.service.DisbursementRecordService;
|
|
|
import com.loan.system.utils.ResultUtil;
|
|
import com.loan.system.utils.ResultUtil;
|
|
@@ -23,9 +22,11 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static com.loan.system.domain.enums.ExceptionEnum.*;
|
|
import static com.loan.system.domain.enums.ExceptionEnum.*;
|
|
|
|
|
+import static com.loan.system.utils.ValidUtil.isAllFieldsNull;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/wechat/repayment")
|
|
@RequestMapping("/wechat/repayment")
|
|
@@ -37,7 +38,9 @@ public class RepaymentController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private StepService stepService;
|
|
private StepService stepService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private DisbursementRecordService disbursementRecordService;
|
|
|
|
|
|
|
+ private ContractService contractService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ContractRepaymentService contractRepaymentService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RepaymentService repaymentService;
|
|
private RepaymentService repaymentService;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -52,38 +55,23 @@ public class RepaymentController {
|
|
|
if(!loanService.existsByIdAndIsDelete(caseId))
|
|
if(!loanService.existsByIdAndIsDelete(caseId))
|
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
|
|
|
|
|
|
- DisbursementDetailVO disbursementDetailVO = disbursementService.getLoanCaseAndCustomerByCaseId(caseId);
|
|
|
|
|
- RepaymentDetailVO repaymentDetailVO = new RepaymentDetailVO();
|
|
|
|
|
- repaymentDetailVO.setCustomer(disbursementDetailVO.getCustomer());
|
|
|
|
|
- repaymentDetailVO.setLoanCase(disbursementDetailVO.getLoanCase());
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
|
|
|
- //填充
|
|
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- List<RepaymentRecordVO> repaymentRecordVOS = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false);
|
|
|
|
|
- Double currentAmount= 0.0;
|
|
|
|
|
- for (RepaymentRecordVO repaymentRecordVO : repaymentRecordVOS)
|
|
|
|
|
- if(!repaymentRecordVO.getIsInterest())//审批、财务环节显示审批通过后的总额
|
|
|
|
|
- currentAmount += repaymentRecordVO.getAmount();
|
|
|
|
|
-
|
|
|
|
|
- repaymentDetailVO.setRepaymentRecords(repaymentRecordVOS);
|
|
|
|
|
- repaymentDetailVO.setCurrentAmount(currentAmount);
|
|
|
|
|
- repaymentDetailVO.setTotalAmount(repayment.getTotalAmount());
|
|
|
|
|
- //财务核算后
|
|
|
|
|
- repaymentDetailVO.setInterests(repayment.getInterest());
|
|
|
|
|
- //余额回款
|
|
|
|
|
- repaymentDetailVO.setWay(repayment.getRepayWay());
|
|
|
|
|
-
|
|
|
|
|
- return ResultUtil.success("success",repaymentDetailVO);
|
|
|
|
|
|
|
+ return ResultUtil.success("success",repaymentService.getDetails(caseId, StepPropertyEnum.REPAY_START.getLabel()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- @PostMapping
|
|
|
|
|
|
|
+ @PostMapping("/{id}")
|
|
|
@ApiOperation(value = "启动回款")
|
|
@ApiOperation(value = "启动回款")
|
|
|
@PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')")
|
|
@PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')")
|
|
|
- public Result addDisbursement(@RequestBody RepaymentRecordDTO repaymentRecordDTO, @RequestParam Long caseId, @RequestParam Long recordId) {
|
|
|
|
|
- if(ObjectUtils.isEmpty(repaymentRecordDTO))
|
|
|
|
|
|
|
+ public Result addDisbursement(@RequestBody RepaymentRecordDTO repaymentRecordDTO, @RequestParam Long caseId, @PathVariable("id") Long recordId) {
|
|
|
|
|
+ if(ObjectUtils.isEmpty(repaymentRecordDTO)||isAllFieldsNull(repaymentRecordDTO))
|
|
|
throw new DescribeException(INPUT_ERROR);
|
|
throw new DescribeException(INPUT_ERROR);
|
|
|
|
|
|
|
|
|
|
+ System.out.println(repaymentRecordDTO);
|
|
|
|
|
+
|
|
|
if(caseId == null ||!loanService.existsByIdAndIsDelete(caseId))
|
|
if(caseId == null ||!loanService.existsByIdAndIsDelete(caseId))
|
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
|
|
|
|
|
@@ -91,35 +79,57 @@ public class RepaymentController {
|
|
|
if(ObjectUtils.isEmpty(stepVO) || !stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
if(ObjectUtils.isEmpty(stepVO) || !stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- //最新回款记录还在审批中,则不能回款
|
|
|
|
|
Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
- List<RepaymentRecordVO> repaymentRecordVOS = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false);
|
|
|
|
|
-
|
|
|
|
|
- //上报计划
|
|
|
|
|
- if(recordId == -1){
|
|
|
|
|
- //审批意见为驳回,无法新增
|
|
|
|
|
- if(repaymentRecordVOS.get(repaymentRecordVOS.size()-1).getApprovalDecision().equals(DecisionEnum.REJECT.getMsg()))
|
|
|
|
|
- throw new DescribeException(DISBURSEMENT_HAS_NOT_COMPLETED);
|
|
|
|
|
- repaymentRecordService.addRepaymentRecord(repaymentRecordDTO,repayment.getId());
|
|
|
|
|
|
|
+ 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<RepaymentRecord> 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{
|
|
} else{
|
|
|
//审批意见为通过,无法修改
|
|
//审批意见为通过,无法修改
|
|
|
- if(repaymentRecordVOS.get(repaymentRecordVOS.size()-1).getApprovalDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
|
|
- throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
|
|
|
|
|
|
|
+ record = repaymentRecordService.findByIdAndIsDelete(recordId);
|
|
|
|
|
+ if(record.getApprovalDecision()==null || record.getApprovalDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
|
|
+ throw new DescribeException(REPAYMENT_HAS_COMPLETED);
|
|
|
|
|
+
|
|
|
repaymentRecordService.updateRepaymentRecordById(repaymentRecordDTO,recordId);
|
|
repaymentRecordService.updateRepaymentRecordById(repaymentRecordDTO,recordId);
|
|
|
|
|
+ //获取合同回款
|
|
|
|
|
+ List<Long> Ids = contractRepaymentService.findByRepaymentRecordIdAndIsDelete(recordId);
|
|
|
|
|
+ contractRepaymentService.deleteByIds(Ids);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //创建新关联关系
|
|
|
|
|
+ Iterator<Map.Entry<Long, Double>> iterator = repaymentRecordDTO.getContractIdAndAmount().entrySet().iterator();
|
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
|
+ Map.Entry<Long, Double> entry = iterator.next();
|
|
|
|
|
+ Long contractId = entry.getKey();
|
|
|
|
|
+ double amount = entry.getValue();
|
|
|
|
|
+ contractRepaymentService.addContractRepayment(recordId,contractId,caseId,amount,record.getRepayTime());
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- // DisbursementVO disbursementVO = disbursementService.addDisbursement(disbursementDTO);
|
|
|
|
|
|
|
|
|
|
//修改状态
|
|
//修改状态
|
|
|
- if(isCleared(caseId)){//若结清,则回款完成
|
|
|
|
|
- repaymentService.updateIsClearedByCaseId(true,caseId);
|
|
|
|
|
|
|
+ if(isCleared(caseId,StepPropertyEnum.REPAY_START.getLabel())){
|
|
|
|
|
+ //若结清,则回款完成
|
|
|
stepService.updateStatusByCaseId( StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_START.getLabel(), caseId);
|
|
stepService.updateStatusByCaseId( StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_START.getLabel(), caseId);
|
|
|
}
|
|
}
|
|
|
- stepService.updateStatusByCaseId( StepEnum.PROCESS.getMsg(),StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ stepService.tryStartStep(StepPropertyEnum.REPAY_START.getLabel(),caseId);
|
|
|
|
|
|
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
// SysMessage message = new SysMessage();
|
|
@@ -136,19 +146,22 @@ public class RepaymentController {
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @GetMapping("/{caseId}/appravalDetails")
|
|
|
|
|
|
|
+ @GetMapping("/{caseId}/approvalDetails")
|
|
|
@ApiOperation("显示审批详情")//与loanContraller的方法一致,但为了规范
|
|
@ApiOperation("显示审批详情")//与loanContraller的方法一致,但为了规范
|
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
|
public Result findLoanCaseDetails2(@PathVariable("caseId")Long caseId){
|
|
public Result findLoanCaseDetails2(@PathVariable("caseId")Long caseId){
|
|
|
- return ResultUtil.success("success",getDetails(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:在回款记录添加审批记录,且每次审批完之后才能再回款
|
|
//TODO:在回款记录添加审批记录,且每次审批完之后才能再回款
|
|
|
@PostMapping("/approval/pass")
|
|
@PostMapping("/approval/pass")
|
|
|
@ApiOperation(value = "回款审批")
|
|
@ApiOperation(value = "回款审批")
|
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
|
- public Result repaymentApproval(@RequestBody ApprovalDTO approvalDTO) {
|
|
|
|
|
- if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null)
|
|
|
|
|
|
|
+ public Result repaymentApproval(@RequestBody RepaymentApprovalDTO approvalDTO,@RequestParam Long chargeId) {
|
|
|
|
|
+ if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null||approvalDTO.getRecordId() == null)
|
|
|
throw new DescribeException(INPUT_ERROR);
|
|
throw new DescribeException(INPUT_ERROR);
|
|
|
|
|
|
|
|
if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId()))
|
|
if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId()))
|
|
@@ -160,15 +173,8 @@ public class RepaymentController {
|
|
|
if(!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
if(!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
//填写审批意见
|
|
//填写审批意见
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.REJECT.getMsg(),repayment.getId());
|
|
|
|
|
-
|
|
|
|
|
|
|
+ repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.PASS.getMsg(),BaseContext.getCurrentId(),approvalDTO.getRecordId());
|
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
// SysMessage message = new SysMessage();
|
|
|
// message.setMobile(null);
|
|
// message.setMobile(null);
|
|
@@ -181,14 +187,14 @@ public class RepaymentController {
|
|
|
// messageService.addMessage(message);
|
|
// messageService.addMessage(message);
|
|
|
// wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage());
|
|
// wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage());
|
|
|
|
|
|
|
|
- //修改出款单
|
|
|
|
|
- repaymentService.updateApprovalUserByCaseId(BaseContext.getCurrentId(),caseId);
|
|
|
|
|
-
|
|
|
|
|
//修改状态
|
|
//修改状态
|
|
|
stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
|
- if(isCleared(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.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.REPAY_APPROVAL.getLabel(), caseId);
|
|
|
- stepService.updateStatusByCaseId( StepEnum.PROCESS.getMsg(), StepPropertyEnum.FINANCE_CHECK.getLabel(),caseId);
|
|
|
|
|
|
|
+ stepService.tryStartStep(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId);
|
|
|
|
|
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
@@ -196,33 +202,21 @@ public class RepaymentController {
|
|
|
@PostMapping("/approval/reject")
|
|
@PostMapping("/approval/reject")
|
|
|
@ApiOperation(value = "回款审批驳回")
|
|
@ApiOperation(value = "回款审批驳回")
|
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
|
- public Result repaymentCancel(@RequestBody ApprovalDTO approvalDTO) {
|
|
|
|
|
- if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null)
|
|
|
|
|
|
|
+ public Result repaymentCancel(@RequestBody RepaymentApprovalDTO approvalDTO) {
|
|
|
|
|
+ if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null||approvalDTO.getRecordId() == null)
|
|
|
throw new DescribeException(INPUT_ERROR);
|
|
throw new DescribeException(INPUT_ERROR);
|
|
|
|
|
|
|
|
if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId()))
|
|
if(!loanService.existsByIdAndIsDelete(approvalDTO.getCaseId()))
|
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
|
|
|
|
|
|
Long caseId = approvalDTO.getCaseId();
|
|
Long caseId = approvalDTO.getCaseId();
|
|
|
- StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_START.getLabel(), caseId);
|
|
|
|
|
- if(step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
|
|
- throw new DescribeException(PRE_STEP_NOT_COMPLETE);
|
|
|
|
|
|
|
|
|
|
StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId);
|
|
StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(),caseId);
|
|
|
if(stepVO.getStatus().equals(StepEnum.COMPLETED.getMsg()))
|
|
if(stepVO.getStatus().equals(StepEnum.COMPLETED.getMsg()))
|
|
|
throw new DescribeException(ExceptionEnum.STEP_HAS_COMPLETEED);
|
|
throw new DescribeException(ExceptionEnum.STEP_HAS_COMPLETEED);
|
|
|
|
|
|
|
|
- Long currentId = stepVO.getUserId1();
|
|
|
|
|
- if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){
|
|
|
|
|
- throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
//填写驳回意见
|
|
//填写驳回意见
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.REJECT.getMsg(),repayment.getId());
|
|
|
|
|
-
|
|
|
|
|
- //修改出款单
|
|
|
|
|
- repaymentService.updateApprovalUserByCaseId(BaseContext.getCurrentId(),caseId);
|
|
|
|
|
|
|
+ repaymentRecordService.updateApprovalById(approvalDTO.getComments(),DecisionEnum.REJECT.getMsg(),BaseContext.getCurrentId(),approvalDTO.getRecordId());
|
|
|
|
|
|
|
|
//修改负责人
|
|
//修改负责人
|
|
|
stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
stepService.updateUserByCaseId(StepPropertyEnum.REPAY_APPROVAL.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
@@ -244,19 +238,67 @@ public class RepaymentController {
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //TODO:用于判断总的金额是否结清
|
|
|
|
|
+ private Boolean isCleared(Long caseId,String stepName){
|
|
|
|
|
+ Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
+ //获取回款记录
|
|
|
|
|
+ List<RepaymentRecord> 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<RepaymentRecord> repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsDelete(repaymentId, false);
|
|
|
|
|
+ List<Long> recordIds= repaymentRecords.stream().map(RepaymentRecord::getId).collect(Collectors.toList());
|
|
|
|
|
+ List<ContractRepayment> contractRepayments = contractRepaymentService.findByRepaymentRecordIdsAndIsDelete(recordIds);
|
|
|
|
|
+
|
|
|
|
|
+ //2.
|
|
|
|
|
+ List<Long> 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")
|
|
@GetMapping("/financeDetails")
|
|
|
@ApiOperation("显示财务核算详情")//与loanContraller的方法一致,但为了规范
|
|
@ApiOperation("显示财务核算详情")//与loanContraller的方法一致,但为了规范
|
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
|
public Result findLoanCaseDetails3(@RequestParam Long caseId){
|
|
public Result findLoanCaseDetails3(@RequestParam Long caseId){
|
|
|
- if(caseId==null)
|
|
|
|
|
- throw new DescribeException(INPUT_ERROR);
|
|
|
|
|
- return ResultUtil.success("success",getDetails(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")
|
|
|
|
|
|
|
+ @PostMapping("/financeCheck/{caseId}")
|
|
|
@ApiOperation(value = "财务核算")
|
|
@ApiOperation(value = "财务核算")
|
|
|
@PreAuthorize("@pms.hasRole('FINANCE')")
|
|
@PreAuthorize("@pms.hasRole('FINANCE')")
|
|
|
- public Result financeDisbursement( @RequestParam Long caseId,@RequestParam Double interest) {
|
|
|
|
|
|
|
+ public Result financeDisbursement( @PathVariable Long caseId,@RequestParam Double interest,@RequestParam Long contractId) {
|
|
|
if(caseId==null||!loanService.existsByIdAndIsDelete(caseId))
|
|
if(caseId==null||!loanService.existsByIdAndIsDelete(caseId))
|
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
|
|
|
|
|
@@ -264,22 +306,28 @@ public class RepaymentController {
|
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
|
|
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- if(!repayment.getIsCleared())
|
|
|
|
|
|
|
+ Contract contract = contractService.findContractById(contractId);
|
|
|
|
|
+ if(!contract.getIsCleared())
|
|
|
throw new DescribeException(FUND_NOT_CLEAR);
|
|
throw new DescribeException(FUND_NOT_CLEAR);
|
|
|
|
|
+ if(contract.getFinanceUserId()!=null && !contract.getFinanceUserId().equals(BaseContext.getCurrentId()))
|
|
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
|
|
|
|
|
-// Long currentId = stepVO.getUserId1();
|
|
|
|
|
-// if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){
|
|
|
|
|
-// throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- //修改回款单
|
|
|
|
|
- repaymentService.updateIntersetsByCaseId(interest,caseId);
|
|
|
|
|
|
|
+ //修改合同信息
|
|
|
|
|
+ contractService.updateRepayById(true,interest,BaseContext.getCurrentId(),contractId,false);
|
|
|
|
|
|
|
|
//修改状态
|
|
//修改状态
|
|
|
stepService.updateUserByCaseId(StepPropertyEnum.FINANCE_CHECK.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
stepService.updateUserByCaseId(StepPropertyEnum.FINANCE_CHECK.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
|
- stepService.updateStatusByCaseId( StepEnum.COMPLETED.getMsg(),StepPropertyEnum.FINANCE_CHECK.getLabel(),caseId);
|
|
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BALANCE_REPAY.getLabel(), caseId);
|
|
|
|
|
|
|
+ boolean flag = true;
|
|
|
|
|
+ List<Contract> 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:微信推送预审通过消息和通知下一环节
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
// SysMessage message = new SysMessage();
|
|
@@ -296,25 +344,20 @@ public class RepaymentController {
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Boolean isCleared(Long caseId){
|
|
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- //获取回款记录
|
|
|
|
|
- List<RepaymentRecordVO> repaymentRecordVOS = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false);
|
|
|
|
|
-
|
|
|
|
|
- Double currentAmount= 0.0;
|
|
|
|
|
- for (RepaymentRecordVO repaymentRecordVO : repaymentRecordVOS)
|
|
|
|
|
- currentAmount += repaymentRecordVO.getAmount();
|
|
|
|
|
-
|
|
|
|
|
- Double totalAmount = repaymentService.findByCaseIdAndIsDelete(caseId, false).getTotalAmount();
|
|
|
|
|
-
|
|
|
|
|
- return (totalAmount-currentAmount)< Double.MIN_VALUE;
|
|
|
|
|
|
|
+ @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")
|
|
@PostMapping("/balanceRepay")
|
|
|
@ApiOperation(value = "费息回款")
|
|
@ApiOperation(value = "费息回款")
|
|
|
@PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')")
|
|
@PreAuthorize("@pms.hasAnyRoles('LEAD_SALES', 'ASSIST_SALES')")
|
|
|
- public Result balanceRepay(@RequestParam Long caseId , @RequestBody RepaymentRecordDTO repaymentRecordDTO , @RequestParam String way) {
|
|
|
|
|
|
|
+ public Result balanceRepay(@RequestParam Long caseId , @RequestBody RepaymentRecordDTO repaymentRecordDTO ) {
|
|
|
if(ObjectUtils.isEmpty(repaymentRecordDTO)||caseId==null)
|
|
if(ObjectUtils.isEmpty(repaymentRecordDTO)||caseId==null)
|
|
|
throw new DescribeException(INPUT_ERROR);
|
|
throw new DescribeException(INPUT_ERROR);
|
|
|
if(!loanService.existsByIdAndIsDelete(caseId))
|
|
if(!loanService.existsByIdAndIsDelete(caseId))
|
|
@@ -324,19 +367,31 @@ public class RepaymentController {
|
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// Long currentId = stepVO.getUserId1();
|
|
|
|
|
+// if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){
|
|
|
|
|
+// throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
- repaymentService.updateRepayWayByCaseId(way,caseId);
|
|
|
|
|
//添加回款记录
|
|
//添加回款记录
|
|
|
repaymentRecordDTO.setIsInterest( true);
|
|
repaymentRecordDTO.setIsInterest( true);
|
|
|
- repaymentRecordService.addRepaymentRecord(repaymentRecordDTO, repaymentService.findByCaseIdAndIsDelete(caseId, false).getId());
|
|
|
|
|
|
|
+ RepaymentRecord record = repaymentRecordService.addRepaymentRecord(repaymentRecordDTO, repaymentService.findByCaseIdAndIsDelete(caseId, false).getId());
|
|
|
|
|
+ //创建新关联关系
|
|
|
|
|
+ Iterator<Map.Entry<Long, Double>> iterator = repaymentRecordDTO.getContractIdAndAmount().entrySet().iterator();
|
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
|
+ Map.Entry<Long, Double> 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);
|
|
stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.BALANCE_REPAY.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.BALANCE_REPAY.getLabel(),caseId);
|
|
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.FINANCE_CONFIRM.getLabel(), 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:微信推送预审通过消息和通知下一环节
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
// SysMessage message = new SysMessage();
|
|
@@ -352,11 +407,38 @@ public class RepaymentController {
|
|
|
|
|
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
|
|
|
+ /*TODO:更新合同费息结清状态
|
|
|
|
|
+ * 1.根据recordId查合同关联表,
|
|
|
|
|
+ * 2.查出每个合同id对应的回款金额
|
|
|
|
|
+ * 3.若全部合同的回款金额与费息相同,则结清
|
|
|
|
|
+ * */
|
|
|
|
|
+ private Boolean interestIsCleared(Long repaymentId) {
|
|
|
|
|
+ //1.
|
|
|
|
|
+ List<RepaymentRecord> repaymentRecords = repaymentRecordService.findByRepaymentIdAndIsInterestAndIsDelete(repaymentId, false);
|
|
|
|
|
+ List<Long> recordIds= repaymentRecords.stream().map(RepaymentRecord::getId).collect(Collectors.toList());
|
|
|
|
|
+ List<ContractRepayment> contractRepayments = contractRepaymentService.findByRepaymentRecordIdsAndIsDelete(recordIds);
|
|
|
|
|
+
|
|
|
|
|
+ //2.
|
|
|
|
|
+ List<Long> 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")
|
|
@PostMapping("/financeConfirm")
|
|
|
@ApiOperation(value = "财务确认")
|
|
@ApiOperation(value = "财务确认")
|
|
|
@PreAuthorize("@pms.hasRole('FINANCE')")
|
|
@PreAuthorize("@pms.hasRole('FINANCE')")
|
|
|
- public Result financeConfirm(@RequestParam Long caseId) {
|
|
|
|
|
|
|
+ public Result financeConfirm(@RequestParam List<Long> recordIds,@RequestParam Long caseId) {//TODO:一下子可以确认多笔
|
|
|
if(caseId==null || !loanService.existsByIdAndIsDelete(caseId))
|
|
if(caseId==null || !loanService.existsByIdAndIsDelete(caseId))
|
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
|
|
|
|
|
|
|
@@ -364,13 +446,22 @@ public class RepaymentController {
|
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
if(ObjectUtils.isEmpty(stepVO)||!stepVO.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
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);
|
|
|
|
|
|
|
+// 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);
|
|
stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.FINANCE_CONFIRM.getLabel(), BaseContext.getCurrentId(), caseId);
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.FINANCE_CONFIRM.getLabel(),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:微信推送预审通过消息和通知下一环节
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
// SysMessage message = new SysMessage();
|
|
@@ -387,29 +478,91 @@ public class RepaymentController {
|
|
|
return ResultUtil.success("success");
|
|
return ResultUtil.success("success");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private RepaymentDetailVO getDetails(Long caseId){
|
|
|
|
|
- DisbursementDetailVO disbursementDetailVO = disbursementService.getLoanCaseAndCustomerByCaseId(caseId);
|
|
|
|
|
- RepaymentDetailVO repaymentDetailVO = new RepaymentDetailVO();
|
|
|
|
|
- repaymentDetailVO.setCustomer(disbursementDetailVO.getCustomer());
|
|
|
|
|
- repaymentDetailVO.setLoanCase(disbursementDetailVO.getLoanCase());
|
|
|
|
|
|
|
+ @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);
|
|
|
|
|
|
|
|
- //填充
|
|
|
|
|
- Repayment repayment = repaymentService.findByCaseIdAndIsDelete(caseId, false);
|
|
|
|
|
- List<RepaymentRecordVO> repaymentRecordVOS = repaymentRecordService.findByRepaymentIdAndIsDelete(repayment.getId(), false);
|
|
|
|
|
- Double currentAmount= 0.0;
|
|
|
|
|
- for (RepaymentRecordVO repaymentRecordVO : repaymentRecordVOS)
|
|
|
|
|
- if(repaymentRecordVO.getApprovalDecision().equals(DecisionEnum.PASS.getMsg())&& !repaymentRecordVO.getIsInterest())//审批、财务环节显示审批通过后的总额
|
|
|
|
|
- currentAmount += repaymentRecordVO.getAmount();
|
|
|
|
|
-
|
|
|
|
|
- repaymentDetailVO.setRepaymentRecords(repaymentRecordVOS);
|
|
|
|
|
- repaymentDetailVO.setCurrentAmount(currentAmount);
|
|
|
|
|
- repaymentDetailVO.setTotalAmount(repayment.getTotalAmount());
|
|
|
|
|
- //财务核算后
|
|
|
|
|
- repaymentDetailVO.setInterests(repayment.getInterest());
|
|
|
|
|
- //余额回款
|
|
|
|
|
- repaymentDetailVO.setWay(repayment.getRepayWay());
|
|
|
|
|
-
|
|
|
|
|
- return repaymentDetailVO;
|
|
|
|
|
|
|
+ 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<StepVO> 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<RepaymentRecord> 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<repaymentRecords.size()-1;i++){
|
|
|
|
|
+// RepaymentRecord repaymentRecord = repaymentRecords.get(i);
|
|
|
|
|
+// if(repaymentRecord.getApprovalDecision().equals(DecisionEnum.PASS.getMsg())&&!repaymentRecord.getIsInterest())//审批、财务环节显示审批通过后的总额
|
|
|
|
|
+// currentAmount += repaymentRecord.getAmount();
|
|
|
|
|
+// }
|
|
|
|
|
+// }else{
|
|
|
|
|
+// for (RepaymentRecord repaymentRecord : repaymentRecords)
|
|
|
|
|
+// if(repaymentRecord.getApprovalDecision().equals(DecisionEnum.PASS.getMsg())&& !repaymentRecord.getIsInterest())//审批、财务环节显示审批通过后的总额
|
|
|
|
|
+// currentAmount += repaymentRecord.getAmount();
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// return Math.abs(totalAmount-currentAmount)< Double.MIN_VALUE;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
}
|
|
}
|