Commit 8e933df0 authored by Quxl's avatar Quxl

x

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