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 = "wx_score_history")
@Data
public class WxScoreHistory implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
    protected Long id;
    
    @Transient
    protected List<String> ids;
    @Transient
    protected String sortColumns;
	
	
	/**租户ID**/
	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	/**会员ID**/
	@io.swagger.annotations.ApiModelProperty(value="会员ID",name="cUserId")
	private Long cUserId;
	/**创建日期**/
	@io.swagger.annotations.ApiModelProperty(value="创建日期",name="createDate")
	private Date createDate;
	/**成长值类型(1:每日登录, 2:消费,3:绑车牌,4:连接wifi,5:微信昵称授权,6:微信手机授权)**/
	@io.swagger.annotations.ApiModelProperty(value="成长值类型",name="scoreType")
	private Integer scoreType;
	/**有效日期**/
	@io.swagger.annotations.ApiModelProperty(value="有效日期",name="validDate")
	private Date validDate;
	/**单据号**/
	@io.swagger.annotations.ApiModelProperty(value="单据号",name="orderId")
	private Long orderId;
	/**支付方式**/
	@io.swagger.annotations.ApiModelProperty(value="支付方式",name="payType")
	private Integer payType;
	/**支付金额**/
	@io.swagger.annotations.ApiModelProperty(value="支付金额",name="payAmount")
	private Integer payAmount;
	/**积分**/
	@io.swagger.annotations.ApiModelProperty(value="积分",name="scoreAmount")
	private Integer scoreAmount;
	/**扣减原因**/
	@io.swagger.annotations.ApiModelProperty(value="扣减原因",name="reason")
	private String reason;

	@Transient
	@io.swagger.annotations.ApiModelProperty(value="开始时间",name="startdate")
	private Date startdate;

	@Transient
	@io.swagger.annotations.ApiModelProperty(value="结束时间",name="enddate")
	private Date enddate;

	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
			,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,CUserId_ASC("`c_user_id` ASC"),CUserId_DESC("`c_user_id` DESC")
			,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC")
			,ScoreType_ASC("`score_type` ASC"),ScoreType_DESC("`score_type` DESC")
			,ValidDate_ASC("`valid_date` ASC"),ValidDate_DESC("`valid_date` DESC")
			,OrderId_ASC("`order_id` ASC"),OrderId_DESC("`order_id` DESC")
			,PayType_ASC("`pay_type` ASC"),PayType_DESC("`pay_type` DESC")
			,PayAmount_ASC("`pay_amount` ASC"),PayAmount_DESC("`pay_amount` DESC")
			,ScoreAmount_ASC("`score_amount` ASC"),ScoreAmount_DESC("`score_amount` 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(WxScoreHistory.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));
		}
	}
}
