浏览代码

feat: 实现不动产资源地图获取土地和建筑统计接口

weijianghai 1 年之前
父节点
当前提交
d4036894af

+ 10 - 1
src/main/java/com/nokia/financeapi/controller/house/HouseResourceMapController.java

@@ -2,7 +2,9 @@ package com.nokia.financeapi.controller.house;
 
 import com.nokia.financeapi.common.R;
 import com.nokia.financeapi.pojo.dto.GetBuildingAreaStatDto;
+import com.nokia.financeapi.pojo.dto.GetLandBuildingStatDto;
 import com.nokia.financeapi.pojo.vo.GetBuildingAreaStatVo;
+import com.nokia.financeapi.pojo.vo.GetLandBuildingStatVo;
 import com.nokia.financeapi.service.house.HouseResourceMapService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -12,8 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.util.List;
 
-@Tag(name = "资源地图")
+@Tag(name = "不动产资源地图")
 @RestController
 @RequestMapping("/api/house/resourceMap")
 public class HouseResourceMapController {
@@ -28,4 +31,10 @@ public class HouseResourceMapController {
     public R<GetBuildingAreaStatVo> getBuildingAreaStat(@Valid @RequestBody GetBuildingAreaStatDto dto) {
         return houseResourceMapService.getBuildingAreaStat(dto);
     }
+
+    @Operation(summary = "获取土地和建筑统计")
+    @PostMapping("/getLandBuildingStat")
+    public R<List<GetLandBuildingStatVo>> getLandBuildingStat(@Valid @RequestBody GetLandBuildingStatDto dto) {
+        return houseResourceMapService.getLandBuildingStat(dto);
+    }
 }

+ 118 - 12
src/main/java/com/nokia/financeapi/dao/house/HouseResourceMapMapper.java

@@ -1,11 +1,15 @@
 package com.nokia.financeapi.dao.house;
 
 import com.nokia.financeapi.pojo.dto.GetBuildingAreaStatDto;
+import com.nokia.financeapi.pojo.dto.GetLandBuildingStatDto;
 import com.nokia.financeapi.pojo.vo.GetBuildingAreaStatVo;
+import com.nokia.financeapi.pojo.vo.GetLandBuildingStatVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.List;
+
 @Mapper
 public interface HouseResourceMapMapper {
     /**
@@ -39,21 +43,123 @@ where
     </if>
 )
 select
-round(area_self_use, 2) as area_self_use,
-round(area_rent, 2) as area_rent,
-round(area_unused, 2) as area_unused,
-round(area_synthesis / area_total * 100, 2) as percent_synthesis,
-round(area_equipment / area_total * 100, 2) as percent_equipment,
-round(area_marketing / area_total * 100, 2) as percent_marketing,
-round(area_affiliate / area_total * 100, 2) as percent_affiliate,
-round(area_administration / area_total * 100, 2) as percent_administration,
-round(area_other / area_total * 100, 2) as percent_other,
-round(area_self_use / area_total * 100, 2) as percent_self_use,
-round(area_rent / area_total * 100, 2) as percent_rent,
-round(area_unused / area_total * 100, 2) as percent_unused
+    round(area_self_use, 2) as area_self_use,
+    round(area_rent, 2) as area_rent,
+    round(area_unused, 2) as area_unused,
+    round(area_synthesis / area_total * 100, 2) as percent_synthesis,
+    round(area_equipment / area_total * 100, 2) as percent_equipment,
+    round(area_marketing / area_total * 100, 2) as percent_marketing,
+    round(area_affiliate / area_total * 100, 2) as percent_affiliate,
+    round(area_administration / area_total * 100, 2) as percent_administration,
+    round(area_other / area_total * 100, 2) as percent_other,
+    round(area_self_use / area_total * 100, 2) as percent_self_use,
+    round(area_rent / area_total * 100, 2) as percent_rent,
+    round(area_unused / area_total * 100, 2) as percent_unused
 from t1
 </script>
 """)
     GetBuildingAreaStatVo getBuildingAreaStat(@Param("dto") GetBuildingAreaStatDto dto);
 
+    /**
+     * 统计各个地市的建筑和土地数量
+     */
+    @Select("""
+with
+t1 as (
+select
+    city as area_name,
+    count(1) as building_count
+from
+    house.building_month
+where
+    year_month = (
+    select
+        max(year_month)
+    from
+        house.building_month)
+group by
+    city
+),
+t2 as (
+select
+    city as area_name,
+    count(1) as land_count
+from
+    house.land_month
+where
+    year_month = (
+    select
+        max(year_month)
+    from
+        house.land_month)
+group by
+    city
+)
+select
+    t1.area_name,
+    t1.building_count,
+    t2.land_count
+from
+    t1
+join t2 on
+    t1.area_name = t2.area_name
+order by
+    t1.area_name
+""")
+    List<GetLandBuildingStatVo> getCityLandBuildingStat();
+
+    /**
+     * 统计某地市各个区县的建筑和土地数量
+     */
+    @Select("""
+<script>
+with
+t1 as (
+select
+    district as area_name,
+    count(1) as building_count
+from
+    house.building_month
+where
+    city = #{dto.city}
+    and district is not null
+    and district != ''
+    and year_month = (
+    select
+        max(year_month)
+    from
+        house.building_month)
+group by
+    district
+),
+t2 as (
+select
+    district as area_name,
+    count(1) as land_count
+from
+    house.land_month
+where
+    city = #{dto.city}
+    and district is not null
+    and district != ''
+    and year_month = (
+    select
+        max(year_month)
+    from
+        house.land_month)
+group by
+    district
+)
+select
+    t1.area_name,
+    t1.building_count,
+    t2.land_count
+from
+    t1
+join t2 on
+    t1.area_name = t2.area_name
+order by t1.area_name
+</script>
+""")
+    List<GetLandBuildingStatVo> getDistrictLandBuildingStat(@Param("dto") GetLandBuildingStatDto dto);
 }

+ 10 - 0
src/main/java/com/nokia/financeapi/pojo/dto/GetLandBuildingStatDto.java

@@ -0,0 +1,10 @@
+package com.nokia.financeapi.pojo.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class GetLandBuildingStatDto {
+    @Schema(description = "地市,不传默认全省", example = "石家庄")
+    private String city;
+}

+ 16 - 0
src/main/java/com/nokia/financeapi/pojo/vo/GetLandBuildingStatVo.java

@@ -0,0 +1,16 @@
+package com.nokia.financeapi.pojo.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class GetLandBuildingStatVo {
+    @Schema(description = "地区名称", example = "石家庄")
+    private String areaName;
+    @Schema(description = "建筑数量", example = "11")
+    private BigDecimal buildingCount;
+    @Schema(description = "土地数量", example = "22")
+    private BigDecimal landCount;
+}

+ 12 - 0
src/main/java/com/nokia/financeapi/service/house/HouseResourceMapService.java

@@ -3,8 +3,13 @@ package com.nokia.financeapi.service.house;
 import com.nokia.financeapi.common.R;
 import com.nokia.financeapi.dao.house.HouseResourceMapMapper;
 import com.nokia.financeapi.pojo.dto.GetBuildingAreaStatDto;
+import com.nokia.financeapi.pojo.dto.GetLandBuildingStatDto;
 import com.nokia.financeapi.pojo.vo.GetBuildingAreaStatVo;
+import com.nokia.financeapi.pojo.vo.GetLandBuildingStatVo;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
 
 @Service
 public class HouseResourceMapService {
@@ -17,4 +22,11 @@ public class HouseResourceMapService {
     public R<GetBuildingAreaStatVo> getBuildingAreaStat(GetBuildingAreaStatDto dto) {
         return R.ok(houseResourceMapMapper.getBuildingAreaStat(dto));
     }
+
+    public R<List<GetLandBuildingStatVo>> getLandBuildingStat(GetLandBuildingStatDto dto) {
+        if (StringUtils.hasText(dto.getCity())) {
+            return R.ok(houseResourceMapMapper.getDistrictLandBuildingStat(dto));
+        }
+        return R.ok(houseResourceMapMapper.getCityLandBuildingStat());
+    }
 }