Pārlūkot izejas kodu

feat(property): 增强合同信息分页查询功能- 新增资产类型、楼宇、楼层和房间名作为查询条件
- 修改分页查询接口支持更多筛选字段
- 更新 Mapper XML 文件以实现关联查询与动态 SQL 条件
- 优化删除逻辑,增加对关联收据和退据的检查
- 调整日期处理方式,增强数据保存时的健壮性
- 注释掉部分冗余代码并重构相关业务逻辑

林仔 6 mēneši atpakaļ
vecāks
revīzija
651b0bf2d3

+ 3 - 4
src/main/java/com/zksy/controller/property/AContractInfoController.java

@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.time.LocalDateTime;
-import java.util.Arrays;
 
 /**
  * @author Administrator
@@ -30,8 +29,8 @@ public class AContractInfoController {
     private AContractInfoService service;
     @GetMapping("/findByPage")
     @ApiOperation(value = "合同信息查询分页")
-    public AjaxResult findByPage(long pageNum, long pageSize, String contractNumber,String contractDate,String contractStatus){
-        return AjaxResult.success(service.findByPage(pageNum, pageSize, contractNumber,contractDate,contractStatus));
+    public AjaxResult findByPage(long pageNum, long pageSize, String contractNumber,String contractDate,String contractStatus,String assetType,String building,String floor,String houseName){
+        return AjaxResult.success(service.findByPage(pageNum, pageSize, contractNumber,contractDate,contractStatus,assetType,building,floor,houseName));
     }
     @GetMapping("/getAContractInfoList")
     @ApiOperation(value = "合同信息查询")
@@ -57,7 +56,7 @@ public class AContractInfoController {
     @PostMapping("/deleteBatch")
     @ApiOperation(value = "合同信息删除")
     public AjaxResult delete(@RequestBody String[] ids) {
-        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
+        return service.removeBatchId(ids) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
     }
 
     @GetMapping("/getBySimplifiedHouseId")

+ 9 - 0
src/main/java/com/zksy/property/domain/AContractInfo.java

@@ -97,6 +97,15 @@ public class AContractInfo implements Serializable {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
+    @TableField(exist = false)
+    private String assetType;
+    @TableField(exist = false)
+    private String building;
+    @TableField(exist = false)
+    private String floor;
+    @TableField(exist = false)
+    private String houseName;
+
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
 }

+ 12 - 2
src/main/java/com/zksy/property/mapper/AContractInfoMapper.java

@@ -1,7 +1,9 @@
 package com.zksy.property.mapper;
 
-import com.zksy.property.domain.AContractInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.zksy.property.domain.AContractInfo;
+import org.apache.ibatis.annotations.Param;
 
 /**
 * @author Administrator
@@ -10,7 +12,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 * @Entity com.zksy.property.domain.AContractInfo
 */
 public interface AContractInfoMapper extends BaseMapper<AContractInfo> {
-
+        // 自定义分页查询(参数:分页对象、查询条件)
+        IPage<AContractInfo> selectContractWithHouse(IPage<AContractInfo> page,
+                                                     @Param("contractNumber") String contractNumber,
+                                                     @Param("contractDate") String contractDate,
+                                                     @Param("contractStatus") String contractStatus,
+                                                     @Param("assetType") String assetType,
+                                                     @Param("building") String building,
+                                                     @Param("floor") String floor,
+                                                     @Param("houseName") String houseName);
 }
 
 

+ 3 - 1
src/main/java/com/zksy/property/service/AContractInfoService.java

@@ -18,7 +18,7 @@ import java.util.List;
 * @createDate 2025-07-14 11:59:44
 */
 public interface AContractInfoService extends IService<AContractInfo> {
-    Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber,String contractDate,String contractStatus);
+    Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber,String contractDate,String contractStatus,String assetType,String building,String floor,String houseName);
     List<AContractInfo> getAContractInfoList(String contractNumber,String contractDate,String contractStatus);
 
     AContractInfo getBySimplifiedHouseId(String simplifiedHouseId);
@@ -36,4 +36,6 @@ public interface AContractInfoService extends IService<AContractInfo> {
     CanBeGetReturnReceiptVo canBeDetReturnReceiptData(String contractId);
 
     String getReturnReceipt(String contractId, ReturnReceiptDto dto);
+
+    boolean removeBatchId(String[] ids);
 }

+ 56 - 18
src/main/java/com/zksy/property/service/impl/AContractInfoServiceImpl.java

@@ -2,6 +2,7 @@ package com.zksy.property.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -16,7 +17,6 @@ import com.zksy.property.factory.ContractFactory;
 import com.zksy.property.mapper.AContractInfoMapper;
 import com.zksy.property.service.*;
 import com.zksy.service.MinioFileStorageService;
-import com.zksy.utils.exception.BusinessException;
 import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -51,6 +51,8 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
 
     @Autowired
     private ARefundService aRefundService;
+    @Autowired
+    private AContractInfoMapper baseMapper;
 
     @Override
     public String returnRent(String houseId) {
@@ -92,12 +94,12 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
 
     @Override
     public String getReceipt(String contractId, ReceiptDto dto) {
-        LambdaQueryWrapper<AReceiptInfo> aReceiptInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        /*LambdaQueryWrapper<AReceiptInfo> aReceiptInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
         aReceiptInfoLambdaQueryWrapper.eq(AReceiptInfo::getContractId,contractId);
         var res = aReceiptInfoService.getOne(aReceiptInfoLambdaQueryWrapper);
         if(res != null){
             throw new BusinessException(999,"此合同已生成收据",res.getAttachmentUrl());
-        }
+        }*/
         AContractInfo contractInfo = this.getById(contractId);
         if (contractInfo == null){
             throw new RuntimeException("数据不存在");
@@ -125,8 +127,10 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
         DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy年M月d日");
         LocalDate rzrqDate = LocalDate.parse(dto.getRzrq(), inputFormatter);
         bo.setD13(rzrqDate.format(outputFormatter));
-        bo.setD14(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
-        bo.setD15(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
+        LocalDate startDate = LocalDate.parse(dto.getStartDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        bo.setD14(startDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
+        LocalDate endDate = LocalDate.parse(dto.getEndDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        bo.setD15(endDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
 
         String attachmentUrl = aRentalContractService.generatorRental("4", bo, true);
         AReceiptInfo receiptInfo = new AReceiptInfo();
@@ -139,12 +143,18 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
         receiptInfo.setPropertyFee(dto.getWyf());
         receiptInfo.setDeposit(dto.getYj());
         receiptInfo.setWaterFee(dto.getSf());
-        receiptInfo.setAccountingDate(LocalDate.parse(dto.getRzrq()));
+        if (StringUtils.isNotBlank(dto.getRzrq())){
+            receiptInfo.setAccountingDate(LocalDate.parse(dto.getRzrq()));
+        }
         receiptInfo.setReceiptReason(dto.getPaymentReason());
         receiptInfo.setAttachmentUrl(attachmentUrl);
         receiptInfo.setGenerationDate(LocalDate.now());
-        receiptInfo.setStartDate(LocalDate.parse(dto.getStartDate()));
-        receiptInfo.setEndDate(LocalDate.parse(dto.getEndDate()));
+        if(StringUtils.isNotBlank(dto.getStartDate())){
+            receiptInfo.setStartDate(LocalDate.parse(dto.getStartDate()));
+        }
+        if(StringUtils.isNotBlank(dto.getEndDate())){
+            receiptInfo.setEndDate(LocalDate.parse(dto.getEndDate()));
+        }
         receiptInfo.setCreateTime(LocalDateTime.now());
         receiptInfo.setUpdateTime(LocalDateTime.now());
         aReceiptInfoService.save(receiptInfo);
@@ -187,12 +197,12 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
 
     @Override
     public String getReturnReceipt(String contractId, ReturnReceiptDto dto) {
-        LambdaQueryWrapper<ARefund> queryWrapper = new LambdaQueryWrapper<>();
+        /*LambdaQueryWrapper<ARefund> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ARefund::getContractId,contractId);
         var  res = aRefundService.getOne(queryWrapper);
         if(res != null){
             throw new BusinessException(999,"此合同已生成退据",res.getAttachmentUrl());
-        }
+        }*/
         AContractInfo contractInfo = this.getById(contractId);
         if (contractInfo == null){
             throw new RuntimeException("数据不存在");
@@ -229,6 +239,37 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
         return attachmentUrl;
     }
 
+    @Override
+    public boolean removeBatchId(String[] ids) {
+        try {
+            for (String id : ids){
+                // 查询是否绑定了退据
+                ARefund refund = aRefundService.getOne(new LambdaQueryWrapper<ARefund>().eq(ARefund::getContractId,id),false);
+                if(refund != null){
+                    throw new RuntimeException("该房屋已存在退据,请先删除退据");
+                }
+                // 查询是否绑定收据
+                AReceiptInfo receiptInfo = aReceiptInfoService.getOne(new LambdaQueryWrapper<AReceiptInfo>().eq(AReceiptInfo::getContractId,id),false);
+                if(receiptInfo != null){
+                    throw new RuntimeException("该房屋已存在收据,请先删除收据");
+                }
+                AContractInfo contractInfo = this.getById(id);
+                // 删除原合同
+                minioFileStorageService.deleteFile(contractInfo.getOriginalContractUrl());
+                // 删除签订后的合同
+                minioFileStorageService.deleteFile(contractInfo.getSignContractUrl());
+                boolean remove = this.removeById(id);
+                if(!remove){
+                    throw new RuntimeException("删除失败");
+                }
+                return true;
+            }
+        }catch (Exception e){
+            throw new RuntimeException(e);
+        }
+        return false;
+    }
+
     @Autowired
     @Lazy
     private ASimplifiedHouseInfoService aSimplifiedHouseInfoService;
@@ -236,15 +277,12 @@ public class AContractInfoServiceImpl extends ServiceImpl<AContractInfoMapper, A
     private ATenantInfoService aTenantInfoService;
 
     @Override
-    public Page<AContractInfo> findByPage(long pageNum, long pageSize, String contractNumber, String contractDate, String contractStatus) {
+    public Page<AContractInfo> findByPage(long pageNum, long pageSize,
+                                          String contractNumber, String contractDate,
+                                          String contractStatus,String assetType,String building,String floor, String houseName) {
         Page<AContractInfo> page = new Page<>(pageNum, pageSize);
-        LambdaQueryWrapper<AContractInfo> queryWrapper = new LambdaQueryWrapper();
-        queryWrapper.like(contractNumber != null, AContractInfo::getContractNumber, contractNumber);
-        queryWrapper.eq(contractDate != null, AContractInfo::getContractDate, contractDate);
-        queryWrapper.like(contractStatus != null, AContractInfo::getContractStatus, contractStatus);
-        queryWrapper.orderByDesc(AContractInfo::getUpdateTime);
-        Page<AContractInfo> page1 = this.page(page, queryWrapper);
-        return page1;
+        IPage<AContractInfo> iPage = baseMapper.selectContractWithHouse(page, contractNumber, contractDate, contractStatus,assetType, building, floor, houseName);
+        return (Page<AContractInfo>) iPage;
     }
 
     @Override

+ 38 - 0
src/main/resources/mapper/property/AContractInfoMapper.xml

@@ -25,4 +25,42 @@
         contract_deposit,contract_status,original_contract_url,sign_contract_url,create_time,
         update_time
     </sql>
+    <select id="selectContractWithHouse" resultType="com.zksy.property.domain.AContractInfo">
+        SELECT
+        c.*,
+        h.asset_type as assetType,
+        h.building,
+        h.floor,
+        h.house_name as houseName
+        FROM a_contract_info c
+        LEFT JOIN a_simplified_house_info h
+        ON c.simplified_house_id = h.id
+        <where>
+            <!-- 合同编号模糊查询 -->
+            <if test="contractNumber != null and contractNumber != ''">
+                AND c.contract_number LIKE CONCAT('%', #{contractNumber}, '%')
+            </if>
+            <!-- 合同日期精确查询 -->
+            <if test="contractDate != null and contractDate != ''">
+                AND c.contract_date = #{contractDate}
+            </if>
+            <!-- 合同状态模糊查询 -->
+            <if test="contractStatus != null and contractStatus != ''">
+                AND c.contract_status LIKE CONCAT('%', #{contractStatus}, '%')
+            </if>
+            <if test="assetType != null and assetType != ''">
+                AND h.asset_type LIKE CONCAT('%', #{assetType}, '%')
+            </if>
+            <if test="building != null and building != ''">
+                AND h.building LIKE CONCAT('%', #{building}, '%')
+            </if>
+            <if test="floor != null and floor != ''">
+                AND h.floor LIKE CONCAT('%', #{floor}, '%')
+            </if>
+            <if test="houseName != null and houseName != ''">
+                AND h.house_name LIKE CONCAT('%', #{houseName}, '%')
+            </if>
+        </where>
+        ORDER BY c.update_time DESC
+    </select>
 </mapper>