| | |
| | | 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.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.*; |
| | | 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; |
| | |
| | | |
| | | 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> |
| | |
| | | |
| | | @Resource |
| | | SmsUtil smsUtil; |
| | | |
| | | @Resource |
| | | SmsProperties smsProperties; |
| | | TencentMailUtil mailUtil; |
| | | |
| | | public PageInfo<TBillDto> queryPage(TBillQuery query){ |
| | | PageInfo<TBill> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | PageInfo<TBillDto> info = tBillMapper.page(pageInfo, query); |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | @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 |
| | |
| | | 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()); |
| | |
| | | * @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; |
| | |
| | | int failNum = 0; |
| | | for (String billId : dto.getBillIds()) { |
| | | TBillDto bill = getDetailByBillId(billId); |
| | | if (bill.getSmsLastTime()!=null |
| | | && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<smsProperties.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())){ |
| | |
| | | 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++; |
| | |
| | | int failNum = 0; |
| | | for (String billId : dto.getBillIds()) { |
| | | TBillDto bill = getDetailByBillId(billId); |
| | | if (bill.getSmsLastTime()!=null |
| | | && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<smsProperties.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++; |
| | |
| | | TBill save = new TBill(); |
| | | save.setId(bill.getId()); |
| | | try { |
| | | //todo 发送邮件 |
| | | mailUtil.send(bill.getEmail(),bill.getHouseName()); |
| | | save.setMailStatus(1); |
| | | }catch (ServiceException e){ |
| | | failNum++; |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |