|
|
|
|
package com.dsideal.FengHuang.Yp.Controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.FengHuang.ExcelImportTemplate.StudentImportExcelUtil;
|
|
|
|
|
import com.dsideal.FengHuang.Interceptor.*;
|
|
|
|
|
import com.dsideal.FengHuang.Util.*;
|
|
|
|
|
import com.dsideal.FengHuang.Yp.Model.YpModel;
|
|
|
|
|
import com.jfinal.aop.Before;
|
|
|
|
|
import com.jfinal.core.Controller;
|
|
|
|
|
import com.jfinal.core.Path;
|
|
|
|
|
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.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.upload.UploadFile;
|
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
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() {
|
|
|
|
|
Record record = model.getCurrentTaskInfo();
|
|
|
|
|
renderJson(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务的开启班型及人数限制
|
|
|
|
|
* 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/getTaskApplyCount?task_id=1
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsNumericInterface({"task_id"})
|
|
|
|
|
public void getTaskApplyCount(int task_id) {
|
|
|
|
|
List<Record> list = model.getTaskApplyCount(task_id);
|
|
|
|
|
renderJson(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:增加任务
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@EmptyInterface({"task_name"})
|
|
|
|
|
public void addTask(String task_name) {
|
|
|
|
|
model.addTask(task_name);
|
|
|
|
|
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) {
|
|
|
|
|
model.updateTask(task_id, task_name);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:启动任务
|
|
|
|
|
*/
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据身份证号计算班型
|
|
|
|
|
* 身份证号生成器: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"})
|
|
|
|
|
public void evalBx(String sfzh) {
|
|
|
|
|
int bx_id = model.evalBx(sfzh);
|
|
|
|
|
Kv kv = Kv.by("success", true);
|
|
|
|
|
kv.set("message", "获取成功!");
|
|
|
|
|
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<Record> 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<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 Upload() {
|
|
|
|
|
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 sfzh = get("sfzh");
|
|
|
|
|
if (StrKit.isBlank(sfzh)) {
|
|
|
|
|
Kv kv = Kv.by("success", false);
|
|
|
|
|
kv.set("message", "没有传入sfzh数据!");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断目录是不是存在
|
|
|
|
|
File file = new File(PathKit.getWebRootPath() + "/upload");
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
file.mkdirs();// 创建文件夹
|
|
|
|
|
}
|
|
|
|
|
String finalPic = PathKit.getWebRootPath() + "/upload/" + sfzh + ".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);
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
//path : /FengHuang/upload/sfzh+".jpg"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|