Ejemplo n.º 1
0
        /// <summary>
        /// 根据设备id获取token
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public static string GetTokenByDeviceId(string imei)
        {
            Device d = DeviceLogic.GetDeviceByImei(imei);

            if (d == null)
            {
                return("");
            }
            return(GetToken(d.UserId));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加设备
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        public JsonResult AjaxAddDevice(string imei)
        {
            BaseResult res = new BaseResult();

            Device _d = DeviceLogic.GetDeviceByImei(imei);

            //验证设备是否存在
            if (_d == null)
            {
                //需先调用设备接口验证
                DeviceCheckModel dcm = DeviceData.CheckDevice(imei, 1);
                if (dcm.State != 0 && dcm.State != 1105)
                {
                    //  res.State = State.Falid;
                    string msg = dcm.Message;
                    res.Message = msg;
                    res.State   = State.Falid;
                    //res.Message = msg;
                    SaveUserLog(AuthUser.LoginName + "添加设备失败:" + msg, LogLevel.Error, AuthUser.LoginName, "AjaxAddDevice", "添加设备");
                    // return Json(res);;
                }
                else
                {
                    //添加设备表
                    Device d = new Device
                    {
                        UserId         = 0,
                        IconId         = 3,
                        Created        = DateTime.Now,
                        Imei           = imei,
                        Status         = (int)Status.Normal,
                        APIDeviceId    = dcm.DeviceId,
                        APIDeviceModel = dcm.Model
                    };
                    DeviceLogic.SaveDevice(d);
                    SaveUserLog(AuthUser.LoginName + "添加了设备:" + imei, LogLevel.Info, AuthUser.LoginName, "AjaxAddDevice", "添加设备");
                    res.State   = State.Success;
                    res.Message = "添加成功";
                    //return Json(res);
                }
            }
            else
            {
                res.State   = State.DeviceIn;
                res.Message = "设备已存在";
            }

            return(Json(res));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 提交用户设备绑定,解绑
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="type"></param>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public JsonResult AjaxSubUD(string imei, int type, string loginName)
        {
            BaseResult res = new BaseResult();

            //解绑
            if (type == 1)
            {
                Device d = DeviceLogic.GetDeviceByImei(imei);
                if (d == null)
                {
                    res.State   = State.NotFind;
                    res.Message = "该设备不存在!";
                    return(Json(res));
                }
                User user = UserLogic.GetUserById(d.UserId);
                if (user != null)
                {
                    BaseModel bm = DeviceData.UnBind(d.Imei);
                    if (bm.State == 0)
                    {
                        d.UserId = 0;
                        DeviceLogic.SaveDevice(d);
                        SaveUserLog(AuthUser.LoginName + "将设备:" + d.Imei + ",从用户" + user.LoginName + "中解绑了。", LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "解绑设备");
                        res.State   = State.Success;
                        res.Message = "解绑成功!";
                    }
                    else
                    {
                        res.State   = State.Falid;
                        res.Message = "解绑失败:" + bm.Message;
                    }
                }
            }
            //绑定
            else if (type == 2)
            {
                User user = UserLogic.GetUser(loginName);

                if (user == null)
                {
                    res.State   = State.NotFind;
                    res.Message = "用户不存在!";
                    return(Json(res));
                }
                user.IMEI = imei;
                //准备绑定设备
                Device d = preBindDevice(user);
                if (d != null)
                {
                    BaseModel bm = DeviceData.BindDevice(d.APIDeviceId.Value, user.APIUserId.Value);
                    if (bm.State != 0)
                    {
                        res.State   = State.Falid;
                        res.Message = "绑定失败:" + bm.Message;
                        return(Json(res));
                    }
                    d.UserId = user.Id;
                    DeviceLogic.SaveDevice(d);
                    SaveUserLog(AuthUser.LoginName + "将设备:" + d.Imei + "绑定到了用户" + loginName, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                    res.State   = 0;
                    res.Message = "绑定成功!";
                }
                else
                {
                    res.State   = State.Falid;
                    res.Message = "设备验证失败";
                }
            }
            else if (type == 3)
            {
                if (AuthUser.UserTypeId == 2 || AuthUser.UserTypeId == 1)
                {
                    Device _d = DeviceLogic.GetDeviceByImei(imei);
                    DeviceLogic.DelDevice(_d.Id);
                    res.State   = State.Success;
                    res.Message = "删除设备成功!";
                    SaveUserLog(AuthUser.LoginName + "删除了设备:" + imei, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                }
                else
                {
                    res.State   = State.Falid;
                    res.Message = "暂无删除设备的权限";
                    SaveUserLog(AuthUser.LoginName + "删除设备失败:" + imei, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                }
            }
            return(Json(res));
        }