|
|
@@ -15,6 +15,7 @@ import com.loan.system.repository.DisbursementRepository;
|
|
|
import com.loan.system.service.*;
|
|
|
import com.loan.system.utils.RedisData;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
@@ -27,10 +28,12 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.loan.system.domain.enums.DecisionEnum.PASS;
|
|
|
import static com.loan.system.domain.enums.ExceptionEnum.*;
|
|
|
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class DisbursementServiceImpl implements DisbursementService {
|
|
|
private final DisbursementRepository disbursementRepository;
|
|
|
private final CustomerService customerService;
|
|
|
@@ -45,6 +48,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
private final ContractDisbursementService contractDisbursementService;
|
|
|
private final LocationDatumService locationDatumService;
|
|
|
private final ContractService contractService;
|
|
|
+ private final ContractBankInfoService contractBankInfoService;
|
|
|
|
|
|
@Override
|
|
|
public DisbursementVO addDisbursement(DisbursementDTO disbursementDTO) {
|
|
|
@@ -135,28 +139,28 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
if (id > 0) {
|
|
|
Disbursement disbursement = disbursementRepository.findByIdAndIsDelete(id, false);
|
|
|
ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(disbursement.getApprovalId());
|
|
|
- if(approvalRecord ==null || approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ if(approvalRecord ==null || approvalRecord.getDecision().equals(PASS.getMsg()))
|
|
|
throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
|
|
|
|
|
|
updateDisbursementByCaseId(disbursementDTO);
|
|
|
//删除记录
|
|
|
contractDisbursementService.deleteByRecordId(id, true);
|
|
|
} else {
|
|
|
- List<Disbursement> disbursements = disbursementRepository.findDisbursementsByCaseId(disbursementDTO.getCaseId(), false);
|
|
|
- if(!ObjectUtils.isEmpty(disbursements)){
|
|
|
- Disbursement disbursement = disbursements.get(disbursements.size()-1);
|
|
|
-
|
|
|
- ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(disbursement.getApprovalId());
|
|
|
- if (approvalRecord == null || !approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
- throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
|
|
|
- }
|
|
|
+// List<Disbursement> disbursements = disbursementRepository.findDisbursementsByCaseId(disbursementDTO.getCaseId(), false);
|
|
|
+// if(!ObjectUtils.isEmpty(disbursements)){
|
|
|
+// Disbursement disbursement = disbursements.get(disbursements.size()-1);
|
|
|
+//
|
|
|
+// ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(disbursement.getApprovalId());
|
|
|
+// if (approvalRecord == null || !approvalRecord.getDecision().equals(PASS.getMsg()))
|
|
|
+// throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
|
|
|
+// }
|
|
|
DisbursementVO disbursementVO = addDisbursement(disbursementDTO);
|
|
|
id = disbursementVO.getId();
|
|
|
}
|
|
|
|
|
|
//设置计划与合同对应
|
|
|
Map<Long, Double> contractAndAmount = disbursementDTO.getContractAndAmount();
|
|
|
- contractDisbursementService.addContractDisbursement(contractAndAmount, id, true);
|
|
|
+ contractDisbursementService.addContractDisbursement(contractAndAmount, id, disbursementDTO.getCaseId(),true);
|
|
|
|
|
|
//修改状态
|
|
|
stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.PLAN_REPORT.getCode(), BaseContext.getCurrentId(), disbursementDTO.getCaseId());
|
|
|
@@ -180,7 +184,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
disbursementRepository.updateUserById(chargeId, assistantId, approvalRecordDTO.getRecordId());
|
|
|
|
|
|
//填写审批意见并绑定审批id
|
|
|
- ApprovalRecord approvalRecord = approvalService.addApprovalRecord(caseId, StepPropertyEnum.PLAN_AUDIT.getCode(), DecisionEnum.PASS.getMsg(), approvalRecordDTO.getComments());
|
|
|
+ ApprovalRecord approvalRecord = approvalService.addApprovalRecord(caseId, StepPropertyEnum.PLAN_AUDIT.getCode(), PASS.getMsg(), approvalRecordDTO.getComments());
|
|
|
disbursementRepository.updateApprovalUserById(approvalRecord.getId(), approvalRecordDTO.getRecordId());
|
|
|
|
|
|
//修改状态
|
|
|
@@ -255,8 +259,8 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
if (split.length > 0)
|
|
|
financeApprovalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
|
|
|
}
|
|
|
- if ((ObjectUtils.isEmpty(approvalRecord) || approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())) &&
|
|
|
- (ObjectUtils.isEmpty(financeApprovalRecord) || financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))
|
|
|
+ if ((ObjectUtils.isEmpty(approvalRecord) || approvalRecord.getDecision().equals(PASS.getMsg())) &&
|
|
|
+ (ObjectUtils.isEmpty(financeApprovalRecord) || financeApprovalRecord.getDecision().equals(PASS.getMsg())))
|
|
|
throw new DescribeException(DISBURSEMENT_HAS_COMPLETED);
|
|
|
}
|
|
|
|
|
|
@@ -283,8 +287,8 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
if (split.length > 0)
|
|
|
financeApprovalRecord = approvalService.findByIdAndIsDelete(Long.parseLong(split[split.length - 1]));
|
|
|
}
|
|
|
- if ((ObjectUtils.isEmpty(approvalRecord) || !approvalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())) &&
|
|
|
- (ObjectUtils.isEmpty(financeApprovalRecord) || !financeApprovalRecord.getDecision().equals(DecisionEnum.PASS.getMsg())))//未审批通过
|
|
|
+ if ((ObjectUtils.isEmpty(approvalRecord) || !approvalRecord.getDecision().equals(PASS.getMsg())) &&
|
|
|
+ (ObjectUtils.isEmpty(financeApprovalRecord) || !financeApprovalRecord.getDecision().equals(PASS.getMsg())))//未审批通过
|
|
|
throw new DescribeException(DISBURSEMENT_HAS_BEEN_REJECTED);
|
|
|
}
|
|
|
}
|
|
|
@@ -293,17 +297,35 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
recordId = disbursementRecord.getId();
|
|
|
}
|
|
|
|
|
|
+ //更新合同实际出款金额状态
|
|
|
+ List<ContractVO> contracts = contractService.findContractByCaseId(caseId);
|
|
|
+ Map<Long, Boolean> contractIdAndIsComplete = disbursementRecordDTO.getContractIdAndIsComplete();
|
|
|
+ for (ContractVO contract : contracts){
|
|
|
+ if (contract.getIsDisbursementComplete().equals(contractIdAndIsComplete.get(contract.getId())))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ contractService.updateIsDisbursementById(contract.getId(), contractIdAndIsComplete.get(contract.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
//设置计划与合同对应
|
|
|
Map<Long, Double> contractAndAmount = disbursementRecordDTO.getContractIdAndAmount();
|
|
|
- contractDisbursementService.addContractDisbursement(contractAndAmount, recordId, false);
|
|
|
+ contractDisbursementService.addContractDisbursement(contractAndAmount, recordId,caseId, false);
|
|
|
|
|
|
//添加当票信息
|
|
|
- pawnTicketService.addPawnTicket(disbursementStartDTO.getContractAndPawn(), recordId, disbursementRecordDTO.getCreateTime(), caseId);
|
|
|
+ pawnTicketService.addPawnTicket(disbursementStartDTO.getContractAndPawn(), recordId,contractAndAmount, disbursementRecordDTO.getCreateTime(), caseId);
|
|
|
new RedisData(redisTemplate).deleteApprovalByKey(caseId, StepPropertyEnum.DISBURSE_START.getLabel(), StepPropertyEnum.DISBURSE_START.getCode());
|
|
|
|
|
|
//修改状态
|
|
|
stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.DISBURSE_START.getCode(), BaseContext.getCurrentId(), caseId);
|
|
|
- if (isComplete || disburseIsComplete(caseId))
|
|
|
+ Map<Long, Boolean> complete = disbursementRecordDTO.getContractIdAndIsComplete();
|
|
|
+ boolean flag = true;
|
|
|
+ for (Boolean aBoolean : complete.values()) {
|
|
|
+ if (!aBoolean) {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag || disburseIsComplete(caseId))
|
|
|
stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.DISBURSE_START.getCode(), caseId);
|
|
|
stepService.tryStartStep(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
|
|
|
|
|
|
@@ -349,7 +371,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
//修改状态
|
|
|
stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.DISBURSE_AUDIT.getCode(), BaseContext.getCurrentId(), caseId);
|
|
|
|
|
|
- if (decision.equals(DecisionEnum.PASS.getMsg())) {
|
|
|
+ if (decision.equals(PASS.getMsg())) {
|
|
|
StepVO step = stepService.findByStepCodeAndCaseId(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
|
|
|
if (ApprovalIsCompleted(caseId, StepPropertyEnum.DISBURSE_AUDIT.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
|
|
|
stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.DISBURSE_AUDIT.getCode(), caseId);
|
|
|
@@ -381,7 +403,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
DisbursementRecord disbursementRecord = disbursementRecordService.addDisbursementRecord(disbursementRecordDTO);
|
|
|
//绑定出款记录与合同id
|
|
|
Map<Long, Double> contractIdAndAmount = disbursementRecordDTO.getContractIdAndAmount();
|
|
|
- contractDisbursementService.addContractDisbursement(contractIdAndAmount, disbursementRecord.getId(), false);
|
|
|
+ contractDisbursementService.addContractDisbursement(contractIdAndAmount, disbursementRecord.getId(), caseId,false);
|
|
|
}
|
|
|
|
|
|
stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.FINANCE_DISBURSE.getCode(), BaseContext.getCurrentId(), caseId);
|
|
|
@@ -431,6 +453,8 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
Map<Long, UserVO> userVOMap2 = new HashMap<>();
|
|
|
if (!ObjectUtils.isEmpty(disbursementDetailVO)) {
|
|
|
//1.List<DisbursementVO> disbursementPlans;
|
|
|
+ Double currentPlanAmount = 0.0;
|
|
|
+ Double currentPlanAmount1 = 0.0;
|
|
|
List<Disbursement> plans = disbursementRepository.findDisbursementsByCaseId(caseId, false);
|
|
|
List<DisbursementVO> planVOs = new ArrayList<>();
|
|
|
for (Disbursement plan : plans) {
|
|
|
@@ -439,6 +463,9 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
if (user != null)
|
|
|
disbursementVO.setOperatorUser(BeanUtil.copyProperties(user, UserVO.class));
|
|
|
disbursementVO.setLocationDatum(locationDatumService.findById(plan.getLocationId()));
|
|
|
+
|
|
|
+ currentPlanAmount += plan.getPlannedAmount();
|
|
|
+
|
|
|
ApprovalRecord approvalRecord = approvalService.findByIdAndIsDelete(plan.getApprovalId());
|
|
|
if (approvalRecord != null) {
|
|
|
ApprovalRecordVO approvalRecordVO = BeanUtil.copyProperties(approvalRecord, ApprovalRecordVO.class);
|
|
|
@@ -446,6 +473,9 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
if (approver != null)
|
|
|
approvalRecordVO.setApprover(BeanUtil.copyProperties(approver, UserVO.class));
|
|
|
disbursementVO.setApprovalRecordVO(approvalRecordVO);
|
|
|
+
|
|
|
+ if (approvalRecord.getDecision().equals(PASS.getMsg()))
|
|
|
+ currentPlanAmount1 += plan.getPlannedAmount();
|
|
|
}
|
|
|
User user1 = userService.findByIdAndIsDelete(plan.getMainUserId());
|
|
|
if (user1 != null) {
|
|
|
@@ -470,13 +500,19 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
planVOs.add(disbursementVO);
|
|
|
}
|
|
|
disbursementDetailVO.setDisbursementPlans(planVOs);
|
|
|
+ disbursementDetailVO.setCurrentPlanAmount(currentPlanAmount);
|
|
|
+ disbursementDetailVO.setCurrentPlanAmount1(currentPlanAmount1);
|
|
|
|
|
|
//2.private List<DisbursementRecordVO> disbursementRecords;
|
|
|
List<DisbursementRecordVO> records = disbursementRecordService.findRecordVOByCaseId(caseId);
|
|
|
- double currentAmount = 0;
|
|
|
+ double currentAmount = 0.0;
|
|
|
+ double currentAmount1 = 0.0;
|
|
|
Map<Long, Double> contractAndCurrentAmount = new HashMap<>();//合同的目前总金额
|
|
|
for (int i = 0; i < records.size(); i++) {
|
|
|
DisbursementRecordVO record = records.get(i);
|
|
|
+ List<ApprovalRecordVO> financeApprovalRecordVOs = record.getFinanceApprovalRecordVOs();
|
|
|
+ if (financeApprovalRecordVOs != null && financeApprovalRecordVOs.get(financeApprovalRecordVOs.size()-1).getDecision().equals(PASS.getMsg()))
|
|
|
+ currentAmount1 += record.getAmount();//财务通过了才算实际出账
|
|
|
currentAmount += record.getAmount();
|
|
|
|
|
|
Long recordId = record.getId();
|
|
|
@@ -508,9 +544,13 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
disbursementDetailVO.setContractAndCurrentAmount(contractAndCurrentAmount);
|
|
|
// 6.private Double currentAmount;//目前金额
|
|
|
disbursementDetailVO.setCurrentAmount(currentAmount);
|
|
|
+ disbursementDetailVO.setCurrentAmount1(currentAmount1);
|
|
|
// 7. private Double totalAmount;//总金额
|
|
|
- disbursementDetailVO.setTotalAmount(disbursementDetailVO.getLoanCase().getTotalLoanAmount());
|
|
|
+ List<ContractVO> contracts = contractService.findContractByCaseId(caseId);
|
|
|
+ disbursementDetailVO.setTotalAmount(contracts.stream().reduce(0.0 , (sum,contract)-> sum+contract.getActualAmount(),Double::sum));
|
|
|
|
|
|
+ List<Long> contractIds = contracts.stream().map(ContractVO::getId).collect(Collectors.toList());
|
|
|
+ disbursementDetailVO.setContractBankInfos(contractBankInfoService.listContractBankInfoByIds(contractIds,disbursementDetailVO.getLoanCase()));
|
|
|
// 5.private List<String> collateralStatus;//押品状态
|
|
|
List<CollateralVO> collateralVOS = collateralService.findByCaseId(caseId);
|
|
|
List<String> collateralStatus = new ArrayList<>();
|
|
|
@@ -523,6 +563,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
disbursementDetailVO.setCollateralStatus(collateralStatus);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
//获取每个合同的出款时间
|
|
|
disbursementDetailVO.setContractAndDateAndAmount(getDateAndAmount(caseId));
|
|
|
|
|
|
@@ -536,13 +577,12 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
List<DisbursementRecordVO> disbursementRecordVOS = disbursementRecordService.findRecordVOByCaseId(caseId);
|
|
|
//按合同划分
|
|
|
for (DisbursementRecordVO disbursementRecordVO : disbursementRecordVOS) {
|
|
|
- DateAndAmountPOJO dateAndAmountPOJO = new DateAndAmountPOJO();
|
|
|
- // 将日期时间格式转换为日期格式
|
|
|
- dateAndAmountPOJO.setDate(disbursementRecordVO.getCreateTime());
|
|
|
-
|
|
|
//寻找该记录的合同
|
|
|
List<ContractDisbursement> contractDisbursements = contractDisbursementService.findByRecordIdAndIsPlan(disbursementRecordVO.getId(), false);
|
|
|
for (ContractDisbursement contractDisbursement : contractDisbursements) {
|
|
|
+ DateAndAmountPOJO dateAndAmountPOJO = new DateAndAmountPOJO();
|
|
|
+ // 将日期时间格式转换为日期格式
|
|
|
+ dateAndAmountPOJO.setDate(disbursementRecordVO.getCreateTime());
|
|
|
dateAndAmountPOJO.setAmount(contractDisbursement.getAmount());
|
|
|
result.computeIfAbsent(contractDisbursement.getContractId(), k -> new ArrayList<>()).add(dateAndAmountPOJO);
|
|
|
}
|
|
|
@@ -552,7 +592,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
Map<Long, List<DateAndAmountPOJO>> processedResult = new HashMap<>();
|
|
|
for (Map.Entry<Long, List<DateAndAmountPOJO>> entry : result.entrySet()) {
|
|
|
Long contractId = entry.getKey();
|
|
|
- List<DateAndAmountPOJO> originalList = entry.getValue();
|
|
|
+ List<DateAndAmountPOJO> originalList = entry.getValue();//原始的时间---现在要合并同一天
|
|
|
Map<String, Double> dateAmountMap = new HashMap<>();
|
|
|
|
|
|
// 按日期累加金额
|
|
|
@@ -579,6 +619,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
processedResult.put(contractId, processedList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//返回每个合同对应的出款时间即金额
|
|
|
return processedResult;
|
|
|
}
|
|
|
@@ -621,16 +662,21 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
//修改状态
|
|
|
stepService.updateUserId1ByCaseIdAndStepCode(StepPropertyEnum.FINANCE_DISBURSE.getCode(), BaseContext.getCurrentId(), caseId);
|
|
|
|
|
|
- if (decision.equals(DecisionEnum.PASS.getMsg())) {
|
|
|
- //修改当前合同的出款金额
|
|
|
+ if (decision.equals(PASS.getMsg())) {
|
|
|
+ StepVO step = stepService.findByStepCodeAndCaseId(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
|
|
|
+
|
|
|
+ //设置实际的合同出款金额
|
|
|
List<ContractDisbursement> contractDisbursements = contractDisbursementService.findByCaseIdAndIsPlan(caseId, false);
|
|
|
Map<Long, Double> contractIdAndAmount = new HashMap<>();
|
|
|
for (ContractDisbursement contractDisbursement : contractDisbursements) {
|
|
|
contractIdAndAmount.merge(contractDisbursement.getContractId(), contractDisbursement.getAmount(), Double::sum);
|
|
|
}
|
|
|
- contractService.updateActualAmountByIds(contractIdAndAmount);
|
|
|
+ if(step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
|
|
|
+ contractService.updateActualAmountAndIsCompleteByIds(contractIdAndAmount,true);
|
|
|
+ else
|
|
|
+ contractService.updateActualAmountAndIsCompleteByIds(contractIdAndAmount,false);
|
|
|
+
|
|
|
|
|
|
- StepVO step = stepService.findByStepCodeAndCaseId(StepPropertyEnum.DISBURSE_START.getCode(), caseId);
|
|
|
if (ApprovalIsCompleted(caseId, StepPropertyEnum.FINANCE_DISBURSE.getCode()) && step.getStatus().equals(StepEnum.COMPLETED.getMsg()))
|
|
|
stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.FINANCE_DISBURSE.getCode(), caseId);
|
|
|
stepService.tryStartStep(StepPropertyEnum.FINANCE_DISBURSE.getCode(), caseId);
|
|
|
@@ -690,7 +736,7 @@ public class DisbursementServiceImpl implements DisbursementService {
|
|
|
|
|
|
List<ApprovalRecordVO> approvalRecordVOS = approvalService.findByIdsAndIsDelete(approvals);
|
|
|
for (ApprovalRecordVO approvalRecordVO : approvalRecordVOS)
|
|
|
- if (!approvalRecordVO.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ if (!approvalRecordVO.getDecision().equals(PASS.getMsg()))
|
|
|
return false;
|
|
|
|
|
|
return true;
|