| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | |
| | | return R.failed("客商查询失败,请检查客商"); |
| | | } |
| | | |
| | | PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | BigDecimal lastTotal = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | lastTotal = lastConfirm.getTotalAmount(); |
| | | } |
| | | |
| | | |
| | | //转入 |
| | | if (StrUtil.equals(addDTO.getInOrOut(), "1")) { |
| | | //保存收款单 |
| | | savePaymentSlip(addDTO,customer,contract); |
| | | //保存收款单 |
| | | savePaymentConfirm(addDTO,contract,customer); |
| | | //处理收款 |
| | | handleSlipToSchedule(addDTO,contract); |
| | | //更新状态 |
| | | updateContractStatus(addDTO,contract); |
| | | } |
| | | //转出 |
| | | if (StrUtil.equals(addDTO.getInOrOut(), "2")) { |
| | | return handleBackSlip(addDTO,contract,customer); |
| | | } |
| | | |
| | | } |
| | | |
| | | //新增付款单 |
| | | PaymentSlip slip = new PaymentSlip(); |
| | | slip.setBusGuestId(customer.getId()); |
| | | slip.setBusGuestName(customer.getCompanyName()); |
| | | slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); |
| | | slip.setPaymentTime(addDTO.getConfirmTime()); |
| | | slip.setPaymentAmount(addDTO.getTransationAmount()); |
| | | slip.setPayType(addDTO.getPayType()); |
| | | slip.setContractId(contract.getId()); |
| | | paymentSlipMapper.insert(slip); |
| | | return R.ok(); |
| | | } |
| | | |
| | | BigDecimal newtotal = addDTO.getTransationAmount().add(lastTotal); |
| | | PaymentConfirm entity = new PaymentConfirm(); |
| | | entity.setContractId(contract.getId()); |
| | | entity.setContractName(contract.getContractName()); |
| | | entity.setContractNo(addDTO.getContractNo()); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | entity.setScheduleId(lastConfirm.getScheduleId()); |
| | | entity.setScheduleName(lastConfirm.getScheduleName()); |
| | | } |
| | | entity.setBusGuestId(customer.getId()); |
| | | entity.setBusGuestName(customer.getCompanyName()); |
| | | entity.setBusinessType("客户付款"); |
| | | if (newtotal.compareTo(new BigDecimal("0")) > 0) { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setAdvanceAmount(newtotal); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } else { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setReceivableAmount(newtotal.multiply(new BigDecimal("-1"))); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } |
| | | private R handleBackSlip(PaymentConfirmAddDTO addDTO,Contract contract,BusinessCustomer customer) { |
| | | PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | PaymentConfirm entity = new PaymentConfirm(); |
| | | entity.setContractId(contract.getId()); |
| | | entity.setContractName(contract.getContractName()); |
| | | entity.setContractNo(contract.getContractNo()); |
| | | |
| | | //更新付款阶段付款 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (CollUtil.isNotEmpty(scheduleList)) { |
| | | BigDecimal remain = addDTO.getTransationAmount(); |
| | | for (ContractPaymentSchedule schedule : scheduleList) { |
| | | BigDecimal lastRemain = remain; |
| | | remain = remain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : |
| | | schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | if (remain.compareTo(new BigDecimal("0")) >= 0) { |
| | | schedule.setActualAmount(schedule.getPlannedAmount()); |
| | | schedule.setPaymentDate(addDTO.getConfirmTime()); |
| | | schedule.setPaymentStatus(2); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //查询是否有当前逾期 |
| | | CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(currentOverdue)) { |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //删除当前逾期 |
| | | currentOverdueMapper.deleteById(currentOverdue); |
| | | } |
| | | } else { |
| | | schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : |
| | | schedule.getActualAmount().add(lastRemain)); |
| | | schedule.setPaymentDate(addDTO.getConfirmTime()); |
| | | schedule.setPaymentStatus(1); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //查询是否有当前逾期 |
| | | CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(currentOverdue)) { |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | historyOverdue.setReceivableAmount(lastRemain); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //更新当前逾期 |
| | | currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | currentOverdueMapper.updateById(currentOverdue); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //非房屋租赁 水电 |
| | | if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | entity.setBusGuestId(customer.getId()); |
| | | entity.setBusGuestName(customer.getCompanyName()); |
| | | entity.setBusinessType("退款"); |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | BigDecimal newtotal = addDTO.getTransationAmount().multiply(new BigDecimal("-1")).add(lastConfirm.getTotalAmount()); |
| | | if (newtotal.compareTo(new BigDecimal("0")) > 0) { |
| | | entity.setAdvanceAmount(newtotal); |
| | | entity.setTotalAmount(newtotal); |
| | | } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { |
| | | entity.setTotalAmount(newtotal); |
| | | } else { |
| | | return R.failed("当前客户余额为" + lastConfirm.getTotalAmount() + "不足以满足当前发生金额,无法操作"); |
| | | } |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | contract.setPaidAmount(contract.getPaidAmount().subtract(addDTO.getTransationAmount())); |
| | | contract.setContractStatus(2); |
| | | contractService.updateById(contract); |
| | | return R.ok(); |
| | | } |
| | | |
| | | private void updateContractStatus(PaymentConfirmAddDTO addDTO,Contract contract) { |
| | | |
| | | //非房屋租赁 水电 |
| | | if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | //更新合同已付款 |
| | | BigDecimal paid = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(contract.getPaidAmount())) { |
| | | paid = contract.getPaidAmount(); |
| | | } |
| | | paid = paid.add(addDTO.getTransationAmount()); |
| | | contract.setPaidAmount(paid); |
| | | if (paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&&contract.getBillingAmout().compareTo(contract.getAmount())==0) { |
| | | contract.setContractStatus(3); |
| | | contract.setPaidAmount(contract.getAmount().subtract(contract.getDropAmount())); |
| | | } |
| | | contractService.updateById(contract); |
| | | }else { |
| | | List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId()) |
| | | .eq(ContractExecDate::getGenFlag,"0")); |
| | | if (CollUtil.isEmpty(execDateList)){ |
| | | //更新合同已付款 |
| | | BigDecimal paid = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(contract.getPaidAmount())) { |
| | |
| | | } |
| | | paid = paid.add(addDTO.getTransationAmount()); |
| | | contract.setPaidAmount(paid); |
| | | if (paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) == 0&&contract.getBillingAmout().compareTo(contract.getAmount())==0) { |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount())==0&&paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) { |
| | | contract.setContractStatus(3); |
| | | contract.setPaidAmount(contract.getAmount().subtract(contract.getDropAmount())); |
| | | contract.setPaidAmount(contract.getAmount()); |
| | | } |
| | | contractService.updateById(contract); |
| | | }else { |
| | | List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId()) |
| | | .eq(ContractExecDate::getGenFlag,"0")); |
| | | if (CollUtil.isEmpty(execDateList)){ |
| | | //更新合同已付款 |
| | | BigDecimal paid = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(contract.getPaidAmount())) { |
| | | paid = contract.getPaidAmount(); |
| | | } |
| | | paid = paid.add(addDTO.getTransationAmount()); |
| | | contract.setPaidAmount(paid); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount())==0&&paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) { |
| | | contract.setContractStatus(3); |
| | | contract.setPaidAmount(contract.getAmount()); |
| | | } |
| | | contractService.updateById(contract); |
| | | } |
| | | } |
| | | //转出 |
| | | if (StrUtil.equals(addDTO.getInOrOut(), "2")) { |
| | | PaymentConfirm entity = new PaymentConfirm(); |
| | | entity.setContractId(contract.getId()); |
| | | entity.setContractName(contract.getContractName()); |
| | | entity.setContractNo(addDTO.getContractNo()); |
| | | |
| | | entity.setBusGuestId(customer.getId()); |
| | | entity.setBusGuestName(customer.getCompanyName()); |
| | | entity.setBusinessType("退款"); |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | BigDecimal newtotal = addDTO.getTransationAmount().multiply(new BigDecimal("-1")).add(lastConfirm.getTotalAmount()); |
| | | if (newtotal.compareTo(new BigDecimal("0")) > 0) { |
| | | entity.setAdvanceAmount(newtotal); |
| | | entity.setTotalAmount(newtotal); |
| | | } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { |
| | | entity.setTotalAmount(newtotal); |
| | | } else { |
| | | return R.failed("当前客户余额为" + lastConfirm.getTotalAmount() + "不足以满足当前发生金额,无法操作"); |
| | | } |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } |
| | | |
| | | } |
| | | // else { |
| | | // |
| | | // List<Contract> customerContractList = contractService.list(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, addDTO.getBusGuestId()) |
| | | // .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).orderByAsc(Contract::getCreateTime) |
| | | // .apply(" ((contract_category != 'water_house' and amount != paid_amount) or contract_category = 'water_house')")); |
| | | // if (ArrayUtil.isEmpty(customerContractList)) { |
| | | // return R.failed("为查询到未付款合同"); |
| | | // } |
| | | // BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() |
| | | // .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getRegisterName, addDTO.getBusGuestName()) |
| | | // .eq(ObjUtil.isNotNull(addDTO.getBusGuestId()), BusinessCustomer::getId, addDTO.getBusGuestId()) |
| | | // .last("limit 1")); |
| | | // if (ObjUtil.isNull(customer)) { |
| | | // return R.failed("客商查询失败"); |
| | | // } |
| | | // //新增付款单 |
| | | // PaymentSlip slip = new PaymentSlip(); |
| | | // slip.setBusGuestId(customer.getId()); |
| | | // slip.setBusGuestName(customer.getRegisterName()); |
| | | // slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); |
| | | // slip.setPaymentTime(addDTO.getConfirmTime()); |
| | | // slip.setPaymentAmount(addDTO.getTransationAmount()); |
| | | // slip.setPayType(addDTO.getPayType()); |
| | | // paymentSlipMapper.insert(slip); |
| | | // |
| | | // BigDecimal transtionAmount = addDTO.getTransationAmount(); |
| | | // //剩余付款 |
| | | // BigDecimal transtionRemainAmount = transtionAmount; |
| | | // //收到付款的合同 |
| | | // List<Contract> payContractList = new ArrayList<>(); |
| | | // //付款完成的合同 |
| | | // List<Contract> payCompleteContractList = new ArrayList<>(); |
| | | // //付款未完成的合同 |
| | | // List<Contract> payNoCompleteContractList = new ArrayList<>(); |
| | | // //有预付款的合同 |
| | | // List<Contract> advanceContractList = new ArrayList<>(); |
| | | // //付款时间 |
| | | // Date payDate = addDTO.getConfirmTime(); |
| | | // Iterator<Contract> iterator = customerContractList.iterator(); |
| | | // while (iterator.hasNext()) { |
| | | // Contract contract = iterator.next(); |
| | | // PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | // .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | // BigDecimal lastTotal = new BigDecimal("0"); |
| | | // if (ObjUtil.isNotNull(lastConfirm)) { |
| | | // lastTotal = lastConfirm.getTotalAmount(); |
| | | // } else { |
| | | // |
| | | // } |
| | | // |
| | | // //合同最近明细总额为0 或 > 0 情况下 |
| | | // if (lastTotal.compareTo(new BigDecimal("0")) >= 0) { |
| | | // log.info("当前合同号:{},明细总额无应收款", contract.getContractNo()); |
| | | // advanceContractList.add(contract); |
| | | // if (iterator.hasNext()) { |
| | | // continue; |
| | | // } |
| | | // } |
| | | // |
| | | // transtionRemainAmount = transtionRemainAmount.add(lastTotal); |
| | | // PaymentConfirm entity = new PaymentConfirm(); |
| | | // entity.setContractId(contract.getId()); |
| | | // entity.setContractName(contract.getContractName()); |
| | | // entity.setContractNo(contract.getContractNo()); |
| | | // if (ObjUtil.isNotNull(lastConfirm)) { |
| | | // entity.setScheduleId(lastConfirm.getScheduleId()); |
| | | // entity.setScheduleName(lastConfirm.getScheduleName()); |
| | | // } |
| | | // entity.setBusGuestId(customer.getId()); |
| | | // entity.setBusGuestName(customer.getRegisterName()); |
| | | // entity.setBusinessType("客户付款"); |
| | | // if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) { |
| | | // entity.setConfirmTime(payDate); |
| | | // // 判断是否是最后一个 |
| | | // if (!iterator.hasNext()) { |
| | | // entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal)); |
| | | // entity.setAdvanceAmount(transtionRemainAmount); |
| | | // entity.setTotalAmount(transtionRemainAmount); |
| | | // } else { |
| | | // entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1"))); |
| | | // entity.setTotalAmount(new BigDecimal("0")); |
| | | // } |
| | | // baseMapper.insert(entity); |
| | | // payContractList.add(contract); |
| | | // } else if (transtionRemainAmount.compareTo(new BigDecimal("0")) == 0) { |
| | | // entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1"))); |
| | | // entity.setTotalAmount(new BigDecimal("0")); |
| | | // entity.setConfirmTime(payDate); |
| | | // baseMapper.insert(entity); |
| | | // payContractList.add(contract); |
| | | // break; |
| | | // } else { |
| | | // entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal)); |
| | | // entity.setReceivableAmount(transtionRemainAmount.multiply(new BigDecimal("-1"))); |
| | | // entity.setTotalAmount(transtionRemainAmount); |
| | | // entity.setConfirmTime(payDate); |
| | | // baseMapper.insert(entity); |
| | | // payContractList.add(contract); |
| | | // break; |
| | | // } |
| | | // } |
| | | // |
| | | // payContractList.stream().forEach(contract -> { |
| | | // //更新付款阶段付款 |
| | | // List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2) |
| | | // .ne(ContractPaymentSchedule::getPaymentStatus, 3) |
| | | // .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | // if (ArrayUtil.isNotEmpty(scheduleList)) { |
| | | // BigDecimal remain = transtionAmount; |
| | | // for (ContractPaymentSchedule schedule : scheduleList) { |
| | | // BigDecimal lastRemain = remain; |
| | | // remain = lastRemain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : |
| | | // schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | // if (remain.compareTo(new BigDecimal("0")) >= 0) { |
| | | // schedule.setActualAmount(schedule.getPlannedAmount()); |
| | | // schedule.setPaymentDate(payDate); |
| | | // schedule.setPaymentStatus(2); |
| | | // contractPaymentScheduleMapper.updateById(schedule); |
| | | // //查询是否有当前逾期 |
| | | // CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | // .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | // if (ObjUtil.isNotNull(currentOverdue)) { |
| | | // //新增逾期历史 |
| | | // HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | // historyOverdue.setPaymentTime(payDate); |
| | | // historyOverdue.setCompId(schedule.getCompId()); |
| | | // historyOverdueMapper.insert(historyOverdue); |
| | | // //删除当前逾期 |
| | | // currentOverdueMapper.deleteById(currentOverdue); |
| | | // } |
| | | // } else { |
| | | // schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : |
| | | // schedule.getActualAmount().add(lastRemain)); |
| | | // schedule.setPaymentDate(payDate); |
| | | // schedule.setPaymentStatus(1); |
| | | // contractPaymentScheduleMapper.updateById(schedule); |
| | | // //查询是否有当前逾期 |
| | | // CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | // .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | // if (ObjUtil.isNotNull(currentOverdue)) { |
| | | // //新增逾期历史 |
| | | // HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | // historyOverdue.setReceivableAmount(lastRemain); |
| | | // historyOverdue.setPaymentTime(payDate); |
| | | // historyOverdue.setCompId(schedule.getCompId()); |
| | | // historyOverdueMapper.insert(historyOverdue); |
| | | // //查询历史已付逾期金额 |
| | | // List<HistoryOverdue> historyOverdueList = historyOverdueMapper.selectList(Wrappers.<HistoryOverdue>lambdaQuery().eq(HistoryOverdue::getScheduleId, currentOverdue.getScheduleId())); |
| | | // BigDecimal hisTotal = historyOverdueList.stream().map(item -> item.getReceivableAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // //更新当前逾期 |
| | | // currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(hisTotal)); |
| | | // currentOverdueMapper.updateById(currentOverdue); |
| | | // } |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // //合同所有付款阶段 |
| | | // List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0) |
| | | // .ne(ContractPaymentSchedule::getPaymentStatus, 3)); |
| | | // if (ArrayUtil.isNotEmpty(payComScheduleList)) { |
| | | // BigDecimal payTotal = payComScheduleList.stream().map(item -> StrUtil.equals(item.getPaymentStatus() + "", "2") ? item.getPlannedAmount() : |
| | | // item.getActualAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // contract.setPaidAmount(payTotal); |
| | | //// if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { |
| | | //// contract.setContractStatus(3); |
| | | //// } |
| | | // if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) { |
| | | // |
| | | // contract.setContractStatus(3); |
| | | // payCompleteContractList.add(contract); |
| | | // } |
| | | // //付款 且 付款未全付 |
| | | // if (contract.getAmount().compareTo(contract.getPaidAmount()) > 0) { |
| | | // payNoCompleteContractList.add(contract); |
| | | // } |
| | | // if (StrUtil.isNotEmpty(contract.getContractCategory()) && StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | // List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery() |
| | | // .eq(ContractExecDate::getContractId, contract.getId()).eq(ContractExecDate::getGenFlag, "0")); |
| | | // if (ArrayUtil.isEmpty(execDateList)) { |
| | | // List<ContractPaymentSchedule> contractPaymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId())); |
| | | // if (ArrayUtil.isNotEmpty(contractPaymentScheduleList) && contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { |
| | | // contract.setContractStatus(3); |
| | | // contractService.updateById(contract); |
| | | // } |
| | | // } |
| | | // } else { |
| | | // contractService.updateById(contract); |
| | | // } |
| | | // |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | //客户预付有剩余 且 有预付款的合同 |
| | | // if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) { |
| | | // if (ArrayUtil.isNotEmpty(payNoCompleteContractList)){ |
| | | // //余额 放到付款未完成合同 预收 |
| | | // Contract lastContract = payNoCompleteContractList.get(0); |
| | | // //保存明细 |
| | | // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); |
| | | // } |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isNotEmpty(advanceContractList)){ |
| | | // //客户预付有剩余 没有预付款的合同 |
| | | // Contract lastContract = advanceContractList.get(0); |
| | | // //保存明细 |
| | | // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); |
| | | // } |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isEmpty(advanceContractList) |
| | | // &&ArrayUtil.isNotEmpty(payCompleteContractList)) { |
| | | // //客户预付有剩余 没有预付款的合同 |
| | | // Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1); |
| | | // //保存明细 |
| | | // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); |
| | | // |
| | | // } |
| | | // } |
| | | // } |
| | | return R.ok(); |
| | | private void handleSlipToSchedule(PaymentConfirmAddDTO addDTO,Contract contract) { |
| | | //更新付款阶段付款 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (CollUtil.isNotEmpty(scheduleList)) { |
| | | BigDecimal remain = addDTO.getTransationAmount(); |
| | | for (ContractPaymentSchedule schedule : scheduleList) { |
| | | BigDecimal lastRemain = remain; |
| | | remain = remain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : |
| | | schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | if (remain.compareTo(new BigDecimal("0")) >= 0) { |
| | | schedule.setActualAmount(schedule.getPlannedAmount()); |
| | | schedule.setPaymentDate(addDTO.getConfirmTime()); |
| | | schedule.setPaymentStatus(2); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //查询是否有当前逾期 |
| | | CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(currentOverdue)) { |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //删除当前逾期 |
| | | currentOverdueMapper.deleteById(currentOverdue); |
| | | } |
| | | } else { |
| | | schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : |
| | | schedule.getActualAmount().add(lastRemain)); |
| | | schedule.setPaymentDate(addDTO.getConfirmTime()); |
| | | schedule.setPaymentStatus(1); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //查询是否有当前逾期 |
| | | CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) |
| | | .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(currentOverdue)) { |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); |
| | | historyOverdue.setReceivableAmount(lastRemain); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //更新当前逾期 |
| | | currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | currentOverdueMapper.updateById(currentOverdue); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void savePaymentConfirm(PaymentConfirmAddDTO addDTO,Contract contract,BusinessCustomer customer) { |
| | | |
| | | PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | BigDecimal lastTotal = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | lastTotal = lastConfirm.getTotalAmount(); |
| | | } |
| | | BigDecimal newtotal = addDTO.getTransationAmount().add(lastTotal); |
| | | PaymentConfirm entity = new PaymentConfirm(); |
| | | entity.setContractId(contract.getId()); |
| | | entity.setContractName(contract.getContractName()); |
| | | entity.setContractNo(addDTO.getContractNo()); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | entity.setScheduleId(lastConfirm.getScheduleId()); |
| | | entity.setScheduleName(lastConfirm.getScheduleName()); |
| | | } |
| | | entity.setBusGuestId(customer.getId()); |
| | | entity.setBusGuestName(customer.getCompanyName()); |
| | | entity.setBusinessType("客户付款"); |
| | | if (newtotal.compareTo(new BigDecimal("0")) > 0) { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setAdvanceAmount(newtotal); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } else { |
| | | entity.setTransationAmount(addDTO.getTransationAmount()); |
| | | entity.setReceivableAmount(newtotal.multiply(new BigDecimal("-1"))); |
| | | entity.setTotalAmount(newtotal); |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } |
| | | } |
| | | |
| | | private void savePaymentSlip(PaymentConfirmAddDTO addDTO,BusinessCustomer customer,Contract contract) { |
| | | //新增付款单 |
| | | PaymentSlip slip = new PaymentSlip(); |
| | | slip.setBusGuestId(customer.getId()); |
| | | slip.setBusGuestName(customer.getCompanyName()); |
| | | slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); |
| | | slip.setPaymentTime(addDTO.getConfirmTime()); |
| | | slip.setPaymentAmount(addDTO.getTransationAmount()); |
| | | slip.setPayType(addDTO.getPayType()); |
| | | slip.setContractId(contract.getId()); |
| | | paymentSlipMapper.insert(slip); |
| | | } |
| | | |
| | | @Override |
| | |
| | | }else { |
| | | params.put("enddate", DateUtil.today()); |
| | | } |
| | | params.put("dc_flag","2");//1 借 2 贷 只查收款 银行角度所以是 贷 |
| | | //单据状态已审批 |
| | | params.put("accentity_code", bipCode); |
| | | String finalAccessToken = accessToken; |
| | |
| | | return; |
| | | } |
| | | log.info("==================开始处理银行流水信息==================="); |
| | | recordList.stream().forEach(record -> { |
| | | |
| | | savePaymentConfirm((JSONObject) record, dept); |
| | | recordList.stream().forEach(obj -> { |
| | | JSONObject record = (JSONObject) obj; |
| | | BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() |
| | | .eq(BusinessCustomer::getCompanyName, record.getString("to_acct_name")) |
| | | .eq(BusinessCustomer::getCompId,dept.getDeptId()) |
| | | ); |
| | | //保存付款单 |
| | | Boolean codeFlag = saveBankStatement(customer, record,dept); |
| | | if (!codeFlag) { |
| | | log.error("付款单id:{},付款单已存在"); |
| | | } |
| | | }); |
| | | log.info("==================结束处理银行流水信息==================="); |
| | | } |
| | | |
| | | private void savePaymentConfirm(JSONObject record, SysDept dept) { |
| | | |
| | | |
| | | BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() |
| | | .eq(BusinessCustomer::getCompanyName, record.getString("to_acct_name")) |
| | | .eq(BusinessCustomer::getCompId,dept.getDeptId()) |
| | | ); |
| | | //保存付款单 |
| | | Boolean codeFlag = saveBankStatement(customer, record,dept); |
| | | if (codeFlag) { |
| | | log.error("付款单id:{},付款单已存在"); |
| | | return; |
| | | } |
| | | |
| | | } |
| | | |
| | | private Boolean saveBankStatement(BusinessCustomer customer, JSONObject record,SysDept dept) { |
| | |
| | | bankStatement.setPayBankAccName(record.getString("to_acct_name")); |
| | | bankStatement.setTranDate(DateUtil.parseDateTime(record.getString("tran_date"))); |
| | | bankStatement.setTranAmount(record.getBigDecimal("tran_amt")); |
| | | bankStatement.setDcFlag(record.getString("dc_flag")); |
| | | bankStatement.setDataId(record.getLong("id")); |
| | | bankStatement.setDataJson(record.toJSONString()); |
| | | if (ObjUtil.isNotNull(customer)) { |