From 41ebfbaa7362f93ccb0fe3109cf5492cfdc0d80a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 11 二月 2025 16:58:20 +0800
Subject: [PATCH] 缴费账单和开票列表

---
 ruoyi-system/src/main/java/com/ruoyi/system/vo/TBillVO.java                    |   11 +++
 ruoyi-admin/src/main/resources/application-test.yml                            |    2 
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TBillController.java   |   40 ++++++++++++-
 ruoyi-system/src/main/resources/mapper/system/TContractMapper.xml              |    2 
 ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java            |   13 ++++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java |   16 +++++
 ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml                  |   62 ++++++++++++++++++++
 ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java               |    2 
 ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java          |   16 +++++
 9 files changed, 157 insertions(+), 7 deletions(-)

diff --git a/ruoyi-admin/src/main/resources/application-test.yml b/ruoyi-admin/src/main/resources/application-test.yml
index e30bce7..4ca4b21 100644
--- a/ruoyi-admin/src/main/resources/application-test.yml
+++ b/ruoyi-admin/src/main/resources/application-test.yml
@@ -21,7 +21,7 @@
   port: 8081
   servlet:
     # 应用的访问路径
-    context-path: /admin
+    context-path: /
   tomcat:
     # tomcat的URI编码
     uri-encoding: UTF-8
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 bee1f33..31ff3da 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
@@ -8,14 +8,12 @@
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DictUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.TBillDto;
 import com.ruoyi.system.dto.TInvoiceDTO;
 import com.ruoyi.system.model.*;
 import com.ruoyi.system.query.TBillQuery;
-import com.ruoyi.system.service.TBillDetailService;
-import com.ruoyi.system.service.TBillService;
-import com.ruoyi.system.service.TInvoiceService;
-import com.ruoyi.system.service.TInvoiceToBillService;
+import com.ruoyi.system.service.*;
 import com.ruoyi.system.vo.TBillVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -44,9 +42,15 @@
     @Autowired
     TBillDetailService billDetailService;
     @Autowired
+    TContractService contractService;
+    @Autowired
+    THouseService houseService;
+    @Autowired
     TInvoiceService invoiceService;
     @Autowired
     TInvoiceToBillService invoiceToBillService;
+    @Autowired
+    TokenService tokenService;
 
     @ApiOperation(value = "缴费账单查询分页列表")
     @PostMapping("list")
@@ -56,6 +60,16 @@
         }
         PageInfo<TBillDto> pageInfo = tBillService.queryPage(query);
         return R.ok(pageInfo);
+    }
+
+    @ApiOperation(value = "缴费账单查询分页列表")
+    @PostMapping("/getBillIds")
+    public R<List<String>> getBillIds(@RequestBody TBillQuery query){
+        if (StringUtils.isEmpty(query.getUserId())){
+            throw new ServiceException("用户ID不能为空");
+        }
+        List<String> billIds = tBillService.getBillIds(query);
+        return R.ok(billIds);
     }
 
     @ApiOperation(value = "查看缴费账单详情")
@@ -70,6 +84,13 @@
                     .eq(TBillDetail::getBillId, id));
             billVO.setBillDetailList(list);
         }
+        // 查询合同信息
+        contractService.lambdaQuery().eq(TContract::getId, bill.getContractId()).oneOpt().ifPresent(contract -> {
+            // 查询房屋信息
+            billVO.setHouse(houseService.getById(contract.getHouseId()));
+            billVO.setMonthRent(contract.getMonthRent());
+            billVO.setPayType(contract.getPayType());
+        });
         billVO.setBillType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_BILL_TYPE,billVO.getBillType()));
         billVO.setPayFeesStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_PAY_FEES_STATUS,billVO.getPayFeesStatus()));
         return R.ok(billVO);
@@ -94,5 +115,16 @@
         return R.ok();
     }
 
+    @ApiOperation(value = "缴费账单开票列表")
+    @PostMapping(value = "/invoiceList")
+    public R<PageInfo<TBillDto>> invoiceList(@RequestBody TBillQuery query) {
+
+//        Long userId = tokenService.getLoginUser().getUserId();
+        String userId = "1";
+        query.setUserId(userId);
+        PageInfo<TBillDto> pageInfo = tBillService.invoiceList(query);
+        return R.ok(pageInfo);
+    }
+
 }
 
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java
index ab6c3dc..49292e8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TBillMapper.java
@@ -5,8 +5,11 @@
 import com.ruoyi.system.dto.TBillDto;
 import com.ruoyi.system.model.TBill;
 import com.ruoyi.system.query.TBillQuery;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * <p>
@@ -16,8 +19,18 @@
  * @author xiaochen
  * @since 2025-01-17
  */
+@Mapper
 public interface TBillMapper extends BaseMapper<TBill> {
 
     PageInfo<TBillDto> page(@Param("pageInfo") PageInfo<TBill> pageInfo, @Param("query") TBillQuery query);
 
+    List<TBillDto> getBillList(@Param("query")TBillQuery query);
+
+    /**
+     * 获取开票列表
+     * @param query
+     * @param pageInfo
+     * @return
+     */
+    List<TBillDto> invoiceList(@Param("query")TBillQuery query, @Param("pageInfo")PageInfo<TBillDto> pageInfo);
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java b/ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java
index e146dcd..13a4795 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/model/TContract.java
@@ -80,7 +80,7 @@
 
     @ApiModelProperty(value = "押金是否随租金递增递减 true=是 false=否")
     @TableField("isIncreasing_deposit")
-    private Boolean isincreasingDeposit;
+    private Boolean isIncreasingDeposit;
 
     @ApiModelProperty(value = "违约金比例")
     @TableField("proportion")
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java
index 22feecc..38e213e 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/TBillService.java
@@ -6,6 +6,8 @@
 import com.ruoyi.system.model.TBill;
 import com.ruoyi.system.query.TBillQuery;
 
+import java.util.List;
+
 /**
  * <p>
  * 租金账单 服务类
@@ -18,4 +20,18 @@
 
     PageInfo<TBillDto> queryPage(TBillQuery query);
 
+    /**
+     * 查询账单id列表
+     * @param query
+     * @return
+     */
+    List<String> getBillIds(TBillQuery query);
+
+    /**
+     * 查询开票列表
+     * @param query
+     * @return
+     */
+    PageInfo<TBillDto> invoiceList(TBillQuery query);
+
 }
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 3a0bdc6..2dff882 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
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.system.dto.TBillDto;
 import com.ruoyi.system.mapper.TBillMapper;
@@ -17,6 +18,8 @@
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -41,6 +44,19 @@
         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;
+    }
 
 
     /**
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/TBillVO.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/TBillVO.java
index 60ad80c..6b4bbbe 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/vo/TBillVO.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/vo/TBillVO.java
@@ -1,11 +1,14 @@
 package com.ruoyi.system.vo;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.ruoyi.system.model.TBill;
 import com.ruoyi.system.model.TBillDetail;
+import com.ruoyi.system.model.THouse;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 @Data
@@ -15,4 +18,12 @@
     @ApiModelProperty(value = "水电费明细")
     private List<TBillDetail> billDetailList;
 
+    @ApiModelProperty(value = "房屋信息")
+    private THouse house;
+
+    @ApiModelProperty(value = "租金")
+    private BigDecimal monthRent;
+
+    @ApiModelProperty(value = "租金支付方式 月付 季付 年付")
+    private String payType;
 }
diff --git a/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml
index 2f8fbd8..da8b419 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml
@@ -63,4 +63,66 @@
             </if>
         </where>
     </select>
+    <select id="getBillList" resultType="com.ruoyi.system.dto.TBillDto">
+        SELECT
+        b.*,
+        t.resident_name as residentName,
+        t.phone,
+        t.account,
+        h.house_name as houseName
+        FROM
+        t_bill b
+        LEFT JOIN t_contract c ON c.contract_number = b.contract_number
+        LEFT JOIN t_house h ON h.id = c.house_id
+        LEFT JOIN t_tenant t ON t.id = c.tenant_id
+        <where>
+            <if test="query.payFeesStatus != null">
+                and b.pay_fees_status = #{query.payFeesStatus}
+            </if>
+            <if test="query.phone != null and query.phone !=''">
+                and t.phone = #{query.phone}
+            </if>
+            <if test="query.residentName != null and query.residentName !=''">
+                and t.resident_name like concat('%',#{query.residentName},'%')
+            </if>
+            <if test="query.contractNumber != null and query.contractNumber !=''">
+                and b.contract_number = #{query.contractNumber}
+            </if>
+            <if test="query.userId != null and query.userId !=''">
+                and t.id = #{query.userId}
+            </if>
+        </where>
+    </select>
+    <select id="invoiceList" resultType="com.ruoyi.system.dto.TBillDto">
+        SELECT
+        b.*,
+        t.resident_name as residentName,
+        t.phone,
+        t.account,
+        h.house_name as houseName
+        FROM
+        t_bill b
+        LEFT JOIN t_contract c ON c.contract_number = b.contract_number
+        LEFT JOIN t_house h ON h.id = c.house_id
+        LEFT JOIN t_tenant t ON t.id = c.tenant_id
+        LEFT JOIN t_invoice_to_bill tb ON b.id = tb.bill_id
+        <where>
+            <if test="query.payFeesStatus != null">
+                and b.pay_fees_status = #{query.payFeesStatus}
+            </if>
+            <if test="query.phone != null and query.phone !=''">
+                and t.phone = #{query.phone}
+            </if>
+            <if test="query.residentName != null and query.residentName !=''">
+                and t.resident_name like concat('%',#{query.residentName},'%')
+            </if>
+            <if test="query.contractNumber != null and query.contractNumber !=''">
+                and b.contract_number = #{query.contractNumber}
+            </if>
+            <if test="query.userId != null and query.userId !=''">
+                and t.id = #{query.userId}
+            </if>
+            and tb.invoice_id IS NULL
+        </where>
+    </select>
 </mapper>
diff --git a/ruoyi-system/src/main/resources/mapper/system/TContractMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TContractMapper.xml
index 09c437c..5a57cac 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TContractMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TContractMapper.xml
@@ -14,7 +14,7 @@
         <result column="pay_type" property="payType" />
         <result column="first_pay_time" property="firstPayTime" />
         <result column="isIncreasing" property="isIncreasing" />
-        <result column="isIncreasing_deposit" property="isincreasingDeposit" />
+        <result column="isIncreasing_deposit" property="isIncreasingDeposit" />
         <result column="proportion" property="proportion" />
         <result column="house_id" property="houseId" />
         <result column="party_one_name" property="partyOneName" />

--
Gitblit v1.7.1