@ -903,19 +903,19 @@ public class CollectModel {
if ( publish_job_type_id = = 1 ) {
if ( xiaShuSchool = = 1 ) {
//query_type_id=1:只查市直属
Page < Record > list = getBureauList ( 1 , "2" , null , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 1 , "2" , null , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
bureauSet . add ( record . getStr ( "org_id" ) ) ;
}
}
if ( xiaShuJiaoFu = = 1 ) {
Page < Record > list = getBureauList ( 1 , "3" , null , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 1 , "3" , null , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
bureauSet . add ( record . getStr ( "org_id" ) ) ;
}
}
if ( xiaShuJiaoYuJu = = 1 ) {
Page < Record > list = getBureauList ( 1 , "1" , null , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 1 , "1" , null , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
bureauSet . add ( record . getStr ( "org_id" ) ) ;
}
@ -925,13 +925,13 @@ public class CollectModel {
else if ( publish_job_type_id = = 2 ) {
if ( xiaShuSchool = = 1 ) {
//query_type_id=2:查县区属
Page < Record > list = getBureauList ( 2 , "2" , area_id , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 2 , "2" , area_id , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
bureauSet . add ( record . getStr ( "org_id" ) ) ;
}
}
if ( xiaShuJiaoFu = = 1 ) {
Page < Record > list = getBureauList ( 2 , "3" , area_id , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 2 , "3" , area_id , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
bureauSet . add ( record . getStr ( "org_id" ) ) ;
}
@ -1583,14 +1583,14 @@ public class CollectModel {
//获取此县区的所有学校
Set < String > targetSet = new HashSet < > ( ) ;
if ( xiaShuSchool = = 1 ) {
Page < Record > list = getBureauList ( 2 , "2" , area_id , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 2 , "2" , area_id , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
targetSet . add ( record . getStr ( "org_id" ) ) ;
}
}
//获取此县区的所有教辅单位
if ( xiaShuJiaoFu = = 1 ) {
Page < Record > list = getBureauList ( 2 , "3" , area_id , null , 1 , 9999 ) ;
Page < Record > list = getBureauList ( 2 , "3" , area_id , null , 1 , 9999 ) ;
for ( Record record : list . getList ( ) ) {
targetSet . add ( record . getStr ( "org_id" ) ) ;
}
@ -1731,6 +1731,17 @@ public class CollectModel {
return Db . find ( sql , job_id ) ;
}
/ * *
* 功 能 : 获 取 指 定 列 的 列 描 述 信 息
*
* @param table_name
* @return
* /
public static List < Record > getTableStructInfo ( String table_name ) {
String sql = "select col.column_name, col.ordinal_position as o, d.description as column_description from information_schema.columns col join pg_class c on c.relname = col.table_name left join pg_description d on d.objoid = c.oid and d.objsubid = col.ordinal_position where col.table_schema = 'public' and table_name=? order by col.ordinal_position" ;
return Db . find ( sql , table_name ) ;
}
/ * *
* 功 能 : 生 成 简 单 的 数 据 汇 集 EXCEL
*
@ -1738,7 +1749,7 @@ public class CollectModel {
* @param filePath
* @throws IOException
* /
public void getSummaryExcel ( int job_id , String filePath ) throws IOException { //给定任务编号,获取它有哪些表
public void getSummaryExcel ForImportExcel ( int job_id , String filePath ) throws IOException { //给定任务编号,获取它有哪些表
// 创建工作簿和工作表
SXSSFWorkbook workbook = new SXSSFWorkbook ( ) ; //默认100行, 超100行将写入临时文件
workbook . setCompressTempFiles ( false ) ; //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
@ -1847,4 +1858,116 @@ public class CollectModel {
FileOutputStream outputStream = new FileOutputStream ( filePath ) ;
workbook . write ( outputStream ) ;
}
/ * *
* 功 能 : 导 出 Form 表 单 式 录 入 的 汇 集 数 据 EXCEL
*
* @param job_id
* @param filePath
* @throws IOException
* /
public void getSummaryExcelForFormFill ( int job_id , String filePath ) throws IOException {
Record jobRecord = getJob ( job_id ) ;
String table_name = jobRecord . getStr ( "form_table_name" ) ; //表格名称
Map < Integer , Record > _map = new HashMap < > ( ) ;
List < Record > listStruct = getTableStructInfo ( table_name ) ;
int idx = 0 ;
for ( Record r : listStruct ) {
String column_name = r . getStr ( "column_name" ) ;
//准备第几列用哪一个字段
if ( column_name . equals ( "id" ) ) continue ;
if ( column_name . equals ( "bureau_id" ) ) continue ;
if ( column_name . equals ( "person_id" ) ) continue ;
if ( column_name . equals ( "class_id" ) ) continue ;
if ( column_name . equals ( "job_id" ) ) continue ;
_map . put ( idx + + , r ) ;
}
//获取数据
List < Record > data = getTableDataByJobId ( job_id , table_name ) ;
//创建Excel
SXSSFWorkbook workbook = new SXSSFWorkbook ( ) ; //默认100行, 超100行将写入临时文件
workbook . setCompressTempFiles ( false ) ; //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
//开始生成EXCEL
String sheet_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 . setCellStyle ( headerStyle ) ;
for ( int i = 0 ; i < _map . size ( ) ; i + + ) {
headerCell = headerRow . createCell ( i ) ;
headerCell . setCellValue ( _map . get ( i ) . getStr ( "column_description" ) ) ;
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 r2 = data . get ( i - 1 ) ;
for ( int j = 0 ; j < _map . size ( ) ; j + + ) {
Cell cell = row . createCell ( j ) ;
cell . setCellValue ( r2 . getStr ( _map . get ( j ) . getStr ( "column_name" ) ) ) ;
cell . setCellStyle ( style ) ;
}
}
// 保存Excel文件
FileOutputStream outputStream = new FileOutputStream ( filePath ) ;
workbook . write ( outputStream ) ;
}
}