You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.FengHuang.Exam.Controller;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.FengHuang.Exam.Model.ExamModel;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.CookieUtil;
import com.dsideal.FengHuang.Util.ExcelCommonUtil;
import com.dsideal.FengHuang.Util.FileUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.io.File;
import java.util.List;
import java.util.UUID;
public class ExamController extends Controller {
//实例化model
ExamModel em = new ExamModel();
/**
* 功能:增加考试人员
*
* @param person_name
* @param ks
* @param tel
*/
@Before({POST.class})
public void addPerson(String person_name, String ks, String tel) {
Kv kv = em.addPerson(person_name, ks, tel);
if (kv.getBoolean("success")) {
CookieUtil.set(getResponse(), "person_id", kv.get("person_id").toString(), false, true);
}
renderJson(kv);
}
/**
* 功能:获取整体信息,比如有几种题型,都是啥,每种题型有几道题
*/
@Before({GET.class})
public void getExamInfo() {
List<Record> list = em.getExamInfo();
renderJson(list);
}
/**
* 功能:获取指定题目的信息
*
* @param order_id
*/
@Before({GET.class})
public void getQuestion(int order_id) {
String person_id = getCookie("person_id");
Record record = em.getQuestion(person_id, order_id);
renderJson(record);
}
/**
* 功能:保存答题结果
*
* @param order_id
* @param reply
*/
@Before({POST.class})
public void save(int order_id, String reply) {
String person_id = getCookie("person_id");
em.save(person_id, order_id, reply);
Kv kv = Kv.by("success", true);
kv.put("message", "保存成功!");
renderJson(kv);
}
/**
* 功能:交卷
*/
@Before({POST.class})
public void jiaoJuan() {
String person_id = getCookie("person_id");
em.jiaoJuan(person_id);
Kv kv = Kv.by("success", true);
kv.put("message", "保存成功!");
renderJson(kv);
}
/**
* 功能:删除考试人员
*
* @param person_id
*/
@Before({POST.class})
public void delPerson(String person_id) {
em.delPerson(person_id);
Kv kv = Kv.by("success", true);
kv.put("message", "删除成功!");
renderJson(kv);
}
/**
* 功能:分页获取人员的答题得分情况
*
* @param page
* @param limit
*/
@Before({GET.class})
public void getPageSummary(int page, int limit) {
Page<Record> list = em.getPageSummary(page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能导出EXCEL
*/
@Before({GET.class})
public void exportExcel() {
Page<Record> list = em.getPageSummary(1, 10000);
//模板文件
String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/");
String filePath = excelPath + "exam.json";
//转成 json对象
JSONObject jo = FileUtil.readJsonFile(filePath);
//导出
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
ExcelCommonUtil.export(list, jo, excelFile);
//提供下载
String filename = "排名结果.xls";
renderFile(new File(excelFile), filename);
}
}