Commit 42ace1e8 authored by Quxl's avatar Quxl

x

parent 8e933df0
package com.egolm.film.api.service;
import java.io.OutputStream;
public interface ExportService {
public void export(OutputStream os);
}
package com.egolm.film.api.service.impl;
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 ExportServiceImpl {
@Autowired
JdbcTemplate jdbcTemplate;
private static final 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>> queryFilmDataList() {
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.queryFilmDataList();
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);
}
}
...@@ -2,11 +2,14 @@ package com.egolm.film.api.web.admin; ...@@ -2,11 +2,14 @@ package com.egolm.film.api.web.admin;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.SQLException; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -20,11 +23,13 @@ import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; ...@@ -20,11 +23,13 @@ import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.Util; import com.egolm.common.Util;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.service.AdminTokenService; import com.egolm.film.api.service.AdminTokenService;
import com.egolm.film.api.service.ExportService;
import com.egolm.film.api.service.ReviewService; import com.egolm.film.api.service.ReviewService;
import com.egolm.film.bean.Fc_admin; import com.egolm.film.bean.Fc_admin;
import com.egolm.film.bean.Fc_logs_ext; import com.egolm.film.bean.Fc_logs_ext;
...@@ -52,6 +57,9 @@ public class WebUtilController { ...@@ -52,6 +57,9 @@ public class WebUtilController {
@Autowired @Autowired
AdminTokenService tokenService; AdminTokenService tokenService;
@Autowired
ExportService exportService;
@Autowired @Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping; private RequestMappingHandlerMapping requestMappingHandlerMapping;
...@@ -187,7 +195,11 @@ public class WebUtilController { ...@@ -187,7 +195,11 @@ public class WebUtilController {
@Transactional @Transactional
@PostMapping("exportExcel") @PostMapping("exportExcel")
@ApiOperation("导出Excel") @ApiOperation("导出Excel")
public void exportExcel(String db_host, String db_name, String username, String password) throws SQLException, IOException { public void exportExcel(HttpServletResponse response) throws IOException {
this.verifyAuth(); this.verifyAuth();
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("影片列表 [" + DateUtil.format(new Date(), "yyMMdd_HHmmss") + "].xls", "UTF-8"));
exportService.export(response.getOutputStream());
} }
} }
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