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.

1097 lines
44 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.QingLong.Collect.Controller;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Base.Model.BaseModel;
import com.dsideal.QingLong.Collect.Model.CollectModel;
import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.dsideal.QingLong.Interceptor.LayUiPageInfoInterface;
import com.dsideal.QingLong.LoginPerson.Model.LoginPersonModel;
import com.dsideal.QingLong.Util.AsposeUtil;
import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.Util.PoiUtil;
import com.dsideal.QingLong.Util.SessionKit;
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.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.*;
public class CollectController extends Controller {
CollectModel cm = new CollectModel();
String basePath = CommonUtil.WebRoot + File.separator + "Excel";
public CollectController() {
}
/********以下为EXCEL模板上传管理功能******************************************************
/**
* EXCEL原始模板上传
*/
@Before({POST.class})
@IsLoginInterface({})
public void uoloadTemplate() throws IOException {
UploadFile excelFile = getFile();//得到文件对象
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
String fileName = excelFile.getFileName();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
if (!suffix.equals("xlsx")) {
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误系统只允许上传xlsx格式"));
return;
}
//判断文件大小大于20b则返回错误信息并终止上传删除上传文件
long size = excelFile.getFile().length();
if (size > 1024 * 1024 * 2) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "xlsx文件大小大于2MB,请检查是否正确!");
renderJson(map);
return;
}
String upload_excel_filename = UUID.randomUUID().toString().toLowerCase() + ".xlsx";
String templateXls = basePath + "/" + upload_excel_filename;
//判断目录是不是存在
File file = new File(basePath);
if (!file.exists()) {
file.mkdirs();// 创建文件夹
}
excelFile.getFile().renameTo(new File(templateXls));
//检查这个上传的文件是不是合规比如是不是每个Sheet都有浅蓝色背景的表头
//解析上传EXCEL中的每个Sheet解析出表头信息表名描述等信息
InputStream is = new FileInputStream(templateXls);
XSSFWorkbook wb = new XSSFWorkbook(is);
int sheetCount = wb.getNumberOfSheets();//Sheet表数量
Kv kv = Kv.create();
List<Kv> kvList = new ArrayList<>();
for (int i = 0; i < sheetCount; i++) {
try {
Kv kvStruct = cm.getTableStruct(wb, i);
if (!kvStruct.getBoolean("success")) {
kv.set("success", false);
kv.set("message", "发现错误:" + kvStruct.getStr("message"));
renderJson(kv);
return;
}
kvStruct.set("upload_excel_filename", upload_excel_filename);
kvList.add(kvStruct);
} catch (Exception err) {
kv.set("success", false);
kv.set("message", "“" + wb.getSheetName(i) + "”表配置错误,请检查后重新上传!");
renderJson(kv);
wb.close();
return;
}
}
//通过后记录新增加了一个任务模板文件共N个模板记录到数据库表中然后提供给前台这些数据信息
int job_id = cm.addExcelJob(publish_role_id, person_id, kvList, upload_excel_filename);
Map map = new HashMap();
map.put("job_id", job_id);
map.put("success", true);
map.put("message", "模板上传成功!");
renderJson(map);
}
/**
* 功能根据任务ID获取有哪些Sheet表
*
* @param job_id
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
public void getSheets(int job_id) {
List<Record> list = cm.getSheets(job_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能获取指定Sheet的表结构也就是列的信息
*
* @param job_id
* @param sheet_index
* @return
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id", "sheet_index"})
public void getSheetStruct(int job_id, int sheet_index) {
//获取数据表的整体配置信息
Record record = cm.getSheet(job_id, sheet_index);
List<Record> list = cm.getSheetStruct(job_id, sheet_index);
Map<String, Object> _map = CommonUtil.renderJsonForLayUI(list);
_map.put("table_name", record.getStr("table_name"));
renderJson(_map);
}
/**
* 功能:获取数据类型下拉列表
*/
@Before({GET.class})
@IsLoginInterface({})
public void getDataTypeDict() {
List<Record> list = cm.getDataTypeDict();
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能保存Sheet属性
*/
@Before({POST.class})
@IsNumericInterface({"job_id", "sheet_index"})
@EmptyInterface({"json", "table_name"})
@IsLoginInterface({})
public void saveSheet(int job_id, int sheet_index, String json, String table_name) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
JSONArray ja;
try {
ja = JSONArray.parseArray(json);
} catch (Exception err) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "上报的json数据格式不正确请检查后重传");
renderJson(kv);
return;
}
String old_table_name = cm.getSheet(job_id, sheet_index).getStr("table_name");
if (old_table_name != null && !old_table_name.equals(table_name) && cm.isTableExist(table_name)) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "表名" + table_name + "已存在,不能保存!");
renderJson(kv);
return;
}
//检查字段名称
String errMsg = "";
int idx = 1;
for (Object o : ja) {
JSONObject jo = (JSONObject) o;
String column_name = jo.getString("column_name");
if (StrKit.isBlank(column_name)) {
errMsg += "第" + idx + "列的列名为空!\n";
continue;
}
if (column_name.length() > 32) {
errMsg += "第" + idx + "列的列名长度大于32位\n";
continue;
}
if (column_name.matches("[a-z][a-z0-9_]*")) {
errMsg += "第" + idx + "列的列名只能是小写字母或者数字、下划线,并且列名不能以数字开头!\n";
continue;
}
idx++;
}
if (!StrKit.isBlank(errMsg)) {
Map map = new HashMap();
map.put("success", false);
map.put("message", errMsg);
renderJson(map);
}
//保存
List<Record> writeList = new ArrayList<>();
for (Object o : ja) {
JSONObject jo = (JSONObject) o;
int column_index = jo.getInteger("column_index");
int data_type_id = jo.getInteger("data_type_id");
String column_name = jo.getString("column_name");
String original_name = jo.getString("original_name");
boolean allow_blank = jo.getBoolean("allow_blank");
String options = jo.getString("options");
Record record = new Record();
record.set("job_id", job_id);
record.set("sheet_index", sheet_index);
record.set("column_index", column_index);
record.set("data_type_id", data_type_id);
record.set("column_name", column_name);
record.set("original_name", original_name);
record.set("allow_blank", allow_blank);
record.set("options", options);
writeList.add(record);
}
cm.saveSheet(job_id, sheet_index, writeList, table_name);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:保存任务并建表
*
* @param job_id
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"job_name"})
public void saveJob(int job_id, String job_name) throws IOException {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//检查所有表是不是全部is_check=1
Kv kvAllCheck = cm.checkAllSheetIsCheck(job_id);
if (!kvAllCheck.getBoolean("success")) {
renderJson(kvAllCheck);
return;
}
List<Record> listJobSheet = cm.getSheets(job_id);
//检查是不是某张表中存在字段名称重复的情况
for (int i = 0; i < listJobSheet.size(); i++) {
List<Record> list = cm.checkColumnNameDuplicate(job_id, i);
if (list.size() > 0) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "第" + (i + 1) + "个Sheet表中存在字段名称重复的情况请检查后重新保存");
map.put("list", list);
renderJson(map);
return;
}
}
//检查通过,处理建表逻辑
for (int i = 0; i < listJobSheet.size(); i++) cm.createTable(job_id, i);//创建表
//检查是不是需要对指定列进行加红星+Comment操作
//操作源文件,拷贝出来,生成系统可以下发的模板
Record jobRecord = cm.getJob(job_id);
String upload_excel_filename = jobRecord.getStr("upload_excel_filename");//原始模板文件
String upload_excel_filename_finish = UUID.randomUUID().toString().toLowerCase() + ".xlsx";//系统中可以提供下载的模板文件
FileUtil.copy(basePath + File.separator + upload_excel_filename, basePath + File.separator + upload_excel_filename_finish, true);
InputStream is = new FileInputStream(basePath + File.separator + upload_excel_filename_finish);
XSSFWorkbook wb = new XSSFWorkbook(is);
for (int i = 0; i < listJobSheet.size(); i++) {
Record sheetRecord = listJobSheet.get(i);
int start_row = sheetRecord.getInt("start_row");
int end_row = sheetRecord.getInt("end_row");
List<Record> list = cm.getSheetStruct(job_id, i);
int colIdx = 0;
for (Record record : list) {
boolean allow_blank = record.getBoolean("allow_blank");
XSSFCell cell = wb.getSheetAt(i).getRow(end_row).getCell(colIdx);
if (!allow_blank) {
//一行时,星号加在一行
//二行时,星号加在二行
if (StrKit.isBlank(cell.getStringCellValue())) {
cell = wb.getSheetAt(i).getRow(start_row).getCell(colIdx);
}
PoiUtil.addStar(wb, cell);
PoiUtil.addComment(wb, cell, "此列内容必须输入!");
}
int data_type_id = record.getInt("data_type_id");
if (data_type_id == 2) {
if (!allow_blank) PoiUtil.addComment(wb, cell, "此列内容必须输入,并且需要输入整数!");
else PoiUtil.addComment(wb, cell, "此列需要输入整数!");
}
if (data_type_id == 3) {
if (!allow_blank) {
PoiUtil.addComment(wb, cell, "此列内容必须输入,并且需要输入小数!");
} else {
PoiUtil.addComment(wb, cell, "此列需要输入小数!");
}
}
if (data_type_id == 4) {
if (!allow_blank) {
PoiUtil.addComment(wb, cell, "此列内容必须输入并且需要输入日期格式为yyyy/mm/dd!");
} else {
PoiUtil.addComment(wb, cell, "此列需要输入日期格式为yyyy/mm/dd!");
}
}
colIdx++;
}
}
//检查是不是需要对于指定的Sheet+指定的列生成下拉框
for (int i = 0; i < listJobSheet.size(); i++) {
Record sheetRecord = listJobSheet.get(i);
int data_start_row = sheetRecord.getInt("data_start_row");
List<Record> list = cm.getSheetStruct(job_id, i);
int colIdx = 0;
for (Record record : list) {
String options = record.getStr("options");
if (!StrKit.isBlank(options)) {
PoiUtil.addValidation(wb, i, options, data_start_row, data_start_row + 20000, colIdx, colIdx);//范围
}
//1 文本
//2 数值
//4 日期(年-月-日)
//3 数值(小数)
int data_type_id = record.getInt("data_type_id");
if (data_type_id == 2) {
PoiUtil.setIntegerStyle(wb, i, colIdx, data_start_row, data_start_row + 20000);
}
if (data_type_id == 3) {
PoiUtil.setFloatStyle(wb, i, colIdx, data_start_row, data_start_row + 20000);
}
if (data_type_id == 4) {
PoiUtil.setDateStyle(wb, i, colIdx, data_start_row, data_start_row + 20000);
}
colIdx++;
}
}
// 取消每一个表单的激活状态
for (int i = 0; i < listJobSheet.size(); i++) wb.getSheetAt(i).setSelected(false);
// 设置活动表单为第一个表单
wb.setActiveSheet(0);
//保存
FileOutputStream fileOut = new FileOutputStream(basePath + File.separator + upload_excel_filename_finish);
wb.write(fileOut);
//关闭Excel
wb.close();
//保存任务名称
cm.saveJob(job_id, job_name, upload_excel_filename_finish);
//返回成功
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:重命名任务
*
* @param job_id
* @param job_name
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"job_name"})
public void renameJob(int job_id, String job_name) {
cm.renameJob(job_id, job_name);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:删除任务
*
* @param job_id
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
public void delJob(int job_id) {
//已发布,并且有人填写的不能删除
Record record = cm.getJob(job_id);
if (record == null) {
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
return;
}
int publish_state = record.getInt("publish_state");
if (publish_state == 1) {
int is_finish_count = 0;
List<Record> list = cm.getJobFill(job_id);
for (Record r : list) {
if (r.getInt("is_finish") == 1) is_finish_count++;
}
if (is_finish_count > 0) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "任务已发布,并且存在填报记录,无法删除!");
renderJson(map);
return;
}
}
cm.delJob(job_id);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:用户导入数据
*/
@Before({POST.class})
@IsLoginInterface({})
public void importData() throws IOException, ParseException {
// 延迟解析比率
ZipSecureFile.setMinInflateRatio(-1.0d);
UploadFile excelFile = getFile();//得到文件对象
int job_id = getInt("job_id");
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//根据人员ID获取人员所在的单位ID
LoginPersonModel personModel = new LoginPersonModel();
Record rs = personModel.getLoginInfoByPersonId(person_id);
String bureau_id = rs.get("bureau_id");
String fileName = excelFile.getFileName();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
if (!suffix.equals("xlsx")) {
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误系统只允许上传xlsx格式"));
return;
}
//判断文件大小大于20b则返回错误信息并终止上传删除上传文件
long size = excelFile.getFile().length();
if (size > 1024 * 1024 * 20) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "xlsx文件大小大于20MB,请检查是否正确!");
renderJson(map);
return;
}
String upload_excel_filename_user = UUID.randomUUID().toString().toLowerCase() + ".xlsx";
//判断目录是不是存在
File file = new File(basePath);
if (!file.exists()) {
file.mkdirs();// 创建文件夹
}
excelFile.getFile().renameTo(new File(basePath + File.separator + upload_excel_filename_user));
Record jobRecord = cm.getJob(job_id);
String upload_excel_filename_finish = jobRecord.getStr("upload_excel_filename_finish");//系统生成的模板文件
//我提供的模板文件
String f1 = basePath + File.separator + upload_excel_filename_finish;
//用户上传的填充完的EXCEL文件
String f2 = basePath + File.separator + upload_excel_filename_user;
//对比两个EXCEL文件 是不是格式一致,也就是是不是上传了正确的模板文件
int sheetCnt = cm.getSheetCount(upload_excel_filename_finish);
for (int i = 0; i < sheetCnt; i++) {
List<Map.Entry<Integer, Integer>> chayi = cm.checkYiZhi(f1, f2, i);
if (chayi.size() > 0) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "第" + (i + 1) + "个Sheet表检查过程中发现与要求上传的模板不一致请重新下载模板填写完成后再次上传");
kv.set("upload_excel_filename_user", upload_excel_filename_user);
renderJson(kv);
return;
}
}
//打开EXCEL进行检查
InputStream is = new FileInputStream(f2);
XSSFWorkbook wb = new XSSFWorkbook(is);
//遍历每个Sheet注册好的信息对用户上传的数据表进行检查
boolean flag = true;
List<Integer> blankSheet = new ArrayList<>();
for (int i = 0; i < sheetCnt; i++) {//表
//Sheet表
XSSFSheet sheet = wb.getSheetAt(i);
//移除所有批注
PoiUtil.RemoveAllComment(sheet);
//数据起始行
Record r = cm.getSheetConfig(upload_excel_filename_finish, i);
int data_start_row = r.getInt("data_start_row");
//恢复背景色
PoiUtil.resetStyle(wb, sheet, data_start_row);
//数据有效行数
int lastRowNum = sheet.getLastRowNum();
if (data_start_row > lastRowNum) blankSheet.add(i);
//遍历每一列
List<Record> list = cm.getSheetMapping(upload_excel_filename_finish, i);
for (Record record : list) {//列
int excel_column_idx = record.getInt("excel_column_idx");//第几列
String column_type = record.getStr("column_type");//类型
String options = record.getStr("options");//下拉框内容
boolean allow_blank = record.getBoolean("allow_blank");//是不是允许为空
if (!allow_blank) {
// 非空项目未填写
for (int j = data_start_row; j <= lastRowNum; j++) {//行
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
if (StrKit.isBlank(PoiUtil.getValue(cell).toString())) {
PoiUtil.addComment(wb, cell, "此处不能为空!");
PoiUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
flag = false;
}
}
}
// 下拉列表不是从下拉列表中选择的
if (!StrKit.isBlank(options)) {
for (int j = data_start_row; j <= lastRowNum; j++) {//行
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
String value = PoiUtil.getValue(cell).toString();
if (StrKit.isBlank(value)) value = "&*^&Y&*(&*(&*()*(";
if (options.indexOf(value) < 0) {
PoiUtil.addComment(wb, cell, "未从指定范围内选择有效值!");
PoiUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
flag = false;
}
}
}
// 检查数据类型是不是和规定的不兼容
for (int j = data_start_row; j <= lastRowNum; j++) {//行
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
Object obj = PoiUtil.getValue(cell);
if (column_type.equals("Integer") && !CommonUtil.isInteger(obj.toString())) {//要求整数,实际不是整数
PoiUtil.addComment(wb, cell, "要求是整数,实际数据类型不是整数!");
PoiUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
flag = false;
} else if (column_type.equals("Double") && !CommonUtil.isDouble(obj.toString())) {//要求是浮点数,实际不是浮点数
PoiUtil.addComment(wb, cell, "要求是小数,实际数据类型不是小数!");
PoiUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
flag = false;
} else if (column_type.equals("Date")) {//要求是日期,实际不是日期
if (!CommonUtil.isDate(obj.toString())) {
PoiUtil.addComment(wb, cell, "要求是日期格式,实际数据类型不是日期格式!");
PoiUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
flag = false;
}
}
}
}
}
// 取消每一个表单的激活状态
for (int i = 0; i < sheetCnt; i++) wb.getSheetAt(i).setSelected(false);
// 设置活动表单为第一个表单
wb.setActiveSheet(0);
//保存文件
FileOutputStream fileOut = new FileOutputStream(f2);
wb.write(fileOut);
if (!blankSheet.isEmpty()) {
StringBuilder t = new StringBuilder();
for (Integer i : blankSheet) t.append(i).append(",");
t = new StringBuilder(t.substring(0, t.length() - 1));
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "检查到输入的文件中存在空的Sheet表序号为" + t + ",请下载文件后查看处理后,重新上传!");
kv.set("upload_excel_filename_user", upload_excel_filename_user);
renderJson(kv);
//关闭Excel
wb.close();
return;
}
if (!flag) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "检查到输入的文件中存在不合法情况,请下载文件后查看处理后,重新上传!");
kv.set("upload_excel_filename_user", upload_excel_filename_user);
renderJson(kv);
//关闭Excel
wb.close();
return;
}
// 检查通过,导入数据
for (int i = 0; i < sheetCnt; i++)
cm.importData(job_id, upload_excel_filename_finish, wb, i, bureau_id, person_id);
//回写完成标记
cm.writeJobFinish(job_id, bureau_id, upload_excel_filename_user);
//关闭Excel
wb.close();
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "所有数据成功导入!");
renderJson(kv);
}
/**
* 功能:获取任务列表,支持关键字查询
*/
@Before({GET.class})
@IsLoginInterface({})
public void getJobList(String job_name, int page, int limit) throws ParseException {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
Page<Record> list = cm.getJobList(publish_role_id, job_name, page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能:获取单位类型
*
* @return
*/
@Before({GET.class})
@IsLoginInterface({})
public void getBureauType() {
List<Record> list = cm.getBureauType();
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能:获取单位列表
*
* @param org_type_id
* @return
*/
@Before({GET.class})
@IsLoginInterface({})
public void getBureauList(int org_type_id, String org_name, int page, int limit) {
Page<Record> list = cm.getBureauList(org_type_id, org_name, page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能:发布任务
*
* @param job_id
* @param deadline_time
* @param shiZhiSchool 市直属学校1选中0未选中
* @param shiZhiJiaoFu 市直属教辅单位1选中0未选中
* @param quXiaoJiaoYuJu 区县教育局1选中0未选中
* @param bureauIds 按单位选择的单位ids
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id", "shiZhiSchool", "shiZhiJiaoFu", "quXiaoJiaoYuJu"})
@EmptyInterface({"deadline_time"})
public void publishJob(int job_id, String deadline_time, int shiZhiSchool,
int shiZhiJiaoFu, int quXiaoJiaoYuJu, String bureauIds) throws ParseException {
cm.publishJob(job_id, deadline_time, shiZhiSchool, shiZhiJiaoFu, quXiaoJiaoYuJu, bureauIds);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:获取任务信息
*
* @param job_id
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
public void getJob(int job_id) {
Record record = cm.getJob(job_id);
renderJson(record);
}
/**
* 功能:延期任务
*
* @param job_id
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"deadline_time"})
public void extensionJob(int job_id, String deadline_time) throws ParseException {
cm.extensionJob(job_id, deadline_time);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能:克隆任务
*
* @param job_id
* @param job_name
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
public void cloneJob(int job_id, String job_name) {
cm.cloneJob(job_id, job_name);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
renderJson(map);
}
/**
* 功能: 任务发布者,查看发布的任务填充情况
*
* @param job_id
* @param keyword
* @param is_finish
* @param page
* @param limit
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id", "is_finish"})
@LayUiPageInfoInterface({"page", "limit"})
public void viewJob(int job_id, String keyword, int is_finish, int page, int limit) {
Page<Record> list = cm.viewJob(job_id, keyword, is_finish, page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能:查看某个单位对于某个任务的填报情况
*
* @param job_id
* @param bureau_id
* @param type_id 1:EXCEL下载 2PDF在线查看
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id", "type_id"})
public void getJobBureauFillInfo(int job_id, String bureau_id, int type_id) throws Exception {
if (StrKit.isBlank(bureau_id)) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//根据人员ID获取人员所在的单位ID
LoginPersonModel personModel = new LoginPersonModel();
Record rs = personModel.getLoginInfoByPersonId(person_id);
bureau_id = rs.get("bureau_id");
}
// 获取任务名称
String job_name = cm.getJob(job_id).getStr("job_name");
// 获取单位名称
BaseModel bm = new BaseModel();
String bureau_name = bm.getOrgInfoById(bureau_id).getStr("org_name");
//文件名称
String excel_filename = job_name + "【" + bureau_name + "】.xlsx";
String pdfName = job_name + "【" + bureau_name + "】";
//1、找到upload_excel_filename_user
Record record = cm.viewFilledJob(job_id, bureau_id);
String upload_excel_filename_user = record.getStr("upload_excel_filename_user");
if (StrKit.isBlank(upload_excel_filename_user)) {
Kv kv = Kv.by("success", false);
kv.set("message", "此单位还没有完成数据上报,无法展示填报情况!");
renderJson(kv);
return;
}
String excelPath = basePath + File.separator + upload_excel_filename_user;
if (!FileUtil.exist(excelPath)) {
Kv kv = Kv.by("success", false);
kv.set("message", "文件没有找到,请联系管理员处理异常!");
renderJson(kv);
return;
}
//2、提供EXCEL
if (type_id == 1) {
renderFile(new File(excelPath), excel_filename);
return;
}
//3、提供PDF
if (type_id == 2) {
String pdfPath = excelPath.replace(".xlsx", ".pdf");
AsposeUtil.xls2pdf(excelPath, pdfPath);
//提供带中文文件名的pdf流
HttpServletResponse response = getResponse();
response.reset();
response.setContentType("application/pdf;charset=UTF-8");
response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(pdfName, "UTF-8"));//这里的名字并不起作用
OutputStream out = response.getOutputStream();
PDDocument document = PDDocument.load(FileUtil.readBytes(pdfPath)); //加载pdf
PDDocumentInformation info = document.getDocumentInformation(); //获得文档属性对象
//对比原来的代码就是在文件流写入响应体之前经过一下pdfbox修改标题属性然后pdfbox的save方法可以直接写入到响应体中。
info.setTitle(pdfName); //修改标题属性 这个标题会被展示
document.setDocumentInformation(info);
document.save(out); //修改完直接输出到响应体中
document.close();
out.close();
renderNull();
}
}
/**
* 功能:学校(单位)查看我该填报或者我已填报的任务列表
*
* @param keyword 搜索关键字
* @param is_finish 0:未填报1已填报-1全部
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"is_finish"})
@LayUiPageInfoInterface({"page", "limit"})
public void viewJobList(String keyword, int is_finish, int page, int limit) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//根据人员ID获取人员所在的单位ID
LoginPersonModel personModel = new LoginPersonModel();
Record rs = personModel.getLoginInfoByPersonId(person_id);
String bureau_id = rs.get("bureau_id");
Page<Record> list = cm.viewJobList(bureau_id, keyword, is_finish, page, limit);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/***** 以下为Form表单式填报模块 *********************************/
/**
* 功能:增加一个表单式的新任务
*
* @param json
*/
@Before({POST.class})
@IsLoginInterface({})
@EmptyInterface({"job_name", "json", "table_name"})
public void addFormJob(String job_name, String json, String table_name) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
if (cm.isTableExist(table_name)) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "表名" + table_name + "已存在,无法创建,请更换后再次提交!");
renderJson(map);
return;
}
int job_id = cm.addFormJob(person_id, publish_role_id, job_name, table_name, json);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("job_id", job_id);
renderJson(map);
}
/**
* 功能:更新一个存在的表单式任务
*
* @param job_id
* @param json
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"json", "job_name", "table_name"})
public void updateFormJob(int job_id, String job_name, String json, String table_name) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
//1、检查输入的表名是不是在排除了自己本JOB_ID对应的表名外存在如果是那么不可以
String form_table_name = cm.getJob(job_id).getStr("form_table_name");
if (!form_table_name.equals(table_name) && cm.isTableExist(table_name)) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "表名" + table_name + "已存在,无法创建,请更换后再次提交!");
renderJson(map);
return;
}
cm.updateFormJob(job_id, job_name, json, table_name);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("job_id", job_id);
renderJson(map);
}
/**
* 功能:填报者保存填报结果
*
* @param job_id
* @param json
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"json"})
public void saveFormJob(int job_id, String json) {
String table_name = cm.getJob(job_id).getStr("form_table_name");
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//根据人员ID获取人员所在的单位ID
LoginPersonModel personModel = new LoginPersonModel();
Record rs = personModel.getLoginInfoByPersonId(person_id);
String bureau_id = rs.get("bureau_id");
cm.saveFormJob(bureau_id, person_id, table_name, json);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("job_id", job_id);
renderJson(map);
}
/**
* 功能:获取指定任务指定单位的填报内容
*
* @param job_id
* @param bureau_id
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"job_id"})
@EmptyInterface({"bureau_id"})
public void getFormFillJob(int job_id, String bureau_id) {
Record record = cm.getFormFillJob(job_id, bureau_id);
renderJson(record);
}
/****以下为管理组概念*****************************************/
/**
* 功能:增加组
*
* @param group_name
* @param bureauIds
*/
@Before({POST.class})
@IsLoginInterface({})
@EmptyInterface({"group_name", "bureauIds"})
public void addGroup(int group_name, String bureauIds) {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
int group_id = cm.addGroup(group_name, bureauIds, publish_role_id);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("group_id", group_id);
renderJson(map);
}
/**
* 功能:更新组
*
* @param group_id
* @param group_name
* @param bureauIds
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"group_id"})
@EmptyInterface({"group_name", "bureauIds"})
public void updateGroup(int group_id, String group_name, String bureauIds) {
cm.updateGroup(group_id, group_name, bureauIds);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("group_id", group_id);
renderJson(map);
}
/**
* 功能:组列表
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"group_id"})
@EmptyInterface({"group_name", "bureauIds"})
public void listGroup() {
//操作人员
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id");
//检查当前登录人员是不是发布任务的角色
Kv kvCheck = cm.checkPublishRole(person_id);
if (!kvCheck.getBoolean("success")) {
renderJson(kvCheck);
return;
}
//获取登录人员第一个发布任务的角色是什么
int publish_role_id = kvCheck.getInt("publish_role_id");
List<Record> list = cm.listGroup(publish_role_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* 功能:删除组
*
* @param group_id
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"group_id"})
public void delGroup(int group_id) {
cm.delGroup(group_id);
Map map = new HashMap();
map.put("success", true);
map.put("message", "保存成功!");
map.put("group_id", group_id);
renderJson(map);
}
/**
* 功能获取组内有哪些单位id
*
* @param group_id
*/
@Before({POST.class})
@IsLoginInterface({})
@IsNumericInterface({"group_id"})
public void getGroup(int group_id) {
List<Record> list = cm.getGroup(group_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
}