|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:查看自己答卷的整体情况,哪个题目答了,哪个题目没有答
|
|
|
* reply为 null或空串表示未答题
|
|
|
*/
|
|
|
@Before({GET.class})
|
|
|
public void getPersonAllInfo() {
|
|
|
String person_id = getCookie("person_id");
|
|
|
List<Record> list = em.getPersonAllInfo(person_id);
|
|
|
renderJson(list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取指定题目的信息(交卷后可见)
|
|
|
*
|
|
|
* @param order_id
|
|
|
*/
|
|
|
@Before({GET.class})
|
|
|
public void getQuestionAfterJiaoJuan(int order_id) {
|
|
|
String person_id = getCookie("person_id");
|
|
|
Record record = em.getQuestionAfterJiaoJuan(person_id, order_id);
|
|
|
renderJson(record);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:查看自己答卷的整体情况,哪个题目答了,哪个题目没有答(交卷后可见)
|
|
|
answer = reply 正确
|
|
|
answer ≠ reply 错误
|
|
|
reply is null || reply == '' 未作答
|
|
|
*/
|
|
|
@Before({GET.class})
|
|
|
public void getPersonAllInfoAfterJiaoJuan() {
|
|
|
String person_id = getCookie("person_id");
|
|
|
List<Record> list = em.getPersonAllInfoAfterJiaoJuan(person_id);
|
|
|
renderJson(list);
|
|
|
}
|
|
|
|
|
|
/********************************上面为答题人员的接口************************************/
|
|
|
|
|
|
|
|
|
/********************************下面为管理人员的接口************************************/
|
|
|
/**
|
|
|
* 功能:删除考试人员
|
|
|
*
|
|
|
* @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);
|
|
|
}
|
|
|
} |