kgdxpr 2 years ago
commit 76c6e6943e

@ -2,6 +2,7 @@ package com.dsideal.FengHuang.Exam.Controller;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.FengHuang.Exam.Model.ExamModel;
import com.dsideal.FengHuang.Interceptor.IsNumericInterface;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.CookieUtil;
import com.dsideal.FengHuang.Util.ExcelCommonUtil;
@ -185,6 +186,7 @@ public class ExamController extends Controller {
* @param limit
*/
@Before({GET.class})
@IsNumericInterface({"page", "limit"})
public void getPageSummary(int page, int limit) {
Page<Record> list = em.getPageSummary(page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
@ -203,7 +205,7 @@ public class ExamController extends Controller {
JSONObject jo = FileUtil.readJsonFile(filePath);
//导出
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
ExcelCommonUtil.export(list, jo, excelFile);
ExcelCommonUtil.export(list, jo, excelFile,null,"名次");
//提供下载
String filename = "排名结果.xls";
renderFile(new File(excelFile), filename);

@ -203,6 +203,17 @@ public class ExamModel {
public Page<Record> getPageSummary(int page, int limit) {
SqlPara sqlPara = Db.getSqlPara("Exam.getPageSummary");
Page<Record> pageRecord = Db.paginate(page, limit, sqlPara);
//1、扩展排名序号
for (int i = 0; i < pageRecord.getList().size(); i++) {
Record record = pageRecord.getList().get(i);
record.set("num", (page - 1) * limit + i + 1);
LocalDateTime st=record.getLocalDateTime("start_time");
LocalDateTime ed=record.getLocalDateTime("end_time");
//2、扩展答题时长
record.set("ys",getYs(st,ed));
record.set("start_time",st.toLocalDate()+" "+st.toLocalTime());
record.set("end_time",st.toLocalDate()+" "+st.toLocalTime());
}
return pageRecord;
}
@ -250,24 +261,24 @@ public class ExamModel {
LocalDateTime end_time = r.getLocalDateTime("end_time");
res.set("start_time", start_time);
res.set("end_time", end_time);
res.set("ys", getYs(start_time, end_time));
return res;
}
public String getYs(LocalDateTime start_time, LocalDateTime end_time) {
// 计算时间差
Duration duration = Duration.between(start_time, end_time);
long seconds = duration.getSeconds(); // 获取时间差秒数
long hour = seconds / 3600;
long minute = (seconds - hour * 3600) / 60;
long second = seconds - hour * 3600 - minute * 60;
res.set("hour", hour);
res.set("minute", minute);
res.set("second", second);
String ys = "";
if (hour > 0) ys += hour + "小时";
if (hour == 0 && minute > 0) ys += minute + "分钟";
if (hour > 0) ys += minute + "分钟";
if (second > 0) ys += second + "秒";
res.set("ys", ys);
return res;
return ys;
}
/**

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
@ -53,7 +54,7 @@ public class ExcelCommonUtil {
export(page, jo, fileName, null);
}
public static void export(Page<?> page, JSONObject jo, String fileName, List<Integer> hiddenColumns) {
public static void export(Page<?> page, JSONObject jo, String fileName, List<Integer> hiddenColumns, String column_name) {
//标题
String title = jo.getString("title");
@ -71,7 +72,8 @@ public class ExcelCommonUtil {
JSONArray colInfo = jo.getJSONArray("colInfo");
if (showNumber != null) {
JSONObject addjo = new JSONObject();
addjo.put("show_column_name", "序号");
if (StrKit.isBlank(column_name)) addjo.put("show_column_name", "序号");
else addjo.put("show_column_name", column_name);
addjo.put("list_column_name", "Number");
addjo.put("width", 20);
colInfo.add(0, addjo);
@ -214,6 +216,11 @@ public class ExcelCommonUtil {
} catch (IOException e) {
e.printStackTrace();
}
}
public static void export(Page<?> page, JSONObject jo, String fileName, List<Integer> hiddenColumns) {
export(page, jo, fileName, hiddenColumns, "");
}
/**
@ -849,7 +856,7 @@ public class ExcelCommonUtil {
* @param fileLists excel
* @param fileName
*/
public static void mergeExcel(List<String> fileLists, String fileName,int whiceRowGetColWidth) {
public static void mergeExcel(List<String> fileLists, String fileName, int whiceRowGetColWidth) {
// 创建新的excel工作簿
XSSFWorkbook book = new XSSFWorkbook();
// 遍历需要合并的excel文件
@ -863,7 +870,7 @@ public class ExcelCommonUtil {
XSSFSheet tmpSheet = tmpWorkBook.getSheetAt(i);
XSSFSheet newExcelSheet = book.createSheet(tmpSheet.getSheetName());
// 复制sheet内容
copyExcelSheet(book, tmpSheet, newExcelSheet,whiceRowGetColWidth);
copyExcelSheet(book, tmpSheet, newExcelSheet, whiceRowGetColWidth);
}
// 关闭tmpWorkBook工作簿
tmpWorkBook.close();

@ -25,5 +25,11 @@
"list_column_name": "end_time",
"width": 40
}
,
{
"show_column_name": "用时",
"list_column_name": "ys",
"width": 40
}
]
}

@ -2,7 +2,7 @@
#sql("getPageSummary")
select t1.person_id,t2.person_name,sum(t1.score) as score,t2.start_time,t2.end_time from t_exam_record as t1
inner join t_exam_person as t2 on t1.person_id=t2.person_id
where t1.reply=t1.answer
where t1.reply=t1.answer and t2.end_time is not null
group by t1.person_id,t2.person_name order by sum(t1.score) desc,timediff(t2.end_time,t2.start_time) asc
#end

@ -25,5 +25,11 @@
"list_column_name": "end_time",
"width": 40
}
,
{
"show_column_name": "用时",
"list_column_name": "ys",
"width": 40
}
]
}

@ -2,7 +2,7 @@
#sql("getPageSummary")
select t1.person_id,t2.person_name,sum(t1.score) as score,t2.start_time,t2.end_time from t_exam_record as t1
inner join t_exam_person as t2 on t1.person_id=t2.person_id
where t1.reply=t1.answer
where t1.reply=t1.answer and t2.end_time is not null
group by t1.person_id,t2.person_name order by sum(t1.score) desc,timediff(t2.end_time,t2.start_time) asc
#end

Loading…
Cancel
Save