123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344 |
- package com.example.service.house;
- import cn.hutool.core.net.URLEncodeUtil;
- import com.baomidou.mybatisplus.core.metadata.OrderItem;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.example.common.PageVo;
- import com.example.common.Rsp;
- import com.example.dao.WzOtnAreaDao;
- import com.example.dao.house.HouseBuildingDao;
- import com.example.entity.house.BuildingIdleStatPo;
- import com.example.entity.house.HouseAgeStatPo;
- import com.example.entity.house.HouseBuildingPo;
- import com.example.entity.house.HouseSitePo;
- import com.example.enums.ListBuildingIdleOrderEnum;
- import com.example.enums.ListBuildingOrderEnum;
- import com.example.enums.OrderEnum;
- import com.example.pojo.bo.BuildingIdleStatBo;
- import com.example.pojo.bo.HouseAgeStatBo;
- import com.example.pojo.bo.ListBuildingBo;
- import com.example.pojo.bo.ListBuildingIdleBo;
- import com.example.pojo.bo.ListHouseSiteBo;
- import com.example.pojo.dto.BuildingIdleStatDto;
- import com.example.pojo.dto.HouseAgeStatDto;
- import com.example.pojo.dto.ListBuildingDto;
- import com.example.pojo.dto.ListBuildingIdleDto;
- import com.example.pojo.dto.ListSiteNameDto;
- import com.example.pojo.dto.ListSiteNumDto;
- import com.example.pojo.vo.BuildingIdleStatVo;
- import com.example.pojo.vo.HouseAgeStatVo;
- import com.example.pojo.vo.ListBuildingIdleVo;
- import com.example.pojo.vo.ListBuildingVo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellStyle;
- import org.apache.poi.ss.usermodel.DataFormat;
- import org.apache.poi.ss.usermodel.HorizontalAlignment;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.VerticalAlignment;
- 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.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.stream.Stream;
- @Slf4j
- @Service
- public class HouseWzBuildManageDetailsService {
- private final HouseBuildingDao houseBuildingDao;
- private final WzOtnAreaDao wzOtnAreaDao;
- public HouseWzBuildManageDetailsService(HouseBuildingDao houseBuildingDao, WzOtnAreaDao wzOtnAreaDao) {
- this.houseBuildingDao = houseBuildingDao;
- this.wzOtnAreaDao = wzOtnAreaDao;
- }
- public Rsp<PageVo<ListBuildingIdleVo>> ideList(ListBuildingIdleDto dto) {
- Page<HouseBuildingPo> page = new Page<>(dto.getPage().getPageNum(), dto.getPage().getPageSize());
- List<HouseBuildingPo> list = getBuildingIdle(dto, page);
- List<ListBuildingIdleVo> vos = new ArrayList<>();
- for (HouseBuildingPo po : list) {
- vos.add(new ListBuildingIdleVo(po));
- }
- PageVo<ListBuildingIdleVo> pageVo = new PageVo<>(vos, page);
- return Rsp.ok(pageVo);
- }
- public void ideListExport(ListBuildingIdleDto.ListBuildingIdleMapDTO dto) {
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes();
- if (servletRequestAttributes == null) {
- return;
- }
- HttpServletResponse response = servletRequestAttributes.getResponse();
- if (response == null) {
- return;
- }
- String filename = "房屋空置_空置1000平方米以上"
- + 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()) {
- writeIdleList(new ListBuildingIdleDto(dto), wb);
- wb.write(response.getOutputStream());
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
-
- private List<HouseBuildingPo> getBuildingIdle(ListBuildingIdleDto dto, Page<HouseBuildingPo> page) {
- ListBuildingIdleBo bo = new ListBuildingIdleBo();
- if (dto.getMap() != null && dto.getMap().getStatisticalMonth() != null) {
- bo.setYearMonth(dto.getMap().getStatisticalMonth());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCity()) && !"全省".equals(dto.getMap().getCity())) {
- bo.setAreaNo(dto.getMap().getCity());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCounty())) {
- bo.setCityNo(dto.getMap().getCounty());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getBuildingAddressNumber())) {
- bo.setSiteNum(dto.getMap().getBuildingAddressNumber());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getBuildingNameAlias())) {
- bo.setSiteName(dto.getMap().getBuildingNameAlias());
- }
- if (dto.getMap() != null && dto.getMap().getOrder() != null && dto.getMap().getSidx() != null) {
- if (OrderEnum.asc.equals(dto.getMap().getOrder())) {
- page.addOrder(OrderItem.asc(dto.getMap().getSidx().getColumnName()));
- } else {
- page.addOrder(OrderItem.desc(dto.getMap().getSidx().getColumnName()));
- }
- } else {
- page.addOrder(OrderItem.desc(ListBuildingIdleOrderEnum.buildingAreaIdelArea.getColumnName()));
- }
- return houseBuildingDao.listBuildingIdle(page, bo);
- }
-
- private void writeIdleList(ListBuildingIdleDto dto, SXSSFWorkbook wb) {
- Page<HouseBuildingPo> page = new Page<>(1, Long.MAX_VALUE);
- List<HouseBuildingPo> list = getBuildingIdle(dto, page);
- DataFormat dataFormat = wb.createDataFormat();
-
- CellStyle numberCellStyle = wb.createCellStyle();
- numberCellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
- numberCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle baseCellStyle = wb.createCellStyle();
- baseCellStyle.setAlignment(HorizontalAlignment.CENTER);
- baseCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
- CellStyle percentCellStyle = wb.createCellStyle();
- percentCellStyle.setDataFormat(dataFormat.getFormat("0.00%"));
- percentCellStyle.setAlignment(HorizontalAlignment.RIGHT);
- SXSSFSheet sheet = wb.createSheet();
- AtomicInteger rowIndex = new AtomicInteger(0);
-
- Row headerRow = sheet.createRow(rowIndex.getAndIncrement());
- List<String> headers = Stream.of("资产所属单位(一级)", "资产所属单位(二级)", "资产所属单位(三级)", "局址编号",
- "局址别名", "建筑别名", "地段", "建筑面积(㎡)","建筑面积-出租(㎡)", "建筑面积-闲置(㎡)", "建筑面积-自用(㎡)",
- "建筑面积-不可使用(㎡)", "上级土地名称", "得房率", "房屋来源", "取得日期", "房龄开始年份", "投资主体", "管理层级",
- "房屋结构", "楼层总数", "是否临街", "是否有院落", "整栋是否独有", "是否有房产证", "无房产证原因", "未关联资产",
- "资产编号", "资产标签号", "使用状态", "建筑用途", "权属状态", "建筑占地面积(㎡)", "使用面积(㎡)",
- "使用面积-自用(㎡)", "使用面积-出租(㎡)", "使用面积-闲置(㎡)", "使用面积-不可使用(㎡)", "楼长姓名",
- "楼长所在单位", "经度", "纬度", "实际产权人").toList();
- int headerLength = headers.size();
- for (int i = 0; i < headerLength; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(headers.get(i));
- cell.setCellStyle(baseCellStyle);
-
- int columnWidth = headers.get(i).length() * 256 * 2 + 256;
- sheet.setColumnWidth(i, columnWidth);
- }
-
- for (HouseBuildingPo po : list) {
- AtomicInteger columnIndex = new AtomicInteger(0);
- Row row = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFirstUnit() != null) {
- firstUnitCell.setCellValue(po.getFirstUnit());
- }
-
- Cell areaNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAreaName() != null) {
- areaNameCell.setCellValue(po.getAreaName());
- }
-
- Cell cityNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCityName() != null) {
- cityNameCell.setCellValue(po.getCityName());
- }
-
- Cell siteNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getSiteName() != null) {
- siteNumCell.setCellValue(po.getSiteNum());
- }
-
- Cell siteNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getSiteName() != null) {
- siteNameCell.setCellValue(po.getSiteName());
- }
-
- Cell buildingNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingName() != null) {
- buildingNameCell.setCellValue(po.getBuildingName());
- }
-
- Cell areaSectorCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAreaSector() != null) {
- areaSectorCell.setCellValue(po.getAreaSector());
- }
-
- Cell buildingAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingArea() != null) {
- buildingAreaCell.setCellValue(po.getBuildingArea().doubleValue());
- }
- buildingAreaCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaRentCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaRent() != null) {
- buildingAreaRentCell.setCellValue(po.getBuildingAreaRent().doubleValue());
- }
- buildingAreaRentCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaIdleCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaIdle() != null) {
- buildingAreaIdleCell.setCellValue(po.getBuildingAreaIdle().doubleValue());
- }
- buildingAreaIdleCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaSelfUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaSelfUse() != null) {
- buildingAreaSelfUseCell.setCellValue(po.getBuildingAreaSelfUse().doubleValue());
- }
- buildingAreaSelfUseCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaUnusableCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaUnusable() != null) {
- buildingAreaUnusableCell.setCellValue(po.getBuildingAreaUnusable().doubleValue());
- }
- buildingAreaUnusableCell.setCellStyle(numberCellStyle);
-
- Cell landNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLandName() != null) {
- landNameCell.setCellValue(po.getLandName());
- }
-
- Cell housingAcquisitionRateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHousingAcquisitionRate() != null) {
- housingAcquisitionRateCell.setCellValue(po.getHousingAcquisitionRate().doubleValue());
- }
- housingAcquisitionRateCell.setCellStyle(percentCellStyle);
-
- Cell housingSourceCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHousingSource() != null) {
- housingSourceCell.setCellValue(po.getHousingSource());
- }
-
- Cell acquisitionDateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAcquisitionDate() != null) {
- acquisitionDateCell.setCellValue(po.getAcquisitionDate());
- }
-
- Cell houseYearBeganCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHouseYearBegan() != null) {
- houseYearBeganCell.setCellValue(po.getHouseYearBegan());
- }
-
- Cell investorCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getInvestor() != null) {
- investorCell.setCellValue(po.getInvestor());
- }
-
- Cell managementLevelCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getManagementLevel() != null) {
- managementLevelCell.setCellValue(po.getManagementLevel());
- }
-
- Cell buildingStructureCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingStructure() != null) {
- buildingStructureCell.setCellValue(po.getBuildingStructure());
- }
-
- Cell totalFloorsCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getTotalFloors() != null) {
- totalFloorsCell.setCellValue(po.getTotalFloors());
- }
-
- Cell frontageCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFrontage() != null) {
- frontageCell.setCellValue(po.getFrontage());
- }
-
- Cell courtyardCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCourtyard() != null) {
- courtyardCell.setCellValue(po.getCourtyard());
- }
-
- Cell wholeBuildingCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getWholeBuilding() != null) {
- wholeBuildingCell.setCellValue(po.getWholeBuilding());
- }
-
- Cell propertyOwnershipCertificateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getPropertyOwnershipCertificate() != null) {
- propertyOwnershipCertificateCell.setCellValue(po.getPropertyOwnershipCertificate());
- }
-
- Cell noPropertyOwnershipCertificateReasonCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getNoPropertyOwnershipCertificateReason() != null) {
- noPropertyOwnershipCertificateReasonCell.setCellValue(
- po.getNoPropertyOwnershipCertificateReason());
- }
-
- Cell unrelatedAssetsCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUnrelatedAssets() != null) {
- unrelatedAssetsCell.setCellValue(po.getUnrelatedAssets());
- }
-
- Cell assetsNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAssetsNum() != null) {
- assetsNumCell.setCellValue(po.getAssetsNum());
- }
-
- Cell assetsTagNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAssetsTagNum() != null) {
- assetsTagNumCell.setCellValue(po.getAssetsTagNum());
- }
-
- Cell usageStatusCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsageStatus() != null) {
- usageStatusCell.setCellValue(po.getUsageStatus());
- }
-
- Cell buildingUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingUse() != null) {
- buildingUseCell.setCellValue(po.getBuildingUse());
- }
-
- Cell ownershipStatusCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getOwnershipStatus() != null) {
- ownershipStatusCell.setCellValue(po.getOwnershipStatus());
- }
-
- Cell floorAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFloorArea() != null) {
- floorAreaCell.setCellValue(po.getFloorArea().doubleValue());
- }
- floorAreaCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableArea() != null) {
- usableAreaCell.setCellValue(po.getUsableArea().doubleValue());
- }
- usableAreaCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaSelfUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaSelfUse() != null) {
- usableAreaSelfUseCell.setCellValue(po.getUsableAreaSelfUse().doubleValue());
- }
- usableAreaSelfUseCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaRentCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaRent() != null) {
- usableAreaRentCell.setCellValue(po.getUsableAreaRent().doubleValue());
- }
- usableAreaRentCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaIdleCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaIdle() != null) {
- usableAreaIdleCell.setCellValue(po.getUsableAreaIdle().doubleValue());
- }
- usableAreaIdleCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaUnusableCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaUnusable() != null) {
- usableAreaUnusableCell.setCellValue(po.getUsableAreaUnusable().doubleValue());
- }
- usableAreaUnusableCell.setCellStyle(numberCellStyle);
-
- Cell communityAssistantNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCommunityAssistantName() != null) {
- communityAssistantNameCell.setCellValue(po.getCommunityAssistantName());
- }
-
- Cell communityAssistantUnitCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCommunityAssistantUnit() != null) {
- communityAssistantUnitCell.setCellValue(po.getCommunityAssistantUnit());
- }
-
- Cell lngJtCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLngJt() != null) {
- lngJtCell.setCellValue(po.getLngJt().toString());
- }
-
- Cell latJtCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLatJt() != null) {
- latJtCell.setCellValue(po.getLatJt().toString());
- }
-
- Cell propertyOwnerCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getPropertyOwner() != null) {
- propertyOwnerCell.setCellValue(po.getPropertyOwner());
- }
- }
- }
- public Rsp<PageVo<String>> listSiteName(ListSiteNameDto dto) {
- if ("全省".equals(dto.getMap().getCity())) {
- dto.getMap().setCity(null);
- dto.getMap().setCounty(null);
- }
- ListHouseSiteBo bo = new ListHouseSiteBo();
- bo.setAreaNo(dto.getMap().getCity());
- bo.setCityNo(dto.getMap().getCounty());
- bo.setSiteName(dto.getMap().getAlias());
- Page<HouseSitePo> page = new Page<>(dto.getPage().getPageNum(), dto.getPage().getPageSize());
- List<HouseSitePo> list = wzOtnAreaDao.listHouseSite(page, bo);
- List<String> vos = list.stream().map(HouseSitePo::getSiteName).toList();
- PageVo<String> pageVo = new PageVo<>(vos, page);
- return Rsp.ok(pageVo);
- }
- public Rsp<PageVo<String>> listSiteNum(ListSiteNumDto dto) {
- if ("全省".equals(dto.getMap().getCity())) {
- dto.getMap().setCity(null);
- dto.getMap().setCounty(null);
- }
- ListHouseSiteBo bo = new ListHouseSiteBo();
- bo.setAreaNo(dto.getMap().getCity());
- bo.setCityNo(dto.getMap().getCounty());
- bo.setSiteNum(dto.getMap().getCode());
- Page<HouseSitePo> page = new Page<>(dto.getPage().getPageNum(), dto.getPage().getPageSize());
- List<HouseSitePo> list = wzOtnAreaDao.listHouseSite(page, bo);
- List<String> vos = list.stream().map(HouseSitePo::getSiteNum).toList();
- PageVo<String> pageVo = new PageVo<>(vos, page);
- return Rsp.ok(pageVo);
- }
- public Rsp<PageVo<ListBuildingVo>> listBuilding(ListBuildingDto dto) {
- Page<HouseBuildingPo> page = new Page<>(dto.getPage().getPageNum(), dto.getPage().getPageSize());
- List<HouseBuildingPo> list = getBuildingList(dto, page);
- List<ListBuildingVo> vos = new ArrayList<>();
- for (HouseBuildingPo po : list) {
- vos.add(new ListBuildingVo(po));
- }
- PageVo<ListBuildingVo> pageVo = new PageVo<>(vos, page);
- return Rsp.ok(pageVo);
- }
-
- private List<HouseBuildingPo> getBuildingList(ListBuildingDto dto, Page<HouseBuildingPo> page) {
- ListBuildingBo bo = new ListBuildingBo();
- if (dto.getMap() != null && dto.getMap().getStatisticalMonth() != null) {
- bo.setYearMonth(dto.getMap().getStatisticalMonth());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCity()) && !"全省".equals(dto.getMap().getCity())) {
- bo.setAreaNo(dto.getMap().getCity());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCounty())) {
- bo.setCityNo(dto.getMap().getCounty());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getBuildingAddressNumber())) {
- bo.setSiteNum(dto.getMap().getBuildingAddressNumber());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getBuildingNameAlias())) {
- bo.setSiteName(dto.getMap().getBuildingNameAlias());
- }
- if (dto.getMap() != null && dto.getMap().getOrder() != null && dto.getMap().getSidx() != null) {
- if (OrderEnum.asc.equals(dto.getMap().getOrder())) {
- page.addOrder(OrderItem.asc(dto.getMap().getSidx().getColumnName()));
- } else {
- page.addOrder(OrderItem.desc(dto.getMap().getSidx().getColumnName()));
- }
- } else {
- page.addOrder(OrderItem.desc(ListBuildingOrderEnum.buildingArea.getColumnName()));
- }
- return houseBuildingDao.listBuilding(page, bo);
- }
- public void listBuildingExport(ListBuildingDto.ListBuildingMapDTO dto) {
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes();
- if (servletRequestAttributes == null) {
- return;
- }
- HttpServletResponse response = servletRequestAttributes.getResponse();
- if (response == null) {
- return;
- }
- 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()) {
- writeListBuilding(new ListBuildingDto(dto), wb);
- wb.write(response.getOutputStream());
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
-
- private void writeListBuilding(ListBuildingDto dto, SXSSFWorkbook wb) {
- Page<HouseBuildingPo> page = new Page<>(1, Long.MAX_VALUE);
- List<HouseBuildingPo> list = getBuildingList(dto, page);
- DataFormat dataFormat = wb.createDataFormat();
-
- CellStyle numberCellStyle = wb.createCellStyle();
- numberCellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
- numberCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle baseCellStyle = wb.createCellStyle();
- baseCellStyle.setAlignment(HorizontalAlignment.CENTER);
- baseCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
-
- CellStyle percentCellStyle = wb.createCellStyle();
- percentCellStyle.setDataFormat(dataFormat.getFormat("0.00%"));
- percentCellStyle.setAlignment(HorizontalAlignment.RIGHT);
- SXSSFSheet sheet = wb.createSheet();
- AtomicInteger rowIndex = new AtomicInteger(0);
-
- Row headerRow = sheet.createRow(rowIndex.getAndIncrement());
- List<String> headers = Stream.of("资产所属单位(一级)", "资产所属单位(二级)", "资产所属单位(三级)", "局址编号",
- "局址别名", "建筑别名", "地段", "建筑面积(㎡)","建筑面积-出租(㎡)", "建筑面积-闲置(㎡)", "建筑面积-自用(㎡)",
- "建筑面积-不可使用(㎡)", "上级土地名称", "得房率", "房屋来源", "取得日期", "房龄开始年份", "投资主体", "管理层级",
- "房屋结构", "楼层总数", "是否临街", "是否有院落", "整栋是否独有", "是否有房产证", "无房产证原因", "未关联资产",
- "资产编号", "资产标签号", "使用状态", "建筑用途", "权属状态", "建筑占地面积(㎡)", "使用面积(㎡)",
- "使用面积-自用(㎡)", "使用面积-出租(㎡)", "使用面积-闲置(㎡)", "使用面积-不可使用(㎡)", "楼长姓名",
- "楼长所在单位", "经度", "纬度", "实际产权人").toList();
- int headerLength = headers.size();
- for (int i = 0; i < headerLength; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(headers.get(i));
- cell.setCellStyle(baseCellStyle);
-
- int columnWidth = headers.get(i).length() * 256 * 2 + 256;
- sheet.setColumnWidth(i, columnWidth);
- }
-
- for (HouseBuildingPo po : list) {
- AtomicInteger columnIndex = new AtomicInteger(0);
- Row row = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFirstUnit() != null) {
- firstUnitCell.setCellValue(po.getFirstUnit());
- }
-
- Cell areaNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAreaName() != null) {
- areaNameCell.setCellValue(po.getAreaName());
- }
-
- Cell cityNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCityName() != null) {
- cityNameCell.setCellValue(po.getCityName());
- }
-
- Cell siteNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getSiteName() != null) {
- siteNumCell.setCellValue(po.getSiteNum());
- }
-
- Cell siteNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getSiteName() != null) {
- siteNameCell.setCellValue(po.getSiteName());
- }
-
- Cell buildingNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingName() != null) {
- buildingNameCell.setCellValue(po.getBuildingName());
- }
-
- Cell areaSectorCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAreaSector() != null) {
- areaSectorCell.setCellValue(po.getAreaSector());
- }
-
- Cell buildingAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingArea() != null) {
- buildingAreaCell.setCellValue(po.getBuildingArea().doubleValue());
- }
- buildingAreaCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaRentCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaRent() != null) {
- buildingAreaRentCell.setCellValue(po.getBuildingAreaRent().doubleValue());
- }
- buildingAreaRentCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaIdleCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaIdle() != null) {
- buildingAreaIdleCell.setCellValue(po.getBuildingAreaIdle().doubleValue());
- }
- buildingAreaIdleCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaSelfUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaSelfUse() != null) {
- buildingAreaSelfUseCell.setCellValue(po.getBuildingAreaSelfUse().doubleValue());
- }
- buildingAreaSelfUseCell.setCellStyle(numberCellStyle);
-
- Cell buildingAreaUnusableCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingAreaUnusable() != null) {
- buildingAreaUnusableCell.setCellValue(po.getBuildingAreaUnusable().doubleValue());
- }
- buildingAreaUnusableCell.setCellStyle(numberCellStyle);
-
- Cell landNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLandName() != null) {
- landNameCell.setCellValue(po.getLandName());
- }
-
- Cell housingAcquisitionRateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHousingAcquisitionRate() != null) {
- housingAcquisitionRateCell.setCellValue(po.getHousingAcquisitionRate().doubleValue());
- }
- housingAcquisitionRateCell.setCellStyle(percentCellStyle);
-
- Cell housingSourceCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHousingSource() != null) {
- housingSourceCell.setCellValue(po.getHousingSource());
- }
-
- Cell acquisitionDateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAcquisitionDate() != null) {
- acquisitionDateCell.setCellValue(po.getAcquisitionDate());
- }
-
- Cell houseYearBeganCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getHouseYearBegan() != null) {
- houseYearBeganCell.setCellValue(po.getHouseYearBegan());
- }
-
- Cell investorCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getInvestor() != null) {
- investorCell.setCellValue(po.getInvestor());
- }
-
- Cell managementLevelCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getManagementLevel() != null) {
- managementLevelCell.setCellValue(po.getManagementLevel());
- }
-
- Cell buildingStructureCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingStructure() != null) {
- buildingStructureCell.setCellValue(po.getBuildingStructure());
- }
-
- Cell totalFloorsCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getTotalFloors() != null) {
- totalFloorsCell.setCellValue(po.getTotalFloors());
- }
-
- Cell frontageCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFrontage() != null) {
- frontageCell.setCellValue(po.getFrontage());
- }
-
- Cell courtyardCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCourtyard() != null) {
- courtyardCell.setCellValue(po.getCourtyard());
- }
-
- Cell wholeBuildingCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getWholeBuilding() != null) {
- wholeBuildingCell.setCellValue(po.getWholeBuilding());
- }
-
- Cell propertyOwnershipCertificateCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getPropertyOwnershipCertificate() != null) {
- propertyOwnershipCertificateCell.setCellValue(po.getPropertyOwnershipCertificate());
- }
-
- Cell noPropertyOwnershipCertificateReasonCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getNoPropertyOwnershipCertificateReason() != null) {
- noPropertyOwnershipCertificateReasonCell.setCellValue(
- po.getNoPropertyOwnershipCertificateReason());
- }
-
- Cell unrelatedAssetsCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUnrelatedAssets() != null) {
- unrelatedAssetsCell.setCellValue(po.getUnrelatedAssets());
- }
-
- Cell assetsNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAssetsNum() != null) {
- assetsNumCell.setCellValue(po.getAssetsNum());
- }
-
- Cell assetsTagNumCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getAssetsTagNum() != null) {
- assetsTagNumCell.setCellValue(po.getAssetsTagNum());
- }
-
- Cell usageStatusCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsageStatus() != null) {
- usageStatusCell.setCellValue(po.getUsageStatus());
- }
-
- Cell buildingUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getBuildingUse() != null) {
- buildingUseCell.setCellValue(po.getBuildingUse());
- }
-
- Cell ownershipStatusCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getOwnershipStatus() != null) {
- ownershipStatusCell.setCellValue(po.getOwnershipStatus());
- }
-
- Cell floorAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getFloorArea() != null) {
- floorAreaCell.setCellValue(po.getFloorArea().doubleValue());
- }
- floorAreaCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableArea() != null) {
- usableAreaCell.setCellValue(po.getUsableArea().doubleValue());
- }
- usableAreaCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaSelfUseCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaSelfUse() != null) {
- usableAreaSelfUseCell.setCellValue(po.getUsableAreaSelfUse().doubleValue());
- }
- usableAreaSelfUseCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaRentCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaRent() != null) {
- usableAreaRentCell.setCellValue(po.getUsableAreaRent().doubleValue());
- }
- usableAreaRentCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaIdleCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaIdle() != null) {
- usableAreaIdleCell.setCellValue(po.getUsableAreaIdle().doubleValue());
- }
- usableAreaIdleCell.setCellStyle(numberCellStyle);
-
- Cell usableAreaUnusableCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getUsableAreaUnusable() != null) {
- usableAreaUnusableCell.setCellValue(po.getUsableAreaUnusable().doubleValue());
- }
- usableAreaUnusableCell.setCellStyle(numberCellStyle);
-
- Cell communityAssistantNameCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCommunityAssistantName() != null) {
- communityAssistantNameCell.setCellValue(po.getCommunityAssistantName());
- }
-
- Cell communityAssistantUnitCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getCommunityAssistantUnit() != null) {
- communityAssistantUnitCell.setCellValue(po.getCommunityAssistantUnit());
- }
-
- Cell lngJtCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLngJt() != null) {
- lngJtCell.setCellValue(po.getLngJt().toString());
- }
-
- Cell latJtCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getLatJt() != null) {
- latJtCell.setCellValue(po.getLatJt().toString());
- }
-
- Cell propertyOwnerCell = row.createCell(columnIndex.getAndIncrement());
- if (po.getPropertyOwner() != null) {
- propertyOwnerCell.setCellValue(po.getPropertyOwner());
- }
- }
- }
- public Rsp<PageVo<HouseAgeStatVo>> houseAgeStat(HouseAgeStatDto dto) {
- HouseAgeStatPo houseAgeStatPos = getHouseAgeStatPos(dto);
- if (houseAgeStatPos == null) {
- return Rsp.ok();
- }
- HouseAgeStatVo vo = new HouseAgeStatVo(houseAgeStatPos, false);
- PageVo<HouseAgeStatVo> pageVo = new PageVo<>(Collections.singletonList(vo));
- return Rsp.ok(pageVo);
- }
-
- public HouseAgeStatPo getHouseAgeStatPos(HouseAgeStatDto dto) {
- HouseAgeStatBo bo = new HouseAgeStatBo();
- if (dto.getMap() != null && dto.getMap().getStatisticalMonth() != null) {
- bo.setYearMonth(dto.getMap().getStatisticalMonth());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCity()) && !"全省".equals(dto.getMap().getCity())) {
- bo.setAreaNo(dto.getMap().getCity());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCounty())) {
- bo.setCityNo(dto.getMap().getCounty());
- }
-
- List<HouseAgeStatPo> houseAgeStatPos = houseBuildingDao.houseAgeStat(bo);
- if (CollectionUtils.isEmpty(houseAgeStatPos)) {
- return null;
- }
-
- HouseAgeStatPo firstUnitPo = new HouseAgeStatPo();
- firstUnitPo.setAreaName("全省");
- firstUnitPo.setCityName("全省");
- LinkedHashMap<String, HouseAgeStatPo> secondUnitPoMap = new LinkedHashMap<>();
-
- for (HouseAgeStatPo houseAgeStatPo : houseAgeStatPos) {
- secondUnitPoMap.putIfAbsent(houseAgeStatPo.getAreaNo(),
- new HouseAgeStatPo(houseAgeStatPo.getAreaNo(), houseAgeStatPo.getAreaName()));
- HouseAgeStatPo secondUnitPo = secondUnitPoMap.get(houseAgeStatPo.getAreaNo());
- secondUnitPo.update(houseAgeStatPo);
- }
- for (HouseAgeStatPo value : secondUnitPoMap.values()) {
- firstUnitPo.update(value);
- }
- return firstUnitPo;
- }
- public void queryHouseYearExport(HouseAgeStatDto.HouseAgeStatMapDTO dto) {
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes();
- if (servletRequestAttributes == null) {
- return;
- }
- HttpServletResponse response = servletRequestAttributes.getResponse();
- if (response == null) {
- return;
- }
- 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()) {
- writeQueryHouseYear(new HouseAgeStatDto(dto), wb);
- wb.write(response.getOutputStream());
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
-
- private void writeQueryHouseYear(HouseAgeStatDto dto, SXSSFWorkbook wb) {
- HouseAgeStatPo firstPo = getHouseAgeStatPos(dto);
- DataFormat dataFormat = wb.createDataFormat();
-
- CellStyle integerCellStyle = wb.createCellStyle();
- integerCellStyle.setDataFormat(dataFormat.getFormat("#,##0"));
- integerCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle numberCellStyle = wb.createCellStyle();
- numberCellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
- numberCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle baseCellStyle = wb.createCellStyle();
- baseCellStyle.setAlignment(HorizontalAlignment.CENTER);
- baseCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
- SXSSFSheet sheet = wb.createSheet();
- AtomicInteger rowIndex = new AtomicInteger(0);
-
- Row headerRow = sheet.createRow(rowIndex.getAndIncrement());
- List<String> headers = Stream.of("资产所属单位(一级)", "资产所属单位(二级)", "资产所属单位(三级)",
- "1-10年", "11-20年", "21-30年", "31-40年", "41-50年", "50年以上", "平均房龄").toList();
- int headerLength = headers.size();
- for (int i = 0; i < headerLength; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(headers.get(i));
- cell.setCellStyle(baseCellStyle);
-
- int columnWidth = headers.get(i).length() * 256 * 2 + 256;
- sheet.setColumnWidth(i, columnWidth);
- }
- if (firstPo == null) {
- return;
- }
-
- AtomicInteger columnIndex1 = new AtomicInteger(0);
-
- Row row1 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getAreaName() != null) {
- firstUnitCell1.setCellValue(firstPo.getAreaName());
- }
-
- Cell areaNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
-
- Cell cityNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
-
- Cell a1Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA1() != null) {
- a1Cell1.setCellValue(firstPo.getA1());
- }
- a1Cell1.setCellStyle(integerCellStyle);
-
- Cell a2Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA2() != null) {
- a2Cell1.setCellValue(firstPo.getA2());
- }
- a2Cell1.setCellStyle(integerCellStyle);
-
- Cell a3Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA3() != null) {
- a3Cell1.setCellValue(firstPo.getA3());
- }
- a3Cell1.setCellStyle(integerCellStyle);
-
- Cell a4Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA4() != null) {
- a4Cell1.setCellValue(firstPo.getA4());
- }
- a4Cell1.setCellStyle(integerCellStyle);
-
- Cell a5Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA5() != null) {
- a5Cell1.setCellValue(firstPo.getA5());
- }
- a5Cell1.setCellStyle(integerCellStyle);
-
- Cell a6Cell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getA6() != null) {
- a6Cell1.setCellValue(firstPo.getA6());
- }
- a6Cell1.setCellStyle(integerCellStyle);
-
- Cell houseAgeAvgCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getHouseAgeAvg() != null) {
- houseAgeAvgCell1.setCellValue(firstPo.getHouseAgeAvg().doubleValue());
- }
- houseAgeAvgCell1.setCellStyle(numberCellStyle);
-
- for (HouseAgeStatPo secondPo : firstPo.getChildren()) {
- AtomicInteger columnIndex2 = new AtomicInteger(0);
- Row row2 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell2 = row2.createCell(columnIndex2.getAndIncrement());
-
- Cell areaNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getAreaName() != null) {
- areaNameCell2.setCellValue(secondPo.getAreaName());
- }
-
- Cell cityNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
-
- Cell a1Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA1() != null) {
- a1Cell2.setCellValue(secondPo.getA1());
- }
- a1Cell2.setCellStyle(integerCellStyle);
-
- Cell a2Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA2() != null) {
- a2Cell2.setCellValue(secondPo.getA2());
- }
- a2Cell2.setCellStyle(integerCellStyle);
-
- Cell a3Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA3() != null) {
- a3Cell2.setCellValue(secondPo.getA3());
- }
- a3Cell2.setCellStyle(integerCellStyle);
-
- Cell a4Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA4() != null) {
- a4Cell2.setCellValue(secondPo.getA4());
- }
- a4Cell2.setCellStyle(integerCellStyle);
-
- Cell a5Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA5() != null) {
- a5Cell2.setCellValue(secondPo.getA5());
- }
- a5Cell2.setCellStyle(integerCellStyle);
-
- Cell a6Cell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getA6() != null) {
- a6Cell2.setCellValue(secondPo.getA6());
- }
- a6Cell2.setCellStyle(integerCellStyle);
-
- Cell houseAgeAvgCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getHouseAgeAvg() != null) {
- houseAgeAvgCell2.setCellValue(secondPo.getHouseAgeAvg().doubleValue());
- }
- houseAgeAvgCell2.setCellStyle(numberCellStyle);
-
- for (HouseAgeStatPo thirdPo : secondPo.getChildren()) {
- AtomicInteger columnIndex3 = new AtomicInteger(0);
- Row row3 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell3 = row3.createCell(columnIndex3.getAndIncrement());
-
- Cell areaNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
-
- Cell cityNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getCityName() != null) {
- cityNameCell3.setCellValue(thirdPo.getCityName());
- }
-
- Cell a1Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA1() != null) {
- a1Cell3.setCellValue(thirdPo.getA1());
- }
- a1Cell3.setCellStyle(integerCellStyle);
-
- Cell a2Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA2() != null) {
- a2Cell3.setCellValue(thirdPo.getA2());
- }
- a2Cell3.setCellStyle(integerCellStyle);
-
- Cell a3Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA3() != null) {
- a3Cell3.setCellValue(thirdPo.getA3());
- }
- a3Cell3.setCellStyle(integerCellStyle);
-
- Cell a4Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA4() != null) {
- a4Cell3.setCellValue(thirdPo.getA4());
- }
- a4Cell3.setCellStyle(integerCellStyle);
-
- Cell a5Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA5() != null) {
- a5Cell3.setCellValue(thirdPo.getA5());
- }
- a5Cell3.setCellStyle(integerCellStyle);
-
- Cell a6Cell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getA6() != null) {
- a6Cell3.setCellValue(thirdPo.getA6());
- }
- a6Cell3.setCellStyle(integerCellStyle);
-
- Cell houseAgeAvgCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getHouseAgeAvg() != null) {
- houseAgeAvgCell3.setCellValue(thirdPo.getHouseAgeAvg().doubleValue());
- }
- houseAgeAvgCell3.setCellStyle(numberCellStyle);
- }
- }
- }
- public Rsp<PageVo<BuildingIdleStatVo>> buildingIdleStat(BuildingIdleStatDto dto) {
- BuildingIdleStatPo buildingIdleStatPos = getBuildingIdleStatPos(dto);
- if (buildingIdleStatPos == null) {
- return Rsp.ok();
- }
- BuildingIdleStatVo vo = new BuildingIdleStatVo(buildingIdleStatPos, false);
- PageVo<BuildingIdleStatVo> pageVo = new PageVo<>(Collections.singletonList(vo));
- return Rsp.ok(pageVo);
- }
- private BuildingIdleStatPo getBuildingIdleStatPos(BuildingIdleStatDto dto) {
- BuildingIdleStatBo bo = new BuildingIdleStatBo();
- if (dto.getMap() != null && dto.getMap().getStatisticalMonth() != null) {
- bo.setYearMonth(dto.getMap().getStatisticalMonth());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCity()) && !"全省".equals(dto.getMap().getCity())) {
- bo.setAreaNo(dto.getMap().getCity());
- }
- if (dto.getMap() != null && StringUtils.hasText(dto.getMap().getCounty())) {
- bo.setCityNo(dto.getMap().getCounty());
- }
-
- List<BuildingIdleStatPo> buildingIdleStatPos = houseBuildingDao.buildingIdleStat(bo);
- if (CollectionUtils.isEmpty(buildingIdleStatPos)) {
- return null;
- }
-
- BuildingIdleStatPo firstUnitPo = new BuildingIdleStatPo();
- firstUnitPo.setAreaName("全省");
- firstUnitPo.setCityName("全省");
- LinkedHashMap<String, BuildingIdleStatPo> secondUnitPoMap = new LinkedHashMap<>();
-
- for (BuildingIdleStatPo houseAgeStatPo : buildingIdleStatPos) {
- secondUnitPoMap.putIfAbsent(houseAgeStatPo.getAreaNo(),
- new BuildingIdleStatPo(houseAgeStatPo.getAreaNo(), houseAgeStatPo.getAreaName()));
- BuildingIdleStatPo secondUnitPo = secondUnitPoMap.get(houseAgeStatPo.getAreaNo());
- secondUnitPo.update(houseAgeStatPo);
- }
- for (BuildingIdleStatPo value : secondUnitPoMap.values()) {
- firstUnitPo.update(value);
- }
- return firstUnitPo;
- }
- public void buildingIdleStatExport(BuildingIdleStatDto.BuildingIdleStatMapDTO dto) {
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes();
- if (servletRequestAttributes == null) {
- return;
- }
- HttpServletResponse response = servletRequestAttributes.getResponse();
- if (response == null) {
- return;
- }
- 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()) {
- writeBuildingIdleStat(new BuildingIdleStatDto(dto), wb);
- wb.write(response.getOutputStream());
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
-
- private void writeBuildingIdleStat(BuildingIdleStatDto dto, SXSSFWorkbook wb) {
- BuildingIdleStatPo firstPo = getBuildingIdleStatPos(dto);
- DataFormat dataFormat = wb.createDataFormat();
-
- CellStyle integerCellStyle = wb.createCellStyle();
- integerCellStyle.setDataFormat(dataFormat.getFormat("#,##0"));
- integerCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle numberCellStyle = wb.createCellStyle();
- numberCellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
- numberCellStyle.setAlignment(HorizontalAlignment.RIGHT);
-
- CellStyle baseCellStyle = wb.createCellStyle();
- baseCellStyle.setAlignment(HorizontalAlignment.CENTER);
- baseCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
-
- CellStyle percentCellStyle = wb.createCellStyle();
- percentCellStyle.setDataFormat(dataFormat.getFormat("0.00%"));
- percentCellStyle.setAlignment(HorizontalAlignment.RIGHT);
- SXSSFSheet sheet = wb.createSheet();
- AtomicInteger rowIndex = new AtomicInteger(0);
-
- Row headerRow = sheet.createRow(rowIndex.getAndIncrement());
- List<String> headers = Stream.of("资产所属单位(一级)", "资产所属单位(二级)", "资产所属单位(三级)",
- "建筑面积(㎡)", "闲置建筑数量", "建筑面积-自用(㎡)","建筑面积-出租(㎡)", "建筑面积-闲置(㎡)", "闲置率(%)").toList();
- int headerLength = headers.size();
- for (int i = 0; i < headerLength; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(headers.get(i));
- cell.setCellStyle(baseCellStyle);
-
- int columnWidth = headers.get(i).length() * 256 * 2 + 256;
- sheet.setColumnWidth(i, columnWidth);
- }
- if (firstPo == null) {
- return;
- }
-
- AtomicInteger columnIndex1 = new AtomicInteger(0);
-
- Row row1 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getAreaName() != null) {
- firstUnitCell1.setCellValue(firstPo.getAreaName());
- }
-
- Cell areaNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
-
- Cell cityNameCell1 = row1.createCell(columnIndex1.getAndIncrement());
-
- Cell buildingAreaSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getBuildingAreaSum() != null) {
- buildingAreaSumCell1.setCellValue(firstPo.getBuildingAreaSum().doubleValue());
- }
- buildingAreaSumCell1.setCellStyle(numberCellStyle);
-
- Cell idleCountCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getIdleCount() != null) {
- idleCountCell1.setCellValue(firstPo.getIdleCount());
- }
- idleCountCell1.setCellStyle(integerCellStyle);
-
- Cell buildingAreaSelfUseSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getBuildingAreaSelfUseSum() != null) {
- buildingAreaSelfUseSumCell1.setCellValue(firstPo.getBuildingAreaSelfUseSum().doubleValue());
- }
- buildingAreaSelfUseSumCell1.setCellStyle(numberCellStyle);
-
- Cell buildingAreaRentSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getBuildingAreaRentSum() != null) {
- buildingAreaRentSumCell1.setCellValue(firstPo.getBuildingAreaRentSum().doubleValue());
- }
- buildingAreaRentSumCell1.setCellStyle(numberCellStyle);
-
- Cell buildingAreaIdleSumCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getBuildingAreaIdleSum() != null) {
- buildingAreaIdleSumCell1.setCellValue(firstPo.getBuildingAreaIdleSum().doubleValue());
- }
- buildingAreaIdleSumCell1.setCellStyle(numberCellStyle);
-
- Cell idlePercentCell1 = row1.createCell(columnIndex1.getAndIncrement());
- if (firstPo.getIdlePercent() != null) {
- idlePercentCell1.setCellValue(firstPo.getIdlePercent().doubleValue());
- }
- idlePercentCell1.setCellStyle(percentCellStyle);
-
- for (BuildingIdleStatPo secondPo : firstPo.getChildren()) {
- AtomicInteger columnIndex2 = new AtomicInteger(0);
-
- Row row2 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell2 = row2.createCell(columnIndex2.getAndIncrement());
-
- Cell areaNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getAreaName() != null) {
- areaNameCell2.setCellValue(secondPo.getAreaName());
- }
-
- Cell cityNameCell2 = row2.createCell(columnIndex2.getAndIncrement());
-
- Cell buildingAreaSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getBuildingAreaSum() != null) {
- buildingAreaSumCell2.setCellValue(secondPo.getBuildingAreaSum().doubleValue());
- }
- buildingAreaSumCell2.setCellStyle(numberCellStyle);
-
- Cell idleCountCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getIdleCount() != null) {
- idleCountCell2.setCellValue(secondPo.getIdleCount());
- }
- idleCountCell2.setCellStyle(integerCellStyle);
-
- Cell buildingAreaSelfUseSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getBuildingAreaSelfUseSum() != null) {
- buildingAreaSelfUseSumCell2.setCellValue(secondPo.getBuildingAreaSelfUseSum().doubleValue());
- }
- buildingAreaSelfUseSumCell2.setCellStyle(numberCellStyle);
-
- Cell buildingAreaRentSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getBuildingAreaRentSum() != null) {
- buildingAreaRentSumCell2.setCellValue(secondPo.getBuildingAreaRentSum().doubleValue());
- }
- buildingAreaRentSumCell2.setCellStyle(numberCellStyle);
-
- Cell buildingAreaIdleSumCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getBuildingAreaIdleSum() != null) {
- buildingAreaIdleSumCell2.setCellValue(secondPo.getBuildingAreaIdleSum().doubleValue());
- }
- buildingAreaIdleSumCell2.setCellStyle(numberCellStyle);
-
- Cell idlePercentCell2 = row2.createCell(columnIndex2.getAndIncrement());
- if (secondPo.getIdlePercent() != null) {
- idlePercentCell2.setCellValue(secondPo.getIdlePercent().doubleValue());
- }
- idlePercentCell2.setCellStyle(percentCellStyle);
-
- for (BuildingIdleStatPo thirdPo : secondPo.getChildren()) {
- AtomicInteger columnIndex3 = new AtomicInteger(0);
- Row row3 = sheet.createRow(rowIndex.getAndIncrement());
-
- Cell firstUnitCell3 = row3.createCell(columnIndex3.getAndIncrement());
-
- Cell areaNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
-
- Cell cityNameCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getCityName() != null) {
- cityNameCell3.setCellValue(thirdPo.getCityName());
- }
-
- Cell buildingAreaSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getBuildingAreaSum() != null) {
- buildingAreaSumCell3.setCellValue(thirdPo.getBuildingAreaSum().doubleValue());
- }
- buildingAreaSumCell3.setCellStyle(numberCellStyle);
-
- Cell idleCountCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getIdleCount() != null) {
- idleCountCell3.setCellValue(thirdPo.getIdleCount());
- }
- idleCountCell3.setCellStyle(integerCellStyle);
-
- Cell buildingAreaSelfUseSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getBuildingAreaSelfUseSum() != null) {
- buildingAreaSelfUseSumCell3.setCellValue(thirdPo.getBuildingAreaSelfUseSum().doubleValue());
- }
- buildingAreaSelfUseSumCell3.setCellStyle(numberCellStyle);
-
- Cell buildingAreaRentSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getBuildingAreaRentSum() != null) {
- buildingAreaRentSumCell3.setCellValue(thirdPo.getBuildingAreaRentSum().doubleValue());
- }
- buildingAreaRentSumCell3.setCellStyle(numberCellStyle);
-
- Cell buildingAreaIdleSumCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getBuildingAreaIdleSum() != null) {
- buildingAreaIdleSumCell3.setCellValue(thirdPo.getBuildingAreaIdleSum().doubleValue());
- }
- buildingAreaIdleSumCell3.setCellStyle(numberCellStyle);
-
- Cell idlePercentCell3 = row3.createCell(columnIndex3.getAndIncrement());
- if (thirdPo.getIdlePercent() != null) {
- idlePercentCell3.setCellValue(thirdPo.getIdlePercent().doubleValue());
- }
- idlePercentCell3.setCellStyle(percentCellStyle);
- }
- }
- }
- }
|