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.

219 lines
6.9 KiB

2 years ago
package com.dsideal.FengHuang.Exam.Controller;
2 years ago
import com.alibaba.fastjson.JSONObject;
2 years ago
import com.dsideal.FengHuang.Exam.Model.ExamModel;
2 years ago
import com.dsideal.FengHuang.Interceptor.EmptyInterface;
2 years ago
import com.dsideal.FengHuang.Interceptor.IsNumericInterface;
2 years ago
import com.dsideal.FengHuang.Util.CommonUtil;
2 years ago
import com.dsideal.FengHuang.Util.CookieUtil;
2 years ago
import com.dsideal.FengHuang.Util.ExcelCommonUtil;
import com.dsideal.FengHuang.Util.FileUtil;
2 years ago
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
2 years ago
import com.jfinal.ext.interceptor.GET;
2 years ago
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
2 years ago
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
2 years ago
import com.jfinal.plugin.activerecord.Page;
2 years ago
import com.jfinal.plugin.activerecord.Record;
2 years ago
import java.io.File;
2 years ago
import java.util.List;
2 years ago
import java.util.UUID;
2 years ago
public class ExamController extends Controller {
//实例化model
ExamModel em = new ExamModel();
/**
*
2 years ago
*
2 years ago
* @param person_name
* @param ks
* @param tel
*/
@Before({POST.class})
2 years ago
@EmptyInterface({"person_name","ks","tel"})
2 years ago
public void addPerson(String person_name, String ks, String tel) {
2 years ago
Kv kv = em.addPerson(person_name, ks, tel);
if (kv.getBoolean("success")) {
CookieUtil.set(getResponse(), "person_id", kv.get("person_id").toString(), false, true);
2 years ago
}
renderJson(kv);
}
2 years ago
/**
*
*/
@Before({GET.class})
public void getExamInfo() {
List<Record> list = em.getExamInfo();
2 years ago
Kv kv = Kv.create();
kv.set("list", list);
int allCount = 0;
for (Record record : list) {
allCount += record.getInt("count");
}
kv.set("allCount", allCount);
renderJson(kv);
2 years ago
}
2 years ago
/**
*
*/
@Before({GET.class})
public void getRemainSecond() {
String person_id = getCookie("person_id");
long remainSecond = em.getRemainSecond(person_id);
Kv kv = Kv.by("success", true);
kv.set("remainSecond", remainSecond);
renderJson(kv);
}
2 years ago
/**
*
2 years ago
*
2 years ago
* @param order_id
*/
@Before({GET.class})
2 years ago
@IsNumericInterface({"order_id","finish"})
2 years ago
public void getQuestion(int order_id, int finish) {
2 years ago
String person_id = getCookie("person_id");
2 years ago
if (finish == 1 && em.HaveJiaoJuan(person_id) <= 0) {
Kv kv = Kv.by("success", false);
kv.set("message", "你还没有交卷,不能使用此接口!");
renderJson(kv);
return;
}
Record record = em.getQuestion(person_id, order_id, finish);
2 years ago
renderJson(record);
}
/**
*
*
* @param order_id
* @param reply
*/
@Before({POST.class})
2 years ago
@EmptyInterface({"reply"})
@IsNumericInterface({"order_id"})
2 years ago
public void save(int order_id, String reply) {
String person_id = getCookie("person_id");
2 years ago
int result = em.save(person_id, order_id, reply);
2 years ago
if (result == -1) {
2 years ago
Kv kv = Kv.by("success", false);
kv.put("message", "交卷后不能再保存数据!");
renderJson(kv);
} else {
Kv kv = Kv.by("success", true);
kv.put("message", "保存成功!");
renderJson(kv);
}
2 years ago
}
/**
*
*/
@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);
}
2 years ago
/**
* ,
* reply null
*/
@Before({GET.class})
public void getPersonAllInfo() {
String person_id = getCookie("person_id");
List<Record> list = em.getPersonAllInfo(person_id);
renderJson(list);
}
2 years ago
/**
* ,
*/
@Before({GET.class})
public void getPersonUnFinishCount() {
String person_id = getCookie("person_id");
int count = em.getPersonUnFinishCount(person_id);
Kv kv = Kv.create();
kv.set("success", true);
kv.set("count", count);
renderJson(kv);
}
2 years ago
/**
* ,()
*/
@Before({GET.class})
public void getPersonAllInfoAfterJiaoJuan() {
String person_id = getCookie("person_id");
2 years ago
if (em.HaveJiaoJuan(person_id) <= 0) {
Kv kv = Kv.by("success", false);
kv.set("message", "你还没有交卷,不能使用此接口!");
renderJson(kv);
return;
}
2 years ago
Kv kv = em.getPersonAllInfoAfterJiaoJuan(person_id);
renderJson(kv);
2 years ago
}
/********************************上面为答题人员的接口************************************/
/********************************下面为管理人员的接口************************************/
2 years ago
/**
*
*
* @param person_id
*/
@Before({POST.class})
2 years ago
@EmptyInterface({"person_id"})
2 years ago
public void delPerson(String person_id) {
em.delPerson(person_id);
Kv kv = Kv.by("success", true);
kv.put("message", "删除成功!");
renderJson(kv);
}
2 years ago
/**
*
*
* @param page
* @param limit
*/
@Before({GET.class})
2 years ago
@IsNumericInterface({"page", "limit"})
2 years ago
public void getPageSummary(int page, int limit) {
2 years ago
Page<Record> list = em.getPageSummary(page, limit);
2 years ago
renderJson(CommonUtil.renderJsonForLayUI(list));
}
2 years ago
/**
* 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";
2 years ago
ExcelCommonUtil.export(list, jo, excelFile,null,"名次");
2 years ago
//提供下载
String filename = "排名结果.xls";
renderFile(new File(excelFile), filename);
}
2 years ago
}