| | |
| | | import com.ruoyi.cwgl.mapper.FundFlowMapper; |
| | | import com.ruoyi.cwgl.domain.FundFlowClaimDetail; |
| | | import com.ruoyi.cwgl.domain.FundFlow; |
| | | import com.ruoyi.cwgl.domain.FundFlowLog; |
| | | import com.ruoyi.cwgl.domain.ReceivableBillSettlementDetail; |
| | | import com.ruoyi.cwgl.domain.PayableBillSettlementDetail; |
| | | import com.ruoyi.cwgl.domain.ReceivableBillManagement; |
| | | import com.ruoyi.cwgl.domain.PayableBillManagement; |
| | | import com.ruoyi.cwgl.service.IFundFlowClaimDetailService; |
| | | import com.ruoyi.cwgl.service.IFundFlowLogService; |
| | | import com.ruoyi.cwgl.service.IReceivableBillSettlementDetailService; |
| | | import com.ruoyi.cwgl.service.IPayableBillSettlementDetailService; |
| | | import com.ruoyi.cwgl.service.IReceivableBillManagementService; |
| | |
| | | |
| | | @Resource |
| | | private IPayableBillManagementService payableBillManagementService; |
| | | |
| | | @Resource |
| | | private IFundFlowLogService fundFlowLogService; |
| | | |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public int deleteFundFlowClaimDetailByIds(Integer[] ids) |
| | | { |
| | | |
| | | |
| | | return fundFlowClaimDetailMapper.deleteFundFlowClaimDetailByIds(ids); |
| | | if (ids == null || ids.length == 0) { |
| | | throw new RuntimeException("删除的认领明细ID不能为空"); |
| | | } |
| | | |
| | | // 由于删除只会有一条记录,取第一条进行处理 |
| | | Integer id = ids[0]; |
| | | FundFlowClaimDetail claimDetail = fundFlowClaimDetailMapper.selectFundFlowClaimDetailById(id); |
| | | if (claimDetail == null) { |
| | | throw new RuntimeException("未找到要删除的认领明细记录,ID: " + id); |
| | | } |
| | | |
| | | Integer fundFlowId = claimDetail.getFundFlowId(); |
| | | BigDecimal deleteAmount = claimDetail.getClaimAmount(); |
| | | |
| | | // 查询资金流水信息 |
| | | FundFlow fundFlow = fundFlowMapper.selectFundFlowById(fundFlowId); |
| | | if (fundFlow == null) { |
| | | throw new RuntimeException("资金流水不存在,ID: " + fundFlowId); |
| | | } |
| | | |
| | | // 更新资金流水的已认领金额 |
| | | BigDecimal newClaimedAmount = fundFlow.getClaimedAmount().subtract(deleteAmount); |
| | | if (newClaimedAmount.compareTo(BigDecimal.ZERO) < 0) { |
| | | newClaimedAmount = BigDecimal.ZERO; |
| | | } |
| | | |
| | | // 根据新的认领金额设置状态 |
| | | String newStatus =fundFlow.getStatus(); |
| | | if (newClaimedAmount.compareTo(BigDecimal.ZERO) == 0) { |
| | | // 已认领金额为0,状态改为1(未认领) |
| | | newStatus = "1"; |
| | | } else if (newClaimedAmount.compareTo(fundFlow.getTransactionAmount()) < 0) { |
| | | // 已认领金额小于交易金额,状态改为2(部分认领) |
| | | newStatus = "2"; |
| | | } |
| | | |
| | | // 更新资金流水状态和已认领金额 |
| | | fundFlow.setStatus(newStatus); |
| | | fundFlow.setClaimedAmount(newClaimedAmount); |
| | | fundFlow.setUpdateTime(DateUtils.getNowDate()); |
| | | int updateResult = fundFlowMapper.updateFundFlow(fundFlow); |
| | | if (updateResult <= 0) { |
| | | throw new RuntimeException("更新资金流水状态失败,ID: " + fundFlowId); |
| | | } |
| | | |
| | | // 删除结算明细并更新账单状态 |
| | | deleteSettlementDetailsAndUpdateBillStatus(claimDetail,fundFlow); |
| | | |
| | | int result = fundFlowClaimDetailMapper.deleteFundFlowClaimDetailByIds(ids); |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | | FundFlowLog log = new FundFlowLog(); |
| | | log.setFlowId(fundFlowId); |
| | | log.setOperation("删除账单认领明细,账单编号:" + claimDetail.getBillNo() + ",认领金额:" + deleteAmount + ",资金流水号:" + fundFlow.getBankFlowNo()); |
| | | fundFlowLogService.insertFundFlowLog(log); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | // 新增:创建结算明细并更新账单状态 |
| | | if (insertResult > 0) { |
| | | |
| | | |
| | | createSettlementDetailsAndUpdateBillStatus(claimDetail, fundFlow); |
| | | |
| | | // 记录操作日志 |
| | | FundFlowLog log = new FundFlowLog(); |
| | | log.setFlowId(fundFlowId); |
| | | log.setOperation("新增账单认领明细,账单编号:" + claimDetail.getBillNo() + ",认领金额:" + claimAmount + ",资金流水号:" + fundFlow.getBankFlowNo()); |
| | | fundFlowLogService.insertFundFlowLog(log); |
| | | } |
| | | |
| | | return insertResult; |
| | |
| | | BigDecimal claimAmount = claimDetail.getClaimAmount(); |
| | | Integer claimDetailId = claimDetail.getId(); |
| | | |
| | | // 根据关联企业类型判断是应收账单还是应付账单 |
| | | // 根据收支标识借贷标志判断是应收账单还是应付账单 |
| | | if (fundFlow.getIncomeExpenseFlag().equals(0)) { |
| | | // 应收账单 |
| | | createReceivableSettlementDetail(billNo, claimAmount, fundFlow, claimDetailId); |
| | |
| | | settlementDetail.setClaimDetailId(claimDetailId); // 设置认领明细ID |
| | | settlementDetail.setReceiptAmount(claimAmount); |
| | | settlementDetail.setReceiptDate(fundFlow.getTransactionDate()); |
| | | settlementDetail.setSettlementMethod("银行转账"); // 根据实际情况设置 |
| | | settlementDetail.setSettlementMethod("0"); // 根据实际情况设置 |
| | | |
| | | // 设置银行账户信息 |
| | | settlementDetail.setCustomerBank(fundFlow.getOurBankName()); // 客户开户行(本方账户开户行) |
| | | settlementDetail.setCustomerBankAccount(fundFlow.getOurAccount()); // 客户银行账号(本方账号) |
| | | settlementDetail.setReceivingBank(fundFlow.getCounterpartyName()); // 收款账户开户行(对方户名) |
| | | settlementDetail.setReceivingBankAccount(fundFlow.getCounterpartyAccount()); // 收款银行账号(对方账号) |
| | | |
| | | settlementDetail.setCreateBy(SecurityUtils.getUsername()); |
| | | settlementDetail.setCreateTime(DateUtils.getNowDate()); |
| | | |
| | |
| | | settlementDetail.setClaimDetailId(claimDetailId); // 设置认领明细ID |
| | | settlementDetail.setPaymentAmount(claimAmount); |
| | | settlementDetail.setPaymentDate(fundFlow.getTransactionDate()); |
| | | settlementDetail.setSettlementMethod("银行转账"); // 根据实际情况设置 |
| | | settlementDetail.setSettlementMethod("0"); // 根据实际情况设置 |
| | | |
| | | // 设置银行账户信息 |
| | | settlementDetail.setPaymentBank(fundFlow.getOurBankName()); // 付款账户开户行(本方账户开户行) |
| | | settlementDetail.setPaymentBankAccount(fundFlow.getOurAccount()); // 付款账户银行账号(本方账号) |
| | | settlementDetail.setSupplierReceivingBank(fundFlow.getCounterpartyName()); // 供应商收款账户开户行(对方户名) |
| | | settlementDetail.setSupplierReceivingAccount(fundFlow.getCounterpartyAccount()); // 供应商收款银行账户(对方账号) |
| | | |
| | | settlementDetail.setCreateBy(SecurityUtils.getUsername()); |
| | | settlementDetail.setCreateTime(DateUtils.getNowDate()); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除结算明细并更新账单状态 |
| | | */ |
| | | private void deleteSettlementDetailsAndUpdateBillStatus(FundFlowClaimDetail claimDetail, FundFlow fundFlow) { |
| | | String billNo = claimDetail.getBillNo(); |
| | | Integer claimDetailId = claimDetail.getId(); |
| | | |
| | | try { |
| | | |
| | | |
| | | // 根据收支标识借贷标志判断是应收账单还是应付账单 |
| | | if (fundFlow.getIncomeExpenseFlag().equals(0)) { |
| | | // 应收账单 |
| | | deleteReceivableSettlementDetail(claimDetailId); |
| | | } else { |
| | | // 应付账单 |
| | | deletePayableSettlementDetail(claimDetailId); |
| | | } |
| | | |
| | | logger.info("成功删除结算明细,认领明细ID:{}", claimDetailId); |
| | | } catch (Exception e) { |
| | | logger.error("删除结算明细失败,认领明细ID:{}", claimDetailId, e); |
| | | // 这里可以选择抛出异常或记录日志,但不中断整个删除流程 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除应收账单结算明细 |
| | | */ |
| | | private void deleteReceivableSettlementDetail(Integer claimDetailId) { |
| | | try { |
| | | // 根据认领明细ID查询应收账单结算明细 |
| | | ReceivableBillSettlementDetail receivableQuery = new ReceivableBillSettlementDetail(); |
| | | receivableQuery.setClaimDetailId(claimDetailId); |
| | | List<ReceivableBillSettlementDetail> receivableDetails = receivableBillSettlementDetailService.selectReceivableBillSettlementDetailList(receivableQuery); |
| | | |
| | | if (!receivableDetails.isEmpty()) { |
| | | Integer[] receivableIds = receivableDetails.stream() |
| | | .map(ReceivableBillSettlementDetail::getId) |
| | | .toArray(Integer[]::new); |
| | | receivableBillSettlementDetailService.deleteReceivableBillSettlementDetailByIds(receivableIds); |
| | | logger.info("成功删除应收账单结算明细,认领明细ID:{}", claimDetailId); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("删除应收账单结算明细失败,认领明细ID:{}", claimDetailId, e); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除应付账单结算明细 |
| | | */ |
| | | private void deletePayableSettlementDetail(Integer claimDetailId) { |
| | | try { |
| | | // 根据认领明细ID查询应付账单结算明细 |
| | | PayableBillSettlementDetail payableQuery = new PayableBillSettlementDetail(); |
| | | payableQuery.setClaimDetailId(claimDetailId); |
| | | List<PayableBillSettlementDetail> payableDetails = payableBillSettlementDetailService.selectPayableBillSettlementDetailList(payableQuery); |
| | | |
| | | if (!payableDetails.isEmpty()) { |
| | | Integer[] payableIds = payableDetails.stream() |
| | | .map(PayableBillSettlementDetail::getId) |
| | | .toArray(Integer[]::new); |
| | | payableBillSettlementDetailService.deletePayableBillSettlementDetailByIds(payableIds); |
| | | logger.info("成功删除应付账单结算明细,认领明细ID:{}", claimDetailId); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("删除应付账单结算明细失败,认领明细ID:{}", claimDetailId, e); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | } |