From c474556f44163526700fd7c99a88e37e4297e23f Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 27 二月 2025 19:14:23 +0800
Subject: [PATCH] 审批流定时任务

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java |  125 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 119 insertions(+), 6 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 14c59f3..fd4ec65 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,23 +1,29 @@
 package com.ruoyi.system.service.impl;
 
-import com.alibaba.fastjson2.JSON;
 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.SmsUtil;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.TencentMailUtil;
 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.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;
@@ -25,15 +31,14 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+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.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
 import java.util.List;
 import java.util.function.Consumer;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * <p>
@@ -71,12 +76,35 @@
     @Autowired
     TOrderBillService orderBillService;
 
+    @Autowired
+    TInvoiceToBillService tInvoiceToBillService;
+
+
+    @Resource
+    SmsUtil smsUtil;
+
+    @Resource
+    TencentMailUtil mailUtil;
+
     public PageInfo<TBillDto> queryPage(TBillQuery query){
         PageInfo<TBill> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
         PageInfo<TBillDto> info = tBillMapper.page(pageInfo, query);
         return info;
     }
 
+    @Override
+    public List<String> getBillIds(TBillQuery query) {
+        List<TBillDto> billDtos = tBillMapper.getBillList(query);
+        return billDtos.stream().map(TBillDto::getId).collect(Collectors.toList());
+    }
+
+    @Override
+    public PageInfo<TBillDto> invoiceList(TBillQuery query) {
+        PageInfo<TBillDto> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+        List<TBillDto> list = tBillMapper.invoiceList(query,pageInfo);
+        pageInfo.setRecords(list);
+        return pageInfo;
+    }
 
     private static final String[] ignorePro = {"payableFeesMoney","payableFeesPenalty","payFeesMoney","outstandingMoney"};
 
@@ -310,5 +338,90 @@
 
     }
 
+    /**
+     * 根据发票编号查询账单列表
+     * @param invoiceId
+     * @return
+     */
+    @Override
+    public PageInfo<TBill> getBillByInvoiceId(String invoiceId){
+        invoiceId = "1889552849671061505";
+        PageInfo<TBill> pageInfo = new PageInfo<>();
+        ArrayList<TBill> 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);
+        }
+        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
+                    && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<mailUtil.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 {
+                smsUtil.sendSms(bill.getPhone(), "", new String[]{""});
+                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.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 (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);
+    }
+
 
 }

--
Gitblit v1.7.1