|
|
@@ -1,21 +1,15 @@
|
|
|
package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
-import com.fdkankan.common.util.DateExtUtil;
|
|
|
import com.fdkankan.manage.constant.CameraOutTypeEnum;
|
|
|
import com.fdkankan.manage.entity.Company;
|
|
|
import com.fdkankan.manage.service.ICameraService;
|
|
|
import com.fdkankan.manage.service.ICompanyService;
|
|
|
import com.fdkankan.manage.service.IExcelService;
|
|
|
-import com.fdkankan.manage.service.IInvoiceService;
|
|
|
import com.fdkankan.manage.util.ExcelUtil;
|
|
|
-import com.fdkankan.manage.vo.InvoicePageParamVO;
|
|
|
-import com.fdkankan.manage.vo.InvoiceVO;
|
|
|
import com.fdkankan.manage.vo.request.CameraInOutParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -26,7 +20,6 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -42,34 +35,37 @@ import java.util.List;
|
|
|
public class ExcelServiceImpl implements IExcelService {
|
|
|
|
|
|
@Autowired
|
|
|
- private IInvoiceService invoiceService;
|
|
|
- @Autowired
|
|
|
ICompanyService companyService;
|
|
|
@Autowired
|
|
|
ICameraService cameraService;
|
|
|
|
|
|
- @Override
|
|
|
- public void exportInvoice(HttpServletRequest request, HttpServletResponse response, InvoicePageParamVO param)
|
|
|
- throws IOException {
|
|
|
+ public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,ExcelWriter excelWriter) throws Exception {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
- String fileName = "开票申请数据" + DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle6) + ".xlsx";
|
|
|
+ String fileName = name + ".xlsx";
|
|
|
fileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
|
- try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), InvoiceVO.class).build()) {
|
|
|
- // 这里注意 如果同一个sheet只要创建一次
|
|
|
- WriteSheet writeSheet = EasyExcel.writerSheet("开票申请数据").build();
|
|
|
- // 去调用写入,这里我调用了五次,实际使用时根据数据库分页的总的页数来
|
|
|
- int pageNum = 1;
|
|
|
- param.setPageSize(5000);
|
|
|
- Page<InvoiceVO> invoiceVOPage;
|
|
|
- do {
|
|
|
- param.setPageNum(pageNum);
|
|
|
- invoiceVOPage = invoiceService.pageInvoice(param);
|
|
|
- excelWriter.write(invoiceVOPage.getRecords(), writeSheet);
|
|
|
- ++pageNum;
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet(name).build();
|
|
|
+ excelWriter.write(result, writeSheet);
|
|
|
+ }
|
|
|
|
|
|
- }while (invoiceVOPage.hasNext());
|
|
|
+ public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,Class<?> clazz) throws Exception {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = name + ".xlsx";
|
|
|
+ fileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ excelWriter = EasyExcel.write(response.getOutputStream(), clazz).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet(name).build();
|
|
|
+ excelWriter.write(result, writeSheet);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(excelWriter != null){
|
|
|
+ excelWriter.finish();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|