|
@ -1,22 +1,45 @@ |
|
|
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.aop.NoRepeatSubmit; |
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
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.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.form.yt.CommunityBuildingManagerPageFormDTO; |
|
|
import com.epmet.dto.form.yt.CommunityBuildingManagerPageFormDTO; |
|
|
import com.epmet.dto.result.CommunityBuildingManagerDTO; |
|
|
import com.epmet.dto.result.CommunityBuildingManagerDTO; |
|
|
import com.epmet.dto.result.yt.CommunityBuildingManagerResultDTO; |
|
|
import com.epmet.dto.result.yt.CommunityBuildingManagerResultDTO; |
|
|
import com.epmet.service.CommunityBuildingManagerService; |
|
|
import com.epmet.service.CommunityBuildingManagerService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
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.http.HttpHeaders; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -26,6 +49,7 @@ import java.util.List; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2023-05-06 |
|
|
* @since v1.0.0 2023-05-06 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("communityBuildingManager") |
|
|
@RequestMapping("communityBuildingManager") |
|
|
public class CommunityBuildingManagerController { |
|
|
public class CommunityBuildingManagerController { |
|
@ -108,4 +132,83 @@ public class CommunityBuildingManagerController { |
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 楼长单元长-下载导入模板 |
|
|
|
|
|
* @param response |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
@RequestMapping(value = "download-tem", method = {RequestMethod.GET, RequestMethod.POST}) |
|
|
|
|
|
public void downloadTemplate(HttpServletResponse response) throws IOException { |
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
response.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition"); |
|
|
|
|
|
//response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel");
|
|
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("楼长单元长导入模版", "UTF-8") + ".xlsx"); |
|
|
|
|
|
|
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream("excel/yantai/community_building_manager_import_temp.xlsx"); |
|
|
|
|
|
try { |
|
|
|
|
|
ServletOutputStream os = response.getOutputStream(); |
|
|
|
|
|
IOUtils.copy(is, os); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (is != null) { |
|
|
|
|
|
is.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 楼长单元长-列表导出 |
|
|
|
|
|
* |
|
|
|
|
|
* @param tokenDto |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
* @param response |
|
|
|
|
|
* @return |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
@PostMapping("export") |
|
|
|
|
|
public void exportCommunityBuildingManager(@LoginUser TokenDto tokenDto, @RequestBody CommunityBuildingManagerPageFormDTO formDTO, HttpServletResponse response) throws IOException { |
|
|
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
|
|
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), CommunityBuildingManagerResultDTO.class) |
|
|
|
|
|
.registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
|
|
|
|
|
.registerWriteHandler(writeHandler).build(); |
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
|
|
PageData<CommunityBuildingManagerResultDTO> data = null; |
|
|
|
|
|
do { |
|
|
|
|
|
data = communityBuildingManagerService.page(formDTO); |
|
|
|
|
|
formDTO.setPageNo(formDTO.getPageNo() + NumConstant.ONE); |
|
|
|
|
|
excelWriter.write(data.getList(), writeSheet); |
|
|
|
|
|
} while (org.apache.commons.collections4.CollectionUtils.isNotEmpty(data.getList()) && data.getList().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(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|