|
|
@ -2,12 +2,17 @@ package com.epmet.datareport.controller.screen; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.datareport.service.evaluationindex.screen.ScreenProjectOrgDailyService; |
|
|
@ -241,30 +246,53 @@ public class ScreenProjectController { |
|
|
|
* @date 2021/11/4 3:38 下午 |
|
|
|
*/ |
|
|
|
@PostMapping("selectcategoryprojectlist/export") |
|
|
|
public void selectProjectCategoryExport(@RequestBody CategoryProjectListFormDTO formDTO,@LoginUser TokenDto tokenDto, HttpServletResponse response) throws Exception { |
|
|
|
//tokenDto.setUserId("36bc0fb38565ecdebf8ab9b476b44548");
|
|
|
|
//tokenDto.setCustomerId("45687aa479955f9d06204d415238f7cc");
|
|
|
|
formDTO.setIsPage(false); |
|
|
|
//formDTO.setStatus("all");
|
|
|
|
//formDTO.setCategoryCode("0102");
|
|
|
|
ValidatorUtils.validateEntity(formDTO, ProjectCategoryFormDTO.CategoryProjectExportForm.class); |
|
|
|
PageCategoryProjectListResultDTO data = screenProjectService.selectCategoryProjectList(formDTO,tokenDto); |
|
|
|
String templatePath = "excel/project_temp.xlsx"; |
|
|
|
public void selectProjectCategoryExport(@RequestBody CategoryProjectListFormDTO formDTO, @LoginUser TokenDto tokenDto, HttpServletResponse response) throws Exception { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
try { |
|
|
|
//tokenDto.setUserId("36bc0fb38565ecdebf8ab9b476b44548");
|
|
|
|
//tokenDto.setCustomerId("45687aa479955f9d06204d415238f7cc");
|
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
Map<String,Object> mapData = new HashMap<>(); |
|
|
|
mapData.put("list",data.getList()); |
|
|
|
mapData.put("orgName",staffInfo.getAgencyName()); |
|
|
|
mapData.put("exportDate",getExportDateStr(formDTO.getStartTime(),formDTO.getEndTime())); |
|
|
|
mapData.put("categoryName", formDTO.getCategoryName()); |
|
|
|
if (StringUtils.isNotBlank(formDTO.getParentCategoryName())){ |
|
|
|
mapData.put("categoryName", formDTO.getParentCategoryName().concat(StrConstant.HYPHEN).concat(formDTO.getCategoryName())); |
|
|
|
} |
|
|
|
formDTO.setIsPage(false); |
|
|
|
ValidatorUtils.validateEntity(formDTO, ProjectCategoryFormDTO.CategoryProjectExportForm.class); |
|
|
|
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new TemplateExportParams(templatePath), mapData); |
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("项目统计.xls", "UTF-8")); |
|
|
|
workbook.write(response.getOutputStream()); |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
Map<String, Object> mapData = new HashMap<>(); |
|
|
|
mapData.put("orgName", staffInfo == null ? StrConstant.EPMETY_STR : staffInfo.getAgencyName()); |
|
|
|
mapData.put("exportDate", getExportDateStr(formDTO.getStartTime(), formDTO.getEndTime())); |
|
|
|
mapData.put("categoryName", formDTO.getCategoryName()); |
|
|
|
if (StringUtils.isNotBlank(formDTO.getParentCategoryName())) { |
|
|
|
mapData.put("categoryName", formDTO.getParentCategoryName().concat(StrConstant.HYPHEN).concat(formDTO.getCategoryName())); |
|
|
|
} |
|
|
|
|
|
|
|
String templatePath = "/excel/project_temp_easy_excel.xlsx"; |
|
|
|
String template = this.getClass().getResource(templatePath).getPath(); |
|
|
|
String fileName = "项目统计.xls"; |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStream(fileName, response)).withTemplate(template).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
|
|
|
excelWriter.fill(mapData, writeSheet); |
|
|
|
|
|
|
|
formDTO.setPageSize(NumConstant.ONE); |
|
|
|
PageCategoryProjectListResultDTO data = null; |
|
|
|
do { |
|
|
|
data = screenProjectService.selectCategoryProjectList(formDTO, tokenDto); |
|
|
|
if (data.getList().isEmpty()) { |
|
|
|
break; |
|
|
|
} |
|
|
|
formDTO.setPageNo(formDTO.getPageNo() + 1); |
|
|
|
excelWriter.fill(data.getList(), writeSheet); |
|
|
|
} while (data.getList().size() == formDTO.getPageSize()); |
|
|
|
|
|
|
|
// String templatePath = "excel/project_temp.xlsx";
|
|
|
|
// Workbook workbook = ExcelExportUtil.exportExcel(new TemplateExportParams(templatePath), mapData);
|
|
|
|
// response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
|
// response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("项目统计.xls", "UTF-8"));
|
|
|
|
// workbook.write(response.getOutputStream());
|
|
|
|
|
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|