|
|
|
@ -1,53 +1,85 @@
|
|
|
|
|
package com.ibeetl.jlw.web;
|
|
|
|
|
|
|
|
|
|
import cn.jlw.Interceptor.RFile;
|
|
|
|
|
import cn.jlw.Interceptor.SCoreUser;
|
|
|
|
|
import cn.jlw.Interceptor.GetFile;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
|
import cn.jlw.validate.ValidateConfig;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.Function;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.file.FileService;
|
|
|
|
|
import com.ibeetl.admin.core.util.ConvertUtil;
|
|
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
|
|
import com.ibeetl.admin.core.util.TimeTool;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseScoreDashboard;
|
|
|
|
|
import com.ibeetl.jlw.service.TeacherOpenCourseScoreDashboardService;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseScoreDashboardQuery;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import com.ibeetl.admin.console.web.dto.DictExcelImportData;
|
|
|
|
|
import com.ibeetl.admin.console.web.query.UserQuery;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.Function;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.service.*;
|
|
|
|
|
import com.ibeetl.jlw.web.query.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开课成绩看板 教师-我的课程-成绩看板 接口
|
|
|
|
|
* 成绩 教师-我的课程-成绩看板 接口
|
|
|
|
|
* 切记不要对非线程安全的静态变量进行写操作
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
public class TeacherOpenCourseScoreDashboardController {
|
|
|
|
|
|
|
|
|
|
private final Log log = LogFactory.getLog(this.getClass());
|
|
|
|
|
private static final String MODEL = "/jlw/teacherOpenCourseScoreDashboard";
|
|
|
|
|
private static final String API = "/api/teacherOpenCourseScoreDashboard";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource private TeacherOpenCourseScoreDashboardService teacherOpenCourseScoreDashboardService;
|
|
|
|
|
@Resource
|
|
|
|
|
private TeacherOpenCourseScoreDashboardService teacherOpenCourseScoreDashboardService;
|
|
|
|
|
|
|
|
|
|
@Resource FileService fileService;
|
|
|
|
|
@Resource
|
|
|
|
|
FileService fileService;
|
|
|
|
|
|
|
|
|
|
/* 前端接口 */
|
|
|
|
|
|
|
|
|
|
@PostMapping(API + "/getPageList.do")
|
|
|
|
|
public JsonResult<PageQuery> getPageList(TeacherOpenCourseScoreDashboardQuery condition,@SCoreUser CoreUser coreUser){
|
|
|
|
|
if(null == coreUser){
|
|
|
|
|
public JsonResult<PageQuery> getPageList(TeacherOpenCourseScoreDashboardQuery condition, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
PageQuery page = condition.getPageQuery();
|
|
|
|
|
teacherOpenCourseScoreDashboardService.queryByConditionQuery(page);
|
|
|
|
|
return JsonResult.success(page);
|
|
|
|
@ -56,23 +88,23 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(API + "/getInfo.do")
|
|
|
|
|
public JsonResult<TeacherOpenCourseScoreDashboard>getInfo(TeacherOpenCourseScoreDashboardQuery param,@SCoreUser CoreUser coreUser) {
|
|
|
|
|
if(null == coreUser){
|
|
|
|
|
public JsonResult<TeacherOpenCourseScoreDashboard> getInfo(TeacherOpenCourseScoreDashboardQuery param, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
TeacherOpenCourseScoreDashboard teacherOpenCourseScoreDashboard = teacherOpenCourseScoreDashboardService.getInfo(param);
|
|
|
|
|
return JsonResult.success(teacherOpenCourseScoreDashboard);
|
|
|
|
|
return JsonResult.success(teacherOpenCourseScoreDashboard);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(API + "/getList.do")
|
|
|
|
|
public JsonResult<List<TeacherOpenCourseScoreDashboard>>getList(TeacherOpenCourseScoreDashboardQuery param,@SCoreUser CoreUser coreUser) {
|
|
|
|
|
if(null == coreUser){
|
|
|
|
|
public JsonResult<List<TeacherOpenCourseScoreDashboard>> getList(TeacherOpenCourseScoreDashboardQuery param, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
|
}else{
|
|
|
|
|
List<TeacherOpenCourseScoreDashboard>list = teacherOpenCourseScoreDashboardService.getValuesByQuery(param);
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
} else {
|
|
|
|
|
List<TeacherOpenCourseScoreDashboard> list = teacherOpenCourseScoreDashboardService.getValuesByQuery(param);
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -82,7 +114,7 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
@GetMapping(MODEL + "/index.do")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.query")
|
|
|
|
|
public ModelAndView index() {
|
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/teacherOpenCourseScoreDashboard/index.html") ;
|
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/teacherOpenCourseScoreDashboard/index.html");
|
|
|
|
|
view.addObject("search", TeacherOpenCourseScoreDashboardQuery.class.getName());
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
@ -100,10 +132,10 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.add")
|
|
|
|
|
public ModelAndView add(Long teacherOpenCourseScoreDashboardId) {
|
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/teacherOpenCourseScoreDashboard/add.html");
|
|
|
|
|
if(null != teacherOpenCourseScoreDashboardId){
|
|
|
|
|
if (null != teacherOpenCourseScoreDashboardId) {
|
|
|
|
|
TeacherOpenCourseScoreDashboard teacherOpenCourseScoreDashboard = teacherOpenCourseScoreDashboardService.queryById(teacherOpenCourseScoreDashboardId);
|
|
|
|
|
view.addObject("teacherOpenCourseScoreDashboard", teacherOpenCourseScoreDashboard);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
view.addObject("teacherOpenCourseScoreDashboard", new TeacherOpenCourseScoreDashboard());
|
|
|
|
|
}
|
|
|
|
|
return view;
|
|
|
|
@ -113,7 +145,7 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
|
|
|
|
|
@PostMapping(MODEL + "/list.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.query")
|
|
|
|
|
public JsonResult<PageQuery> list(TeacherOpenCourseScoreDashboardQuery condition){
|
|
|
|
|
public JsonResult<PageQuery> list(TeacherOpenCourseScoreDashboardQuery condition) {
|
|
|
|
|
PageQuery page = condition.getPageQuery();
|
|
|
|
|
teacherOpenCourseScoreDashboardService.queryByCondition(page);
|
|
|
|
|
return JsonResult.success(page);
|
|
|
|
@ -121,29 +153,29 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
|
|
|
|
|
@PostMapping(MODEL + "/addAll.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.add")
|
|
|
|
|
public JsonResult addAll(TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery,@SCoreUser CoreUser coreUser){
|
|
|
|
|
if(null == coreUser){
|
|
|
|
|
public JsonResult addAll(TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
|
}else{
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(coreUser.getId());
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(coreUser.getOrgId());
|
|
|
|
|
} else {
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(coreUser.getId());
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(coreUser.getOrgId());
|
|
|
|
|
String msg = teacherOpenCourseScoreDashboardService.addAll(teacherOpenCourseScoreDashboardQuery);
|
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
} else {
|
|
|
|
|
return JsonResult.failMessage("新增失败,"+msg);
|
|
|
|
|
return JsonResult.failMessage("新增失败," + msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(MODEL + "/add.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.add")
|
|
|
|
|
public JsonResult add(@Validated(ValidateConfig.ADD.class) TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, BindingResult result,@SCoreUser CoreUser coreUser){
|
|
|
|
|
if(result.hasErrors()){
|
|
|
|
|
public JsonResult add(@Validated(ValidateConfig.ADD.class) TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, BindingResult result, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (result.hasErrors()) {
|
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
|
}else{
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(coreUser.getId());
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(coreUser.getOrgId());
|
|
|
|
|
} else {
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(coreUser.getId());
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(coreUser.getOrgId());
|
|
|
|
|
return teacherOpenCourseScoreDashboardService.add(teacherOpenCourseScoreDashboardQuery);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -151,16 +183,16 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
@PostMapping(MODEL + "/edit.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.edit")
|
|
|
|
|
public JsonResult<String> update(@Validated(ValidateConfig.UPDATE.class) TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, BindingResult result) {
|
|
|
|
|
if(result.hasErrors()){
|
|
|
|
|
if (result.hasErrors()) {
|
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
|
}else {
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(null);
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(null);
|
|
|
|
|
} else {
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setUserId(null);
|
|
|
|
|
teacherOpenCourseScoreDashboardQuery.setOrgId(null);
|
|
|
|
|
String msg = teacherOpenCourseScoreDashboardService.edit(teacherOpenCourseScoreDashboardQuery);
|
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
} else {
|
|
|
|
|
return JsonResult.failMessage("更新失败,"+msg);
|
|
|
|
|
return JsonResult.failMessage("更新失败," + msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -168,16 +200,16 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
|
|
|
|
|
@GetMapping(MODEL + "/view.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.query")
|
|
|
|
|
public JsonResult<TeacherOpenCourseScoreDashboard>queryInfo(Long teacherOpenCourseScoreDashboardId) {
|
|
|
|
|
TeacherOpenCourseScoreDashboard teacherOpenCourseScoreDashboard = teacherOpenCourseScoreDashboardService.queryById( teacherOpenCourseScoreDashboardId);
|
|
|
|
|
return JsonResult.success(teacherOpenCourseScoreDashboard);
|
|
|
|
|
public JsonResult<TeacherOpenCourseScoreDashboard> queryInfo(Long teacherOpenCourseScoreDashboardId) {
|
|
|
|
|
TeacherOpenCourseScoreDashboard teacherOpenCourseScoreDashboard = teacherOpenCourseScoreDashboardService.queryById(teacherOpenCourseScoreDashboardId);
|
|
|
|
|
return JsonResult.success(teacherOpenCourseScoreDashboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(MODEL + "/getValues.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.query")
|
|
|
|
|
public JsonResult<List<TeacherOpenCourseScoreDashboard>>getValues(TeacherOpenCourseScoreDashboardQuery param) {
|
|
|
|
|
List<TeacherOpenCourseScoreDashboard>list = teacherOpenCourseScoreDashboardService.getValuesByQuery(param);
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
public JsonResult<List<TeacherOpenCourseScoreDashboard>> getValues(TeacherOpenCourseScoreDashboardQuery param) {
|
|
|
|
|
List<TeacherOpenCourseScoreDashboard> list = teacherOpenCourseScoreDashboardService.getValuesByQuery(param);
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -190,4 +222,210 @@ public class TeacherOpenCourseScoreDashboardController{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下载模板信息
|
|
|
|
|
@GetMapping(MODEL + "/downloadTemplate.json")
|
|
|
|
|
public void download(HttpServletRequest request, HttpServletResponse response, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
try {
|
|
|
|
|
//TODO 改导入模板名字
|
|
|
|
|
is = new FileInputStream(GetFile.p + File.separator + "filesystem" + File.separator + "template" + File.separator + "导入模板.xlsx");
|
|
|
|
|
|
|
|
|
|
workbook = new XSSFWorkbook(is);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (null != is) {
|
|
|
|
|
is.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
|
//八进制输出流
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为template.xls
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename=competitionTeacher(" + TimeTool.getNowTime("YMD") + ").xls");
|
|
|
|
|
|
|
|
|
|
//刷新缓冲
|
|
|
|
|
response.flushBuffer();
|
|
|
|
|
|
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (null != workbook) {
|
|
|
|
|
workbook.close();
|
|
|
|
|
}
|
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
|
response.getOutputStream().close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//导入模板信息
|
|
|
|
|
@PostMapping(MODEL + "/importTemplate.json")
|
|
|
|
|
@Function("teacherOpenCourseScoreDashboard.importTemplate")
|
|
|
|
|
public JsonResult importTemplate(@RFile List<FileEntity> fileEntityList, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
|
}
|
|
|
|
|
List<Long> list = new ArrayList<>();
|
|
|
|
|
JsonResult jsonResult = teacherOpenCourseScoreDashboardService.importTemplate(fileEntityList, list, coreUser);
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
teacherOpenCourseScoreDashboardService.deleteByList(list);
|
|
|
|
|
}
|
|
|
|
|
return jsonResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//导出信息
|
|
|
|
|
@RequestMapping(MODEL + "/excel/export.json")
|
|
|
|
|
public void export(HttpServletRequest request, HttpServletResponse response, TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, @SCoreUser CoreUser coreUser) {
|
|
|
|
|
if (null == coreUser) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
HSSFWorkbook workbook = null;
|
|
|
|
|
try {
|
|
|
|
|
//表头数据
|
|
|
|
|
String[] header = {
|
|
|
|
|
"学生",
|
|
|
|
|
"签到成绩",
|
|
|
|
|
"章节练习成绩",
|
|
|
|
|
"课程实操成绩",
|
|
|
|
|
"作业成绩",
|
|
|
|
|
"考试成绩",
|
|
|
|
|
"互动成绩",
|
|
|
|
|
"总成绩",
|
|
|
|
|
"手动调整的分数",
|
|
|
|
|
"最终成绩",
|
|
|
|
|
"成绩状态",
|
|
|
|
|
"创建时间"
|
|
|
|
|
};
|
|
|
|
|
String[] headerCode = {
|
|
|
|
|
"studentId",
|
|
|
|
|
"signinScore",
|
|
|
|
|
"courseScore",
|
|
|
|
|
"realOperationScore",
|
|
|
|
|
"questionHomeworkScore",
|
|
|
|
|
"examScore",
|
|
|
|
|
"chatScore",
|
|
|
|
|
"totalScore",
|
|
|
|
|
"manualScore",
|
|
|
|
|
"lastScore",
|
|
|
|
|
"lastStatus",
|
|
|
|
|
"createTime"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//数据内容
|
|
|
|
|
List<Map<String, Object>> mapList = teacherOpenCourseScoreDashboardService.getExcelValues(teacherOpenCourseScoreDashboardQuery);
|
|
|
|
|
|
|
|
|
|
//内容宽度
|
|
|
|
|
Map<String, Object> widthMap = mapList.get(0);
|
|
|
|
|
mapList.remove(0);
|
|
|
|
|
|
|
|
|
|
//声明一个工作簿
|
|
|
|
|
workbook = new HSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
//生成一个表格,设置表格名称为"Sheet1"
|
|
|
|
|
HSSFSheet sheet = workbook.createSheet("Sheet1");
|
|
|
|
|
|
|
|
|
|
//冻结表头
|
|
|
|
|
sheet.createFreezePane(0, 1, 0, 1);
|
|
|
|
|
|
|
|
|
|
//设置默认列宽度为5个字节
|
|
|
|
|
sheet.setDefaultColumnWidth(5);
|
|
|
|
|
|
|
|
|
|
//创建第一行表头
|
|
|
|
|
HSSFRow headRow = sheet.createRow(0);
|
|
|
|
|
|
|
|
|
|
//头部样式
|
|
|
|
|
HSSFCellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
|
//垂直居中
|
|
|
|
|
headerStyle.setVerticalAlignment(headerStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
|
//水平居中
|
|
|
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
|
|
|
|
|
//单元格样式
|
|
|
|
|
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
|
//垂直居中
|
|
|
|
|
cellStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
|
//水平居左
|
|
|
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
//自动换行
|
|
|
|
|
cellStyle.setWrapText(true);
|
|
|
|
|
|
|
|
|
|
//遍历添加表头
|
|
|
|
|
for (int i = 0; i < header.length; i++) {
|
|
|
|
|
|
|
|
|
|
//设置表格特定的列宽度
|
|
|
|
|
if (null != widthMap.get(headerCode[i])) {
|
|
|
|
|
String width = widthMap.get(headerCode[i]).toString().split("\\.")[0];
|
|
|
|
|
Integer w = Integer.parseInt(width) > header[i].length() * 3 ? Integer.parseInt(width) : header[i].length() * 3;
|
|
|
|
|
sheet.setColumnWidth(i, w * 190);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建一个单元格
|
|
|
|
|
HSSFCell cell = headRow.createCell(i);
|
|
|
|
|
|
|
|
|
|
//创建一个内容对象
|
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(header[i]);
|
|
|
|
|
|
|
|
|
|
//将内容对象的文字内容写入到单元格中
|
|
|
|
|
cell.setCellValue(text);
|
|
|
|
|
|
|
|
|
|
//设置样式
|
|
|
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//遍历结果集,把内容加入表格
|
|
|
|
|
for (int i = 0; i < mapList.size(); i++) {
|
|
|
|
|
HSSFRow row = sheet.createRow(i + 1);
|
|
|
|
|
|
|
|
|
|
row.setHeight((short) (50 * 10));
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = mapList.get(i);
|
|
|
|
|
for (int j = 0; j < headerCode.length; j++) {
|
|
|
|
|
HSSFCell cell = row.createCell(j);
|
|
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(null != map.get(headerCode[j]) ? map.get(headerCode[j]).toString() : " ");
|
|
|
|
|
cell.setCellValue(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
|
//八进制输出流
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为student.xls
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename=competitionTeacher(" + TimeTool.getNowTime("YMD") + ").xls");
|
|
|
|
|
|
|
|
|
|
//刷新缓冲
|
|
|
|
|
response.flushBuffer();
|
|
|
|
|
|
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (null != workbook) {
|
|
|
|
|
workbook.close();
|
|
|
|
|
}
|
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
|
response.getOutputStream().close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|