Commit c3155945 authored by Quxl's avatar Quxl

x

parent fcb32b39
package com.egolm.film.api.web.admin;
import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,6 +33,7 @@ import com.egolm.film.bean.Fc_logs_ext;
import com.egolm.film.bean.Fc_member_film;
import com.egolm.film.bean.Fc_member_film_enroll;
import com.egolm.film.config.XRException;
import com.egolm.film.util.Export;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -73,6 +78,16 @@ public class WebUtilController {
return Rjx.jsonOk();
}
@Transactional
@PostMapping("exportExcel")
@ApiOperation("导出Excel")
public void exportExcel(String db_host, String db_name, String username, String password, HttpServletResponse response) throws SQLException, IOException {
String filename = "export.xls";
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
response.setContentType("application/octet-stream");
new Export(db_host, db_name, username, password).export(response.getOutputStream());
}
@ResponseBody
@Transactional
@PostMapping("initAllEnrollType")
......
package com.egolm.film.util;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
......@@ -18,7 +18,6 @@ import com.egolm.common.jdbc.JUtil;
public class Export {
private String root;
private String db_name;
private Connection conn;
......@@ -30,18 +29,17 @@ public class Export {
}
}
public Export(String root, String db_host, String db_name, String username, String password) throws SQLException {
this.root = root;
public Export(String db_host, String db_name, String username, String password) throws SQLException {
this.db_name = db_name;
this.conn = DriverManager.getConnection("jdbc:mysql://" + db_host + "/information_schema?useSSL=false&useUnicode=true&characterEncoding=utf8" , username, password);
}
public List<Map<String, Object>> getTableDesc(String tableName) throws SQLException {
private List<Map<String, Object>> getTableDesc(String tableName) throws SQLException {
String sql = "SELECT DISTINCT C.COLUMN_NAME, C.COLUMN_TYPE, C.COLUMN_COMMENT, CU.CONSTRAINT_NAME FROM COLUMNS C LEFT JOIN KEY_COLUMN_USAGE CU ON CU.TABLE_SCHEMA = C.TABLE_SCHEMA AND CU.TABLE_NAME = C.TABLE_NAME AND CU.COLUMN_NAME = C.COLUMN_NAME WHERE C.TABLE_SCHEMA = '" + this.db_name + "' AND C.TABLE_NAME = '" + tableName + "'";
return this.queryForList(sql);
}
public List<Map<String, Object>> queryForList(String sql) throws SQLException {
private List<Map<String, Object>> queryForList(String sql) throws SQLException {
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
return JUtil.resultSetToList(resultSet);
......@@ -65,7 +63,7 @@ public class Export {
types.put("supportingActor", "男配角");
types.put("supportingActress", "女配角");
}
public List<Map<String, Object>> queryDataList(String tableName) throws SQLException {
private List<Map<String, Object>> queryDataList(String tableName) throws SQLException {
String sql = "select t.* from " + this.db_name + "." + tableName + " t";
String sql0 = "select group_concat(fp.playactor_name) text, fp.film_id, fp.playactor_type from " + this.db_name + ".fc_member_film_playactor fp group by fp.film_id, fp.playactor_type";
String sql1 = "select group_concat(fi.issuer_company, ' ', fi.issuer_company_en) text, fi.film_id from " + this.db_name + ".fc_member_film_issuer fi group by fi.film_id";
......@@ -92,8 +90,8 @@ public class Export {
return list;
}
public static void main(String[] args) throws Exception {
Export exp = new Export("D:/tv.xls", "10.10.0.111", "tv", "root", "egolm#2018");
public void export(OutputStream os) throws SQLException {
Export exp = new Export("10.10.0.111", "tv", "root", "egolm#2018");
List<Map<String, Object>> desc = exp.getTableDesc("fc_member_film");
List<Map<String, Object>> list = exp.queryDataList("fc_member_film");
List<String> argsList = new ArrayList<String>();
......@@ -116,8 +114,7 @@ public class Export {
titleList.add("发行方");
argsList.add("show");
titleList.add("参加过的电视节");
ExcelUtil.excel(new FileOutputStream(exp.root), argsList.toArray(new String[argsList.size()]), titleList.toArray(new String[titleList.size()]), null, list);
ExcelUtil.excel(os, argsList.toArray(new String[argsList.size()]), titleList.toArray(new String[titleList.size()]), null, list);
}
}
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