From 8c05349b9781e061e413f1efe1f33d00a2b68053 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 06 三月 2025 20:33:06 +0800
Subject: [PATCH] bug修改
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java | 190 +++++++++++++++++++++++++++++++++++------------
1 files changed, 140 insertions(+), 50 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
index fd4ec65..1dd6cad 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.system.service.impl;
+import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.config.SmsProperties;
@@ -7,23 +8,15 @@
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.utils.DateUtils;
-import com.ruoyi.common.utils.SmsUtil;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.TencentMailUtil;
+import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.uuid.UUID;
-import com.ruoyi.system.dto.OfflinePayCheckDto;
-import com.ruoyi.system.dto.SmsByBillDto;
-import com.ruoyi.system.dto.TBillDto;
-import com.ruoyi.system.dto.TbillSaveDto;
+import com.ruoyi.system.dto.*;
import com.ruoyi.system.mapper.TBillMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TBillQuery;
import com.ruoyi.system.query.TInvoiceToBillQuery;
import com.ruoyi.system.service.*;
import com.taxi591.bankapi.dto.ChargeBillRequest;
-import com.tencentcloudapi.sms.v20190711.SmsClient;
-import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
@@ -33,12 +26,15 @@
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
-import java.util.*;
-import java.util.stream.Collectors;
import java.math.BigDecimal;
import java.text.ParseException;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
/**
* <p>
@@ -173,7 +169,7 @@
BigDecimal result = presist.getPayFeesMoney().add(tBill.getPayFeesMoney());
save.setPayFeesMoney(result);
//缴费后的欠费 =(应缴费+违约金)-已缴费金额
- BigDecimal outstand = save.getPayableFeesMoney()
+ BigDecimal outstand = presist.getPayableFeesMoney()
.add(presist.getPayableFeesPenalty())
.subtract(save.getPayFeesMoney());
save.setOutstandingMoney(outstand);
@@ -243,32 +239,51 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public boolean checkOfflinePay(OfflinePayCheckDto dto) {
- List<TBill> tBills = listByIds(dto.getBillIds());
- TBillConfirm confirm = tBillConfirmService.getById(dto.getConfirmId());
- lockAndUpdateByAmountBatch(tBills,dto.getAmount(),(bill)->{
- TFlowManagement save = new TFlowManagement();
- save.setPayType(3);
- save.setPayer(dto.getPayer());
- save.setPayTime(dto.getPayTime()==null?DateUtils.dateToLocalDateTime(confirm.getPayTime()):dto.getPayTime());
- save.setBankSerialNumber(dto.getBankSerilNum());
- save.setFlowType(2);
- save.setPaymentBillId(bill.getId());
- save.setDeductionMoney(bill.getDeductionMoney());
- save.setFlowMoney(dto.getAmount());
- save.setRemainingMoney(bill.getOutstandingMoney());
- save.setPreOutstand(bill.getPreOutstand());
- tFlowManagementService.save(save);
- });
- TBankFlow bankFlow = new TBankFlow();
- bankFlow.setPayType(3);
- bankFlow.setPayer(dto.getPayer());
- bankFlow.setPayTime(dto.getPayTime()==null?DateUtils.dateToLocalDateTime(confirm.getPayTime()):dto.getPayTime());
- bankFlow.setBankSerialNumber(dto.getBankSerilNum());
- bankFlow.setFlowMoney(dto.getAmount());
- bankFlow.setFlowStatus(1);
- tBankFlowService.save(bankFlow);
- return false;
+ TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId());
+ TBillDto bill = getDetailByBillId(dto.getBillId());
+ if (bankflow.getRemainingMoney().compareTo(BigDecimal.ZERO)<=0){
+ throw new ServiceException("该流水已无可抵扣剩余金额");
+ }
+ if (bankflow.getRemainingMoney().compareTo(dto.getAmount())<0){
+ throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额");
+ }
+ //如果实付金额大于欠费金额
+ if (dto.getAmount().compareTo(bill.getOutstandingMoney())>0){
+ throw new ServiceException("实付金额不能高于该账单欠费金额");
+ }
+
+ TBill billSave = new TBill();
+ billSave.setId(bill.getId());
+ billSave.setPayFeesMoney(dto.getAmount());
+ billSave.setBankSerialNumber(bankflow.getBankSerialNumber());
+ billSave.setPayFeesTime(bankflow.getPayTime());
+ billSave.setVoucher(dto.getVoucher());
+ billSave.setPayFeesType(2);
+ TBill back = lockAndUpdateInfo(billSave, 2);
+
+ //更新银行流水的已抵扣金额和剩余可抵扣金额
+ TBankFlow saveBankFlow = new TBankFlow();
+ saveBankFlow.setId(bankflow.getId());
+ saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
+ saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
+ tBankFlowService.updateById(saveBankFlow);
+ //存流水
+ TFlowManagement save = new TFlowManagement();
+ save.setPayType(3);
+ save.setPayer(dto.getPayer());
+ save.setPayTime(bankflow.getPayTime());
+ save.setSysSerialNumber(OrderNos.getDid(30));
+ save.setBankSerialNumber(bankflow.getBankSerialNumber());
+ save.setFlowType(2);
+ save.setPaymentBillId(back.getId());
+ save.setDeductionMoney(back.getDeductionMoney());
+ save.setFlowMoney(dto.getAmount());
+ save.setRemainingMoney(back.getOutstandingMoney());
+ save.setPreOutstand(back.getPreOutstand());
+ tFlowManagementService.save(save);
+ return true;
}
@Override
@@ -316,6 +331,7 @@
saveFlow.setPayType(1);
saveFlow.setPayer(order.getUserId());
saveFlow.setPayTime(DateUtils.dateToLocalDateTime(save.getPayTime()));
+ saveFlow.setSysSerialNumber(OrderNos.getDid(30));
saveFlow.setBankSerialNumber(save.getPayNo());
saveFlow.setFlowType(2);
saveFlow.setPaymentBillId(bill.getId());
@@ -344,16 +360,18 @@
* @return
*/
@Override
- public PageInfo<TBill> getBillByInvoiceId(String invoiceId){
- invoiceId = "1889552849671061505";
- PageInfo<TBill> pageInfo = new PageInfo<>();
- ArrayList<TBill> bills = new ArrayList<>();
+ public PageInfo<TBillDto> getBillByInvoiceId(String invoiceId){
+ PageInfo<TBillDto> pageInfo = new PageInfo<>();
+ ArrayList<TBillDto> bills = new ArrayList<>();
TInvoiceToBillQuery query = new TInvoiceToBillQuery();
query.setInvoiceId(invoiceId);
List<TInvoiceToBill> tInvoiceToBills = tInvoiceToBillService.makeQuery(query);
for (TInvoiceToBill tInvoiceToBill : tInvoiceToBills) {
- TBill byId = getById(tInvoiceToBill.getBillId());
- bills.add(byId);
+ TBill bill = getById(tInvoiceToBill.getBillId());
+ if (bill != null && bill.getId() != null){
+ TBillDto detailByBillId = getDetailByBillId(bill.getId());
+ bills.add(detailByBillId);
+ }
}
pageInfo.setRecords(bills);
return pageInfo;
@@ -366,8 +384,8 @@
int failNum = 0;
for (String billId : dto.getBillIds()) {
TBillDto bill = getDetailByBillId(billId);
- if (bill.getSmsLastTime()!=null
- && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<mailUtil.getPro().getBillSmsDelayPeriod()*60*1000L)){
+ if (bill.getSmsLastTime()!=null && bill.getSmsStatus()==1
+ && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<smsUtil.getPro().getBillSmsDelayPeriod()*60*1000L)){
throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getSmsLastTime()));
}
if (StringUtils.isEmpty(bill.getPhone())){
@@ -377,7 +395,8 @@
TBill save = new TBill();
save.setId(bill.getId());
try {
- smsUtil.sendSms(bill.getPhone(), "", new String[]{""});
+ String name = bill.getPartyTwoName().length()>5?bill.getPartyTwoName().substring(0,5):bill.getPartyTwoName();
+ smsUtil.sendSms(bill.getPhone(), "2365726", new String[]{name});
save.setSmsStatus(1);
}catch (ServiceException e){
failNum++;
@@ -395,9 +414,9 @@
int failNum = 0;
for (String billId : dto.getBillIds()) {
TBillDto bill = getDetailByBillId(billId);
- if (bill.getSmsLastTime()!=null
- && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<mailUtil.getPro().getBillMailDelayPeriod()*60*1000L)){
- throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getSmsLastTime()));
+ if (bill.getMailLastTime()!=null && bill.getMailStatus()==1
+ && (System.currentTimeMillis()-bill.getMailLastTime().getTime()<mailUtil.getPro().getBillMailDelayPeriod()*60*1000L)){
+ throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getMailLastTime()));
}
if (StringUtils.isEmpty(bill.getEmail())){
failNum++;
@@ -423,5 +442,76 @@
return getBaseMapper().selectDetailByBillId(billId);
}
+ /**
+ * 收款、类型可能是现金、银行
+ * @param dto
+ * @return
+ */
+ @Transactional(rollbackFor = Exception.class)
+ @Override
+ public Boolean cashPay(CachPayDto dto) {
+ TBill back = null;
+ TBankFlow bankflow = null;
+ if (dto.getPayType()==1){
+ if (StringUtils.isEmpty(dto.getFlowId())){
+ throw new ServiceException("银行流水不能为空");
+ }
+ bankflow = tBankFlowService.getById(dto.getFlowId());
+ TBillDto bill = getDetailByBillId(dto.getBillId());
+ if (bankflow.getRemainingMoney().compareTo(BigDecimal.ZERO)<=0){
+ throw new ServiceException("该流水已无可抵扣剩余金额");
+ }
+ if (bankflow.getRemainingMoney().compareTo(dto.getAmount())<0){
+ throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额");
+ }
+ //如果实付金额大于欠费金额
+ if (dto.getAmount().compareTo(bill.getOutstandingMoney())>0){
+ throw new ServiceException("实付金额不能高于该账单欠费金额");
+ }
+ }
+ TBillDto bill = getDetailByBillId(dto.getBillId());
+ TBill billSave = new TBill();
+ billSave.setId(bill.getId());
+ billSave.setPayFeesMoney(dto.getAmount());
+ billSave.setBankSerialNumber(bankflow!=null?bankflow.getBankSerialNumber():null);
+ billSave.setPayFeesTime(bankflow!=null?bankflow.getPayTime():DateUtils.dateToLocalDateTime(new Date()));
+ billSave.setVoucher(dto.getVoucher());
+ billSave.setPayFeesType(2);
+ back = lockAndUpdateInfo(billSave, 2);
+ if (dto.getPayType()==1){
+ //更新银行流水的已抵扣金额和剩余可抵扣金额
+ TBankFlow saveBankFlow = new TBankFlow();
+ saveBankFlow.setId(bankflow.getId());
+ saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
+ saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
+ tBankFlowService.updateById(saveBankFlow);
+ }
+ //存流水
+ TFlowManagement save = new TFlowManagement();
+ save.setPayType(3);
+ save.setPayer(dto.getPayer());
+ save.setPayTime(bankflow!=null?bankflow.getPayTime():DateUtils.dateToLocalDateTime(new Date()));
+ save.setSysSerialNumber(OrderNos.getDid());
+ save.setBankSerialNumber(bankflow!=null?bankflow.getBankSerialNumber():null);
+ save.setFlowType(dto.getPayType()==1?2:1);
+ save.setPaymentBillId(back.getId());
+ save.setDeductionMoney(back.getDeductionMoney());
+ save.setFlowMoney(dto.getAmount());
+ save.setRemainingMoney(back.getOutstandingMoney());
+ save.setPreOutstand(back.getPreOutstand());
+ tFlowManagementService.save(save);
+ return true;
+ }
+
+ @Override
+ public BillStatisticsDto statistics() {
+ BillStatisticsDto dto = new BillStatisticsDto();
+ dto.setRent(getBaseMapper().statisticsAllRent());
+ dto.setNopay(getBaseMapper().statisticsNoPay());
+ dto.setPayed(getBaseMapper().statisticsPayed());
+ dto.setOverdue(getBaseMapper().statisticsOverdue());
+ return dto;
+ }
+
}
--
Gitblit v1.7.1