package com.qmth.teachcloud.common.bean.result;

import io.swagger.annotations.ApiModelProperty;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: excel结果
 * @Author: CaoZixuan
 * @Date: 2024-03-26
 */
public class ExcelResult<T> {

    @ApiModelProperty("数据")
    private List<T> datasource;

    @ApiModelProperty("是否成功")
    private boolean success;

    /**
     * 报错信息map : key为行数，value为报错信息
     */
    @ApiModelProperty("报错信息map")
    private Map<Integer, String> errorMap;

    public List<T> getDatasource() {
        return datasource;
    }

    public void setDatasource(List<T> datasource) {
        this.datasource = datasource;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Map<Integer, String> getErrorMap() {
        return errorMap;
    }

    public void setErrorMap(Map<Integer, String> errorMap) {
        this.errorMap = errorMap;
    }

    /**
     * 获取报错信息
     *
     * @return 报错文本信息
     */
    public String getErrorMsg() {
        return errorMap.entrySet().stream().map(entry -> String.format("第[%s]行,%s", entry.getKey(), entry.getValue()))
                .collect(Collectors.joining(System.lineSeparator()));
    }
}
