|
@ -17,23 +17,47 @@ |
|
|
|
|
|
|
|
|
package com.epmet.controller; |
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle; |
|
|
|
|
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; |
|
|
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
import com.epmet.commons.tools.annotation.MaskResponse; |
|
|
import com.epmet.commons.tools.annotation.MaskResponse; |
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.dto.form.PageFormDTO; |
|
|
import com.epmet.commons.tools.dto.form.PageFormDTO; |
|
|
import com.epmet.commons.tools.dto.result.OptionResultDTO; |
|
|
import com.epmet.commons.tools.dto.result.OptionResultDTO; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
|
|
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.dto.IcHouseDTO; |
|
|
import com.epmet.dto.IcHouseDTO; |
|
|
import com.epmet.dto.form.CheckHouseInfoFormDTO; |
|
|
import com.epmet.dto.form.CheckHouseInfoFormDTO; |
|
|
import com.epmet.dto.form.HouseCountPictureFormDTO; |
|
|
import com.epmet.dto.form.HouseCountPictureFormDTO; |
|
|
import com.epmet.dto.form.HouseFormDTO; |
|
|
import com.epmet.dto.form.HouseFormDTO; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.dto.result.*; |
|
|
|
|
|
import com.epmet.excel.EnterpriseExportExcelDTO; |
|
|
|
|
|
import com.epmet.excel.HousePictureListExcelDTO; |
|
|
import com.epmet.service.IcHouseService; |
|
|
import com.epmet.service.IcHouseService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@ -44,6 +68,7 @@ import java.util.Map; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2021-10-25 |
|
|
* @since v1.0.0 2021-10-25 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("ichouse") |
|
|
@RequestMapping("ichouse") |
|
|
public class IcHouseController { |
|
|
public class IcHouseController { |
|
@ -196,4 +221,49 @@ public class IcHouseController { |
|
|
public Result<PageData<HousePictureListResultDTO>> getHousePictureList(@RequestBody HouseCountPictureFormDTO dto){ |
|
|
public Result<PageData<HousePictureListResultDTO>> getHousePictureList(@RequestBody HouseCountPictureFormDTO dto){ |
|
|
return new Result<PageData<HousePictureListResultDTO>>().ok(icHouseService.getHousePictureList(dto)); |
|
|
return new Result<PageData<HousePictureListResultDTO>>().ok(icHouseService.getHousePictureList(dto)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("export") |
|
|
|
|
|
public void export(@RequestBody HouseCountPictureFormDTO formDTO, HttpServletResponse response) throws IOException { |
|
|
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
|
|
formDTO.setPageNo(NumConstant.ONE); |
|
|
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
|
|
try { |
|
|
|
|
|
String fileName = "房屋列表" + DateUtils.format(new Date()) + ".xlsx"; |
|
|
|
|
|
// 头的策略
|
|
|
|
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
|
|
|
|
|
// 背景设置为红色
|
|
|
|
|
|
headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); |
|
|
|
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
|
|
|
|
|
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
|
|
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); |
|
|
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), HousePictureListExcelDTO.class) |
|
|
|
|
|
.registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
|
|
|
|
|
.registerWriteHandler(writeHandler).build(); |
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
|
|
PageData<HousePictureListResultDTO> data = null; |
|
|
|
|
|
List<HousePictureListExcelDTO> list = null; |
|
|
|
|
|
do { |
|
|
|
|
|
data = icHouseService.getHousePictureList(formDTO); |
|
|
|
|
|
list = ConvertUtils.sourceToTarget(data.getList(), HousePictureListExcelDTO.class); |
|
|
|
|
|
formDTO.setPageNo(formDTO.getPageNo() + NumConstant.ONE); |
|
|
|
|
|
excelWriter.write(list, writeSheet); |
|
|
|
|
|
} while (CollectionUtils.isNotEmpty(list) && list.size() == formDTO.getPageSize()); |
|
|
|
|
|
} catch (EpmetException e) { |
|
|
|
|
|
response.reset(); |
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
response.setHeader("content-type", "application/json; charset=UTF-8"); |
|
|
|
|
|
PrintWriter printWriter = response.getWriter(); |
|
|
|
|
|
Result<Object> result = new Result<>().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), e.getMsg()); |
|
|
|
|
|
printWriter.write(JSON.toJSONString(result)); |
|
|
|
|
|
printWriter.close(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("房屋列表导出异常export exception", e); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (excelWriter != null) { |
|
|
|
|
|
excelWriter.finish(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|