|
|
@ -17,15 +17,21 @@ |
|
|
|
|
|
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
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.aop.NoRepeatSubmit; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
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.poi.excel.handler.FreezeAndFilter; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.commons.tools.validator.group.AddGroup; |
|
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
@ -53,11 +59,9 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -116,23 +120,36 @@ public class IcPartyActivityController { |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("export") |
|
|
|
public void export(@RequestBody PartyActivityFormDTO formDTO, HttpServletResponse response) throws Exception { |
|
|
|
List<IcPartyActivityDTO> list = icPartyActivityService.list(formDTO); |
|
|
|
List<IcPartyActivityExcel> excelList = new ArrayList<>(); |
|
|
|
AtomicInteger i = new AtomicInteger(1); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
excelList = list.stream().map(item -> { |
|
|
|
IcPartyActivityExcel excel = new IcPartyActivityExcel(); |
|
|
|
excel.setIndex(i.getAndIncrement()); |
|
|
|
excel.setUnitName(item.getUnitName()); |
|
|
|
excel.setTitle(item.getTitle()); |
|
|
|
excel.setAddress(item.getAddress()); |
|
|
|
excel.setPeopleCount(item.getPeopleCount()); |
|
|
|
excel.setActivityTime(DateUtils.format(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN)); |
|
|
|
return excel; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
public void export(@LoginUser TokenDto tokenDto, @RequestBody PartyActivityFormDTO formDTO, HttpServletResponse response) throws Exception { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setIsPage(false); |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
int pageNo = formDTO.getPageNo(); |
|
|
|
try { |
|
|
|
// 这里 需要指定写用哪个class去写
|
|
|
|
String today= DateUtils.format(new Date(),DateUtils.DATE_PATTERN_MMDD); |
|
|
|
String fileName = "联建活动".concat(today); |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), IcPartyActivityExcel.class).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
PageData<IcPartyActivityDTO> data = null; |
|
|
|
List<IcPartyActivityExcel> list = null; |
|
|
|
do { |
|
|
|
data = icPartyActivityService.search(formDTO); |
|
|
|
list = ConvertUtils.sourceToTarget(data.getList(), IcPartyActivityExcel.class); |
|
|
|
formDTO.setPageNo(++pageNo); |
|
|
|
excelWriter.write(list, writeSheet); |
|
|
|
} while (CollectionUtils.isNotEmpty(data.getList()) && data.getList().size() == formDTO.getPageSize()); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("export exception", e); |
|
|
|
} finally { |
|
|
|
// 千万别忘记finish 会帮忙关闭流
|
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
ExcelUtils.exportExcelToTarget(response, null, excelList, IcPartyActivityExcel.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|