Exemple #1
0
        public HttpResponseMessage Detail(string appId, string token, int Id)
        {
            ReturnResult obj = new ReturnResult();

            //dynamic json = jData;
            //string appId = json.appId;
            //string token = json.token;
            //int Id = Convert.ToInt32(json.Id);
            try
            {
                var data = db.Equipment.Where(d => d.token == token && d.Id == Id).SingleOrDefault();
                if (data != null)
                {
                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = JsonHelp.ObjectToString(data);
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "设备详情!", "Detail", appId, "Equipment");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #2
0
        public HttpResponseMessage List(string appId, string token, string username)
        {
            ReturnResult obj = new ReturnResult();

            //dynamic json = jData;
            //string appId = json.appId;
            //string token = json.token;
            //string username = json.username;
            try
            {
                var data = db.FeedBack.Where(d => d.token == token && d.username == username).SingleOrDefault();
                if (data != null)
                {
                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = JsonHelp.ObjectToString(data);
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "反馈列表!", "List", appId, "FeedBack");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #3
0
        public HttpResponseMessage Change(JObject jData)
        {
            ReturnResult obj      = new ReturnResult();
            dynamic      json     = jData;
            string       appId    = json.appId;
            string       token    = json.token;
            string       parent   = json.parent;
            string       name     = json.name;
            string       type     = json.type;
            string       contacts = json.contacts;
            string       phone    = json.phone;

            try
            {
                var model = db.NodeList.Where(d => d.token == token && d.name == name && d.type == type).SingleOrDefault();
                if (model != null)
                {
                    model.appId       = json.appId;
                    model.contacts    = json.contacts;
                    model.createDate  = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    model.description = "";
                    model.name        = json.name;
                    model.parent      = json.parent;
                    model.phone       = json.phone;
                    model.token       = json.token;
                    model.type        = json.type;

                    db.SaveChanges();

                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = "";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点修改!", "Change", json.appId, "Node");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "no";
                    obj.data   = "修改失败";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点修改!", "Change", json.appId, "Node");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }



            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #4
0
        public HttpResponseMessage Change(JObject jData)
        {
            ReturnResult obj      = new ReturnResult();
            dynamic      json     = jData;
            string       appId    = json.appId;
            string       token    = json.token;
            string       clientId = json.clientId;
            string       type     = json.type;
            string       model    = json.model;
            string       name     = json.name;
            string       sn       = json.sn;
            string       code     = json.code;

            try
            {
                var data = db.Equipment.Where(d => d.clientId == clientId && d.token == token && d.sn == sn).SingleOrDefault();
                if (data != null)
                {
                    data.appId    = appId;
                    data.clientId = clientId;
                    data.token    = token;
                    data.type     = type;
                    data.model    = model;
                    data.name     = name;
                    data.sn       = sn;
                    data.code     = code;

                    db.SaveChanges();


                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = "修改设备信息";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "修改设备信息!", "Change", appId, "Equipment");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "no";
                    obj.data   = "失败";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "修改设备信息!", "Change", appId, "Equipment");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #5
0
        public HttpResponseMessage Login(JObject jData)
        {
            //定义
            ResponseResult obj      = new ResponseResult();
            dynamic        json     = jData;
            string         username = json.phone;
            string         password = json.password;
            string         appId    = json.appId;
            var            model    = GetLoginModel(username, password);

            if (model != null)
            {
                if (ValidateTicket(model.token))
                {
                    obj.Token = model.token;
                }
                else
                {
                    var token = Guid.NewGuid().ToString("N");
                    model.token      = token;
                    model.expireDate = DateTime.Now.AddDays(7);
                    obj.Token        = token;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
                    }
                }
                obj.status = "0";
                obj.msg    = "ok";
                obj.data   = JsonHelp.ObjectToString(model);
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "用户登录", "Login", appId, "Account");
            }
            else
            {
                obj.status = "2";
                obj.msg    = "用户名或密码错误";
                obj.data   = "";
                obj.Token  = "";
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "用户名或密码错误", "Login", appId, "Account");
            }
            var resultObj = JsonConvert.SerializeObject(obj, Formatting.Indented);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #6
0
        public HttpResponseMessage Create(JObject jData)
        {
            ReturnResult obj      = new ReturnResult();
            dynamic      json     = jData;
            string       appId    = json.appId;
            string       token    = json.token;
            string       clientId = json.clientId;
            string       type     = json.type;
            string       model    = json.model;
            string       name     = json.name;
            string       sn       = json.sn;
            string       code     = json.code;

            try
            {
                Equipment data = new Equipment();
                data.appId    = appId;
                data.clientId = clientId;
                data.token    = token;
                data.type     = type;
                data.model    = model;
                data.name     = name;
                data.sn       = sn;
                data.code     = code;

                db.Equipment.Add(data);
                db.SaveChanges();


                obj.status = "0";
                obj.msg    = "ok";
                obj.data   = "设备入库";
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "设备入库!", "Create", appId, "Equipment");
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #7
0
        public HttpResponseMessage Change(JObject jData)
        {
            ReturnResult obj      = new ReturnResult();
            dynamic      json     = jData;
            string       token    = json.token;
            string       appId    = json.appId;
            string       clientId = json.clientId;
            string       name     = json.name;
            string       status   = json.status;
            string       module   = json.module;
            string       contacts = json.contacts;
            string       phone    = json.phone;
            string       email    = json.email;
            string       address  = json.address;

            try
            {
                Merchant model = db.Merchant.Where(d => d.token == token).Where(d => d.phone == phone).Where(d => d.name == name).SingleOrDefault();
                model.address  = address;
                model.clientId = clientId;
                model.token    = token;
                model.name     = name;
                model.status   = status;
                model.module   = module;
                model.email    = email;
                model.phone    = phone;
                model.appId    = appId;
                model.contacts = contacts;

                db.SaveChanges();
                obj.status = "0";
                obj.msg    = "成功";
                obj.data   = JsonHelp.ObjectToString(model);
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "商户修改", "Change", appId, "Merchant");
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #8
0
        public HttpResponseMessage Create(JObject jData)
        {
            ReturnResult obj       = new ReturnResult();
            dynamic      json      = jData;
            string       appId     = json.appId;
            string       token     = json.token;
            string       parent    = json.parent;
            string       name      = json.name;
            string       shortname = json.shortname;
            string       level     = json.level;
            string       type      = json.type;

            District model = new District();

            model.appId       = appId;
            model.token       = token;
            model.parent      = parent;
            model.name        = name;
            model.shortname   = shortname;
            model.level       = level;
            model.type        = type;
            model.createDate  = DateTime.Now;
            model.description = "";


            try
            {
                db.District.Add(model);
                db.SaveChanges();

                obj.status = "0";
                obj.msg    = "ok";
                obj.data   = model.Id.ToString();
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "区域创建!", "Create", appId, "District");
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #9
0
        public HttpResponseMessage GetToken(string user, string pwd, string appId)
        {
            ResponseResult obj = new ResponseResult();

            try
            {
                var model = GetLoginModel(user, pwd);
                if (model != null && model.token != "")
                {
                    string token = Guid.NewGuid().ToString("N");
                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = model.ToString();
                    obj.Token  = token;

                    model.token = token;
                    db.SaveChanges();
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "获取token", "GetToken", appId, "Account");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "用户名或密码错误";
                    obj.data   = "";
                    obj.Token  = "";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "重新获取失败(用户名或密码错误)!", "GetToken", appId, "Account");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.Token  = "";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj, Formatting.Indented);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #10
0
        public HttpResponseMessage List(JObject jData)
        {
            ReturnResult obj    = new ReturnResult();
            dynamic      json   = jData;
            string       appId  = json.appId;
            string       token  = json.token;
            string       parent = json.parent;
            string       type   = json.tyep;

            try
            {
                var data = db.NodeList.Where(d => d.token == token && d.parent == parent && d.type == type).SingleOrDefault();
                if (data != null)
                {
                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = JsonHelp.ObjectToString(data);
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点列表!", "List", appId, "Node");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "no";
                    obj.data   = "没有数据";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点列表!", "List", appId, "Node");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }



            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #11
0
        public HttpResponseMessage Delete(JObject jData)
        {
            ReturnResult obj   = new ReturnResult();
            dynamic      json  = jData;
            string       appId = json.appId;
            string       token = json.token;
            int          Id    = Convert.ToInt32(json.Id);

            try
            {
                var data = db.NodeList.Where(d => d.Id == Id && d.token == token).SingleOrDefault();
                if (data != null)
                {
                    db.NodeList.Remove(data);
                    db.SaveChanges();

                    obj.status = "0";
                    obj.msg    = "ok";
                    obj.data   = "删除设备";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点删除!", "Delete", appId, "Node");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "no";
                    obj.data   = "没有数据";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点删除!", "Delete", appId, "Node");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #12
0
        public HttpResponseMessage Register([FromBody] Account users)
        {
            ResponseResult obj   = new ResponseResult();
            Account        model = new Account();
            string         token = Guid.NewGuid().ToString("N");

            model.name = users.name;
            string password = users.Password;

            model.Password    = EncryptHelper.MD5Encrypt32(password);
            model.phone       = users.phone;
            model.status      = 1;
            model.token       = token;
            model.expireDate  = DateTime.Now.AddDays(1);
            model.email       = users.email;
            model.createDate  = DateTime.Now.ToString();
            model.description = users.description;
            model.appId       = users.appId;
            db.Account.Add(model);
            try
            {
                db.SaveChanges();
                obj.status = "0";
                obj.msg    = "OK";
                obj.Token  = token;
                obj.data   = model.ToString();
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "注册", "Register", users.appId, "Account");
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.Token  = "";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #13
0
        public HttpResponseMessage List(string token, string appId, string status)
        {
            ReturnResult obj = new ReturnResult();
            //dynamic json = jData;
            //string token = json.token;
            //string appId = json.appId;
            //string status = json.status;
            Merchant model = new Merchant();

            try
            {
                model = db.Merchant.Where(d => d.token == token && d.status == status).SingleOrDefault();
                if (model != null)
                {
                    obj.status = "0";
                    obj.msg    = "成功";
                    obj.data   = JsonHelp.ObjectToString(model);
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "商户列表信息", "List", appId, "Merchant");
                }
                else
                {
                    obj.status = "2";
                    obj.msg    = "失败!";
                    obj.data   = "";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "商户列表信息", "List", appId, "Merchant");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #14
0
        public HttpResponseMessage Create(JObject jData)
        {
            NodeList     model = new NodeList();
            ReturnResult obj   = new ReturnResult();
            dynamic      json  = jData;

            model.appId       = json.appId;
            model.contacts    = json.contacts;
            model.createDate  = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            model.description = "";
            model.name        = json.name;
            model.parent      = json.parent;
            model.phone       = json.phone;
            model.token       = json.token;
            model.type        = json.type;

            try
            {
                db.NodeList.Add(model);
                db.SaveChanges();

                obj.status = "0";
                obj.msg    = "ok";
                obj.data   = model.Id.ToString();
                UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "节点创建!", "Create", json.appId, "Node");
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #15
0
        public HttpResponseMessage UserModifyPwd(JObject jData)
        {
            ResponseResult obj    = new ResponseResult();
            dynamic        json   = jData;
            string         user   = json.phone;
            string         oldpwd = json.oldpwd;
            string         newpwd = json.newpwd;
            string         appId  = json.appId;

            try
            {
                oldpwd = EncryptHelper.MD5Encrypt32(oldpwd);
                newpwd = EncryptHelper.MD5Encrypt32(newpwd);
                var users = db.Account.Where(d => d.phone == user && d.Password == oldpwd).SingleOrDefault();
                if (users != null)
                {
                    users.Password = newpwd;
                    db.SaveChanges();
                    obj.status = "0";
                    obj.Token  = "";
                    obj.msg    = "修改成功";
                    obj.data   = "";
                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "修改密码", "UserModifyPwd", appId, "Account");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.Token  = "";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }


            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #16
0
        public HttpResponseMessage LogOut(JObject jData)
        {
            ResponseResult obj   = new ResponseResult();
            dynamic        json  = jData;
            string         user  = json.phone;
            string         pwd   = json.pwd;
            string         appId = json.appId;

            try
            {
                var model = GetLoginModel(user, pwd);
                if (model != null)
                {
                    model.token = "";//删除token
                    db.SaveChanges();
                    obj.status = "0";
                    obj.Token  = "";
                    obj.msg    = "退出成功";
                    obj.data   = "";

                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "退出登录", "LogOut", appId, "Account");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.Token  = "";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }

            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #17
0
        public HttpResponseMessage GetAccountInfo(string user, string pwd, string appId, string token)
        {
            ResponseResult obj = new ResponseResult();

            //dynamic json = jData;
            //string user = json.phone;
            //string pwd = json.pwd;
            //string appId = json.appId;
            try
            {
                var model = GetLoginModel(user, pwd);
                if (model != null)
                {
                    obj.status = "0";
                    obj.Token  = model.token;
                    obj.msg    = "成功";
                    obj.data   = JsonHelp.ObjectToString(model);

                    UtilSysLog.NewLogInfo(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "获取用户信息", "GetAccountInfo", appId, "Account");
                }
            }
            catch (Exception ex)
            {
                obj.status = "6";
                obj.msg    = "失败";
                obj.Token  = "";
                obj.data   = "";
                UtilSysLog.NewLogErre(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.ToString());
            }
            var resultObj = JsonConvert.SerializeObject(obj);
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
Exemple #18
0
        public string DahuaTest(JObject jData)
        {
            //响应头开放(用于Web前端的XHR2调用)
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST");
            //DHModel db = new DHModel();
            ReturnResult                result = new ReturnResult();
            YLMDBDBEntities             db     = new YLMDBDBEntities();
            Dictionary <string, string> dic    = new Dictionary <string, string>();
            dynamic json        = jData;
            string  key         = json.key;      //由雅量提供,专门用于大华客流的固定字符串
            string  deviceid    = json.deviceid; //设备ID
            string  data        = json.data;     //数据:【时间/进人数/出人数/设备MAC】
            string  SysKey      = JsonHelp.GetValue("key");
            string  Sysdeviceid = string.Empty;
            var     deviceidLs  = db.YLDeviceidData.Where(d => d.Deviceid == deviceid).FirstOrDefault();

            if (deviceidLs != null && deviceidLs.Deviceid != "")
            {
                Sysdeviceid = deviceidLs.Deviceid;
            }
            else
            {
                result.status = "6";
                result.msg    = "设备Id或key错误";
                result.data   = null;
                log.Info("时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "异常信息:设备Id或key错误");
            }
            //GetValue("deviceid");
            //string result = string.Empty;
            if (key.Equals(SysKey) && deviceid.Equals(Sysdeviceid))
            {
                var list = JsonHelp.Deserialize <DahuaInfo>(data);

                IntelligentData da = null;

                da              = new YLDB.IntelligentData();
                da.GatewayID    = 9999;
                da.InNum        = list.InNum;
                da.OutNum       = list.OutNum;
                da.MAC          = "";
                da.IMEI         = deviceid;
                da.Flage        = 1;
                da.DataDateTime = Convert.ToDateTime(list.DataDateTime);
                db.IntelligentData.Add(da);
                try
                {
                    db.SaveChanges();
                    dic.Add("key", key);
                    dic.Add("deviceid", deviceid);
                    dic.Add("InNum", list.InNum + "");
                    dic.Add("OutNum", list.OutNum + "");
                    dic.Add("DataDateTime", list.DataDateTime + "");

                    result.status = "ok";
                    result.msg    = "成功";
                    result.data   = JsonHelp.ObjectToString(dic);
                    log.Info("时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "信息:成功!" + "key=" + key + ",   deviceid=" + deviceid);
                    //result = string.Format("result:数据推送成功![key={0},deviceid={1},InNum={2},OutNum={3},DataDateTime={4}]",key,deviceid,list[0].InNum,list[0].OutNum,list[0].DataDateTime);
                }
                catch (Exception ex)
                {
                    result.status = "6";
                    result.msg    = "程序异常";
                    result.data   = null;
                    UtilSysLog.LogErr(ex);
                    log.Error("时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "异常信息:" + ex.ToString());
                }
            }
            else
            {
                result.status = "2";
                result.msg    = "设备Id或key错误";
                result.data   = null;
                log.Info("时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "异常信息:设备Id或key错误");
            }
            var strResult = string.Empty;

            try
            {
                strResult = JsonHelp.ObjectToString(result);
            }
            catch (Exception ex)
            {
                result.status = "6";
                result.msg    = "程序异常";
                result.data   = null;
                log.Error("时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "异常信息:" + ex.ToString());
            }
            return(strResult);

            //[{"datetime":"2018-5-18 12:23 251","in":1,"out":0,"MAC":"00:72:11:60:22:f0"},{"datetime":"2018-5-18 12:20 512","in":0,"out":2,"MAC":"00:72:11:60:22:f0"}]
        }