package com.huimv.env.admin.common.utils;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project : huimv-breed
 * @Package : IntelliJ IDEA
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2022/9/27
 **/
@Component
public class ResultUtil {

    public static Result result(int rows){
        if(rows == 0){
            return new Result(ResultCode.FAIL,"处理失败.");
        }else{
            return new Result(ResultCode.SUCCESS,"处理成功.");
        }
    }

    public static Result list(List o){
        if(ObjectUtil.isNotEmpty(o) ){
            return new Result(ResultCode.SUCCESS,o);
        }else{
            return new Result(ResultCode.FAIL,new ArrayList<>());
        }
    }
    public static Result getResult(Integer rows){
        if(rows > 0){
            return new Result(ResultCode.SUCCESS);
        }else{
            return new Result(ResultCode.FAIL);
        }
    }

    public static Result addResult(Integer rows){
        if(rows > 0){
            return new Result(10000, "添加成功",true);
        }else{
            return new Result(10001, "添加失败",false);
        }
    }
    public static Result updateResult(Integer rows){
        if(rows > 0){
            return new Result(10000, "修改成功",true);
        }else{
            return new Result(10001, "修改失败",false);
        }
    }
    public static Result deleteResult(Integer rows){
        if(rows > 0){
            return new Result(10000, "删除成功",true);
        }else{
            return new Result(10001, "删除失败",false);
        }
    }

    public static Result exist(){
       return new Result(10001, "该数据已存在",false);
    }
    public static Result isNull(){
        return new Result(ResultCode.DATA_NULL);
    }
}
