package com.sunxung.factoring.entity;

import java.util.HashMap;
import java.util.Map;

/**
 * @className:ExcelIOBaseModel
 * @description:Excel导入导出基础类
 * @author:杜小姣
 * @e-mail:1261237207@qq.com
 * @date:2018年4月9日 上午11:54:40
 */
public class ExcelIOBaseModel {

    /** 错误信息 */
    protected Map<String, String> errorMessages;

    public String getErrorMessage(String key) {
        if (errorMessages != null && errorMessages.size() > 0) {
            return errorMessages.get(key);
        }
        return null;
    }

    public boolean isError() {
        return errorMessages != null && errorMessages.size() > 0;
    }

    public String getErrorMessage() {
        return (errorMessages == null || errorMessages.size() < 1) ? null : stitchingMsg();
    }

    private String stitchingMsg() {
        StringBuilder errorMsg = new StringBuilder();
        for (String dataKey : errorMessages.keySet()) {
            errorMsg.append(errorMessages.get(dataKey));
        }
        return errorMsg.toString();
    }

    public Map<String, String> getErrorMessages() {
        return (errorMessages == null || errorMessages.size() < 1) ? null : errorMessages;
    }

    public void putErrorMessage(String key, String value) {
        if (errorMessages == null)
            errorMessages = new HashMap<String, String>();
        errorMessages.put(key, value);
    }
}
