package com.mtcarpenter.mall.common.util;

import lombok.Getter;

/**
 * 服务接口返回状态信息枚举定义
 *
 * @author yys
 */
@Getter
public enum ResultEnum {

    SUCCESS(0, "操作成功"),
    FAILURE(1, "操作失败"),
    FAILED(-1, "非法用户，请输入正确的accessToken"),
    SYS_ERROR(500, "系统开小差了，请稍后再试"),
    SYS_BREAK_ERROR(501, "系统服务中断，请稍后再试"),
    SYS_PASSWD_ERROR(502, "旧密码验证错误，请重试"),
    PERMISSION_DENIED(403, "没有权限"),
    ACCOUNT_ALREADY_LOGIN(404, "该账号已经在其他设备上登录"),
    NOT_LOGIN(401, "请先登录"),
    RELOGIN(402, "请重新登录"),
    LOGIN_ACCOUNT_MISS(407, "账号有错误，请检查账号信息"),
    LOGIN_PWD_MISS(408, "密码有误，请重新输入"),
    LOGIN_FORBIDED(406, "用户被禁用，请联系管理员"),
    TOKEN_EXPIRED(405, "登录已过期，请重新登录"),
    CODE_EXPIRED(409, "验证码不正确,请重新输入"),
    FAIL_LOGIN_LOGIN_NAME(600, "用户账号或密码不正确"),
    LOGINING_USER(601, "用户正在登陆系统，不能删除"),
    ASSAY_APPLIED(602, "请勿重复提交检验申请"),
    USER_IS_NOT(603, "用户已存在，请登录"),
    WECHAT_USER_NOT_EXIST(604, "投诉用户不存在"),
    ENCRYPTION_ERROR(605, "加密操作失败"),
    PARAMETER_NOT_NULL(606, "参数不能为空"),
    PARAMETER_INPUT_ERROR(620, "错误的输入参数！"),
    FILE_NOT_FOUND(607, "文件不存在"),
    USER_IS_HAVA(608, "用户登陆错误"),
    WRONG_PHONE(609, "手机号相关错误"),
    FORM_VALIDATION(610, "表单验证相关错误"),
    CODE_ERROR(611, "验证码错误或已过期"),
    FAILED_AUTHORIZE_LOGIN(612, "授权登录失败"),
    LOGIN_FAILED(613, "登录失败"),
    USER_IS_NUll(614, "用户数据不存在"),
    USER_IS_BINDING(615, "该手机号已被使用"),
    PAYORDER_ADD_ERROR(616, "支付订单新增失败"),
    PAYORDER_UPDATE_ERROR(617, "支付订单更新失败"),
    ORG_IS_NOT(618, "企业编码重复！"),
    CODE_DEL_DUPLICATE(619, "溯源码重复废弃！"),
    CODE_BATCH_DUPLICATE(621, "产品批次码重复！"),
    ORDER_PAY_DUPLICATE(622, "订单已支付,请勿重复支付！"),
    ORDER_PAY_COMPLETE(623, "订单已完成，请勿再次支付！"),
    GOODS_BUY_AUTH(624, "该用户购买商品超出购买权限！"),
    WX_AUTH_INFO_SUCCESS(625, "微信认证信息检测成功！"),
    WX_AUTH_INFO_FAIL(626, "微信认证信息检测失败！"),
    SIGNATURE_OK(718, "签名成功"),
    SIGNATURE_ERROR(719, "签名失败"),
    FILE_UPLOAD_ERROR(720, "文件上传失败!"),
    
    /** 基础管理错误信息 */
    ORG_EXIST(800, "部门重复！"),
    
    /** 店铺管理错误信息 */
    STORE_EXIST(830,"店铺已存在！"),
    STORE_LINKPHONE_EXIST(831,"店铺联系电话已存在！"),
    ROLE_NAME_EXIST(832,"职位重复!"),
    ROLE_CODE_EXIST(833,"职位编码重复!"),
    STORE_PERSON_EXIST(834,"职员联系电话已存在!"),
    STORE_NOT_DEL(835,"职位有关联职员,需要解除以后才能进行删除"),
    
    WAREHOUSE_NAME_EXIST(837,"仓库名称已存在!"),
    
    CUSTOMER_CODE_EXIST(840,"客户编码已存在!"),
    CUSTOMER_LINKPHONE_EXIST(841,"客户联系电话已存在!"),
    
    PROVIDER_CODE_EXIST(845,"供应商编码已存在!"),
    PROVIDER_LINKPHONE_EXIST(846,"供应商联系电话已存在!"),
    
    GOODS_NAME_EXIST(850,"规格型号商品已存在!"),
    GOODS_REGISTERCODE_EXIST(851,"商品登记证号已存在!"),
    GOODS_NOT_DEL(852,"商品有交易订单,该商品不能删除"),
    ORDER_CODE_DUPLICATE(869,"订单编号重复"),
    
    /** 库存管理错误信息  **/
    INVENTORYRECORD_STOCKPILEGUID_NULL(860,"库存id不能为空"),
    INVENTORYRECORD_GOODSGUID_NULL(861,"商品id不能为空"),
    INVENTORYRECORD_WAREHOUSEGUID_NULL(862,"仓库id不能为空"),
    INVENTORYRECORD_GOODSNAME_NULL(863,"商品名称不能为空"),
    INVENTORYRECORD_INITCOUNT_NULL(864,"盘点前库存数量不能为空"),
    INVENTORYRECORD_INVENTORYCOUNT_NULL(865,"盘存数量不能为空"),
    INVENTORYRECORD_DIFFCOUNT_NULL(866,"盘存差额不能为空"),
    INVENTORYRECORD_WAREHOUSENAME_NULL(867,"仓库名称不能为空"),
    INVENTORYRECORD_REMARK_NULL(868,"备注不能为空"),


    /** 参数设置管理模块错误信息  */
    DICT_TYPE_FOUND(900,"字典类型已经存在"),
    DICT_CODE_FOUND(901,"字典编码已经存在"),
    DICT_TYPE_USED(902,"字典类型被下级数据引用，请先删除关联的下级数据"),
    DICT_VALUE_FOUND(903,"字典值已经存在"),
    DICT_SEQ_FOUND(904,"字典序列号已经存在"),
    DICT_NOT_DEL(905,"基础字典类型不能删除"),
    DICT_CODE_NOTEDIT(906,"基础字典编码不能修改"),
    
    SELLER_ALREADY_EXIST(720, "该档口已经存在管理员，请选择其他档口");


    private Integer code;

    private String msg;

    ResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 通过枚举code获取枚举msg
     */
    public static String getMsgByCode(Integer code) {
        for (ResultEnum resultEnum : ResultEnum.values()) {
            if (code.equals(resultEnum.getCode())) {
                return resultEnum.getMsg();
            }
        }
        return null;
    }

    /**
     * 通过枚举code获取枚举对象
     */
    public static ResultEnum getResultEnumByCode(Integer code) {
        for (ResultEnum resultEnum : ResultEnum.values()) {
            if (code.equals(resultEnum.getCode())) {
                return resultEnum;
            }
        }
        return null;
    }

}
