package com.app.framework.core.log.result;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 日志结果对象
 * 	操作类型和操作的列
 */
public class LogResult {

	/** 操作人ID */
	private Long 	operatorId;

	/** 操作人姓名 */
	private String	operatorName;

	/** 操作类型 */
	private String 	operType;

	/** 操作字段集合 */
	private List<LogColumn> logColumns = new ArrayList<LogColumn>();

	public LogResult() {}

	public LogResult(String operType) {
		this.operType = operType;
	}

	public Long getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(Long operatorId) {
		this.operatorId = operatorId;
	}

	public String getOperatorName() {
		return operatorName;
	}

	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}

	public String getOperType() {
		return operType;
	}

	public void setOperType(String operType) {
		this.operType = operType;
	}

	public LogResult addColumn(String key, String column, Object v) {
		logColumns.add(new LogColumn(key, column, v));
		return this;
	}
	public LogResult addColumn(LogColumn column) {
		logColumns.add(column);
		return this;
	}

	public List<LogColumn> getLogColumns() {
		return logColumns;
	}

	public void setLogColumns(List<LogColumn> logColumns) {
		this.logColumns = logColumns;
	}

	/**
	 * 处理 columnList
	 * @return
	 */
	public String processLogColmnList() {
		StringBuilder str = new StringBuilder();
		for (int i = 0, size = logColumns.size(); i < size; i++) {
			LogColumn column = logColumns.get(i);
			if(StringUtils.isNotBlank(column.getColumnName())){
				str.append(column.getColumnName());
				str.append(":");
			}
			if(!column.isColumnValueEmpty()) {
				str.append(column.getColumnValue());
			}
			if (i < size - 1)
				str.append(",");
		}
		return str.toString();
	}
}
