Commit f799c56b authored by Quxl's avatar Quxl

x

parent 2654b70e
package com.egolm.film.util;
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.egolm.common.ExcelUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.bean.Fc_member_film;
@Component
public class Export {
@Autowired
private JdbcTemplate jdbcTemplate;
static Map<String, String> types = new HashMap<String, String>();
static {
types.put("director", "导演");
types.put("producer", "监制");
types.put("original", "原著");
types.put("screenwriter", "编剧");
types.put("photographer", "摄影师");
types.put("musicAuthor", "音乐");
types.put("filmEditor", "剪辑");
types.put("presenter", "主持人");
types.put("officiatingGuests", "主持嘉宾");
types.put("art", "美术");
types.put("stylist", "造型");
types.put("effectArtist", "特效");
types.put("hero", "男主演");
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";
String sql0 = "select group_concat(fp.playactor_name) text, fp.film_id, fp.playactor_type from 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 fc_member_film_issuer fi group by fi.film_id";
String sql2 = "select group_concat(fs.show_filmfest) text, fs.film_id from fc_member_film_show fs group by fs.film_id";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
List<Map<String, Object>> playactors = jdbcTemplate.queryForList(sql0);
List<Map<String, Object>> issuers = jdbcTemplate.queryForList(sql1);
List<Map<String, Object>> shows = jdbcTemplate.queryForList(sql2);
Map<String, Map<String, Object>> playactorMM = Util.listToMM(playactors, ",", "film_id", "playactor_type");
Map<String, Map<String, Object>> issuerMM = Util.listToMM(issuers, ",", "film_id");
Map<String, Map<String, Object>> showMM = Util.listToMM(shows, ",", "film_id");
for(Map<String, Object> map : list) {
String id_str = "" + map.get("id");
for(String playactor_type : types.keySet()) {
Map<String, Object> playactorMap = playactorMM.get(id_str + "," + playactor_type);
map.put(playactor_type, playactorMap == null ? null : playactorMap.get("text"));
}
Map<String, Object> issuerMap = issuerMM.get(id_str);
Map<String, Object> showMap = showMM.get(id_str);
map.put("issuer", issuerMap == null ? null : issuerMap.get("text"));
map.put("issuer", showMap == null ? null : showMap.get("text"));
}
return 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