Commit 8e933df0 authored by Quxl's avatar Quxl

x

parent 28491703
package com.egolm.film.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Column;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.egolm.common.ExcelUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.jdbc.JUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.bean.Fc_member_film;
......@@ -47,6 +42,8 @@ public class Export {
types.put("heroine", "女主演");
types.put("supportingActor", "男配角");
types.put("supportingActress", "女配角");
types.put("issuser", "发行方");
types.put("show", "参加过的电视节");
}
private List<Map<String, Object>> queryDataList() {
String sql = "select t.* from fc_member_film t";
......@@ -75,23 +72,37 @@ public class Export {
return list;
}
public void export() {
// String[] attrs = Util.clzAttributes(Fc_member_film.class);
// List<Map<String, Object>> list = this.queryDataList();
// List<String> argsList = new ArrayList<String>();
// for(String attr : attrs) {
// argsList.add(attr);
// }
//
// for(String key : types.keySet()) {
// argsList.add(key);
// titleList.add(types.get(key));
// }
// argsList.add("issuser");
// titleList.add("发行方");
// argsList.add("show");
// titleList.add("参加过的电视节");
// ExcelUtil.excel(new FileOutputStream("/data/export.xls"), argsList.toArray(new String[argsList.size()]), titleList.toArray(new String[titleList.size()]), null, list);
public void export(OutputStream os) {
List<Map<String, Object>> list = this.queryDataList();
List<String> argsList = new ArrayList<String>();
List<String> titleList = new ArrayList<String>();
Class<?> clz = Fc_member_film.class;
Field[] fs = clz.getDeclaredFields();
for(Field f : fs) {
String columnName = f.getName();
String columnComment = columnName;
if(f.isAnnotationPresent(Column.class)) {
Column column = f.getAnnotation(Column.class);
if(StringUtil.isNotBlank(column.name())) {
columnName = column.name();
}
String columnDefinition = column.columnDefinition();
if(StringUtil.isNotBlank(columnDefinition)) {
String regex = "COMMENT '(.+)'";
String comment = StringUtil.search(columnDefinition, regex, 1)[0];
if(StringUtil.isNotBlank(comment)) {
columnComment = comment;
}
}
}
argsList.add(columnName);
titleList.add(columnComment);
}
for(String key : types.keySet()) {
argsList.add(key);
titleList.add(types.get(key));
}
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