package com.iformall.domain.po;

import lombok.Data;
import javax.persistence.*;
import java.util.*;
import java.math.*;
import javax.persistence.Transient;
import java.util.List;
import javax.persistence.Id;
import java.io.Serializable;

@Table(name = "mall_user_action")
@Data
public class MallUserAction implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
    protected Long id;
    
    @Transient
    protected List<Long> ids;
    @Transient
    protected String sortColumns;

    @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
    private String tenantId;
	@io.swagger.annotations.ApiModelProperty(value="用户ID",name="userId")
	private Long userId;
	@io.swagger.annotations.ApiModelProperty(value="类型 0-controller, 1-service",name="type")
	private Integer type;
	@io.swagger.annotations.ApiModelProperty(value="",name="ip")
	private String ip;
	@io.swagger.annotations.ApiModelProperty(value="功能描述",name="actionDesc")
	private String actionDesc;
	@io.swagger.annotations.ApiModelProperty(value="访问时间",name="actionTime")
	private Date actionTime;



	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
            ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,UserId_ASC("`user_id` ASC"),UserId_DESC("`user_id` DESC")
			,Type_ASC("`type` ASC"),Type_DESC("`type` DESC")
			,Ip_ASC("`ip` ASC"),Ip_DESC("`ip` DESC")
			,Desc_ASC("`action_desc` ASC"),Desc_DESC("`action_desc` DESC")
			,ActionTime_ASC("`action_time` ASC"),ActionTime_DESC("`action_time` DESC")
	;
		private String value;
		Field(String value){
			this.value = value;
		}
		public String getValue() {
			return value;
		}
		public void setCol(String value) {
			this.value = value;
		}
		@Override
		public String toString() {
			return this.getValue();
		}
	}
	
	public void setSortColumns(MallUserAction.Field... fields)
	{
		if (fields == null || fields.length == 0) {
			return;
		}
		for (int k = 0; k < fields.length; k++) {
			if (fields[k] == null) {
				return;
			}
		}
		StringBuilder sb = new StringBuilder(fields[0].toString());
		for (int k = 1; k < fields.length; k++) {
			sb.append(",");
			sb.append(fields[k].toString());
		}
        this.sortColumns = sb.toString();
	}
	
	public void setSortColumns(String sortColumns)
	{
		if (sortColumns == null || "".equals(sortColumns.trim())) {
			return;
		}
		if (sortColumns.contains(",")) {
			String[] cols = sortColumns.split(",");
			java.util.List<Field> fList = new java.util.ArrayList();
			for (int k = 0; k < cols.length; k++) {
				fList.add(Field.valueOf(cols[k]));
			}
			this.setSortColumns(fList.toArray(new Field[fList.size()]));
		} else {
			this.setSortColumns(Field.valueOf(sortColumns));
		}
	}
}
