|
@@ -0,0 +1,365 @@
|
|
|
+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.dao.house.HouseBuildingDao;
|
|
|
+import com.example.entity.house.HouseBuildingPo;
|
|
|
+import com.example.enums.OrderEnum;
|
|
|
+import com.example.pojo.bo.ListBuildingIdleBo;
|
|
|
+import com.example.pojo.dto.ListBuildingIdleDto;
|
|
|
+import com.example.pojo.vo.ListBuildingIdleVo;
|
|
|
+import com.example.utils.PageUtils;
|
|
|
+import com.example.utils.R;
|
|
|
+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.ss.util.CellReference;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+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.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class HouseWzBuildManageDetailsService {
|
|
|
+ private final HouseBuildingDao houseBuildingDao;
|
|
|
+
|
|
|
+ public HouseWzBuildManageDetailsService(HouseBuildingDao houseBuildingDao) {
|
|
|
+ this.houseBuildingDao = houseBuildingDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ public R 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));
|
|
|
+ }
|
|
|
+ PageUtils pageUtil = new PageUtils(vos, page);
|
|
|
+ return R.ok().put("page", pageUtil);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ideListExport(ListBuildingIdleDto 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(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 && 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()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return houseBuildingDao.listBuildingIdle(page, bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写空置1000平米以上建筑文件
|
|
|
+ */
|
|
|
+ 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 columnIndex = new AtomicInteger(0);
|
|
|
+ // 表头
|
|
|
+ Row headerRow = sheet.createRow(columnIndex.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 houseBuildingPo : list) {
|
|
|
+ Row row = sheet.createRow(columnIndex.getAndIncrement());
|
|
|
+ // 资产所属单位(一级)
|
|
|
+ Cell a = row.createCell(CellReference.convertColStringToIndex("a"));
|
|
|
+ if (houseBuildingPo.getFirstUnit() != null) {
|
|
|
+ a.setCellValue(houseBuildingPo.getFirstUnit());
|
|
|
+ }
|
|
|
+ // 二级单位
|
|
|
+ Cell b = row.createCell(CellReference.convertColStringToIndex("b"));
|
|
|
+ if (houseBuildingPo.getAreaName() != null) {
|
|
|
+ b.setCellValue(houseBuildingPo.getAreaName());
|
|
|
+ }
|
|
|
+ // 三级单位
|
|
|
+ Cell c = row.createCell(CellReference.convertColStringToIndex("c"));
|
|
|
+ if (houseBuildingPo.getCityName() != null) {
|
|
|
+ c.setCellValue(houseBuildingPo.getCityName());
|
|
|
+ }
|
|
|
+ // 建筑别名
|
|
|
+ Cell d = row.createCell(CellReference.convertColStringToIndex("d"));
|
|
|
+ if (houseBuildingPo.getBuildingName() != null) {
|
|
|
+ d.setCellValue(houseBuildingPo.getBuildingName());
|
|
|
+ }
|
|
|
+ // 地段
|
|
|
+ Cell e = row.createCell(CellReference.convertColStringToIndex("e"));
|
|
|
+ if (houseBuildingPo.getAreaSector() != null) {
|
|
|
+ e.setCellValue(houseBuildingPo.getAreaSector());
|
|
|
+ }
|
|
|
+ // 建筑面积(㎡)
|
|
|
+ Cell f = row.createCell(CellReference.convertColStringToIndex("f"));
|
|
|
+ if (houseBuildingPo.getBuildingArea() != null) {
|
|
|
+ f.setCellValue(houseBuildingPo.getBuildingArea().doubleValue());
|
|
|
+ }
|
|
|
+ f.setCellStyle(numberCellStyle);
|
|
|
+ // 建筑面积-出租(㎡)
|
|
|
+ Cell g = row.createCell(CellReference.convertColStringToIndex("g"));
|
|
|
+ if (houseBuildingPo.getBuildingAreaRent() != null) {
|
|
|
+ g.setCellValue(houseBuildingPo.getBuildingAreaRent().doubleValue());
|
|
|
+ }
|
|
|
+ g.setCellStyle(numberCellStyle);
|
|
|
+ // 建筑面积-闲置(㎡)
|
|
|
+ Cell h = row.createCell(CellReference.convertColStringToIndex("h"));
|
|
|
+ if (houseBuildingPo.getBuildingAreaIdle() != null) {
|
|
|
+ h.setCellValue(houseBuildingPo.getBuildingAreaIdle().doubleValue());
|
|
|
+ }
|
|
|
+ h.setCellStyle(numberCellStyle);
|
|
|
+ // 上级局址名称
|
|
|
+ Cell i = row.createCell(CellReference.convertColStringToIndex("i"));
|
|
|
+ if (houseBuildingPo.getSiteName() != null) {
|
|
|
+ i.setCellValue(houseBuildingPo.getSiteName());
|
|
|
+ }
|
|
|
+ // 建筑面积-自用(㎡)
|
|
|
+ Cell j = row.createCell(CellReference.convertColStringToIndex("j"));
|
|
|
+ if (houseBuildingPo.getBuildingAreaSelfUse() != null) {
|
|
|
+ j.setCellValue(houseBuildingPo.getBuildingAreaSelfUse().doubleValue());
|
|
|
+ }
|
|
|
+ j.setCellStyle(numberCellStyle);
|
|
|
+ // 建筑面积-不可使用(㎡)
|
|
|
+ Cell k = row.createCell(CellReference.convertColStringToIndex("k"));
|
|
|
+ if (houseBuildingPo.getBuildingAreaUnusable() != null) {
|
|
|
+ k.setCellValue(houseBuildingPo.getBuildingAreaUnusable().doubleValue());
|
|
|
+ }
|
|
|
+ k.setCellStyle(numberCellStyle);
|
|
|
+ // 上级土地名称
|
|
|
+ Cell l = row.createCell(CellReference.convertColStringToIndex("l"));
|
|
|
+ if (houseBuildingPo.getLandName() != null) {
|
|
|
+ l.setCellValue(houseBuildingPo.getLandName());
|
|
|
+ }
|
|
|
+ // 得房率
|
|
|
+ Cell m = row.createCell(CellReference.convertColStringToIndex("m"));
|
|
|
+ if (houseBuildingPo.getHousingAcquisitionRate() != null) {
|
|
|
+ m.setCellValue(houseBuildingPo.getHousingAcquisitionRate().doubleValue());
|
|
|
+ }
|
|
|
+ m.setCellStyle(percentCellStyle);
|
|
|
+ // 房屋来源
|
|
|
+ Cell n = row.createCell(CellReference.convertColStringToIndex("n"));
|
|
|
+ if (houseBuildingPo.getHousingSource() != null) {
|
|
|
+ n.setCellValue(houseBuildingPo.getHousingSource());
|
|
|
+ }
|
|
|
+ // 取得日期
|
|
|
+ Cell o = row.createCell(CellReference.convertColStringToIndex("o"));
|
|
|
+ if (houseBuildingPo.getAcquisitionDate() != null) {
|
|
|
+ o.setCellValue(houseBuildingPo.getAcquisitionDate());
|
|
|
+ }
|
|
|
+ // 房龄开始年份
|
|
|
+ Cell p = row.createCell(CellReference.convertColStringToIndex("p"));
|
|
|
+ if (houseBuildingPo.getHouseYearBegan() != null) {
|
|
|
+ p.setCellValue(houseBuildingPo.getHouseYearBegan());
|
|
|
+ }
|
|
|
+ // 投资主体
|
|
|
+ Cell q = row.createCell(CellReference.convertColStringToIndex("q"));
|
|
|
+ if (houseBuildingPo.getInvestor() != null) {
|
|
|
+ q.setCellValue(houseBuildingPo.getInvestor());
|
|
|
+ }
|
|
|
+ // 管理层级
|
|
|
+ Cell r = row.createCell(CellReference.convertColStringToIndex("r"));
|
|
|
+ if (houseBuildingPo.getManagementLevel() != null) {
|
|
|
+ r.setCellValue(houseBuildingPo.getManagementLevel());
|
|
|
+ }
|
|
|
+ // 房屋结构
|
|
|
+ Cell s = row.createCell(CellReference.convertColStringToIndex("s"));
|
|
|
+ if (houseBuildingPo.getBuildingStructure() != null) {
|
|
|
+ s.setCellValue(houseBuildingPo.getBuildingStructure());
|
|
|
+ }
|
|
|
+ // 楼层总数
|
|
|
+ Cell t = row.createCell(CellReference.convertColStringToIndex("t"));
|
|
|
+ if (houseBuildingPo.getTotalFloors() != null) {
|
|
|
+ t.setCellValue(houseBuildingPo.getTotalFloors());
|
|
|
+ }
|
|
|
+ // 是否临街
|
|
|
+ Cell u = row.createCell(CellReference.convertColStringToIndex("u"));
|
|
|
+ if (houseBuildingPo.getFrontage() != null) {
|
|
|
+ u.setCellValue(houseBuildingPo.getFrontage());
|
|
|
+ }
|
|
|
+ // 是否有院落
|
|
|
+ Cell v = row.createCell(CellReference.convertColStringToIndex("v"));
|
|
|
+ if (houseBuildingPo.getCourtyard() != null) {
|
|
|
+ v.setCellValue(houseBuildingPo.getCourtyard());
|
|
|
+ }
|
|
|
+ // 整栋是否独有
|
|
|
+ Cell w = row.createCell(CellReference.convertColStringToIndex("w"));
|
|
|
+ if (houseBuildingPo.getWholeBuilding() != null) {
|
|
|
+ w.setCellValue(houseBuildingPo.getWholeBuilding());
|
|
|
+ }
|
|
|
+ // 是否有房产证
|
|
|
+ Cell x = row.createCell(CellReference.convertColStringToIndex("x"));
|
|
|
+ if (houseBuildingPo.getPropertyOwnershipCertificate() != null) {
|
|
|
+ x.setCellValue(houseBuildingPo.getPropertyOwnershipCertificate());
|
|
|
+ }
|
|
|
+ // 无房产证原因
|
|
|
+ Cell y = row.createCell(CellReference.convertColStringToIndex("y"));
|
|
|
+ if (houseBuildingPo.getNoPropertyOwnershipCertificateReason() != null) {
|
|
|
+ y.setCellValue(houseBuildingPo.getNoPropertyOwnershipCertificateReason());
|
|
|
+ }
|
|
|
+ // 未关联资产
|
|
|
+ Cell z = row.createCell(CellReference.convertColStringToIndex("z"));
|
|
|
+ if (houseBuildingPo.getUnrelatedAssets() != null) {
|
|
|
+ z.setCellValue(houseBuildingPo.getUnrelatedAssets());
|
|
|
+ }
|
|
|
+ // 资产编号
|
|
|
+ Cell aa = row.createCell(CellReference.convertColStringToIndex("aa"));
|
|
|
+ if (houseBuildingPo.getAssetsNum() != null) {
|
|
|
+ aa.setCellValue(houseBuildingPo.getAssetsNum());
|
|
|
+ }
|
|
|
+ // 资产标签号
|
|
|
+ Cell ab = row.createCell(CellReference.convertColStringToIndex("ab"));
|
|
|
+ if (houseBuildingPo.getAssetsTagNum() != null) {
|
|
|
+ ab.setCellValue(houseBuildingPo.getAssetsTagNum());
|
|
|
+ }
|
|
|
+ // 使用状态
|
|
|
+ Cell ac = row.createCell(CellReference.convertColStringToIndex("ac"));
|
|
|
+ if (houseBuildingPo.getUsageStatus() != null) {
|
|
|
+ ac.setCellValue(houseBuildingPo.getUsageStatus());
|
|
|
+ }
|
|
|
+ // 建筑用途
|
|
|
+ Cell ad = row.createCell(CellReference.convertColStringToIndex("ad"));
|
|
|
+ if (houseBuildingPo.getBuildingUse() != null) {
|
|
|
+ ad.setCellValue(houseBuildingPo.getBuildingUse());
|
|
|
+ }
|
|
|
+ // 权属状态
|
|
|
+ Cell ae = row.createCell(CellReference.convertColStringToIndex("ae"));
|
|
|
+ if (houseBuildingPo.getOwnershipStatus() != null) {
|
|
|
+ ae.setCellValue(houseBuildingPo.getOwnershipStatus());
|
|
|
+ }
|
|
|
+ // 建筑占地面积(㎡)
|
|
|
+ Cell af = row.createCell(CellReference.convertColStringToIndex("af"));
|
|
|
+ if (houseBuildingPo.getFloorArea() != null) {
|
|
|
+ af.setCellValue(houseBuildingPo.getFloorArea().doubleValue());
|
|
|
+ }
|
|
|
+ af.setCellStyle(numberCellStyle);
|
|
|
+ // 使用面积(㎡)
|
|
|
+ Cell ag = row.createCell(CellReference.convertColStringToIndex("ag"));
|
|
|
+ if (houseBuildingPo.getUsableArea() != null) {
|
|
|
+ ag.setCellValue(houseBuildingPo.getUsableArea().doubleValue());
|
|
|
+ }
|
|
|
+ ag.setCellStyle(numberCellStyle);
|
|
|
+ // 使用面积-自用(㎡)
|
|
|
+ Cell ah = row.createCell(CellReference.convertColStringToIndex("ah"));
|
|
|
+ if (houseBuildingPo.getUsableAreaSelfUse() != null) {
|
|
|
+ ah.setCellValue(houseBuildingPo.getUsableAreaSelfUse().doubleValue());
|
|
|
+ }
|
|
|
+ ah.setCellStyle(numberCellStyle);
|
|
|
+ // 使用面积-出租(㎡)
|
|
|
+ Cell ai = row.createCell(CellReference.convertColStringToIndex("ai"));
|
|
|
+ if (houseBuildingPo.getUsableAreaRent() != null) {
|
|
|
+ ai.setCellValue(houseBuildingPo.getUsableAreaRent().doubleValue());
|
|
|
+ }
|
|
|
+ ai.setCellStyle(numberCellStyle);
|
|
|
+ // 使用面积-闲置(㎡)
|
|
|
+ Cell aj = row.createCell(CellReference.convertColStringToIndex("aj"));
|
|
|
+ if (houseBuildingPo.getUsableAreaIdle() != null) {
|
|
|
+ aj.setCellValue(houseBuildingPo.getUsableAreaIdle().doubleValue());
|
|
|
+ }
|
|
|
+ aj.setCellStyle(numberCellStyle);
|
|
|
+ // 使用面积-不可使用(㎡)
|
|
|
+ Cell ak = row.createCell(CellReference.convertColStringToIndex("ak"));
|
|
|
+ if (houseBuildingPo.getUsableAreaUnusable() != null) {
|
|
|
+ ak.setCellValue(houseBuildingPo.getUsableAreaUnusable().doubleValue());
|
|
|
+ }
|
|
|
+ ak.setCellStyle(numberCellStyle);
|
|
|
+ // 楼长姓名
|
|
|
+ Cell al = row.createCell(CellReference.convertColStringToIndex("al"));
|
|
|
+ if (houseBuildingPo.getCommunityAssistantName() != null) {
|
|
|
+ al.setCellValue(houseBuildingPo.getCommunityAssistantName());
|
|
|
+ }
|
|
|
+ // 楼长所在单位
|
|
|
+ Cell am = row.createCell(CellReference.convertColStringToIndex("am"));
|
|
|
+ if (houseBuildingPo.getCommunityAssistantUnit() != null) {
|
|
|
+ am.setCellValue(houseBuildingPo.getCommunityAssistantUnit());
|
|
|
+ }
|
|
|
+ // 经度
|
|
|
+ Cell an = row.createCell(CellReference.convertColStringToIndex("an"));
|
|
|
+ if (houseBuildingPo.getLngJt() != null) {
|
|
|
+ an.setCellValue(houseBuildingPo.getLngJt().toString());
|
|
|
+ }
|
|
|
+ // 纬度
|
|
|
+ Cell ao = row.createCell(CellReference.convertColStringToIndex("ao"));
|
|
|
+ if (houseBuildingPo.getLatJt() != null) {
|
|
|
+ ao.setCellValue(houseBuildingPo.getLatJt().toString());
|
|
|
+ }
|
|
|
+ // 实际产权人
|
|
|
+ Cell ap = row.createCell(CellReference.convertColStringToIndex("ap"));
|
|
|
+ if (houseBuildingPo.getPropertyOwner() != null) {
|
|
|
+ ap.setCellValue(houseBuildingPo.getPropertyOwner());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|