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.

324 lines
11 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;
2 years ago
import com.dsideal.FengHuang.Util.*;
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.*;
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 {
2 years ago
Kv kv = Kv.by("task_id", 0);
2 years ago
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
/**
*
* 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));
}
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"})
2 years ago
public void updateTask(int task_id, String task_name, String bx_ids, String limits) {
model.updateTask(task_id, task_name, bx_ids, limits);
2 years ago
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
/**
*
2 years ago
*
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({"code", "name", "xb", "sfzh", "address", "father_name", "mother_name", "tel", "uuid"})
2 years ago
public void save(String code, int task_id, String name, String xb, int bx_id, String address, String father_name, String mother_name, String sfzh, String tel, String uuid) {
2 years ago
Kv kv = Kv.create();
boolean r = validateCaptcha(code);
if (!r) {
kv.set("success", false);
kv.set("message", "验证码错误!");
}
2 years ago
int result = model.save(task_id, name, xb, bx_id, address, father_name, mother_name, sfzh, tel, uuid);
2 years ago
2 years ago
2 years ago
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
*/
@Before(GET.class)
2 years ago
@IsNumericInterface({"task_id"})
public void exportExcel(int task_id) {
//此次任务有哪些班型
List<Record> list = model.getBx(task_id);
String task_name = model.getTask(task_id).getStr("task_name");
//需要合并的excel文件路径
ArrayList<String> mergeList = new ArrayList<>();
2 years ago
//模板文件
2 years ago
String excelPath = PathKit.getWebRootPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/");
2 years ago
String filePath = excelPath + "YangPuZhaoShengExcel.json";
2 years ago
//按班型逐个生成
for (int i = 0; i < list.size(); i++) {
Record record = list.get(i);
2 years ago
boolean selected = record.getBoolean("selected");
if (!selected) continue;
2 years ago
int bx_id = record.getInt("bx_id");
String bx_name = record.getStr("bx_name");
//转成 json对象
JSONObject jo = FileUtil.readJsonFile(filePath);
//导出
Page<Record> rs = model.getTaskInfo(task_id, bx_id, 1, 99999);
2 years ago
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xlsx";
2 years ago
ExcelExportUtil.export(rs, jo, excelFile, task_name + "申报结果(" + bx_name + ")", bx_name);
2 years ago
mergeList.add(excelFile);
}
2 years ago
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xlsx";
2 years ago
ExcelCommonUtil.mergeExcel(mergeList, excelFile, 1);
2 years ago
2 years ago
//提供下载
2 years ago
String filename = task_name + "申报结果.xlsx";
2 years ago
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
//判断文件大小大于20mb则返回错误信息并终止上传删除上传文件
long size = picFile.getFile().length();
if (size > 1024 * 1024 * 20) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "图片文件大小大于20MB,请检查后重传!");
renderJson(map);
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);
}
2 years ago
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
/**
*
2 years ago
*
* <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是用户提交过来的验证码
2 years ago
*/
@Before(GET.class)
public void getYzm() {
renderCaptcha();
}
2 years ago
}