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.

312 lines
9.9 KiB

2 years ago
package com.dsideal.FengHuang.Yp.Controller;
import com.alibaba.fastjson.JSONObject;
2 years ago
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;
2 years ago
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;
2 years ago
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;
import com.jfinal.plugin.activerecord.Record;
2 years ago
import com.jfinal.upload.UploadFile;
2 years ago
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 YpController extends Controller {
YpModel model = new YpModel();
/**
*
* http://10.10.21.20:9000/FengHuang/yp/getCurrentTaskInfo
*
* @return
*/
@Before(GET.class)
public void getCurrentTaskInfo() {
2 years ago
List<Record> list = model.getCurrentTaskInfo();
if (list.size() > 0) {
renderJson(list.get(0));
} else {
Kv kv = Kv.by("task_id", -1);
renderJson(kv);
}
2 years ago
}
/**
*
* 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);
}
2 years ago
/**
*
*/
@Before(POST.class)
2 years ago
@EmptyInterface({"task_name", "bx_ids", "limits"})
public void addTask(String task_name, String bx_ids, String limits) {
model.addTask(task_name, bx_ids, limits);
2 years ago
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);
}
2 years ago
/**
*
* @param task_id
*/
@Before(GET.class)
@IsNumericInterface({"task_id"})
public void getTask(int task_id) {
Record record = model.getTask(task_id);
renderJson(record);
}
2 years ago
/**
2 years ago
*
2 years ago
*/
@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);
}
2 years ago
2 years ago
/**
*
*
* @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);
}
2 years ago
/**
*
* 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"})
2 years ago
@IsNumericInterface({"task_id"})
public void evalBx(int task_id, String sfzh) {
Kv kv = model.evalBx(task_id, sfzh);
2 years ago
kv.set("success", true);
2 years ago
renderJson(kv);
}
2 years ago
/**
*
*
* @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)
2 years ago
@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);
2 years ago
2 years ago
Kv kv = Kv.create();
if (result == 1) {
2 years ago
kv.set("success", true);
2 years ago
kv.set("message", "保存成功!");
}
if (result == 2) {
2 years ago
kv.set("success", false);
2 years ago
kv.set("message", "此身份证号已申请过,不能重复申请!");
}
if (result == 3) {
2 years ago
kv.set("success", false);
2 years ago
kv.set("message", "指定班型人数已达上限,不能申请!");
}
2 years ago
renderJson(kv);
}
/**
*
*
* @param task_id
* @param bx_id
* @param page
* @param limit
*/
@Before(GET.class)
2 years ago
@IsNumericInterface({"task_id", "bx_id", "page", "limit"})
2 years ago
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
2 years ago
* @param bx_id 0:ID
2 years ago
*/
@Before(GET.class)
@IsNumericInterface({"task_id", "page", "limit"})
2 years ago
public void exportExcel(int task_id, int bx_id) {
2 years ago
//模板文件
String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/");
String filePath = excelPath + "YangPuZhaoShengExcel.json";
//转成 json对象
JSONObject jo = FileUtil.readJsonFile(filePath);
//导出
2 years ago
Page<Record> rs = model.getTaskInfo(task_id, bx_id, 1, 99999);
2 years ago
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
ExcelExportUtil.export(rs, jo, excelFile);
//提供下载
String filename = "招生.xls";
renderFile(new File(excelFile), filename);
}
2 years ago
/**
*
*/
@Before({POST.class})
2 years ago
public void uploadPic() {
2 years ago
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;
}
2 years ago
String uuid = UUID.randomUUID().toString();
2 years ago
//判断目录是不是存在
File file = new File(PathKit.getWebRootPath() + "/upload");
if (!file.exists()) {
file.mkdirs();// 创建文件夹
}
2 years ago
String finalPic = PathKit.getWebRootPath() + "/upload/" + uuid + ".jpg";
2 years ago
picFile.getFile().renameTo(new File(finalPic));
//输出base64编码的jpg文件
String base64 = Base64Util.fileToBase64(new File(finalPic));
2 years ago
Kv kv = Kv.by("success", true);
kv.set("message", "上传成功!");
2 years ago
kv.set("base64", base64);
2 years ago
kv.set("uuid", uuid);
2 years ago
renderJson(kv);
//path : /FengHuang/upload/sfzh+".jpg"
}
2 years ago
/**
*
*
* @param task_id
* @param bx_id
* @param limit
*/
@Before(POST.class)
@IsNumericInterface({"task_id", "bx_id", "limit"})
public void addBx(int task_id, int bx_id, int limit) {
model.addBx(task_id, bx_id, limit);
Kv kv = Kv.by("success", true);
kv.set("message", "保存成功!");
renderJson(kv);
}
/**
*
*
* @param task_id
* @param bx_id
* @param limit
*/
@Before(POST.class)
@IsNumericInterface({"task_id", "bx_id", "limit"})
public void updateBx(int task_id, int bx_id, int limit) {
model.updateBx(task_id, bx_id, limit);
Kv kv = Kv.by("success", true);
kv.set("message", "保存成功!");
renderJson(kv);
}
/**
*
*
* @param task_id
* @param bx_id
*/
@Before(POST.class)
@IsNumericInterface({"task_id", "bx_id"})
public void delBx(int task_id, int bx_id) {
model.delBx(task_id, bx_id);
Kv kv = Kv.by("success", true);
kv.set("message", "保存成功!");
renderJson(kv);
}
2 years ago
/**
2 years ago
*
2 years ago
*/
@Before(GET.class)
@IsNumericInterface({"task_id"})
public void getBx(int task_id) {
List<Record> list = model.getBx(task_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
2 years ago
}