package com.dayou.report.html;

import lombok.Data;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

import static com.dayou.report.html.TableHTML.TD;

/**
 * 类说明：
 *
 * @author: wucl
 * @since: 2023/9/14
 * created with IntelliJ IDEA.
 */
@Data
public abstract class DataToHtmlBO {

    public String dataToHtml(){
        StringBuilder stringBuilder = new StringBuilder("<tr>");
        List<Field> fields = Arrays.asList(this.getClass().getDeclaredFields());
        fields.stream().forEach(x->{
            x.setAccessible(true);
            try {
                stringBuilder.append(TD.replace("content", String.valueOf(x.get(this))));
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        });
        stringBuilder.append("</tr>");
        return stringBuilder.toString();
    }

}
