|
@@ -5,6 +5,12 @@ package com.jeeplus.lyservice.controller;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
+
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.EasyExcelFactory;
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
+import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import com.jeeplus.core.excel.EasyExcelUtils;
|
|
import com.jeeplus.core.excel.EasyExcelUtils;
|
|
import com.jeeplus.core.excel.ExcelOptions;
|
|
import com.jeeplus.core.excel.ExcelOptions;
|
|
@@ -30,9 +36,8 @@ import com.jeeplus.lyservice.service.LyServiceService;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.Calendar;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* LyServiceController
|
|
* LyServiceController
|
|
@@ -211,6 +216,110 @@ public class LyServiceController {
|
|
EasyExcelUtils.newInstance ( lyServiceService, lyServiceWrapper ).exportExcel ( result, options.getSheetName ( ), LyServiceDTO.class, fileName,options.getExportFields (), response );
|
|
EasyExcelUtils.newInstance ( lyServiceService, lyServiceWrapper ).exportExcel ( result, options.getSheetName ( ), LyServiceDTO.class, fileName,options.getExportFields (), response );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 导出服务对接数据
|
|
|
|
+ *
|
|
|
|
+ * @param response
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @ApiLog("导出服务对接数据")
|
|
|
|
+ @PreAuthorize("hasAnyAuthority('service:lyService:export')")
|
|
|
|
+ @GetMapping("export2")
|
|
|
|
+ public void exportFile2( String name,String des1,String beginTime,String endTime,String state, ExcelOptions options, HttpServletResponse response) throws Exception {
|
|
|
|
+ String fileName = options.getFilename ( );
|
|
|
|
+ List<HashMap<String,Object>> result = lyServiceService.getPersonInfo(name,des1,beginTime,endTime,state);
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType ( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
|
|
|
|
+ response.setCharacterEncoding ( "utf-8" );
|
|
|
|
+ //响应内容格式
|
|
|
|
+ response.setHeader ( "Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx" );
|
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
|
+
|
|
|
|
+ excelWriter = EasyExcelFactory.write(response.getOutputStream()).build();
|
|
|
|
+ // 组装表头
|
|
|
|
+ List<List<String>> excelHead = getExportHead("1");
|
|
|
|
+ fileName = URLEncoder.encode ( fileName, "UTF-8" ).replaceAll ( "\\+", "%20" );
|
|
|
|
+ if (result.size()>0){
|
|
|
|
+ WriteSheet writeSheet = EasyExcel
|
|
|
|
+ .writerSheet("sheet1")
|
|
|
|
+ .head(excelHead)
|
|
|
|
+ .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20))
|
|
|
|
+ .build();
|
|
|
|
+ excelWriter.write(dataList( result,"1"), writeSheet);
|
|
|
|
+ excelWriter.finish();
|
|
|
|
+ }else {
|
|
|
|
+ throw new RuntimeException("暂无数据可供下载");
|
|
|
|
+ }
|
|
|
|
+// EasyExcelUtils.newInstance ( lyServiceService, lyServiceWrapper ).exportExcel ( result, options.getSheetName ( ), LyServiceDTO.class, fileName,options.getExportFields (), response );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导出服务对接数据
|
|
|
|
+ *
|
|
|
|
+ * @param response
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @ApiLog("导出服务对接数据")
|
|
|
|
+ @PreAuthorize("hasAnyAuthority('service:lyService:export')")
|
|
|
|
+ @GetMapping("export3")
|
|
|
|
+ public void exportFile3( String name,String des1,String beginTime,String endTime,String state, ExcelOptions options, HttpServletResponse response) throws Exception {
|
|
|
|
+ String fileName = options.getFilename ( );
|
|
|
|
+ List<HashMap<String,Object>> result = lyServiceService.getCompanyInfo(name,des1,beginTime,endTime,state);
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType ( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
|
|
|
|
+ response.setCharacterEncoding ( "utf-8" );
|
|
|
|
+ //响应内容格式
|
|
|
|
+ response.setHeader ( "Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx" );
|
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
|
+
|
|
|
|
+ excelWriter = EasyExcelFactory.write(response.getOutputStream()).build();
|
|
|
|
+ // 组装表头
|
|
|
|
+ List<List<String>> excelHead = getExportHead("2");
|
|
|
|
+ fileName = URLEncoder.encode ( fileName, "UTF-8" ).replaceAll ( "\\+", "%20" );
|
|
|
|
+ if (result.size()>0){
|
|
|
|
+ WriteSheet writeSheet = EasyExcel
|
|
|
|
+ .writerSheet("sheet1")
|
|
|
|
+ .head(excelHead)
|
|
|
|
+ .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20))
|
|
|
|
+ .build();
|
|
|
|
+ excelWriter.write(dataList( result,"2"), writeSheet);
|
|
|
|
+ excelWriter.finish();
|
|
|
|
+ }else {
|
|
|
|
+ throw new RuntimeException("暂无数据可供下载");
|
|
|
|
+ }
|
|
|
|
+// EasyExcelUtils.newInstance ( lyServiceService, lyServiceWrapper ).exportExcel ( result, options.getSheetName ( ), LyServiceDTO.class, fileName,options.getExportFields (), response );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<List<Object>> dataList( List<HashMap<String,Object>> mapList,String type) {
|
|
|
|
+ List<List<Object>> list = new ArrayList();
|
|
|
|
+ List<Map<String, Object>> table_heads = lyServiceService.getTableTitle(type);
|
|
|
|
+ for (int i = 0; i < mapList.size(); i++) {
|
|
|
|
+
|
|
|
|
+ Map row = mapList.get(i);
|
|
|
|
+ List<Object> data = new ArrayList();
|
|
|
|
+ data.add(i+1);
|
|
|
|
+ for (int j = 1; j < table_heads.size(); j++) {
|
|
|
|
+ String filed = table_heads.get(j).get("field").toString();
|
|
|
|
+ Object objVal = row.get(filed);
|
|
|
|
+ String val = Objects.toString(objVal, "");
|
|
|
|
+ data.add(val);
|
|
|
|
+ }
|
|
|
|
+ list.add(data);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<List<String>> getExportHead(String type) {
|
|
|
|
+ List<List<String>> head_list = new ArrayList<>();
|
|
|
|
+ List<Map<String, Object>> table_heads = lyServiceService.getTableTitle(type);
|
|
|
|
+ for (int i = 0; i < table_heads.size(); i++) {
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ list.add(table_heads.get(i).get("title").toString());
|
|
|
|
+ head_list.add(list);
|
|
|
|
+ }
|
|
|
|
+ return head_list;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 导入服务对接数据
|
|
* 导入服务对接数据
|
|
*
|
|
*
|