|
|
|
|
package com.dsideal.FengHuang.Yp.Controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.FengHuang.Interceptor.EmptyInterface;
|
|
|
|
|
import com.dsideal.FengHuang.Interceptor.IsNumericInterface;
|
|
|
|
|
import com.dsideal.FengHuang.Util.Base64Util;
|
|
|
|
|
import com.dsideal.FengHuang.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.FengHuang.Util.ExcelExportUtil;
|
|
|
|
|
import com.dsideal.FengHuang.Util.FileUtil;
|
|
|
|
|
import com.dsideal.FengHuang.Yp.Model.YpModel;
|
|
|
|
|
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 com.jfinal.upload.UploadFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class YpController extends Controller {
|
|
|
|
|
YpModel model = new YpModel();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取当前任务名称
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/getCurrentTaskInfo
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
public void getCurrentTaskInfo() {
|
|
|
|
|
List<Record> list = model.getCurrentTaskInfo();
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
renderJson(list.get(0));
|
|
|
|
|
} else {
|
|
|
|
|
Kv kv = Kv.by("task_id", 0);
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务的开启班型及人数限制
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/getTaskLimit?task_id=1
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void getTaskLimit(int task_id) {
|
|
|
|
|
List<Record> list = model.getTaskLimit(task_id);
|
|
|
|
|
renderJson(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:任务列表
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/listTask
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"page", "limit"})
|
|
|
|
|
public void listTask(int page, int limit) {
|
|
|
|
|
Page<Record> list = model.listTask(page, limit);
|
|
|
|
|
renderJson(CommonUtil.renderJsonForLayUI(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:增加任务
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@EmptyInterface({"task_name", "bx_ids", "limits"})
|
|
|
|
|
public void addTask(String task_name, String bx_ids, String limits) {
|
|
|
|
|
model.addTask(task_name, bx_ids, limits);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:修改任务
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
@EmptyInterface({"task_name"})
|
|
|
|
|
public void updateTask(int task_id, String task_name, String bx_ids, String limits) {
|
|
|
|
|
model.updateTask(task_id, task_name, bx_ids, limits);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:删除任务
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void delTask(int task_id) {
|
|
|
|
|
model.delTask(task_id);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取任务信息
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void getTask(int task_id) {
|
|
|
|
|
Record record = model.getTask(task_id);
|
|
|
|
|
renderJson(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:启动任务
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void startTask(int task_id) {
|
|
|
|
|
model.startTask(task_id);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:停止任务
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void stopTask(int task_id) {
|
|
|
|
|
model.stopTask(task_id);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据身份证号计算班型
|
|
|
|
|
* 身份证号生成器:http://www.chineseidcard.com/?region=110101&birthday=20210307&sex=1&num=5&r=28
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/evalBx?sfzh=222301197710110018 不在规定范围内的身份证号 -2
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/evalBx?sfzh=222301202210110018 无效身份证号 -1
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/evalBx?sfzh=110101201903072653 正确返回3 中班
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/evalBx?sfzh=110101202003079950 正确返回2 小班
|
|
|
|
|
* http://10.10.21.20:9000/FengHuang/yp/evalBx?sfzh=11010120210307417X 正确返回1 托班
|
|
|
|
|
*
|
|
|
|
|
* @param sfzh
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@EmptyInterface({"sfzh"})
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void evalBx(int task_id, String sfzh) {
|
|
|
|
|
Kv kv = model.evalBx(task_id, sfzh);
|
|
|
|
|
kv.set("success", true);
|
|
|
|
|
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({"name", "xb", "sfzh", "address", "father_name", "mother_name", "tel", "uuid"})
|
|
|
|
|
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, String uuid) {
|
|
|
|
|
int result = model.save(task_id, name, xb, bx_id, address, father_name, mother_name, sfzh, tel, uuid);
|
|
|
|
|
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
if (result == 1) {
|
|
|
|
|
kv.set("success", true);
|
|
|
|
|
kv.set("message", "保存成功!");
|
|
|
|
|
}
|
|
|
|
|
if (result == 2) {
|
|
|
|
|
kv.set("success", false);
|
|
|
|
|
kv.set("message", "此身份证号已申请过,不能重复申请!");
|
|
|
|
|
}
|
|
|
|
|
if (result == 3) {
|
|
|
|
|
kv.set("success", false);
|
|
|
|
|
kv.set("message", "指定班型人数已达上限,不能申请!");
|
|
|
|
|
}
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:查看指定任务的结果
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param bx_id
|
|
|
|
|
* @param page
|
|
|
|
|
* @param limit
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"task_id", "bx_id", "page", "limit"})
|
|
|
|
|
public void getTaskInfo(int task_id, int bx_id, int page, int limit) {
|
|
|
|
|
Page<Record> list = model.getTaskInfo(task_id, bx_id, page, limit);
|
|
|
|
|
renderJson(CommonUtil.renderJsonForLayUI(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:导出excel
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param bx_id 0:全部,否则指定的班型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<Record> 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:上传户口本照片
|
|
|
|
|
*/
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
public void uploadPic() {
|
|
|
|
|
UploadFile picFile = getFile();//得到 文件对象
|
|
|
|
|
String fileName = picFile.getFileName();
|
|
|
|
|
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
|
|
|
|
|
if (!suffix.equals("jpg")) {
|
|
|
|
|
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误!系统只允许上传jpg格式!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
//判断目录是不是存在
|
|
|
|
|
File file = new File(PathKit.getWebRootPath() + "/upload");
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
file.mkdirs();// 创建文件夹
|
|
|
|
|
}
|
|
|
|
|
String finalPic = PathKit.getWebRootPath() + "/upload/" + uuid + ".jpg";
|
|
|
|
|
picFile.getFile().renameTo(new File(finalPic));
|
|
|
|
|
//输出base64编码的jpg文件
|
|
|
|
|
String base64 = Base64Util.fileToBase64(new File(finalPic));
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "上传成功!");
|
|
|
|
|
kv.set("base64", base64);
|
|
|
|
|
kv.set("uuid", uuid);
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
//path : /FengHuang/upload/sfzh+".jpg"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务下的班型选择情况
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void getBx(int task_id) {
|
|
|
|
|
List<Record> list = model.getBx(task_id);
|
|
|
|
|
renderJson(CommonUtil.renderJsonForLayUI(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取验证码
|
|
|
|
|
* 调用方法:
|
|
|
|
|
* <img title="点击刷新" class="captcha" src="/login/captcha" onclick="updateCaptcha();">
|
|
|
|
|
* <script>
|
|
|
|
|
* function updateCaptcha() {
|
|
|
|
|
* $(".captcha").attr("src", "/FengHuang/yp/getYzm?v=" + Math.random());
|
|
|
|
|
* $("#captchaInput").val("");
|
|
|
|
|
* }
|
|
|
|
|
* </script>
|
|
|
|
|
* <p>
|
|
|
|
|
* 后台验证验证码是否正确
|
|
|
|
|
* boolean result = validateCaptcha("inputRandomCode");//inputRandomCode是用户提交过来的验证码
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
public void getYzm() {
|
|
|
|
|
renderCaptcha();
|
|
|
|
|
}
|
|
|
|
|
}
|