Просмотр исходного кода

feat: 不动产报告接口实现日期筛选

weijianghai 1 год назад
Родитель
Сommit
3e8d91718e

+ 42 - 0
src/main/java/com/nokia/financeapi/dao/house/HouseReportDao.java

@@ -0,0 +1,42 @@
+package com.nokia.financeapi.dao.house;
+
+import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
+import com.nokia.financeapi.pojo.po.house.HouseReportsPo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface HouseReportDao {
+    /**
+     * 获取最新报告
+     */
+    @Select("""
+select
+    *
+from
+    house.house_reports
+where
+    year_month = (
+    select
+        max(year_month)
+    from
+        house.house_reports)
+    and file_type = #{dto.fileType}
+""")
+    HouseReportsPo getLatest(@Param("dto") GetHouseReportDto dto);
+
+    /**
+     * 根据年月获取报告
+     */
+    @Select("""
+select
+    *
+from
+    house.house_reports
+where
+    year_month = #{dto.endDate}
+    and file_type = #{dto.fileType}
+""")
+    HouseReportsPo getByDate(@Param("dto") GetHouseReportDto dto);
+}

+ 6 - 0
src/main/java/com/nokia/financeapi/pojo/dto/GetHouseReportDto.java

@@ -1,5 +1,6 @@
 package com.nokia.financeapi.pojo.dto;
 
+import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
@@ -7,4 +8,9 @@ import lombok.Data;
 public class GetHouseReportDto {
     @Schema(description = "账期", example = "202307")
     private Integer endDate;
+    /**
+     * 文件类型:pdf, word
+     */
+    @Hidden
+    private String fileType;
 }

+ 22 - 0
src/main/java/com/nokia/financeapi/pojo/po/house/HouseReportsPo.java

@@ -0,0 +1,22 @@
+package com.nokia.financeapi.pojo.po.house;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Data
+public class HouseReportsPo {
+
+    /**
+     * 报告年月
+     */
+    private Integer yearMonth;
+    /**
+     * 文件类型
+     */
+    private String fileType;
+    /**
+     * 报告url
+     */
+    private String url;
+}

+ 30 - 9
src/main/java/com/nokia/financeapi/service/house/HouseReportService.java

@@ -1,32 +1,53 @@
 package com.nokia.financeapi.service.house;
 
 import com.nokia.financeapi.common.R;
+import com.nokia.financeapi.dao.house.HouseReportDao;
 import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
+import com.nokia.financeapi.pojo.po.house.HouseReportsPo;
 import com.nokia.financeapi.pojo.vo.GetHouseReportVo;
 import com.nokia.financeapi.service.common.file.FileService;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 @Service
 public class HouseReportService {
     private final FileService fileService;
+    private final HouseReportDao houseReportDao;
 
-    public HouseReportService(FileService fileService) {
+    public HouseReportService(FileService fileService, HouseReportDao houseReportDao) {
         this.fileService = fileService;
+        this.houseReportDao = houseReportDao;
     }
 
     public R<GetHouseReportVo> getReportWord(GetHouseReportDto dto) {
-        GetHouseReportVo vo = new GetHouseReportVo();
-        String object = "oss/reports/house/202307.doc";
-        String url = fileService.getDownloadUrl(object);
-        vo.setUrl(url);
-        return R.ok(vo);
+        dto.setFileType("word");
+        return getGetHouseReport(dto);
     }
 
     public R<GetHouseReportVo> getReportPdf(GetHouseReportDto dto) {
+        dto.setFileType("pdf");
+        return getGetHouseReport(dto);
+    }
+
+    private R<GetHouseReportVo> getGetHouseReport(GetHouseReportDto dto) {
         GetHouseReportVo vo = new GetHouseReportVo();
-        String object = "oss/reports/house/202307.pdf";
-        String url = fileService.getDownloadUrl(object);
-        vo.setUrl(url);
+        vo.setUrl("");
+        String object = null;
+        if (dto.getEndDate() == null) {
+            HouseReportsPo po = houseReportDao.getLatest(dto);
+            if (po != null) {
+                object = po.getUrl();
+            }
+        } else {
+            HouseReportsPo po = houseReportDao.getByDate(dto);
+            if (po != null) {
+                object = po.getUrl();
+            }
+        }
+        if (StringUtils.hasText(object)) {
+            String url = fileService.getDownloadUrl(object);
+            vo.setUrl(url);
+        }
         return R.ok(vo);
     }
 }