package cn.com.ty.lift.ud.common;

import java.io.Serializable;

import javax.validation.constraints.NotNull;

import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 排序对象
 * @author 90001463
 * @date 2019/07/08
 */
@ApiModel(description = "排序对象")
public final class Sorting implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @NotNull
    @ApiModelProperty("排序字段")
    private String orderBy;

    @ApiModelProperty("排序方式：asc,desc")
    private String order = "asc";

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public Order toOrder() {
        Direction direction;
        if ("asc".equalsIgnoreCase(order)) {
            direction = Direction.ASC;
        } else if ("desc".equalsIgnoreCase(order)) {
            direction = Direction.DESC;
        } else {
            direction = Direction.ASC;
        }
        return new Order(direction, orderBy);
    }

}
