add: 政策导入导出
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import com.adc.da.slrs.processModel.utils.TrainFormDate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tjzdw
|
||||
* @description
|
||||
* @date 2023/10/28
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExcelExportUtil {
|
||||
|
||||
private ExcelExportUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel文件
|
||||
* @param params 导出参数,主要包含,导出的文件名,导出类型
|
||||
* @param tClass 导出文件的对象类
|
||||
* @param datas 数据
|
||||
* @return 工作簿
|
||||
*/
|
||||
public static Workbook exportWithData(ExportParams params, Class<?> tClass , List<?> datas) {
|
||||
Workbook wb = null;
|
||||
|
||||
if (params.getType().equals(ExcelType.XSSF)) {
|
||||
wb = new XSSFWorkbook();
|
||||
} else {
|
||||
wb = new HSSFWorkbook();
|
||||
}
|
||||
|
||||
// 第二步,在workbook中添加一个sheet,对应Excel文件中的sheet
|
||||
Sheet sheet = wb.createSheet(params.getSheetName());
|
||||
|
||||
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
|
||||
Row row = sheet.createRow(0);
|
||||
|
||||
// 第四步,创建单元格,并设置值表头 设置表头居中
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
//声明列对象
|
||||
Cell cell = null;
|
||||
Map<Integer, Excel> map = new HashMap<>();
|
||||
Map<Integer, Field> mapField = new HashMap<>();
|
||||
Field[] fields = tClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
Excel excel = field.getAnnotation(Excel.class);
|
||||
if (null != excel) {
|
||||
map.put(Integer.valueOf(excel.orderNum()), excel);
|
||||
mapField.put(Integer.valueOf(excel.orderNum()), field);
|
||||
}
|
||||
}
|
||||
//创建标题行
|
||||
DataFormat df = wb.createDataFormat();
|
||||
for (Integer i : map.keySet()) {
|
||||
sheet.setColumnWidth(i, (int) (map.get(i).width() * 256));
|
||||
cell = row.createCell(i);
|
||||
cell.setCellValue(map.get(i).name());
|
||||
if (null != map.get(i).exportFormat()) {
|
||||
CellStyle style1 = wb.createCellStyle();
|
||||
style1.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
|
||||
style1.setDataFormat(df.getFormat(map.get(i).exportFormat()));
|
||||
sheet.setDefaultColumnStyle(i, style1);
|
||||
}
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
//赋值数据
|
||||
int rowNum = 1;
|
||||
for (Object o : datas) {
|
||||
Row row1 = sheet.createRow(rowNum);
|
||||
for (Integer i : map.keySet()) {
|
||||
Cell cell1 = row1.createCell(i);
|
||||
Field field = null;
|
||||
try {
|
||||
field = o.getClass().getDeclaredField(mapField.get(i).getName());
|
||||
} catch (NoSuchFieldException e) {
|
||||
log.warn(e.getMessage());
|
||||
}
|
||||
if (null != field) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object fieldVal = field.get(o);
|
||||
if (null != map.get(i).exportFormat() && !"".equals(map.get(i).exportFormat())) {
|
||||
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : TrainFormDate.dealWithTimeZoneyyyy(String.valueOf(fieldVal), map.get(i).exportFormat()));
|
||||
} else {
|
||||
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : String.valueOf(fieldVal));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
log.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(o.toString());
|
||||
rowNum++;
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,14 @@ public class FieldConvertUtil {
|
||||
// 内外部会议关联表 表头
|
||||
public static String exportFieldNamesMeetingTopic = "议题名称,汇报人,汇报单位,议题主要内容";
|
||||
|
||||
// 政策法规资料 表头
|
||||
public static String exportFieldLawsInformation = "一级资料类别,二级资料类别,三级资料类别,四级资料类别,资料名称,资料归属部门,作者,资料说明";
|
||||
|
||||
// 政策课题 表头
|
||||
public static String exportFieldLawsTopic = "课题名称,课题承办单位,课题指导单位,课题参与单位,开始时间,结题时间,课题费用(万元),课题组会议列表,课题组联系方式,内部联系方式";
|
||||
// 政策课题关联表 表头
|
||||
public static String exportFieldLawsTopicRelation = "会议名称,会议时间,会议地点,参会人员(内部),会议主要内容,姓名,单位,电话,邮箱,身份,姓名,单位,电话,邮箱,身份";
|
||||
|
||||
public static String exportBaseFieldNamesBussCode = "起草部门,废止日期,代替企标编号,复审日期,起草人,被代替企标编号,采用标准,文件上传人员,采标程度,引用标准,适用车型,能源类型,适用产品线,上传时间,体系类别,备案日期,关联模块-乘用车VPPS编码,关联模块--乘用车vpps中文名称,关联模块--卡车VPPS编码,关联模块--卡车vpps中文名称";
|
||||
|
||||
public static String exportAttrFieldNamesBuss = "SVPPS,规范性引用文件,废止日期,复审日期,密级,授权,相关部门," +
|
||||
@@ -85,6 +93,11 @@ public class FieldConvertUtil {
|
||||
"7.关联模块-乘用车VPPS编码和关联模块--卡车VPPS编码是填写数据库中已有的编码从而带出乘用车VPPS名称和卡车VPPS名称\n" +
|
||||
"8.发布稿,编制说明,历史版本,其他文件,修改单,关联文件为附件文件,需要放在Excel文档同级目录中";
|
||||
|
||||
// TODO
|
||||
public static String exportInsideOutsideMeetingDesc = "内部会议,外部会议";
|
||||
|
||||
public static String exportLawsInformationDesc = "";
|
||||
|
||||
public static String exportFieldName = "*企标类别,*企标编号,*标准年份,*企标名称,企标英文名称,*文本状态,发布日期,企标实施日期,起草部门,起草人,适用车型,能源类型,适用产品线,体系类别,关联模块-乘用车VPPS编码,关联模块--卡车VPPS编码,发布稿,编制说明,历史版本,其他文件,修改单,代替企标编号,采用标准,采标程度,引用标准,关联文件,";
|
||||
|
||||
/***
|
||||
|
||||
@@ -138,10 +138,10 @@ public class InsideOutsideMeetingExportUtil {
|
||||
value = insideOutsideMeeting.getMeetingContent();
|
||||
break;
|
||||
case "一级会议类别":
|
||||
value = insideOutsideMeeting.getFirstMeetingType();
|
||||
value = insideOutsideMeeting.getFirstMeetingTypeName();
|
||||
break;
|
||||
case "二级会议类别":
|
||||
value = insideOutsideMeeting.getSecondMeetingType();
|
||||
value = insideOutsideMeeting.getSecondMeetingTypeName();
|
||||
break;
|
||||
default:
|
||||
value = null;
|
||||
|
||||
Reference in New Issue
Block a user