导入导出 模版下载 bug修复

This commit is contained in:
liumengyu
2026-08-21 12:08:52 +08:00
parent 2a5bf443fe
commit 179b12e3bf
65 changed files with 389 additions and 964 deletions
@@ -6,6 +6,7 @@ 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.KSBZXM;
import com.roomroot.jwgl.entity.XYDB;
import com.roomroot.jwgl.entity.XYXX;
import org.apache.poi.ss.usermodel.Cell;
@@ -19,6 +20,7 @@ import java.io.InputStream;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
@@ -322,6 +324,68 @@ public class ExcelParseUtil {
return result;
}
/**
* 解析联教联训(课时补助项目)导入 Excel 文件(支持 .xls / .xlsx)。
* <p>模板表头顺序:</p>
* 序号, 补助项目名称, 性质, 依据, 开始日期, 结束日期, 项目说明, 项目备注,
* 教研室名称, 补助教员姓名, 补助课时量, 课时量备注
* <p>只映射课时补助项目表存在的字段;序号/教研室名称/补助教员姓名/课时量备注无对应列,忽略。</p>
*
* @return 课时补助项目实体列表(创建/修改时间由业务层填充)
* @throws Exception 解析异常
*/
public static List<KSBZXM> parseKSBZXMExcel(InputStream inputStream, String fileName) throws Exception {
List<KSBZXM> 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;
}
KSBZXM entity = new KSBZXM();
// 补助项目名称
entity.setMc(getCellStringValue(row.getCell(1)));
// 性质
entity.setXz(getCellStringValue(row.getCell(2)));
// 依据
entity.setYj(getCellStringValue(row.getCell(3)));
// 开始日期
entity.setKsrq(parseDateTimeCell(row.getCell(4)));
// 结束日期
entity.setJsrq(parseDateTimeCell(row.getCell(5)));
// 项目说明
entity.setSm(getCellStringValue(row.getCell(6)));
// 项目备注
entity.setBz(getCellStringValue(row.getCell(7)));
// 补助课时量 -> 基本课时量
String ksl = getCellStringValue(row.getCell(10));
if (ksl != null && !ksl.isEmpty()) {
try {
entity.setJbksl(Float.parseFloat(ksl));
} catch (NumberFormatException ignored) {
entity.setJbksl(0f);
}
}
// 天数:由开始与结束日期计算(含首尾,不足整天按自然日计)
if (entity.getKsrq() != null && entity.getJsrq() != null) {
long days = ChronoUnit.DAYS.between(
entity.getKsrq().toLocalDate(), entity.getJsrq().toLocalDate()) + 1;
entity.setTs((float) Math.max(days, 1));
}
// 至少要有名称才视为有效行
if (entity.getMc() != null && !entity.getMc().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")) {