|
|
|
@ -23,9 +23,11 @@ import com.jfinal.plugin.activerecord.Page;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.SqlPara;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
@ -963,13 +965,11 @@ public class CollectModel {
|
|
|
|
|
* @param job_id
|
|
|
|
|
*/
|
|
|
|
|
public void delJob(int job_id) {
|
|
|
|
|
/*
|
|
|
|
|
* 检查此任务是否关联的表,只被它一个人使用,如果是,就删除相关表
|
|
|
|
|
*/
|
|
|
|
|
// 检查此任务是否关联的表,只被它一个人使用,如果是,就删除相关表
|
|
|
|
|
String sql = "select form_table_name from t_collect_job where job_id=?";
|
|
|
|
|
String form_table_name = Db.findFirst(sql, job_id).getStr("form_table_name");
|
|
|
|
|
if (!StrKit.isBlank(form_table_name)) {
|
|
|
|
|
sql = "select count(1) as c from t_collect_job where form_table_name=? and job_id<>?";
|
|
|
|
|
sql = "select count(1) as c from t_collect_job where form_table_name=? and job_id<>?";
|
|
|
|
|
int c = Db.findFirst(sql, form_table_name, job_id).getInt("c");
|
|
|
|
|
if (c == 0) dropTable(form_table_name);
|
|
|
|
|
}
|
|
|
|
@ -994,6 +994,24 @@ public class CollectModel {
|
|
|
|
|
|
|
|
|
|
sql = "delete from t_collect_job_sheet_col where job_id=?";
|
|
|
|
|
Db.update(sql, job_id);
|
|
|
|
|
|
|
|
|
|
//删除关联子任务
|
|
|
|
|
List<Record> childList = getChildJobList(job_id);
|
|
|
|
|
for (Record record : childList) {
|
|
|
|
|
int child_job_id = record.getInt("job_id");
|
|
|
|
|
delJob(child_job_id);//递归删除子任务
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定job下有哪些子任务
|
|
|
|
|
*
|
|
|
|
|
* @param job_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getChildJobList(int job_id) {
|
|
|
|
|
String sql = "select * from t_collect_job where parent_id=?";
|
|
|
|
|
return Db.find(sql, job_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -1634,4 +1652,157 @@ public class CollectModel {
|
|
|
|
|
int child_job_id = record.getInt("job_id");
|
|
|
|
|
return viewJob(child_job_id, null, -1, 0, page, limit, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****下面的代码用于生成通用的EXCEL导出功能****/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据任务号获取它有哪些Sheet表,对应哪些数据库表
|
|
|
|
|
*
|
|
|
|
|
* @param job_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getAllSheetByJobId(int job_id) {
|
|
|
|
|
String sql = "select * from t_collect_job_sheet where job_id=? order by sheet_index";
|
|
|
|
|
return Db.find(sql, job_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据表名,获取表的结构信息
|
|
|
|
|
*
|
|
|
|
|
* @param table_name
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getTableStruct(String table_name) {
|
|
|
|
|
String sql = "select column_name,excel_column_idx,original_name from t_collect_mapping where table_name=?";
|
|
|
|
|
return Db.find(sql, table_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务+指定表名下的所有填报数据
|
|
|
|
|
*
|
|
|
|
|
* @param job_id
|
|
|
|
|
* @param table_name
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getTableDataByJobId(int job_id, String table_name) {
|
|
|
|
|
String sql = "select * from " + table_name + " where job_id = ?";
|
|
|
|
|
return Db.find(sql, job_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:生成简单的数据汇集EXCEL
|
|
|
|
|
*
|
|
|
|
|
* @param job_id
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public void getSummaryExcel(int job_id, String filePath) throws IOException { //给定任务编号,获取它有哪些表
|
|
|
|
|
// 创建工作簿和工作表
|
|
|
|
|
SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行,超100行将写入临时文件
|
|
|
|
|
workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
|
|
|
|
|
|
|
|
|
|
//开始生成EXCEL
|
|
|
|
|
List<Record> allSheet = getAllSheetByJobId(job_id);
|
|
|
|
|
for (Record rSheet : allSheet) {
|
|
|
|
|
//表名
|
|
|
|
|
String table_name = rSheet.getStr("table_name");
|
|
|
|
|
String sheet_name = rSheet.getStr("sheet_name");
|
|
|
|
|
//读取表的结构信息
|
|
|
|
|
List<Record> list = getTableStruct(table_name);
|
|
|
|
|
Map<Integer, Record> _map = new HashMap<>();
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
Record r = new Record();
|
|
|
|
|
r.set("column_name", record.getStr("column_name"));
|
|
|
|
|
r.set("original_name", record.getStr("original_name"));
|
|
|
|
|
_map.put(record.getInt("excel_column_idx") + 1, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取数据
|
|
|
|
|
List<Record> data = getTableDataByJobId(job_id, table_name);
|
|
|
|
|
Sheet sheet = workbook.createSheet(sheet_name);
|
|
|
|
|
// 创建单元格样式对象
|
|
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
|
// 设置水平居中
|
|
|
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
// 设置垂直居中
|
|
|
|
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
// 设置边框样式
|
|
|
|
|
headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
|
|
headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
|
|
headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
|
|
headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
|
|
|
|
|
|
|
// 创建字体对象并设置字体颜色为白色
|
|
|
|
|
Font font = workbook.createFont();
|
|
|
|
|
font.setFontHeightInPoints((short) 14);
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
font.setFontName("黑体");
|
|
|
|
|
font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
|
|
// 设置背景色为浅蓝色 #d2f4f2
|
|
|
|
|
//颜色
|
|
|
|
|
String str = "#d2f4f2";
|
|
|
|
|
String sr = str.substring(1, 3);
|
|
|
|
|
String sg = str.substring(3, 5);
|
|
|
|
|
String sb = str.substring(5, 7);
|
|
|
|
|
//16进制的字符串转为int
|
|
|
|
|
int r = Integer.parseInt(sr, 16);
|
|
|
|
|
int g = Integer.parseInt(sg, 16);
|
|
|
|
|
int b = Integer.parseInt(sb, 16);
|
|
|
|
|
XSSFColor rbg = new XSSFColor(new java.awt.Color(r, g, b), new DefaultIndexedColorMap());
|
|
|
|
|
headerStyle.setFillForegroundColor(rbg);
|
|
|
|
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
// 将字体应用于样式
|
|
|
|
|
headerStyle.setFont(font);
|
|
|
|
|
|
|
|
|
|
// 在第一行创建单元格并设置样式
|
|
|
|
|
Row headerRow = sheet.createRow(0);
|
|
|
|
|
Cell headerCell = headerRow.createCell(0);
|
|
|
|
|
headerCell.setCellValue("单位");
|
|
|
|
|
headerCell.setCellStyle(headerStyle);
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
headerCell = headerRow.createCell(i + 1);
|
|
|
|
|
headerCell.setCellValue(_map.get(i + 1).getStr("original_name"));
|
|
|
|
|
headerCell.setCellStyle(headerStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建字体对象并设置字体大小为12
|
|
|
|
|
font = workbook.createFont();
|
|
|
|
|
font.setFontHeightInPoints((short) 12);
|
|
|
|
|
|
|
|
|
|
// 创建单元格样式对象并将字体应用于样式
|
|
|
|
|
CellStyle style = workbook.createCellStyle();
|
|
|
|
|
style.setFont(font);
|
|
|
|
|
// 设置行高度为28
|
|
|
|
|
sheet.setDefaultRowHeightInPoints(28);
|
|
|
|
|
// 设置每个单元格的宽度为30
|
|
|
|
|
sheet.setDefaultColumnWidth(30);
|
|
|
|
|
// 设置边框样式
|
|
|
|
|
style.setBorderTop(BorderStyle.THIN);
|
|
|
|
|
style.setBorderBottom(BorderStyle.THIN);
|
|
|
|
|
style.setBorderLeft(BorderStyle.THIN);
|
|
|
|
|
style.setBorderRight(BorderStyle.THIN);
|
|
|
|
|
// 设置水平居中
|
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
// 设置垂直居中
|
|
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
|
|
|
|
|
// 填充数据集的其余行
|
|
|
|
|
for (int i = 1; i <= data.size(); i++) {
|
|
|
|
|
Row row = sheet.createRow(i);
|
|
|
|
|
Record record = data.get(i - 1);
|
|
|
|
|
Cell cell = row.createCell(0);
|
|
|
|
|
cell.setCellValue(record.getStr("bureau_name"));
|
|
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
for (int j = 0; j < list.size(); j++) {
|
|
|
|
|
cell = row.createCell(j + 1);
|
|
|
|
|
cell.setCellValue(record.getStr(_map.get(j + 1).getStr("column_name")));
|
|
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存Excel文件
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(filePath);
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
}
|
|
|
|
|
}
|