Selaa lähdekoodia

fix: 修复不动产数据稽查异常数据稽核表错误

weijianghai 10 kuukautta sitten
vanhempi
commit
1eb919b299

+ 1 - 1
scripts/backup-financialdb.sh

@@ -4,7 +4,7 @@ echo "$(date) backup financialdb start"
 export PGPASSWORD='Finance@unicom23'
 backup_dir=/backup/postgres/financialdb/$(date +%Y%m)/$(date +%Y%m%d)/$(date +%Y%m%d%H%M%S)
 mkdir -p "${backup_dir}"
-host='127.0.0.1'
+host='172.16.107.5'
 port='5432'
 username='finance'
 dbname='financialdb'

+ 7 - 1
src/main/java/com/nokia/financeapi/controller/house/HouseDataCheckController.java

@@ -38,9 +38,15 @@ public class HouseDataCheckController {
         houseDataCheckService.getBuildingAreaDiffExport(dto);
     }
 
-    @Operation(summary = "异常数据稽核表")
+    @Operation(summary = "查询异常数据稽核表")
     @PostMapping("/getHouseAbnormalData")
     public R<GetHouseAbnormalDataVo> getHouseAbnormalData(@Valid @RequestBody GetHouseAbnormalDataDto dto) {
         return houseDataCheckService.getHouseAbnormalData(dto);
     }
+
+    @Operation(summary = "异常数据稽核表导出")
+    @GetMapping("/getHouseAbnormalDataExport")
+    public void getHouseAbnormalDataExport(@Valid GetHouseAbnormalDataDto dto) {
+        houseDataCheckService.getHouseAbnormalDataExport(dto);
+    }
 }

+ 46 - 59
src/main/java/com/nokia/financeapi/dao/house/HouseDataCheckDao.java

@@ -137,80 +137,67 @@ from
     List<GetBuildingAreaDiffVo> buildingAreaDiff(@Param("dto") GetBuildingAreaDiffDto dto);
 
     /**
-     * 获取不动产异常数据稽核最新的日期
-     */
-    @Select("""
-select max(year_month) from house.abnormal_data
-""")
-    Integer getAbnormalDataMaxDate();
-
-    /**
-     * 全省不动产异常数据稽核
-     */
-    @Select("""
-select
-    '全省' as unit_name,
-    sum(wei_guan_lian_ju_zhi) as wei_guan_lian_ju_zhi_sum,
-    sum(xian_zhi_jian_zhu_mian_ji) as xian_zhi_jian_zhu_mian_ji_sum
-from
-    house.abnormal_data
-where
-    year_month = #{dto.endDate}
-""")
-    GetHouseAbnormalDataVo getFirstUnitAbnormalData(@Param("dto") GetHouseAbnormalDataDto dto);
-
-    /**
-     * 二级单位不动产异常数据稽核
+     * 查询不动产异常数据稽核
      */
     @Select("""
+<script>
 with
 t101 as (
 select
-    second_unit as unit_name,
-    second_unit,
+    area_no,
+    city_no,
     sum(wei_guan_lian_ju_zhi) as wei_guan_lian_ju_zhi_sum,
     sum(xian_zhi_jian_zhu_mian_ji) as xian_zhi_jian_zhu_mian_ji_sum
 from
     house.abnormal_data
-where
-    year_month = #{dto.endDate}
+<choose>
+  <when test="dto.endDate != null">
+    where year_month = #{dto.endDate}
+  </when>
+  <otherwise>
+    where year_month = (select max(year_month) from house.abnormal_data)
+  </otherwise>
+</choose>
+<if test="dto.areaNo != null and dto.areaNo != ''">
+  and area_no = #{dto.areaNo}
+</if>
+<if test="dto.cityNo != null and dto.cityNo != ''">
+  and city_no = #{dto.cityNo}
+</if>
 group by
-    second_unit
+    area_no,
+    city_no
 ),
 t102 as (
 select
-    *
-from
-    t101
-left join house.second_unit_sort on
-    t101.second_unit = house.second_unit_sort.second_unit
-order by
-    house.second_unit_sort.sort desc
-)
-select
-    *
-from
-    t102
-""")
-    List<GetHouseAbnormalDataVo> getSecondUnitAbnormalData(@Param("dto") GetHouseAbnormalDataDto dto);
-
-    /**
-     * 三级单位不动产异常数据稽核
-     */
-    @Select("""
-select
-    third_unit as unit_name,
-    second_unit,
-    third_unit,
-    wei_guan_lian_ju_zhi as wei_guan_lian_ju_zhi_sum,
-    xian_zhi_jian_zhu_mian_ji as xian_zhi_jian_zhu_mian_ji_sum
+    b.id as area_no,
+    b."name" as area_name,
+    a.id as city_no,
+    a."name" as city_name,
+    a."name" as unit_name,
+    coalesce(c.wei_guan_lian_ju_zhi_sum, 0) as wei_guan_lian_ju_zhi_sum,
+    coalesce(c.xian_zhi_jian_zhu_mian_ji_sum, 0) as xian_zhi_jian_zhu_mian_ji_sum
 from
-    house.abnormal_data
+    common.organization a
+left join common.organization b on
+    a.parent_id = b.id
+left join t101 c on
+    a.id = c.city_no
 where
-    year_month = #{dto.endDate}
+    a.grade = 2
+    and a.unhide = 1
+    and a.parent_id != '-12'
+<if test="dto.areaNo != null and dto.areaNo != ''">
+  and a.parent_id = #{dto.areaNo}
+</if>
+<if test="dto.cityNo != null and dto.cityNo != ''">
+  and a.id = #{dto.cityNo}
+</if>
 order by
-    second_unit,
-    third_unit
+    b.order_num, a.order_num
+)
+select * from t102
+</script>
 """)
-    List<GetHouseAbnormalDataVo> getThirdUnitAbnormalData(@Param("dto") GetHouseAbnormalDataDto dto);
+    List<GetHouseAbnormalDataVo> getAbnormalData(@Param("dto") GetHouseAbnormalDataDto dto);
 }

+ 4 - 0
src/main/java/com/nokia/financeapi/pojo/dto/GetHouseAbnormalDataDto.java

@@ -7,4 +7,8 @@ import lombok.Data;
 public class GetHouseAbnormalDataDto {
     @Schema(description = "账期", example = "202307")
     private Integer endDate;
+    @Schema(description = "二级组织机构id")
+    private String areaNo;
+    @Schema(description = "三级级组织机构id")
+    private String cityNo;
 }

+ 35 - 4
src/main/java/com/nokia/financeapi/pojo/vo/GetHouseAbnormalDataVo.java

@@ -3,18 +3,21 @@ package com.nokia.financeapi.pojo.vo;
 import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
-import lombok.NoArgsConstructor;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
-@NoArgsConstructor
 @Data
 public class GetHouseAbnormalDataVo {
     @Hidden
-    private String secondUnit;
+    private String areaNo;
     @Hidden
-    private String thirdUnit;
+    private String areaName;
+    @Hidden
+    private String cityNo;
+    @Hidden
+    private String cityName;
     @Schema(description = "单位名称", example = "全省")
     private String unitName;
     @Schema(description = "既未对应土地又未对应建筑的局址数量", example = "3")
@@ -23,4 +26,32 @@ public class GetHouseAbnormalDataVo {
     private BigDecimal xianZhiJianZhuMianJiSum;
     @Schema(description = "子列表")
     private List<GetHouseAbnormalDataVo> children;
+
+    public GetHouseAbnormalDataVo() {
+        this.areaNo = "";
+        this.areaName = "";
+        this.cityNo = "";
+        this.cityName = "";
+        this.unitName = "";
+        this.weiGuanLianJuZhiSum = 0;
+        this.xianZhiJianZhuMianJiSum = BigDecimal.ZERO;
+        this.children = new ArrayList<>();
+    }
+
+    public GetHouseAbnormalDataVo(String areaNo, String areaName) {
+        this.areaNo = areaNo;
+        this.areaName = areaName;
+        this.cityNo = areaNo;
+        this.cityName = areaName;
+        this.unitName = areaName;
+        this.weiGuanLianJuZhiSum = 0;
+        this.xianZhiJianZhuMianJiSum = BigDecimal.ZERO;
+        this.children = new ArrayList<>();
+    }
+
+    public void update(GetHouseAbnormalDataVo po) {
+        this.weiGuanLianJuZhiSum += po.weiGuanLianJuZhiSum;
+        this.xianZhiJianZhuMianJiSum = this.xianZhiJianZhuMianJiSum.add(po.xianZhiJianZhuMianJiSum);
+        this.children.add(po);
+    }
 }

+ 215 - 30
src/main/java/com/nokia/financeapi/service/house/HouseDataCheckService.java

@@ -18,13 +18,15 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletResponse;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -76,35 +78,6 @@ public class HouseDataCheckService {
         return firstUnitPo;
     }
 
-    public R<GetHouseAbnormalDataVo> getHouseAbnormalData(GetHouseAbnormalDataDto dto) {
-        Integer endDate = dto.getEndDate();
-        // 账期为空则取最新的账期
-        if (dto.getEndDate() == null) {
-            endDate = houseDataCheckDao.getAbnormalDataMaxDate();
-        }
-        if (endDate == null) {
-            return R.ok();
-        }
-        dto.setEndDate(endDate);
-        GetHouseAbnormalDataVo vo = houseDataCheckDao.getFirstUnitAbnormalData(dto);
-        if (vo == null || vo.getWeiGuanLianJuZhiSum() == null || vo.getXianZhiJianZhuMianJiSum() == null) {
-            return R.ok();
-        }
-        List<GetHouseAbnormalDataVo> l2 = houseDataCheckDao.getSecondUnitAbnormalData(dto);
-        vo.setChildren(l2);
-        List<GetHouseAbnormalDataVo> l3 = houseDataCheckDao.getThirdUnitAbnormalData(dto);
-        for (GetHouseAbnormalDataVo second : l2) {
-            List<GetHouseAbnormalDataVo> l33 = new ArrayList<>();
-            second.setChildren(l33);
-            for (GetHouseAbnormalDataVo third : l3) {
-                if (second.getSecondUnit().equals(third.getSecondUnit())) {
-                    l33.add(third);
-                }
-            }
-        }
-        return R.ok(vo);
-    }
-
     public void getBuildingAreaDiffExport(GetBuildingAreaDiffDto dto) {
         ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
                 .getRequestAttributes();
@@ -115,6 +88,12 @@ public class HouseDataCheckService {
         if (response == null) {
             return;
         }
+        if (StringUtils.hasText(dto.getAreaNo())) {
+            dto.setAreaNo(URLDecoder.decode(dto.getAreaNo(), StandardCharsets.UTF_8));
+        }
+        if (StringUtils.hasText(dto.getCityNo())) {
+            dto.setCityNo(URLDecoder.decode(dto.getCityNo(), StandardCharsets.UTF_8));
+        }
         String filename = "数据稽查_自用面积比较"
                 + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xlsx";
         response.setHeader("Content-Disposition", "attachment;filename=" + URLEncodeUtil.encode(filename));
@@ -383,4 +362,210 @@ public class HouseDataCheckService {
             }
         }
     }
+
+    public R<GetHouseAbnormalDataVo> getHouseAbnormalData(GetHouseAbnormalDataDto dto) {
+        GetHouseAbnormalDataVo vo = getHouseAbnormalDataVo(dto);
+        if (vo == null) {
+            return R.ok();
+        }
+        return R.ok(vo);
+    }
+
+    private GetHouseAbnormalDataVo getHouseAbnormalDataVo(GetHouseAbnormalDataDto dto) {
+        if ("全省".equals(dto.getAreaNo())) {
+            dto.setAreaNo(null);
+            dto.setCityNo(null);
+        }
+        // 查询三级单位统计
+        List<GetHouseAbnormalDataVo> pos = houseDataCheckDao.getAbnormalData(dto);
+        if (CollectionUtils.isEmpty(pos)) {
+            return null;
+        }
+        // 一级单位统计
+        GetHouseAbnormalDataVo firstUnitPo = new GetHouseAbnormalDataVo();
+        firstUnitPo.setAreaName("全省");
+        firstUnitPo.setCityName("全省");
+        firstUnitPo.setUnitName("全省");
+        LinkedHashMap<String, GetHouseAbnormalDataVo> secondUnitPoMap = new LinkedHashMap<>();
+        // 二级单位统计
+        for (GetHouseAbnormalDataVo houseAgeStatPo : pos) {
+            secondUnitPoMap.putIfAbsent(houseAgeStatPo.getAreaNo(),
+                    new GetHouseAbnormalDataVo(houseAgeStatPo.getAreaNo(), houseAgeStatPo.getAreaName()));
+            GetHouseAbnormalDataVo secondUnitPo = secondUnitPoMap.get(houseAgeStatPo.getAreaNo());
+            secondUnitPo.update(houseAgeStatPo);
+        }
+        for (GetHouseAbnormalDataVo value : secondUnitPoMap.values()) {
+            firstUnitPo.update(value);
+        }
+        return firstUnitPo;
+    }
+
+    public void getHouseAbnormalDataExport(GetHouseAbnormalDataDto dto) {
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
+                .getRequestAttributes();
+        if (servletRequestAttributes == null) {
+            return;
+        }
+        HttpServletResponse response = servletRequestAttributes.getResponse();
+        if (response == null) {
+            return;
+        }
+        if (StringUtils.hasText(dto.getAreaNo())) {
+            dto.setAreaNo(URLDecoder.decode(dto.getAreaNo(), StandardCharsets.UTF_8));
+        }
+        if (StringUtils.hasText(dto.getCityNo())) {
+            dto.setCityNo(URLDecoder.decode(dto.getCityNo(), StandardCharsets.UTF_8));
+        }
+        String filename = "数据稽查_异常数据稽核表"
+                + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xlsx";
+        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncodeUtil.encode(filename));
+        response.setContentType("application/octet-stream");
+        try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
+            writeHouseAbnormalData(dto, wb);
+            wb.write(response.getOutputStream());
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    private void writeHouseAbnormalData(GetHouseAbnormalDataDto dto, SXSSFWorkbook wb) {
+        GetHouseAbnormalDataVo po1 = getHouseAbnormalDataVo(dto);
+        DataFormat dataFormat = wb.createDataFormat();
+        // 数字样式
+        CellStyle numberCellStyle = wb.createCellStyle();
+        numberCellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
+        numberCellStyle.setAlignment(HorizontalAlignment.RIGHT);
+        // 整数样式
+        CellStyle integerCellStyle = wb.createCellStyle();
+        integerCellStyle.setDataFormat(dataFormat.getFormat("#,##0"));
+        integerCellStyle.setAlignment(HorizontalAlignment.RIGHT);
+        // 表头样式
+        CellStyle headerCellStyle = wb.createCellStyle();
+        headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+        headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        headerCellStyle.setWrapText(true);
+        SXSSFSheet sheet = wb.createSheet();
+        AtomicInteger rowIndex = new AtomicInteger(0);
+        // 表头
+        Row headerRow = sheet.createRow(rowIndex.getAndIncrement());
+        List<String> headers = Stream.of("资产所属单位(一级)", "资产所属单位(二级)", "资产所属单位(三级)",
+                "既未对应土地又未对应建筑的局址数量", "闲置建筑面积").toList();
+        int headerSize = headers.size();
+        for (int i = 0; i < headerSize; i++) {
+            Cell cell = headerRow.createCell(i);
+            cell.setCellValue(headers.get(i));
+            cell.setCellStyle(headerCellStyle);
+            // 根据内容长度设置列宽
+//            int columnWidth = headers.get(i).length() * 256 * 2 + 256;
+//            sheet.setColumnWidth(i, columnWidth);
+            sheet.setColumnWidth(i, 256 * 25);
+        }
+        Row explainRow = sheet.createRow(rowIndex.getAndIncrement());
+        List<String> headers2 = Stream.of("说明", "", "", "错误数据,应删除该局址", "需核实闲置面积是否有遗漏")
+                .toList();
+        int headerSize2 = headers2.size();
+        for (int i = 0; i < headerSize2; i++) {
+            Cell cell = explainRow.createCell(i);
+            cell.setCellValue(headers2.get(i));
+            cell.setCellStyle(headerCellStyle);
+        }
+        if (po1 == null) {
+            return;
+        }
+        // 数据
+        AtomicInteger columnIndex1 = new AtomicInteger(0);
+        // 一级单位统计
+        Row row1 = sheet.createRow(rowIndex.getAndIncrement());
+        // 资产所属单位(一级)
+        Cell firstUnitCell1 = row1.createCell(columnIndex1.getAndIncrement());
+        if (po1.getAreaName() != null) {
+            firstUnitCell1.setCellValue(po1.getAreaName());
+        }
+        // 二级单位
+        Cell areaNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
+//        if (po1.getAreaName() != null) {
+//            areaNameCell1.setCellValue(po1.getAreaName());
+//        }
+        // 三级单位
+        Cell cityNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
+//        if (po1.getCityName() != null) {
+//            cityNameCell1.setCellValue(po1.getCityName());
+//        }
+        // 既未对应土地又未对应建筑的局址数量
+        Cell weiGuanLianJuZhiSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
+        if (po1.getWeiGuanLianJuZhiSum() != null) {
+            weiGuanLianJuZhiSumCell1.setCellValue(po1.getWeiGuanLianJuZhiSum());
+        }
+        weiGuanLianJuZhiSumCell1.setCellStyle(integerCellStyle);
+        // 闲置建筑面积
+        Cell xianZhiJianZhuMianJiSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
+        if (po1.getXianZhiJianZhuMianJiSum() != null) {
+            xianZhiJianZhuMianJiSumCell1.setCellValue(po1.getXianZhiJianZhuMianJiSum().doubleValue());
+        }
+        xianZhiJianZhuMianJiSumCell1.setCellStyle(numberCellStyle);
+        // 二级单位统计
+        for (GetHouseAbnormalDataVo po2 : po1.getChildren()) {
+            AtomicInteger columnIndex2 = new AtomicInteger(0);
+            Row row2 = sheet.createRow(rowIndex.getAndIncrement());
+            // 资产所属单位(一级)
+            Cell firstUnitCell2 = row2.createCell(columnIndex2.getAndIncrement());
+//            if (po2.getAreaName() != null) {
+//                firstUnitCell2.setCellValue(po2.getAreaName());
+//            }
+            // 二级单位
+            Cell areaNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
+            if (po2.getAreaName() != null) {
+                areaNameCell2.setCellValue(po2.getAreaName());
+            }
+            // 三级单位
+            Cell cityNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
+//            if (po2.getCityName() != null) {
+//                cityNameCell2.setCellValue(po2.getCityName());
+//            }
+            // 既未对应土地又未对应建筑的局址数量
+            Cell weiGuanLianJuZhiSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
+            if (po2.getWeiGuanLianJuZhiSum() != null) {
+                weiGuanLianJuZhiSumCell2.setCellValue(po2.getWeiGuanLianJuZhiSum());
+            }
+            weiGuanLianJuZhiSumCell2.setCellStyle(integerCellStyle);
+            // 闲置建筑面积
+            Cell xianZhiJianZhuMianJiSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
+            if (po2.getXianZhiJianZhuMianJiSum() != null) {
+                xianZhiJianZhuMianJiSumCell2.setCellValue(po2.getXianZhiJianZhuMianJiSum().doubleValue());
+            }
+            xianZhiJianZhuMianJiSumCell2.setCellStyle(numberCellStyle);
+            // 三级单位统计
+            for (GetHouseAbnormalDataVo po3 : po2.getChildren()) {
+                AtomicInteger columnIndex3 = new AtomicInteger(0);
+                Row row3 = sheet.createRow(rowIndex.getAndIncrement());
+                // 资产所属单位(一级)
+                Cell firstUnitCell3 = row3.createCell(columnIndex3.getAndIncrement());
+//                if (po3.getAreaName() != null) {
+//                    firstUnitCell3.setCellValue(po3.getAreaName());
+//                }
+                // 二级单位
+                Cell areaNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
+//                if (po3.getAreaName() != null) {
+//                    areaNameCell3.setCellValue(po3.getAreaName());
+//                }
+                // 三级单位
+                Cell cityNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
+                if (po3.getCityName() != null) {
+                    cityNameCell3.setCellValue(po3.getCityName());
+                }
+                // 既未对应土地又未对应建筑的局址数量
+                Cell weiGuanLianJuZhiSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
+                if (po3.getWeiGuanLianJuZhiSum() != null) {
+                    weiGuanLianJuZhiSumCell3.setCellValue(po3.getWeiGuanLianJuZhiSum());
+                }
+                weiGuanLianJuZhiSumCell3.setCellStyle(integerCellStyle);
+                // 闲置建筑面积
+                Cell xianZhiJianZhuMianJiSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
+                if (po3.getXianZhiJianZhuMianJiSum() != null) {
+                    xianZhiJianZhuMianJiSumCell3.setCellValue(po3.getXianZhiJianZhuMianJiSum().doubleValue());
+                }
+                xianZhiJianZhuMianJiSumCell3.setCellStyle(numberCellStyle);
+            }
+        }
+    }
 }

+ 6 - 7
src/main/resources/application-dev.yml

@@ -2,14 +2,13 @@ server:
   port: 39100
 spring:
   datasource:
-#    username: postgres
-#    password: Test!234
-#    driver-class-name: org.postgresql.Driver
-#    url: jdbc:postgresql://192.168.65.128:5432/financialdb
-    username: finance
-    password: Finance@unicom23
     driver-class-name: org.postgresql.Driver
-    url: jdbc:postgresql://172.16.107.5:5432/financialdb
+#    url: jdbc:postgresql://172.16.107.5:5432/financialdb
+#    username: finance
+#    password: Finance@unicom23
+    url: jdbc:postgresql://192.168.50.3:15432/financialdb
+    username: postgres
+    password: NFQCgBA6YhNvgAqG6THw
 logging:
   level:
     com: