Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

满足继承将ExcelHeader 中order 设置为唯一 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

quadimodo
Copy link

你好,我一直在使用你的excel工具类,一直都很好用,但是最近有一个需求,我发现你的工具类没法满足,就是我想子类如果有和父类相同的order ,可以覆盖掉父类的标题。父类是一个通用字段类,但是存在某些字类只需要导出部分字段。如下面的类,有两个order 为7,因此字类的标题为7的字段可以顶掉父类为7的字段达到我想要的结果

//查询用户基础数据
Set<BasePersonInfoVo> basePersonInfoVos = searcherChain.doChainSearch(Stream.of(tagNode, village).collect(Collectors.toList()));
       //枚举中存在具体类名便于反射获取对象
        Class<?> baseReportClass = Class.forName(extraInfoEnum.getClassName());
        AtomicInteger atomicInteger = new AtomicInteger(1);
        return basePersonInfoVos.stream()
                .map(personInfo -> {
                    try {
                       //获取子对象
                        BaseReport report = (BaseReport) baseReportClass.newInstance();
                        report.setNum(atomicInteger.getAndIncrement());
                        //将公共的参数导入
                        report.convertPerson2Report(personInfo, villageName);
                        return report;
                    } catch (InstantiationException | IllegalAccessException e) {
                        LOGGER.error(e.getMessage(), e);
                        throw new RuntimeException(e);
                    }
                })
                .collect(Collectors.toList());
/**
* 父类
**/
public abstract class BaseReport implements IExcelDocument {

    @ExcelField(title = "序号", order = 1)
    private Integer num;

    @ExcelField(title = "姓名", order = 2)
    private String name;

    @ExcelField(title = "性别", order = 3)
    private String sex;

    @ExcelField(title = "身份证号", order = 4)
    private String identity;

    @ExcelField(title = "户籍地", order = 5)
    private String permanentAddress;

    @ExcelField(title = "现居地址", order = 6)
    private String currentHomeAddress;

    @ExcelField(title = "身份", order = 7)
    private String career;

    private String village;

   //getter and setter

}

/**
 * 字类
 */
public class ChildReport extends BaseReport {

    @ExcelField(title = "重写父类order", order = 7)
    private String sentenceReson;

    @ExcelField(title = "时间", order = 8, writeConverter = DateWithoutTime.class)
    private Date sentenceTime;

    @ExcelField(title = "期限", order = 9)
    private String sentenceRange;

    @ExcelField(title = "地点", order = 10)
    private String sentencePlace;
   
  //getter and setter

2. 修改Utils.getHeaderList() 方法,使用set代替list 获取标题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant