refactor gao module

This commit is contained in:
Timi
2026-08-06 10:52:50 +08:00
parent 568563475e
commit 1709316ce1
67 changed files with 1770 additions and 3319 deletions
@@ -0,0 +1,65 @@
package com.imyeyu.api.util;
import com.imyeyu.api.modules.user.bean.Gender;
import com.imyeyu.java.TimiJava;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.IOException;
import java.util.List;
///
///
/// @author 夜雨
/// @since 2026-08-04 15:57
public abstract class BaseXSSFBuilder<T> {
public abstract byte[] build(List<T> list) throws IOException;
protected CellStyle createTitleStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
font.setFontHeightInPoints((short) 14);
style.setFont(font);
return style;
}
protected CellStyle createHeaderStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
style.setFont(font);
return style;
}
protected void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
Row row = sheet.createRow(rowIndex);
for (int index = 0; index < values.length; index++) {
row.createCell(index).setCellValue(values[index]);
if (style != null) {
row.getCell(index).setCellStyle(style);
}
}
}
protected String text(Object obj) {
if (obj == null) {
return "";
}
return TimiJava.defaultIfEmpty(obj.toString(), "");
}
protected String gender(Gender gender) {
if (gender == null) {
return "";
}
return switch (gender) {
case MALE -> "";
case FEMALE -> "";
};
}
}