|
|
@ -1,10 +1,15 @@ |
|
|
|
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.dto.form.PageFormDTO; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constant.IcResiUserConstant; |
|
|
@ -13,6 +18,8 @@ import com.epmet.dto.form.IcTripReportFormDTO; |
|
|
|
import com.epmet.dto.form.MyReportedTripFormDTO; |
|
|
|
import com.epmet.dto.form.PageTripReportFormDTO; |
|
|
|
import com.epmet.service.IcTripReportRecordService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.commons.lang3.ArrayUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -33,6 +40,7 @@ import java.util.List; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2022-03-25 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@RestController |
|
|
|
@RequestMapping("tripreport") |
|
|
|
public class IcTripReportRecordController { |
|
|
@ -157,5 +165,42 @@ public class IcTripReportRecordController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* pc:行程上报-导出 |
|
|
|
* @param tokenDto |
|
|
|
* @param formDTO |
|
|
|
* @param response |
|
|
|
*/ |
|
|
|
@NoRepeatSubmit |
|
|
|
@PostMapping("export") |
|
|
|
public void export(@LoginUser TokenDto tokenDto, @RequestBody PageTripReportFormDTO formDTO, HttpServletResponse response) { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setUserId(tokenDto.getUserId()); |
|
|
|
// formDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
|
|
|
|
// formDTO.setUserId("35005df15fb0f7c791344f0b424870b7");
|
|
|
|
formDTO.setPage(false); |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
int pageNo = formDTO.getPageNo(); |
|
|
|
try { |
|
|
|
// 这里 需要指定写用哪个class去写
|
|
|
|
String fileName = "行程上报.xlsx"; |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), IcTripReportRecordDTO.class).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").build(); |
|
|
|
PageData<IcTripReportRecordDTO> data = null; |
|
|
|
do { |
|
|
|
data = icTripReportRecordService.page(formDTO); |
|
|
|
formDTO.setPageNo(++pageNo); |
|
|
|
excelWriter.write(data.getList(), 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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|