From 099ea14bba367fd86f0dde37d908f07cc04c3d39 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 10 四月 2025 15:38:01 +0800
Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/xizang

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java
index 2ab98bb..b9d8a9e 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java
@@ -9,7 +9,6 @@
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.CodeGenerateUtils;
 import com.ruoyi.common.utils.DictUtils;
-import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.BatchBillDTO;
 import com.ruoyi.system.dto.TBillDto;
@@ -22,12 +21,14 @@
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -64,7 +65,7 @@
     public R<PageInfo<TBillDto>> list(@RequestBody TBillQuery query){
         String userId = tokenService.getLoginUserApplet().getUserId();
         query.setUserId(userId);
-        PageInfo<TBillDto> pageInfo = tBillService.queryPage(query);
+        PageInfo<TBillDto> pageInfo = tBillService.queryPageForApplet(query);
         return R.ok(pageInfo);
     }
 
@@ -129,17 +130,39 @@
     @PostMapping(value = "/invoice")
     public R<String> invoice(@RequestBody TInvoiceDTO dto) {
         String userId = tokenService.getLoginUserApplet().getUserId();
+        List<String> billIds = dto.getBillIds();
         dto.setApplyName(tenantService.getById(userId).getResidentName());
         String code;
         do {
             code = CodeGenerateUtils.generateVolumeSn();
         } while (invoiceService.count(Wrappers.lambdaQuery(TInvoice.class).eq(TInvoice::getInvoiceNumber, code)) > 0);
         dto.setInvoiceNumber(CodeGenerateUtils.generateVolumeSn());
+        String deptId = "";
+        List<TBill> list = tBillService.list(Wrappers.lambdaQuery(TBill.class).in(TBill::getId, billIds));
+        for (String billId : billIds) {
+            TBill tBill = list.stream().filter(bill -> bill.getId().equals(billId)).findFirst().orElse(null);
+            if(StringUtils.hasLength(deptId)){
+                if(Objects.nonNull(tBill)){
+                    if(!deptId.equals(tBill.getBusinessDeptId())){
+                        return R.fail("请选择同一运营部门账单开票");
+                    }else {
+                        deptId = tBill.getBusinessDeptId();
+                    }
+                }
+            }else {
+                if(Objects.nonNull(tBill)){
+                    deptId = tBill.getBusinessDeptId();
+                }else {
+                    return R.fail("请选择同一运营部门账单开票");
+                }
+            }
+        }
+        dto.setBusinessDeptId(deptId);
+
         // 添加开票信息
         invoiceService.save(dto);
 
         // 添加开票信息中间表信息
-        List<String> billIds = dto.getBillIds();
         List<TInvoiceToBill> sysInvoiceToBills = new ArrayList<>();
         for (String billId : billIds) {
             TInvoiceToBill tInvoiceToBill = new TInvoiceToBill();

--
Gitblit v1.7.1