Commit 39cf8d46 by yangyang

天枢导出提交(湖南)

parent 4ff6f0fa
......@@ -101,9 +101,13 @@ public class HttpClient {
httpPost.setConfig(requestConfig);
BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue);
cookie.setDomain(".tianshu.gat.zj");
cookie.setPath("/");
cookieStore.addCookie(cookie);
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
httpPost.setHeader("Cookie",cookie.toString());
try{
//设置参数解决中文乱码
if (null != json){
......
......@@ -26,7 +26,7 @@ public class TokenConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
String[] excludePatterns = new String[]{"/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**",
"/api", "/api-docs", "/api-docs/**", "/doc.html/**", "/koTime/**","/exportTsHn/export"};
"/api", "/api-docs", "/api-docs/**", "/doc.html/**", "/koTime/**","/exportTsHn/export","/ts/export"};
registry.addInterceptor(tokenInterceptor)
.addPathPatterns("/**")//指定该类拦截的url
.excludePathPatterns(skInterceptorController.findAllUrl())
......
package com.founder.publicapi.controller.SkInterface;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.util.ExportExcelUtil;
import com.founder.commonutils.util.HttpClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
@Api(tags = "天枢导出")
@RestController
@RequestMapping("/ts")
public class TsinfoControllerTest {
@GetMapping("/export")
@ApiOperation("Excel接口")
public void export(@RequestParam(name = "id") String id,@RequestParam(name = "sessionid") String sessionid,HttpServletResponse response){
XSSFWorkbook wb = new XSSFWorkbook();
try {
List<Map<String,Object>> listLogin = new ArrayList<>();
Map<String,Object> mapLogin = new HashMap<>();
mapLogin.put("asjbh","A65656");
mapLogin.put("ajmc","登录66");
listLogin.add(mapLogin);
Map<String,Object> mapLogin2 = new HashMap<>();
mapLogin2.put("asjbh","9999");
mapLogin2.put("ajmc","登录77");
listLogin.add(mapLogin2);
List<Map<String,Object>> listZc = new ArrayList<>();
Map<String,Object> mapZc = new HashMap<>();
mapZc.put("zc1","注册注册");
mapZc.put("zc2","注册名称66");
listZc.add(mapZc);
Map<String,Object> mapZc2 = new HashMap<>();
mapZc2.put("zc1","注册注册");
mapZc2.put("zc2","注册名称77");
listZc.add(mapZc2);
List<Map<String,Object>> listJy = new ArrayList<>();
Map<String,Object> mapJy = new HashMap<>();
mapJy.put("jy1","交易55");
mapJy.put("jy2","交易名称66");
listJy.add(mapJy);
Map<String,Object> mapJy2 = new HashMap<>();
mapJy2.put("jy1","交易999");
mapJy2.put("jy2","交易名称77");
listJy.add(mapJy2);
// table 登录(logon_log_acc) 注册(register) 账户明细(consume_query_real_time)
String[] headersNamelogon = {"登录1","登录2"};
String[] headersFieldlogon = {"asjbh","ajmc"};
createExcel(listLogin, "登录", wb,headersNamelogon,headersFieldlogon);
String[] headersNameregister = {"注册1","注册2"};
String[] headersFieldregister= {"zc1","zc2"};
createExcel(listZc,"注册", wb,headersNameregister,headersFieldregister);
String[] headersNameConsumer = {"交易1","交易2"};
String[] headersFieldConsumer = {"jy1","jy2"};
createExcel(listJy, "交易", wb,headersNameConsumer,headersFieldConsumer);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="
.concat("log.xls"));
OutputStream out = response.getOutputStream();
Thread.sleep(5000);
wb.write(out);
wb.close();
out.close();;
} catch (Exception e) {
e.printStackTrace();
}
}
public void createExcel(List<Map<String, Object>> mapList,String title,XSSFWorkbook wb,String[] headersNamelogon,String[] headersFieldlogon) {
//获取数据源的 key, 用于获取列数及设置标题
Map<String, Object> map = mapList.get(0);
// 表头
List<String> headList = Arrays.asList(headersNamelogon);
// 字段
List<String> headFieldList = Arrays.asList(headersFieldlogon);
//创建一个Sheet页
XSSFSheet sheet = wb.createSheet(title);
//设置行高
sheet.setDefaultRowHeight((short) (2 * 256));
//为有数据的每列设置列宽
for (int i = 0; i < headList.size(); i++) {
sheet.setColumnWidth(i, 8000);
}
//设置单元格字体样式
XSSFFont font = wb.createFont();
font.setFontName("等线");
font.setFontHeightInPoints((short) 16);
// 创建单元格文字居中样式并设置标题单元格居中
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
//获得表格第二行
XSSFRow row = sheet.createRow(0);
//根据数据源信息给第二行每一列设置标题
for (int i = 0; i < headList.size(); i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(headList.get(i));
}
XSSFRow rows;
XSSFCell cells;
//循环拿到的数据给所有行每一列设置对应的值
for (int i = 0; i < mapList.size(); i++) {
//在这个sheet页里创建一行
rows = sheet.createRow(i + 1);
//给该行数据赋值
for (int j = 0; j < headFieldList.size(); j++) {
String value;
if (mapList.get(i).get(headFieldList.get(j)) !=null){
value = mapList.get(i).get(headFieldList.get(j)).toString();
}else {
value = "";
}
cells = rows.createCell(j);
cells.setCellValue(value);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment