From 0ab9dfd8f122195e4e9f09bd50c59e0a47450bec Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 19 三月 2025 15:50:03 +0800 Subject: [PATCH] fix: resolve merge conflicts in .gitignore --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java | 274 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 241 insertions(+), 33 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 2c1bc20..0376220 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,17 +1,16 @@ 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; import com.ruoyi.common.constant.AmountConstant; 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.StringUtils; +import com.ruoyi.common.utils.*; import com.ruoyi.common.utils.uuid.UUID; -import com.ruoyi.system.dto.OfflinePayCheckDto; -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; @@ -25,12 +24,17 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; -import java.util.stream.Collectors; +import javax.annotation.Resource; +import javax.validation.constraints.NotEmpty; 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> @@ -70,6 +74,13 @@ @Autowired TInvoiceToBillService tInvoiceToBillService; + + + @Resource + SmsUtil smsUtil; + + @Resource + TencentMailUtil mailUtil; public PageInfo<TBillDto> queryPage(TBillQuery query){ PageInfo<TBill> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); @@ -158,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); @@ -228,32 +239,81 @@ } @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)->{ + TBillDto bill = getDetailByBillId(dto.getBillId()); + if (dto.getPayType()==1){ //银行 + if (StringUtils.isEmpty(dto.getFlowId())){ + throw new ServiceException("银行流水ID不能为空"); + } + TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId()); + 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())); + BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount()); + saveBankFlow.setRemainingMoney(subtract); + if (BigDecimal.ZERO.compareTo(subtract) == 0){ + saveBankFlow.setFlowStatus(1); + } + tBankFlowService.updateById(saveBankFlow); + //更新银行流水的已抵扣金额和剩余可抵扣金额 + + //存流水 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.setPayTime(bankflow.getPayTime()); + save.setSysSerialNumber(OrderNos.getDid(30)); + save.setBankSerialNumber(bankflow.getBankSerialNumber()); save.setFlowType(2); - save.setPaymentBillId(bill.getId()); - save.setDeductionMoney(bill.getDeductionMoney()); + save.setPaymentBillId(back.getId()); + save.setDeductionMoney(back.getDeductionMoney()); save.setFlowMoney(dto.getAmount()); - save.setRemainingMoney(bill.getOutstandingMoney()); - save.setPreOutstand(bill.getPreOutstand()); + save.setRemainingMoney(back.getOutstandingMoney()); + save.setPreOutstand(back.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; + return true; + } + //现金支付 + TBill billSave = new TBill(); + billSave.setId(bill.getId()); + billSave.setPayFeesMoney(dto.getAmount()); + billSave.setPayFeesTime(dto.getPayTime()!=null?dto.getPayTime():DateUtils.dateToLocalDateTime(new Date())); + billSave.setVoucher(dto.getVoucher()); + billSave.setPayFeesType(2); + TBill back = lockAndUpdateInfo(billSave, 2); + + TFlowManagement save = new TFlowManagement(); + save.setPayType(3); + save.setPayer(dto.getPayer()); + save.setPayTime(billSave.getPayFeesTime()); + save.setSysSerialNumber(OrderNos.getDid(30)); + save.setFlowType(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 @@ -301,6 +361,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()); @@ -329,20 +390,167 @@ * @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; } + + @Override + public Integer sendSmsByBillIds(SmsByBillDto dto) { + int failNum = 0; + for (String billId : dto.getBillIds()) { + TBillDto bill = getDetailByBillId(billId); + 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())){ + failNum++; + continue; + } + TBill save = new TBill(); + save.setId(bill.getId()); + try { + 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++; + save.setSmsStatus(2); + } + save.setSmsLastTime(new Date()); + save.setSmsSendUserid(dto.getSendUserId()); + lockAndUpdateInfo(save,1); + } + return failNum; + } + + @Override + public Integer sendMailBatchByBillIds(SmsByBillDto dto) { + int failNum = 0; + for (String billId : dto.getBillIds()) { + TBillDto bill = getDetailByBillId(billId); + 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++; + continue; + } + TBill save = new TBill(); + save.setId(bill.getId()); + try { + mailUtil.send(bill.getEmail(),bill.getHouseName()); + save.setMailStatus(1); + }catch (ServiceException e){ + failNum++; + save.setMailStatus(2); + } + save.setMailLastTime(new Date()); + save.setMailSendUserid(dto.getSendUserId()); + lockAndUpdateInfo(save,1); + } + return failNum; + } + + public TBillDto getDetailByBillId(@NotEmpty String billId) { + 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())); + BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount()); + saveBankFlow.setRemainingMoney(subtract); + if (BigDecimal.ZERO.compareTo(subtract) == 0){ + saveBankFlow.setFlowStatus(1); + } + 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; + } + + @Override + public Integer batchBillCount(String userId, List<String> billIds) { + return this.baseMapper.batchBillCount(userId,billIds); + } + + } -- Gitblit v1.7.1