From 06b8c7137f61902522dbb605da5ec7634dc92b6b Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 28 二月 2025 13:45:31 +0800
Subject: [PATCH] Merge branch 'xizang-changyun' of https://gitee.com/xiaochen991015/xizang

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java |   94 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 88 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 2c1bc20..3e5b73b 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
@@ -2,14 +2,18 @@
 
 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;
@@ -17,7 +21,10 @@
 import com.ruoyi.system.query.TBillQuery;
 import com.ruoyi.system.query.TInvoiceToBillQuery;
 import com.ruoyi.system.service.*;
+import com.ruoyi.system.vo.TBillVO;
 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,6 +32,8 @@
 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;
@@ -70,6 +79,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());
@@ -329,20 +345,86 @@
      * @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
+                    && (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