diff --git a/src/main/java/com/dsideal/FengHuang/Yp/Controller/YpController.java b/src/main/java/com/dsideal/FengHuang/Yp/Controller/YpController.java index 844250b..9aebc76 100644 --- a/src/main/java/com/dsideal/FengHuang/Yp/Controller/YpController.java +++ b/src/main/java/com/dsideal/FengHuang/Yp/Controller/YpController.java @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject; import com.dsideal.FengHuang.Interceptor.*; import com.dsideal.FengHuang.LoginPerson.Model.LoginPersonModel; import com.dsideal.FengHuang.Util.CommonUtil; +import com.dsideal.FengHuang.Util.ExcelExportUtil; +import com.dsideal.FengHuang.Util.FileUtil; import com.dsideal.FengHuang.Util.IpUtil; import com.dsideal.FengHuang.Yp.Model.YpModel; import com.jfinal.aop.Before; @@ -11,10 +13,14 @@ 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 YpController extends Controller { YpModel model = new YpModel(); @@ -125,4 +131,67 @@ public class YpController extends Controller { kv.set("bx_id", bx_id); renderJson(kv); } + + /** + * 功能:保存申报结果 + * + * @param task_id + * @param name + * @param xb + * @param bx_id + * @param address + * @param father_name + * @param mother_name + * @param sfzh + * @param tel + */ + @Before(POST.class) + @EmptyInterface({"sfzh"}) + public void save(int task_id, String name, String xb, int bx_id, String address, String father_name, String mother_name, String sfzh, String tel) { + int result = model.save(task_id, name, xb, bx_id, address, father_name, mother_name, sfzh, tel); + + Kv kv = Kv.by("success", result); + if (result == 1) kv.set("message", "获取成功!"); + if (result == 2) kv.set("message", "此身份证号已申请过,不能重复申请!"); + if (result == 3) kv.set("message", "指定班型人数已达上限,不能申请!"); + renderJson(kv); + } + + /** + * 功能:查看指定任务的结果 + * + * @param task_id + * @param bx_id + * @param page + * @param limit + */ + @Before(GET.class) + @IsNumericInterface({"task_id", "page", "limit"}) + public void getTaskInfo(int task_id, int bx_id, int page, int limit) { + Page list = model.getTaskInfo(task_id, bx_id, page, limit); + renderJson(CommonUtil.renderJsonForLayUI(list)); + } + + /** + * 功能:导出excel + * + * @param task_id + * @param bx_id + */ + @Before(GET.class) + @IsNumericInterface({"task_id", "page", "limit"}) + public void exportExcel(int task_id, int bx_id) { + //模板文件 + String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/"); + String filePath = excelPath + "YangPuZhaoShengExcel.json"; + //转成 json对象 + JSONObject jo = FileUtil.readJsonFile(filePath); + //导出 + Page rs = model.getTaskInfo(task_id, bx_id, 1, 99999); + String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls"; + ExcelExportUtil.export(rs, jo, excelFile); + //提供下载 + String filename = "招生.xls"; + renderFile(new File(excelFile), filename); + } } \ No newline at end of file diff --git a/src/main/java/com/dsideal/FengHuang/Yp/Model/YpModel.java b/src/main/java/com/dsideal/FengHuang/Yp/Model/YpModel.java index 81eb431..ee878db 100644 --- a/src/main/java/com/dsideal/FengHuang/Yp/Model/YpModel.java +++ b/src/main/java/com/dsideal/FengHuang/Yp/Model/YpModel.java @@ -3,8 +3,11 @@ package com.dsideal.FengHuang.Yp.Model; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdcardUtil; +import com.jfinal.kit.Kv; import com.jfinal.plugin.activerecord.Db; +import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; +import com.jfinal.plugin.activerecord.SqlPara; import java.util.Calendar; import java.util.List; @@ -115,4 +118,59 @@ public class YpModel { } return result;//如果result=-2表示不在指定的时间段内 } + + /** + * 功能:保存申报结果 + * + * @param task_id + * @param name + * @param xb + * @param bx_id + * @param address + * @param father_name + * @param mother_name + * @param sfzh + * @param tel + */ + public int save(int task_id, String name, String xb, int bx_id, String address, String father_name, String mother_name, String sfzh, String tel) { + //1、检查身份证号是不是已存在 + String sql = "select count(1) as count from t_yp_record where sfzh=?"; + int count = Db.findFirst(sql, sfzh).getInt("count"); + if (count > 0) return 2; + //2、是不是指定班型已招满 + sql = "select count(1) as count from t_yp_record where task_id=? and bx_id=?"; + count = Db.findFirst(sql, task_id, bx_id).getInt("count"); + //可以招多少人? + sql = "select * from t_yp_task_bx_limit where task_id=? and bx_id=?"; + int limit_count = Db.findFirst(sql, task_id, bx_id).getInt("limit"); + if (count >= limit_count) return 3; + + //3、保存 + Record record = new Record(); + record.set("task_id", task_id); + record.set("name", name); + record.set("xb", xb); + record.set("bx_id", bx_id); + record.set("address", address); + record.set("father_name", father_name); + record.set("mother_name", mother_name); + record.set("sfzh", sfzh); + record.set("tel", tel); + Db.save("t_yp_record", "id", record); + return 1; + } + /** + * 功能:查看指定任务的结果 + * @param task_id + * @param bx_id + * @param page + * @param limit + */ + public Page getTaskInfo(int task_id,int bx_id, int page, int limit){ + Kv kv = Kv.by("task_id", task_id); + kv.set("bx_id",bx_id); + SqlPara sqlPara = Db.getSqlPara("yp.getTaskInfo", kv); + Page pageRecord = Db.paginate(page, limit, sqlPara); + return pageRecord; + } } \ No newline at end of file diff --git a/src/main/resource/ExcelExportTemplate/YangPuZhaoShengExcel.json b/src/main/resource/ExcelExportTemplate/YangPuZhaoShengExcel.json new file mode 100644 index 0000000..b0b4960 --- /dev/null +++ b/src/main/resource/ExcelExportTemplate/YangPuZhaoShengExcel.json @@ -0,0 +1,49 @@ +{ + "title": "招生结果", + "sheetName": "结果", + "titleHeight": 30, + "rowHeight": 30, + "showNumber": true, + "colInfo": [ + { + "show_column_name": "姓名", + "list_column_name": "name", + "width": 40 + }, + { + "show_column_name": "性别", + "list_column_name": "xb", + "width": 20 + }, + { + "show_column_name": "家庭住址", + "list_column_name": "address", + "width": 50 + }, + { + "show_column_name": "父亲姓名", + "list_column_name": "address", + "width": 40 + }, + { + "show_column_name": "母亲姓名", + "list_column_name": "address", + "width": 40 + }, + { + "show_column_name": "身份证号", + "list_column_name": "sfzh", + "width": 40 + }, + { + "show_column_name": "联系电话", + "list_column_name": "tel", + "width": 40 + }, + { + "show_column_name": "申报时间", + "list_column_name": "create_time", + "width": 40 + } + ] +} \ No newline at end of file diff --git a/src/main/resource/Sql/yp.sql b/src/main/resource/Sql/yp.sql new file mode 100644 index 0000000..9fa9bfc --- /dev/null +++ b/src/main/resource/Sql/yp.sql @@ -0,0 +1,7 @@ +-- 应用接入命名空间 +#namespace("yp") + #sql("getTaskInfo") + select * from t_yp_record where task_id=#para(task_id) and bx_id=#para(bx_id) + #end + +#end \ No newline at end of file diff --git a/target/classes/Sql/yp.sql b/target/classes/Sql/yp.sql new file mode 100644 index 0000000..9fa9bfc --- /dev/null +++ b/target/classes/Sql/yp.sql @@ -0,0 +1,7 @@ +-- 应用接入命名空间 +#namespace("yp") + #sql("getTaskInfo") + select * from t_yp_record where task_id=#para(task_id) and bx_id=#para(bx_id) + #end + +#end \ No newline at end of file