| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- 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<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{
- //审批意见为通过,无法修改
- 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<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());
- }
- //修改状态
- 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<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")
- @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<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:微信推送预审通过消息和通知下一环节
- // 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<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);
- 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<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")
- @ApiOperation(value = "财务确认")
- @PreAuthorize("@pms.hasRole('FINANCE')")
- public Result financeConfirm(@RequestParam List<Long> 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<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;
- // }
- }
|