package com.iformall.domain.po;

import lombok.Data;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

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

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

	@Transient
	@io.swagger.annotations.ApiModelProperty(value="手机号",name="phone")
	private String phone;

	@Transient
	@io.swagger.annotations.ApiModelProperty(value="姓名",name="name")
	private String name;

	@Transient
	@io.swagger.annotations.ApiModelProperty(value="花费Str",name="spendStr")
	private String spendStr;

	/**租户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="creditAmount")
	private Integer creditAmount;
	/**每笔积分明细*/
	@io.swagger.annotations.ApiModelProperty(value="每笔积分明细",name="creditNum")
	private Integer creditNum;
	/**积分类型*/
	@io.swagger.annotations.ApiModelProperty(value="积分类型 1每日登录,2消费,3绑车牌,4连接WIFI,5微信用户昵称授权,6微信用户手机授权,7完善个人信息,8积分导入,10新增积分,11积分兑换,12消费积分 注：11积分兑换改为走订单接口",name="creditType")
	private Integer creditType;
	/**创建日期*/
	@io.swagger.annotations.ApiModelProperty(value="创建日期",name="createDate")
	private Date createDate;
	/**小票URL*/
	@io.swagger.annotations.ApiModelProperty(value="小票URL",name="receiptUrl")
	private String receiptUrl;
	/**操作人类型*/
	@io.swagger.annotations.ApiModelProperty(value="操作人类型 1:C端用户,2:A端会员,3:B端用户,4:A端用户",name="operatorType")
	private Integer operatorType;
	/**操作人ID*/
	@io.swagger.annotations.ApiModelProperty(value="操作人ID",name="operatorId")
	private Long operatorId;
	/**商户ID*/
	@io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId")
	private Long merchantId;
	/**券ID（积分兑换券时生成）*/
	@io.swagger.annotations.ApiModelProperty(value="券ID（积分兑换券时生成）",name="couponId")
	private Long couponId;
	/**业态ID（计算新增积分时使用）*/
	@io.swagger.annotations.ApiModelProperty(value="业态ID（计算新增积分时使用）",name="businessId")
	private Long businessId;
	/**花费*/
	@io.swagger.annotations.ApiModelProperty(value="花费",name="spend")
	private Integer spend;
	/**兑换用途*/
	@io.swagger.annotations.ApiModelProperty(value="兑换用途",name="changePurpose")
	private String changePurpose;



	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")
			,CreditAmount_ASC("`credit_amount` ASC"),CreditAmount_DESC("`credit_amount` DESC")
			,CreditNum_ASC("`credit_num` ASC"),CreditNum_DESC("`credit_num` DESC")
			,CreditType_ASC("`credit_type` ASC"),CreditType_DESC("`credit_type` DESC")
			,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC")
			,ReceiptUrl_ASC("`receipt_url` ASC"),ReceiptUrl_DESC("`receipt_url` DESC")
			,OperatorType_ASC("`operator_type` ASC"),OperatorType_DESC("`operator_type` DESC")
			,OperatorId_ASC("`operator_id` ASC"),OperatorId_DESC("`operator_id` DESC")
			,MerchantId_ASC("`merchant_id` ASC"),MerchantId_DESC("`merchant_id` DESC")
			,CouponId_ASC("`coupon_id` ASC"),CouponId_DESC("`coupon_id` DESC")
			,BusinessId_ASC("`business_id` ASC"),BusinessId_DESC("`business_id` DESC")
			,Spend_ASC("`spend` ASC"),Spend_DESC("`spend` 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(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(",");
			List<Field> fList = new 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));
		}
	}
}
