Commit dedc1814 by zhangxingmin

配置

parent 69b63b70
...@@ -79,6 +79,7 @@ public class ApiExcelServiceImpl implements ApiExcelService { ...@@ -79,6 +79,7 @@ public class ApiExcelServiceImpl implements ApiExcelService {
response.setMap(result); response.setMap(result);
return Result.success(response); return Result.success(response);
} catch (Exception e) { } catch (Exception e) {
log.info("Excel解析异常:{}",e.getMessage());
throw new BusinessException("Excel解析异常!"); throw new BusinessException("Excel解析异常!");
} }
} }
......
...@@ -5,11 +5,66 @@ import java.lang.annotation.Retention; ...@@ -5,11 +5,66 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
// Excel集合注解 /**
@Retention(RetentionPolicy.RUNTIME) * 增强的Excel集合注解,支持复杂数据结构
*/
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelCollection { public @interface ExcelCollection {
Class<?> type(); // 集合元素类型
int startRow(); // 集合起始行 /**
int endRow() default -1; // 集合结束行(-1表示自动检测) * 集合元素类型
*/
Class<?> type();
/**
* 起始行(0-based)
*/
int startRow();
/**
* 结束行(0-based,-1表示自动检测)
*/
int endRow() default -1;
/**
* 每个对象占用的行数(默认1行)
*/
int rowSpan() default 1;
/**
* 数据分组模式
*/
GroupMode groupMode() default GroupMode.SINGLE_ROW;
/**
* 分组键字段(用于GROUP_BY_KEY模式)
*/
String groupKey() default "";
// 在 ExcelCollection 注解中添加
String endFlagField() default ""; // 用于判断集合结束的字段名
/**
* 下一个对象的第一个字段标题,用于判断集合结束
*/
String nextFieldTitle() default "";
/**
* 数据分组模式枚举
*/
enum GroupMode {
/**
* 单行模式:每行一个对象
*/
SINGLE_ROW,
/**
* 固定行跨度:每个对象占用固定行数
*/
FIXED_ROW_SPAN,
/**
* 按键分组:根据指定字段的值进行分组
*/
GROUP_BY_KEY
}
} }
\ No newline at end of file
...@@ -5,14 +5,110 @@ import java.lang.annotation.Retention; ...@@ -5,14 +5,110 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
// Excel字段注解 /**
@Retention(RetentionPolicy.RUNTIME) * 通用Excel字段注解
*/
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelField { public @interface ExcelField {
String name(); // 标题名称
int titleRow(); // 标题所在行 /**
int titleCol(); // 标题所在列 * 字段名称(用于日志和错误提示)
int valueRow() default -1; // 值所在行(默认与标题同行) */
int valueCol() default -1; // 值所在列(默认标题列+1) String name() default "";
String dateFormat() default "yyyy/MM/dd"; // 日期格式
/**
* 标题行(0-based)
*/
int titleRow() default -1;
/**
* 标题列(0-based)
*/
int titleCol() default -1;
/**
* 值行(0-based,-1表示使用titleRow)
*/
int valueRow() default -1;
/**
* 值列(0-based,-1表示使用titleCol + 1)
*/
int valueCol() default -1;
/**
* 日期格式
*/
String dateFormat() default "yyyy/MM/dd";
/**
* 是否必须
*/
boolean required() default false;
/**
* 默认值
*/
String defaultValue() default "";
/**
* 字段类型
*/
FieldType fieldType() default FieldType.SINGLE;
/**
* 字段类型枚举
*/
enum FieldType {
/**
* 单值字段
*/
SINGLE,
/**
* 列表字段(水平方向)
*/
HORIZONTAL_LIST,
/**
* 列表字段(垂直方向)
*/
VERTICAL_LIST
}
/**
* 列表字段配置(当fieldType为LIST时使用)
*/
ListConfig listConfig() default @ListConfig;
@interface ListConfig {
/**
* 起始行(0-based)
*/
int startRow() default -1;
/**
* 起始列(0-based)
*/
int startCol() default -1;
/**
* 结束行(0-based,-1表示自动检测)
*/
int endRow() default -1;
/**
* 结束列(0-based,-1表示自动检测)
*/
int endCol() default -1;
/**
* 方向:true为水平,false为垂直
*/
boolean horizontal() default true;
/**
* 元素类型
*/
Class<?> elementType() default String.class;
}
} }
...@@ -5,10 +5,35 @@ import java.lang.annotation.Retention; ...@@ -5,10 +5,35 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
// Excel Sheet注解 /**
@Retention(RetentionPolicy.RUNTIME) * 通用Excel Sheet注解
*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelSheet { public @interface ExcelSheet {
int sheetIndex() default 0; // Sheet索引
String sheetName() default ""; // Sheet名称 /**
* Sheet索引(0-based)
*/
int sheetIndex() default 0;
/**
* Sheet名称
*/
String sheetName() default "";
/**
* 数据起始行(0-based)
*/
int dataStartRow() default 0;
/**
* 是否跳过空行
*/
boolean skipEmptyRows() default true;
/**
* 最大行数限制
*/
int maxRows() default 1000;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment