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.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.model.newPublicEntity.MapRestResult;
import com.founder.commonutils.model.vo.response.SkRelatedResultInterFace;
import com.founder.commonutils.model.vo.response.SkRelatedResultVO;
import com.founder.commonutils.util.ExportExcelUtil;
import com.founder.commonutils.util.HttpClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -19,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
......@@ -28,39 +25,47 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("/exportTsHn")
public class TsinfoController {
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
String url = "http://tianshu.gat.zj/tsure/assistQueryResult/queryAssistForPage.json";
@GetMapping("/export")
@ApiOperation("Excel接口")
public void export(@RequestParam(name = "id") String id,HttpServletResponse response){
public void export(@RequestParam(name = "id") String id,@RequestParam(name = "sessionid") String sessionid,HttpServletResponse response){
XSSFWorkbook wb = new XSSFWorkbook();
try {
// table 登录(logon_log_acc) 注册(register) 账户明细(consume_query_real_time)
createExcel(exportData("logon_log_acc",id), "登录", wb);
createExcel(exportData("register",id),"注册", wb);
createExcel(exportData("consume_query_real_time",id), "交易", wb);
String[] headersNamelogon = {"登录账号","支付宝用户ID","账户名","客户端IP","操作发生时间","对应的协查数据"};
String[] headersFieldlogon = {"loginId","userId","name","clientIp","actionDt","principalValue"};
createExcel(exportData("logon_log_acc",id,sessionid), "登录", wb,headersNamelogon,headersFieldlogon);
String[] headersNameregister = {"用户ID","登录邮箱","登录手机","账户名称","证件类型","证件号","用户可用余额","绑定手机","注册日期","绑定银行卡","对应的协查数据"};
String[] headersFieldregister= {"userId","loginEmail","userLoginId","realName","certType","certNo","balance","bindMobile","registerDate","bindCard","principalValue"};
createExcel(exportData("register",id,sessionid),"注册", wb,headersNameregister,headersFieldregister);
String[] headersNameConsumer = {"交易号","商户订单号","创建时间","付款时间","交易来源地","交易类型","用户信息","用户信息","交易对方信息","交易对方信息","消费名称","金额(元)","支付方式","收/支","交易状态","对应的协查数据","收入金额(+)(元)","支出金额(-)(元)","余额(元)","服务费","成功退款(元)","银行清算流水号","关联交易号","付款方银行卡账号","付款方银行名称","收款方银行卡账号","收款方银行名称","收货人姓名","收货人电话","收货人地址"};
String[] headersFieldConsumer = {"bizInNo","bizOutNo","gmtBizCreate","gmtBizModified","consumeSite","consumeType","userId","userName","oppositeUserId","oppositeUserName","consumeTitle","consumeFee","fundToolTypeName","inOut","bizState","principalValue","balanceInAmount","balanceOutAmount","accountBalance","serviceFee","consumeRefundFee","bankTransactionSerial","refBizInNo","transOutCardNumber","transOutBankName","transInCardNumber","transInBankName","receiverName","receiverMobileNo","receiverAddress"};
createExcel(exportData("consume_query_real_time",id,sessionid), "交易", wb,headersNameConsumer,headersFieldConsumer);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="
.concat("log.xls"));
OutputStream out = response.getOutputStream();
wb.write(out);
wb.close();
out.close();;
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Map<String, Object>> exportData(String table,String id) throws Exception {
int size = getCount(table,id);
public List<Map<String, Object>> exportData(String table,String id,String sessionid) throws Exception {
int size = getCount(table,id,sessionid);
List<Map<String, Object>> list = new ArrayList<>();
// 分页
int limit=1000;
long threadNum = size / limit;
int startnum = 0;
int startnum = 1;
int endnum = 0;
int page = 0;
// 按需分配线程池
for (int i = 0; i < threadNum + 1; i++) {
startnum = i * limit;
......@@ -74,13 +79,15 @@ public class TsinfoController {
if (startnum == endnum) {
break;
}
Task task = new Task( table,limit,startnum,id);
page ++;
Task task = new Task( table,limit,page,id,sessionid);
FutureTask<List<Map<String, Object>>> futureTask = new FutureTask<>(task);
ExecutorService executorService = Executors.newFixedThreadPool(100);
executorService.submit(futureTask);
List<Map<String, Object>> list1 = futureTask.get();
list.addAll(list1);
executorService.shutdown();
}
return list;
}
......@@ -89,11 +96,13 @@ public class TsinfoController {
private Integer pageSize;
private Integer pageNum;
private String id;
public Task(String table,Integer pageSize,Integer pageNum,String id) {
private String sessionid;
public Task(String table,Integer pageSize,Integer pageNum,String id,String sessionid) {
this.table = table;
this.pageSize = pageSize;
this.pageNum = pageNum;
this.id = id;
this.sessionid = sessionid;
}
@Override
public List<Map<String, Object>> call() {
......@@ -102,11 +111,11 @@ public class TsinfoController {
JSONObject params = new JSONObject();
params.put("pageSize", pageSize);
params.put("pageNum", pageNum);
params.put("tsureRequireId", "311072023091100672254");
params.put("tsureRequireId", id);
params.put("tableName", table);
JSONObject result = null;
try {
result = httpClient.doPostJsonHunanTs(url, params.toJSONString(),"JSESSIONID",id);
result = httpClient.doPostJsonHunanTs(url, params.toJSONString(),"SESSION",sessionid);
if (result != null) {
if ("true".equals(result.getString("success"))) {
JSONArray jsonArray = result.getJSONArray("data");
......@@ -121,18 +130,18 @@ public class TsinfoController {
}
// 获取总数
public Integer getCount(String table,String id){
public Integer getCount(String table,String id,String sessionid){
Integer totalCount = 0;
HttpClient httpClient = new HttpClient();
JSONObject params = new JSONObject();
// table 登录(logon_log_acc) 注册(register) 账户明细(consume_query_real_time)
params.put("pageSize", 0);
params.put("pageNum", 1);
params.put("tsureRequireId", "311072023091100672254");
params.put("tsureRequireId", id);
params.put("tableName", table);
JSONObject result = null;
try {
result = httpClient.doPostJsonHunanTs(url, params.toJSONString(),"JSESSIONID",id);
result = httpClient.doPostJsonHunanTs(url, params.toJSONString(),"SESSION",sessionid);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -185,11 +194,11 @@ public class TsinfoController {
return map;
}
public void createExcel(List<Map<String, Object>> mapList,String title,XSSFWorkbook wb) {
//获取数据源的 key, 用于获取列数及设置标题
Map<String, Object> map = mapList.get(0);
Set<String> stringSet = map.keySet();
ArrayList<String> headList = new ArrayList<>(stringSet);
public void createExcel(List<Map<String, Object>> mapList,String title,XSSFWorkbook wb,String[] headersNamelogon,String[] headersFieldlogon) {
// 表头
List<String> headList = Arrays.asList(headersNamelogon);
// 字段
List<String> headFieldList = Arrays.asList(headersFieldlogon);
//创建一个Sheet页
XSSFSheet sheet = wb.createSheet(title);
//设置行高
......@@ -202,16 +211,11 @@ public class TsinfoController {
XSSFFont font = wb.createFont();
font.setFontName("等线");
font.setFontHeightInPoints((short) 16);
//在sheet里创建第一行,并设置单元格内容为 title (标题)
XSSFRow titleRow = sheet.createRow(0);
XSSFCell titleCell = titleRow.createCell(0);
titleCell.setCellValue(title);
// 创建单元格文字居中样式并设置标题单元格居中
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
titleCell.setCellStyle(cellStyle);
//获得表格第二行
XSSFRow row = sheet.createRow(1);
//获得表格第一行
XSSFRow row = sheet.createRow(0);
//根据数据源信息给第二行每一列设置标题
for (int i = 0; i < headList.size(); i++) {
XSSFCell cell = row.createCell(i);
......@@ -222,18 +226,33 @@ public class TsinfoController {
//循环拿到的数据给所有行每一列设置对应的值
for (int i = 0; i < mapList.size(); i++) {
//在这个sheet页里创建一行
rows = sheet.createRow(i + 2);
rows = sheet.createRow(i + 1);
//给该行数据赋值
for (int j = 0; j < headList.size(); j++) {
for (int j = 0; j < headFieldList.size(); j++) {
String value;
if (mapList.get(i).get(headList.get(j)) !=null){
value = mapList.get(i).get(headList.get(j)).toString();
String filed = headFieldList.get(j);
if (mapList.get(i).get(headFieldList.get(j)) !=null){
value = mapList.get(i).get(headFieldList.get(j)).toString();
}else {
value = "";
}
// 时间戳转时间
if(Arrays.asList("actionDt","registerDate","gmtBizCreate","gmtBizModified").contains(filed)){
value = stampToDate(value);
}
cells = rows.createCell(j);
cells.setCellValue(value);
}
}
}
// 时间戳转时间
public String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
}
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