package com.gree.mall.manager.bean.member;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gree.mall.manager.plus.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel
@Data
public class MemberSortBean {

    @ApiModelProperty(value = "会员排序对应值 ID=编号 SEX=性别 CREATE=注册时间 STATUS=状态")
    private String sortColumn;
    @ApiModelProperty(value = "true=升序 false=倒序")
    private boolean type = true ;


    public static void convertColumn(JSONArray array, LambdaQueryWrapper<User> memberLambdaQueryWrapper) {

        for(int i = 0; i < array.size(); i++) {
            MemberSortBean bean = array.getObject(i, MemberSortBean.class);
            switch (bean.getSortColumn()) {
                case "ID" :
                    memberLambdaQueryWrapper.orderBy(true, bean.isType(), User::getUserId);
                    break;
                case "SEX" :
                    memberLambdaQueryWrapper.orderBy(true, bean.isType(), User::getSex);
                    break;
                case "CREATE" :
                    memberLambdaQueryWrapper.orderBy(true, bean.isType(), User::getCreateTime);
                    break;
                case "STATUS" :
                    memberLambdaQueryWrapper.orderBy(true, bean.isType(), User::getStatus);
                    break;
                default :
            }
        }
    }
}
