部分功能重写,增加,去除冗余
This commit is contained in:
@@ -6,6 +6,8 @@ import com.roomroot.jwgl.dto.courserunning.SingleCourseImportDTO;
|
||||
import com.roomroot.jwgl.dto.departmentpersonnel.DepartmentPersonnelCreateDTO;
|
||||
import com.roomroot.jwgl.entity.JXSSJH;
|
||||
import com.roomroot.jwgl.entity.JYSB;
|
||||
import com.roomroot.jwgl.entity.XYDB;
|
||||
import com.roomroot.jwgl.entity.XYXX;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@@ -215,6 +217,111 @@ public class ExcelParseUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析班次(学员队表)导入 Excel 文件(支持 .xls / .xlsx)。
|
||||
* <p>表头顺序与学员队表字段一致:</p>
|
||||
* 学员队编号, 学员队名称, 学员队人数, 年级, 专业代号, 专业教室编号, 备注,
|
||||
* 在校状态, 序号, 任务类别, 虚实类型, 入学日期, 毕业日期, 学员队类型,
|
||||
* 培训任务标识号, 节次类别, 系统模式, JSONZD, 简称, 所属单位, 主体培训任务
|
||||
*
|
||||
* @return 学员队实体列表
|
||||
* @throws Exception 解析异常
|
||||
*/
|
||||
public static List<XYDB> parseXYDBExcel(InputStream inputStream, String fileName) throws Exception {
|
||||
List<XYDB> result = new ArrayList<>();
|
||||
Workbook workbook = createWorkbook(inputStream, fileName);
|
||||
try {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
|
||||
Row row = sheet.getRow(rowNum);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
XYDB entity = new XYDB();
|
||||
entity.setXydbh(getCellStringValue(row.getCell(0)));
|
||||
entity.setXydmc(getCellStringValue(row.getCell(1)));
|
||||
entity.setXydrs(parseIntCell(row.getCell(2)));
|
||||
entity.setNj(getCellStringValue(row.getCell(3)));
|
||||
entity.setZydh(getCellStringValue(row.getCell(4)));
|
||||
entity.setZyjsbh(getCellStringValue(row.getCell(5)));
|
||||
entity.setBz(getCellStringValue(row.getCell(6)));
|
||||
entity.setZxzt(getCellStringValue(row.getCell(7)));
|
||||
entity.setXh(getCellStringValue(row.getCell(8)));
|
||||
entity.setRwlb(getCellStringValue(row.getCell(9)));
|
||||
entity.setXslx(parseIntCell(row.getCell(10)));
|
||||
entity.setRxrq(parseDateTimeCell(row.getCell(11)));
|
||||
entity.setByrq(parseDateTimeCell(row.getCell(12)));
|
||||
entity.setXydlx(getCellStringValue(row.getCell(13)));
|
||||
entity.setPxrwbsh(getCellStringValue(row.getCell(14)));
|
||||
entity.setJclb(getCellStringValue(row.getCell(15)));
|
||||
entity.setXtms(getCellStringValue(row.getCell(16)));
|
||||
entity.setJsonzd(getCellStringValue(row.getCell(17)));
|
||||
entity.setJc(getCellStringValue(row.getCell(18)));
|
||||
entity.setSsdw(getCellStringValue(row.getCell(19)));
|
||||
entity.setZtpxrw(parseIntCell(row.getCell(20)));
|
||||
|
||||
// 至少要有学员队编号或名称才视为有效行
|
||||
if (entity.getXydbh() != null && !entity.getXydbh().isEmpty()
|
||||
|| entity.getXydmc() != null && !entity.getXydmc().isEmpty()) {
|
||||
result.add(entity);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
workbook.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析学员信息批量导入 Excel 文件(支持 .xls / .xlsx)。
|
||||
* <p>表头顺序:</p>
|
||||
* 编号, 学号, 姓名, 学员队期编号, 证件号码, 政治面貌, 性别,
|
||||
* 出生日期, 名族, 籍贯, 身份证号, 联系电话, 通信地址, 学员类别, 曾用名
|
||||
*
|
||||
* @return 学员信息实体列表
|
||||
* @throws Exception 解析异常
|
||||
*/
|
||||
public static List<XYXX> parseXYXXExcel(InputStream inputStream, String fileName) throws Exception {
|
||||
List<XYXX> result = new ArrayList<>();
|
||||
Workbook workbook = createWorkbook(inputStream, fileName);
|
||||
try {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
|
||||
Row row = sheet.getRow(rowNum);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
XYXX entity = new XYXX();
|
||||
entity.setBh(getCellStringValue(row.getCell(0)));
|
||||
entity.setXh(getCellStringValue(row.getCell(1)));
|
||||
entity.setXm(getCellStringValue(row.getCell(2)));
|
||||
entity.setXydqbh(getCellStringValue(row.getCell(3)));
|
||||
entity.setZjhm(getCellStringValue(row.getCell(4)));
|
||||
entity.setZzmm(getCellStringValue(row.getCell(5)));
|
||||
entity.setXb(getCellStringValue(row.getCell(6)));
|
||||
entity.setCsrq(getCellStringValue(row.getCell(7)));
|
||||
entity.setMz(getCellStringValue(row.getCell(8)));
|
||||
entity.setJg(getCellStringValue(row.getCell(9)));
|
||||
entity.setSfzh(getCellStringValue(row.getCell(10)));
|
||||
entity.setLxdh(getCellStringValue(row.getCell(11)));
|
||||
entity.setTxdz(getCellStringValue(row.getCell(12)));
|
||||
entity.setXylb(getCellStringValue(row.getCell(13)));
|
||||
entity.setCym(getCellStringValue(row.getCell(14)));
|
||||
|
||||
// 至少要有编号或姓名才视为有效行
|
||||
if (entity.getBh() != null && !entity.getBh().isEmpty()
|
||||
|| entity.getXm() != null && !entity.getXm().isEmpty()) {
|
||||
result.add(entity);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
workbook.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Workbook createWorkbook(InputStream inputStream, String fileName) throws Exception {
|
||||
String name = fileName == null ? "" : fileName.toLowerCase();
|
||||
if (!name.endsWith(".xlsx") && !name.endsWith(".xls")) {
|
||||
|
||||
Reference in New Issue
Block a user