|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|