Пример #1
0
 /// <summary>
 /// 通知某个员工的所有设备,有员工信息更新
 /// </summary>
 /// <param name="empCode"></param>
 public void HasEmpUpdate(string empCode)
 {
     try
     {
         using (BemEntities db = new BemEntities())
         {
             var devList = db.deviceemployeerelation.Where(m => m.EmpCode == empCode);
             if (devList.Count() == 0)
             {
                 return;
             }
             foreach (var dev in devList)
             {
                 ClientTask task = new ClientTask();
                 task.ClientID = dev.DevCode;
                 task.TaskID   = Guid.NewGuid().ToString();
                 TaskManager.TaskEnqueue(task);
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("更新下发失败", ex);
     }
 }
Пример #2
0
 public bool DeleteRelation(string empCode, string devCode)
 {
     try
     {
         using (BemEntities db = new BemEntities())
         {
             int count = 0;
             count = db.Database.ExecuteSqlCommand(string.Format("update DeviceEmployeeRelation set operate={0} where EmpCode='{1}' and DevCode='{2}';", (int)OPERATETYPE.DEBIND, empCode, devCode));
             if (count > 0)
             {
                 ClientTask task = new ClientTask();
                 task.ClientID = devCode;
                 task.TaskID   = Guid.NewGuid().ToString();
                 TaskManager.TaskEnqueue(task);
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         LogHelper.Error("删除绑定关系失败", ex);
         return(false);
     }
 }
Пример #3
0
        public IHttpActionResult GetSyncConfigTime(HttpRequestMessage request)
        {
            string deviceCode;

            if (TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized)
                }));
            }
            try
            {
                using (BemEntities db = new BemEntities())
                {
                    var config = db.syncconfig.Find(deviceCode);
                    return(Ok(new { synctimeStart = config.SyncBegin, synctimeEnd = config.SyncEnd }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取名单同步配置失败", ex);
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.SyncConfigFail, errmsg = "同步时间获取失败"
                }));
            }
        }
Пример #4
0
 private bool RegRecordExists(long id)
 {
     using (BemEntities db = new BemEntities())
     {
         return(db.regrecord.Count(e => e.RecordID == id) > 0);
     }
 }
Пример #5
0
        public bool DeleteRelationByDev(string devCode, List <string> excepts)
        {
            StringBuilder condition = new StringBuilder();

            try
            {
                bool hasCondition = false;


                if (excepts != null && excepts.Count > 0)
                {
                    hasCondition = true;
                    condition.Append("not in (");
                    int index = 0;
                    foreach (var itm in excepts)
                    {
                        if (index == 0)
                        {
                            condition.Append(string.Format("'{0}'", itm));
                        }
                        else
                        {
                            condition.Append(string.Format(",'{0}'", itm));
                        }
                        index++;
                    }
                    condition.Append(")");
                }
                using (BemEntities db = new BemEntities())
                {
                    int count = 0;
                    if (hasCondition == false)
                    {
                        count = db.Database.ExecuteSqlCommand(string.Format("update DeviceEmployeeRelation set operate={0} where DevCode='{1}';", (int)OPERATETYPE.DEBIND, devCode));
                    }
                    else
                    {
                        count = db.Database.ExecuteSqlCommand(string.Format("update DeviceEmployeeRelation set operate={0} where DevCode='{1}' and EmpCode {2};", (int)OPERATETYPE.DEBIND, devCode, condition.ToString()));
                    }

                    if (count > 0)
                    {
                        ClientTask task = new ClientTask();
                        task.ClientID = devCode;
                        task.TaskID   = Guid.NewGuid().ToString();
                        TaskManager.TaskEnqueue(task);
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                LogHelper.Error("删除绑定关系失败", ex);
                return(false);
            }
        }
Пример #6
0
        public IHttpActionResult GetVideo(HttpRequestMessage request)
        {
            string deviceCode = string.Empty;

            ////检查授权
            if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized)
                }));
            }
            //检查超时
            if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now))
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime)
                }));
            }
            softwareupdate sf = null;

            using (BemEntities db = new BemEntities())
            {
                if (db.softwareupdate.Where(m => m.type == 1).Count() > 0)
                {
                    sf = db.softwareupdate.Where(m => m.type == 1).OrderByDescending(m => m.uploadTime).First();
                }
            }
            if (sf == null)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                }));
            }
            else
            {
                string filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content");
                string packPath = filePath + "\\video\\" + sf.version;

                if (!System.IO.File.Exists(packPath))
                {
                    return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo()
                    {
                        errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                    }));
                }
                string  path = string.Format(@"{0}/{1}", FtpHelper.VideoFtpURL, sf.version);
                FtpPath vf   = new FtpPath();
                vf.FtpURL = path;
                return(Ok(vf));
            }
        }
Пример #7
0
        // GET: Department
        public ActionResult Index(string index)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(index))
            {
                index = "1";
            }
            int indexInt = 0;

            if (!int.TryParse(index, out indexInt))
            {
                indexInt = 1;
            }
            List <CheckInGroup> totalList = null;

            try
            {
                using (BemEntities db = new BemEntities())
                {
                    if (indexInt == 1)
                    {
                        total_count = db.checkingroup.Count();
                    }
                    totalList = db.checkingroup.OrderBy(m => m.GroupCode.Length).ThenBy(m => m.GroupCode).Skip((indexInt - 1) * page_size).Take(page_size).ToList();
                    if (totalList == null || totalList.Count == 0)
                    {
                        return(View());
                    }
                    PageModel page = new PageModel()
                    {
                        CurrentIndex = indexInt, TotalCount = total_count
                    };
                    ViewData["pagemodel"] = page;
                    return(View(totalList));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取部门信息异常", ex);
                return(View());
            }
        }
Пример #8
0
        public async Task <ActionResult> Index(string empData, string devData)
        {
            int           count    = 0;
            List <string> empCodes = new List <string>();
            List <string> devCodes = new List <string>();

            try
            {
                string[] splitEmp = empData.Split(',');

                for (int i = 0; i < splitEmp.Length - 1; i++)
                {
                    empCodes.Add(splitEmp[i].Split('=')[1]);
                }
                string[] spliteDev = devData.Split(',');
                for (int j = 0; j < spliteDev.Length - 1; j++)
                {
                    devCodes.Add(spliteDev[j].Split('=')[1]);
                }
                using (BemEntities db = new BemEntities())
                {
                    foreach (string dev in devCodes)
                    {
                        List <DeviceEmployeeRelation> relation = new List <DeviceEmployeeRelation>();
                        foreach (string emp in empCodes)
                        {
                            DeviceEmployeeRelation relationItem = new DeviceEmployeeRelation();
                            relationItem.DevCode = dev;
                            relationItem.EmpCode = emp;
                            relationItem.HasGet  = 0;
                            relationItem.Operate = (int)OPERATETYPE.ADD;
                            relation.Add(relationItem);
                        }

                        db.deviceemployeerelation.AddRange(relation);
                        count += await db.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("设备下发失败", ex);
                return(Content("设备下发失败", "text/html"));
            }
            if (count <= 0)
            {
                LogHelper.Info("设备下发失败count=" + count);
                return(Content("设备下发失败", "text/html"));
            }
            LogHelper.Info("设备下发成功时间:" + DateTime.Now);
            SendToClient(devCodes);
            return(Content("OK", "text/html"));
        }
Пример #9
0
        public async Task <ActionResult> Edit(CheckInGroup info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            try
            {
                if (ModelState.IsValid)
                {
                    using (BemEntities db = new BemEntities())
                    {
                        if (db.checkingroup.Where(m => (m.GroupCode == info.GroupCode && m.GroupName == info.GroupName)).Count() > 0)
                        {
                            return(RedirectToAction("Index", "Department")); //没做任何改变
                        }
                        if (db.checkingroup.Where(m => (m.GroupName == info.GroupName)).Count() > 0)
                        {
                            ModelState.AddModelError("Title", "相同部门名称的记录已存在");
                            return(View());
                        }
                        CheckInGroup matchOne = db.checkingroup.Where(m => m.GroupCode == info.GroupCode).ToList().First();
                        if (matchOne != null)
                        {
                            matchOne.GroupName = info.GroupName;
                            db.checkingroup.Attach(matchOne);
                            db.Entry(matchOne).State = System.Data.Entity.EntityState.Modified;
                            string cmdStr = string.Format("update employee set EmpGroupName='{0}' where EmpGroupCode= '{1}';", info.GroupName, info.GroupCode);
                            db.Database.ExecuteSqlCommand(cmdStr);
                            await db.SaveChangesAsync();

                            return(RedirectToAction("Index", "Department"));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.Error("编辑部门异常", e);
                ModelState.AddModelError("Title", "数据保存异常");
            }

            return(View());
        }
Пример #10
0
        // GET: SoftwareUpdate
        public ActionResult Index()
        {
            string name, error;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }

            UpdatesPackage package    = new UpdatesPackage();
            softwareupdate updateInfo = null;

            try
            {
                package.devices = new List <clientdevice>();
                using (BemEntities db = new BemEntities())
                {
                    if (db.softwareupdate.Where(m => m.type == 0).OrderByDescending(m => m.uploadTime).Count() > 0)
                    {
                        updateInfo = db.softwareupdate.Where(m => m.type == 0).OrderByDescending(m => m.uploadTime).First();
                    }
                    package.updateInfo = updateInfo;
                    var devlist = db.clientdevice;
                    foreach (var dev in devlist)
                    {
                        package.devices.Add(dev);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取软件升级信息出错", ex);
            }
            return(View(package));
        }
Пример #11
0
 /// <summary>
 /// 从设备上移除对应员工
 /// </summary>
 /// <param name="empCode"></param>
 /// <returns></returns>
 public bool DeleteRelation(string empCode, OPERATETYPE type)
 {
     try
     {
         using (BemEntities db = new BemEntities())
         {
             var devList = db.deviceemployeerelation.Where(m => m.EmpCode == empCode);
             if (devList.Count() == 0)
             {
                 return(false);
             }
             var           groups   = devList.GroupBy(m => m.DevCode);
             List <string> devCodes = new List <string>();
             foreach (var dev in devList)
             {
                 devCodes.Add(dev.DevCode);
             }
             int count = 0;
             count = db.Database.ExecuteSqlCommand(string.Format("update DeviceEmployeeRelation set operate={0} where EmpCode='{1}';", (int)type, empCode));
             if (count > 0)
             {
                 foreach (string devCode in devCodes)
                 {
                     ClientTask task = new ClientTask();
                     task.ClientID = devCode;
                     task.TaskID   = Guid.NewGuid().ToString();
                     TaskManager.TaskEnqueue(task);
                 }
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         LogHelper.Error("删除绑定关系失败", ex);
         return(false);
     }
 }
Пример #12
0
        public async Task <ActionResult> Delete(string id)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            using (BemEntities db = new BemEntities())
            {
                CheckInGroup group = db.checkingroup.Where(m => m.GroupCode == id).ToList().First();
                db.checkingroup.Attach(group);
                db.Entry(group).State = System.Data.Entity.EntityState.Deleted;
                await db.SaveChangesAsync();
            }
            return(RedirectToAction("", "department"));
        }
Пример #13
0
        public void DeleteUpdatesByServer(string devCode)
        {
            string taskId = string.Empty;

            try
            {
                LogHelper.Info(string.Format("设备[{0}]请求删除绑定", devCode));
                if (TaskManager.CheckDeleteLegal(devCode, out taskId) == true)
                {
                    //进行清理操作
                    using (BemEntities db = new BemEntities())
                    {
                        using (var scope = db.Database.BeginTransaction())
                        {
                            try
                            {
                                db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DEBIND, devCode)); //解除绑定

                                db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DELETE, devCode)); //解除绑定
                                db.Database.ExecuteSqlCommand(string.Format("update deviceemployeerelation set Operate=0 where devCode='{0}';", devCode));
                                scope.Commit();                                                                                                                                            //正常完成,提交事务
                                TaskManager.RemoveTasks(taskId);                                                                                                                           //从任务缓存中移除任务
                            }
                            catch (Exception ex)
                            {
                                scope.Rollback();               //发生异常后回滚
                                LogHelper.Error("GetAllEmployees更新清理出错", ex);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("GetAllEmployees清除更新信息失败", ex);
            }
        }
Пример #14
0
        public ActionResult Edit(string id)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Device"));
            }
            using (BemEntities db = new BemEntities())
            {
                CheckInGroup matchOne = db.checkingroup.Where(m => m.GroupCode == id).ToList().First();
                return(View(matchOne));
            }
        }
Пример #15
0
        private static bool ChangeStatus(string devCode, sbyte online, DateTime dt)
        {
            try
            {
                int result = 0;
                using (BemEntities db = new BemEntities())
                {
                    if (online == 1)
                    {
                        result = db.Database.ExecuteSqlCommand(string.Format("update ClientDevice SET DevStatus={0},DevUpdateTime='{1}' WHERE DevCode='{2}';", online, dt.ToString("yyyy-MM-dd HH:mm:ss"), devCode));
                    }
                    else
                    {
                        result = db.Database.ExecuteSqlCommand(string.Format("update ClientDevice SET DevStatus={0} WHERE DevCode='{1}';", online, devCode));
                    }

                    return(result > 0);
                }
            }
            catch (Exception ex) {
                LogHelper.Error("[" + devCode + "]设备状态更新数据库失败", ex);
                return(false);
            }
        }
Пример #16
0
        public ActionResult Create(CheckInGroup group)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }


            try
            {
                using (BemEntities db = new BemEntities())
                {
                    if (db.checkingroup.Where(m => (m.GroupCode == group.GroupCode || m.GroupName == group.GroupName)).Count() > 0)
                    {
                        return(Content("false:相同部门编号或部门名称的记录已存在", "text/html"));
                    }
                    group.GroupParent = "0";
                    db.checkingroup.Add(group);
                    db.SaveChangesAsync();
                    return(Content("true:OK", "text/html"));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("部门新增失败", ex);
                return(Content("false:部门新增失败", "text/html"));
            }
        }
Пример #17
0
 //初始化
 public static void InitStatus()
 {
     try
     {
         List <ClientDevice> devList = new List <ClientDevice>();
         using (BemEntities db = new BemEntities())
         {
             devList = db.clientdevice.OrderByDescending(m => m.DevCreateTime).ToList();
             if (devList == null || devList.Count == 0)
             {
                 LogHelper.Info("InitStatus 获取设备初始状态为空");
                 return;
             }
         }
         string   token;
         DateTime dt = DateTime.MinValue;
         foreach (var item in devList)
         {
             if (string.IsNullOrEmpty(item.DevToken))
             {
                 continue;
             }
             else
             {
                 token = item.DevToken;
             }
             dt = item.DevUpdateTime.HasValue ? (DateTime)item.DevUpdateTime : dt;
             DeviceTokenList.TryAdd(item.DevCode, token);
             DeviceKeepLiveTimeList.TryAdd(item.DevCode, dt);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("状态初始化失败", ex);
     }
 }
Пример #18
0
        public async Task <ActionResult> Upload(HttpPostedFileBase file)
        {
            try
            {
                if (file == null)
                {
                    return(Content("上传为空,请重新选择", "text/html"));
                }
                string path      = file.FileName;
                string content   = string.Empty;
                string extension = Path.GetExtension(path);
                if (extension.ToLower() != ".mp4")
                {
                    return(Content("上传文件格式错误,当前只支持mp4文件", "text/html"));
                }

                string fileName   = Path.GetFileName(path);
                string savePath   = Server.MapPath("~/Content");
                string folderPath = savePath + "\\video";
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                List <string> prePackagePath = new List <string>();
                if (new DirectoryInfo(folderPath).GetFiles().Where(m => Path.GetExtension(m.FullName).ToLower() == ".mp4").Count() > 0)
                {
                    List <FileInfo> files = new DirectoryInfo(folderPath).GetFiles().Where(m => Path.GetExtension(m.FullName).ToLower() == ".mp4").ToList();
                    foreach (var item in files)
                    {
                        prePackagePath.Add(item.FullName);   //把其他的文件保存,以便新文件进来后,把老文件删除
                    }
                }
                string newFileName = Path.GetFileNameWithoutExtension(file.FileName);
                if (prePackagePath.Where(m => Path.GetFileName(m) == fileName).Count() > 0)
                {
                    newFileName = newFileName + "(1)";
                }
                await Task.Run(delegate()
                {
                    using (FileStream fileToSave = new FileStream(folderPath + "\\" + newFileName + ".mp4", FileMode.Create, FileAccess.Write))
                    {
                        byte[] bytes = new byte[file.InputStream.Length];
                        file.InputStream.Read(bytes, 0, (int)file.InputStream.Length);
                        fileToSave.Write(bytes, 0, bytes.Length);
                        fileToSave.Flush();
                    }
                    foreach (var item in prePackagePath)
                    {
                        try
                        {
                            System.IO.File.Delete(item);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error("视频文件删除失败", ex);
                        }
                    }
                    softwareupdate updatesOne = new softwareupdate();
                    updatesOne.version        = newFileName + ".mp4";
                    updatesOne.uploadTime     = DateTime.Now;
                    updatesOne.type           = 1;
                    using (BemEntities db = new BemEntities())
                    {
                        db.softwareupdate.Add(updatesOne);
                        db.SaveChanges();
                    }
                });

                return(Content("OK", "text/html"));
            }
            catch (Exception ex)
            {
                //日志记录
                LogHelper.Error("上传视频文件失败", ex);
                return(Content("上传视频文件失败,请检查", "text/html"));
            }
        }
Пример #19
0
        public IHttpActionResult GetUpdates(HttpRequestMessage request, string id)
        {
            string deviceCode;

            if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized)
                }));
            }
            try
            {
                LogHelper.Info(string.Format("设备[{0}]GetUpdates完毕", deviceCode));
                if (TaskManager.CheckDeleteLegal(deviceCode, id) == true)
                {
                    //进行清理操作
                    using (BemEntities db = new BemEntities())
                    {
                        using (var scope = db.Database.BeginTransaction())
                        {
                            try
                            {
                                db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DEBIND, deviceCode));//解除绑定

                                //var list = (from devRel in db.deviceemployeerelation
                                //           join emp in db.employee
                                //           on devRel.EmpCode equals emp.EmpCode
                                //           where devRel.Operate == 4
                                //           where devRel.DevCode==deviceCode
                                //           select emp).ToList();

                                db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DELETE, deviceCode)); //解除绑定
                                db.Database.ExecuteSqlCommand(string.Format("update deviceemployeerelation set Operate=0 where devCode='{0}';", deviceCode));
                                scope.Commit();                                                                                                                                               //正常完成,提交事务
                                TaskManager.RemoveTasks(id);                                                                                                                                  //从任务缓存中移除任务
                                return(Ok());
                            }
                            catch (Exception ex)
                            {
                                scope.Rollback();               //发生异常后回滚
                                LogHelper.Error("更新清理出错", ex);
                                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                                {
                                    errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException)
                                }));
                            }
                        }
                    }
                }
                else
                {
                    return(Content <ApiErrorInfo>(HttpStatusCode.Forbidden, new ApiErrorInfo()
                    {
                        errcode = (int)ErrorCode.IllegalRequest, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.IllegalRequest)
                    }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("清除更新信息失败", ex);
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException)
                }));
            }
        }
Пример #20
0
 public async Task <IHttpActionResult> PostRecords(RecordsQuery queryItem)
 {
     try
     {
         if (queryItem == null)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError)
             }));
         }
         DateTime dt1 = DateTime.Now;
         DateTime dt2 = DateTime.Now;
         if (DateTime.TryParse(queryItem.startTime, out dt1) == false || DateTime.TryParse(queryItem.endTime, out dt2) == false)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError)
             }));
         }
         if ((dt2 - dt1).TotalDays > 60)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.QueryExceed, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.QueryExceed)
             }));
         }
         using (BemEntities db = new BemEntities())
         {
             var recordsList = from record in db.regrecord
                               join dev in db.clientdevice
                               on record.RecordDeviceID equals dev.DevCode
                               where record.RecordTime >= dt1 && record.RecordTime <= dt2
                               select new
             {
                 empName        = record.RecordEmpName,
                 empCode        = record.RecordEmpCode,
                 empID          = record.RecordEmpID,
                 departmentName = record.RecordGroupName,
                 departmentCode = record.RecordGroupCode,
                 recordTime     = record.RecordTime,
                 deviceCode     = record.RecordDeviceID,
                 deviceName     = dev.DevName
             };
             if (!string.IsNullOrEmpty(queryItem.empCode))
             {
                 recordsList = recordsList.Where(m => m.empCode == queryItem.empCode);
             }
             if (!string.IsNullOrEmpty(queryItem.deviceCode))
             {
                 recordsList = recordsList.Where(m => m.deviceCode == queryItem.deviceCode);
             }
             if (!string.IsNullOrEmpty(queryItem.departmentCode))
             {
                 recordsList = recordsList.Where(m => m.departmentCode == queryItem.departmentCode);
             }
             var contentList = recordsList.OrderBy(m => m.recordTime).ToList();
             if (contentList.Count > 0)
             {
                 return(Ok(contentList));
             }
             else
             {
                 return(Content <ApiErrorInfo>(HttpStatusCode.NoContent, new ApiErrorInfo()
                 {
                     errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("查询原始记录出错", ex);
         return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
         {
             errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError)
         }));
     }
 }
Пример #21
0
        public async Task <IHttpActionResult> PostRegRecord(HttpRequestMessage request, RegRecordJsonObj regRecordObj)
        {
            string deviceCode;

            if (TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized)
                }));
            }
            //检查超时
            if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now))
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime)
                }));
            }
            if (regRecordObj == null)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError)
                }));
            }
            try
            {
                RegRecord newRecord = new RegRecord();
                newRecord.RecordDeviceID  = regRecordObj.devCode == null ? string.Empty : regRecordObj.devCode;
                newRecord.RecordEmpCode   = regRecordObj.empCode == null ? string.Empty : regRecordObj.empCode;
                newRecord.RecordEmpName   = regRecordObj.empName == null ? string.Empty : regRecordObj.empName;
                newRecord.RecordEmpID     = regRecordObj.empID == null ? string.Empty : regRecordObj.empID;
                newRecord.RecordGroupCode = regRecordObj.groupCode == null ? string.Empty : regRecordObj.groupCode;
                newRecord.RecordGroupName = regRecordObj.groupName == null ? string.Empty : regRecordObj.groupName;
                newRecord.RecordTime      = DateTime.Parse(regRecordObj.recordTime);
                using (BemEntities db = new BemEntities())
                {
                    db.regrecord.Add(newRecord);
                    await db.SaveChangesAsync();
                }
                SaveImage(regRecordObj.empImage1, regRecordObj.empImage2, newRecord.RecordID, newRecord.RecordEmpCode, newRecord.RecordEmpName, newRecord.RecordTime);
                return(Ok());
            }
            catch (DbEntityValidationException dbex)
            {
                LogHelper.Error("数据添加失败" + dbex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage + "empCode=" + regRecordObj.empCode + "empName" + regRecordObj.empName);
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError)
                }));
            }
            catch (Exception ex)
            {
                LogHelper.Error("数据添加失败", ex);
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError)
                }));
            }
        }
Пример #22
0
        public ActionResult Index()
        {
            string name, error;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out LoginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = LoginName;
            }
            List <CompanyItem>  unBindItemList   = new List <CompanyItem>();
            List <CompanyItem>  bindItemList     = new List <CompanyItem>();
            List <ClientDevice> deviceList       = new List <ClientDevice>();
            List <CompanyItem>  bindResultList   = new List <CompanyItem>();
            List <CompanyItem>  unBindResultList = new List <CompanyItem>();

            try
            {
                using (BemEntities db = new BemEntities())
                {
                    deviceList          = db.clientdevice.ToList();
                    ViewData["devList"] = deviceList;

                    //var companyList = from emp in db.employee
                    //                  join rel in db.deviceemployeerelation
                    //                  on emp.EmpCode equals rel.EmpCode into dc
                    //                  from dci in dc.DefaultIfEmpty()
                    //                  group dci by new { emp.EmpGroupCode, emp.EmpGroupName, emp.EmpCode, emp.EmpName, dci.DevCode } into g
                    //                  select new { grpName = g.Key.EmpGroupName, grpCode = g.Key.EmpGroupCode, empName = g.Key.EmpName, empCode = g.Key.EmpCode, devCode = g.Key.DevCode };
                    var unbindList = from item in (from emp in db.employee
                                                   join rel in db.deviceemployeerelation
                                                   on emp.EmpCode equals rel.EmpCode into dc
                                                   from dci in dc.DefaultIfEmpty()
                                                   where string.IsNullOrEmpty(dci.DevCode) == true
                                                   select new { emp.EmpCode, emp.EmpName, emp.EmpGroupCode, emp.EmpGroupName })
                                     group item by new { item.EmpGroupCode, item.EmpGroupName } into g
                    select g;

                    var bindlist = from item in (from emp in db.employee
                                                 join rel in db.deviceemployeerelation
                                                 on emp.EmpCode equals rel.EmpCode into dc
                                                 from dci in dc.DefaultIfEmpty()
                                                 where string.IsNullOrEmpty(dci.DevCode) == false
                                                 select new { emp.EmpCode, emp.EmpName, emp.EmpGroupCode, emp.EmpGroupName })
                                   group item by new { item.EmpGroupCode, item.EmpGroupName } into g
                    select g;
                    foreach (var item in unbindList)
                    {
                        CompanyItem item1 = new CompanyItem();
                        item1.CompanyCode = item.Key.EmpGroupCode;
                        item1.CompanyName = item.Key.EmpGroupName;
                        item1.subList     = new List <Employee>();
                        foreach (var subItem in item)
                        {
                            item1.subList.Add(new Employee()
                            {
                                EmpCode = subItem.EmpCode, EmpName = subItem.EmpName
                            });
                        }
                        unBindItemList.Add(item1);
                    }
                    foreach (var item in bindlist)
                    {
                        CompanyItem item1 = new CompanyItem();
                        item1.CompanyCode = item.Key.EmpGroupCode;
                        item1.CompanyName = item.Key.EmpGroupName;
                        item1.subList     = new List <Employee>();
                        foreach (var subItem in item)
                        {
                            if (item1.subList.Where(m => m.EmpCode == subItem.EmpCode).Count() <= 0)
                            {
                                item1.subList.Add(new Employee()
                                {
                                    EmpCode = subItem.EmpCode, EmpName = subItem.EmpName
                                });
                            }
                        }
                        bindItemList.Add(item1);
                    }
                    //foreach (var company in result)
                    //{
                    //    CompanyItem item1 = new CompanyItem();
                    //    item1.CompanyCode = company.Key.grpCode;
                    //    item1.CompanyName = company.Key.grpName;
                    //    item1.subList = new List<Employee>();

                    //    CompanyItem item2 = new CompanyItem();
                    //    item2.CompanyCode = company.Key.grpCode;
                    //    item2.CompanyName = company.Key.grpName;
                    //    item2.subList = new List<Employee>();
                    //    foreach (var emp in company)
                    //    {
                    //        if (string.IsNullOrEmpty(emp.devCode))
                    //        {
                    //            item1.subList.Add(new Employee() { EmpCode = emp.empCode, EmpName = emp.empName });
                    //        }
                    //        else
                    //        {
                    //            if (item2.subList.Where(m => m.EmpCode == emp.empCode).Count() <= 0)
                    //            {
                    //                item2.subList.Add(new Employee() { EmpCode = emp.empCode, EmpName = emp.empName });
                    //            }
                    //        }
                    //    }

                    //    unBindItemList.Add(item1);
                    //    bindItemList.Add(item2);
                    //}

                    foreach (var item in unBindItemList)
                    {
                        if (item.subList.Count > 0)
                        {
                            unBindResultList.Add(item);
                        }
                    }
                    foreach (var item in bindItemList)
                    {
                        if (item.subList.Count > 0)
                        {
                            bindResultList.Add(item);
                        }
                    }
                    ViewData["notBindList"] = unBindResultList;
                    ViewData["bindList"]    = bindResultList;
                    return(View());
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("设备下发获取部门信息失败", ex);
            }
            return(View());
        }
Пример #23
0
        /// <summary>
        /// 获取指定设备的任务列表
        /// </summary>
        /// <param name="clientID"></param>
        /// <returns></returns>
        public static UpdatesJsonObj GetTasks(string clientID)
        {
            ClientTask task = _taskQueueHelper._taskList.Where(item => item.ClientID == clientID).First();

            if (task == null)
            {
                return(null);
            }
            UpdatesJsonObj obj = new UpdatesJsonObj();

            obj.taskID = task.TaskID;
            using (BemEntities db = new BemEntities())
            {
                var updates = from devRel in db.deviceemployeerelation
                              join user in db.employee
                              on devRel.EmpCode equals user.EmpCode into dic
                              from item in dic.DefaultIfEmpty()
                              where devRel.DevCode == clientID
                              where devRel.Operate != 0
                              group new { devRel, item } by devRel.Operate into g
                    select new
                {
                    g.Key,
                    g
                };
                obj.updatesSubItems = new List <UpdatesSubItem>();
                foreach (var itm in updates)
                {
                    UpdatesSubItem subItem = new UpdatesSubItem();
                    subItem.operateType = (sbyte)itm.Key;
                    subItem.employees   = new List <EmployeeJsonObj>();
                    foreach (var emp in itm.g)
                    {
                        EmployeeJsonObj employee1 = new EmployeeJsonObj();
                        if (emp.item != null)
                        {
                            employee1.empCode         = emp.item.EmpCode;
                            employee1.empID           = emp.item.EmpIDCard;
                            employee1.empName         = emp.item.EmpName;
                            employee1.empTelephone    = emp.item.Telephone == null ? string.Empty : emp.item.Telephone;
                            employee1.empAdmin        = emp.item.Administrator == null ? string.Empty : emp.item.Administrator;
                            employee1.empBirth        = emp.item.EmpBirth.ToString("yyyy-MM-dd HH:mm:ss");
                            employee1.empGender       = emp.item.EmpGender.HasValue ? (emp.item.EmpGender == 0 ? "女" : "男") : "女";
                            employee1.empGroupName    = emp.item.EmpGroupName;
                            employee1.empGroupCode    = emp.item.EmpGroupCode;
                            employee1.empLeftNum      = emp.item.LeftNum.HasValue ? (int)emp.item.LeftNum : 0;
                            employee1.empRightNum     = emp.item.RightNum.HasValue ? (int)emp.item.RightNum : 0;
                            employee1.empTemplate     = emp.item.Template == null ? string.Empty : Convert.ToBase64String(emp.item.Template);
                            employee1.empLeftEyeImg   = string.Empty;
                            employee1.empRightEyeImg  = string.Empty;
                            employee1.empTemplateSize = emp.item.TemplateSize.HasValue ? (int)emp.item.TemplateSize : 0;
                            employee1.empFaceTemplate = emp.item.FaceTemplate == null ? string.Empty : Convert.ToBase64String(emp.item.FaceTemplate);
                            employee1.empFaceImg      = string.Empty;
                        }
                        else
                        {
                            employee1.empCode         = emp.devRel.EmpCode;
                            employee1.empID           = string.Empty;
                            employee1.empName         = string.Empty;
                            employee1.empTelephone    = string.Empty;
                            employee1.empAdmin        = string.Empty;
                            employee1.empBirth        = string.Empty;
                            employee1.empGender       = string.Empty;
                            employee1.empGroupName    = string.Empty;
                            employee1.empGroupCode    = string.Empty;
                            employee1.empLeftNum      = 0;
                            employee1.empRightNum     = 0;
                            employee1.empTemplate     = string.Empty;
                            employee1.empLeftEyeImg   = string.Empty;
                            employee1.empRightEyeImg  = string.Empty;
                            employee1.empTemplateSize = 0;
                            employee1.empFaceTemplate = string.Empty;
                            employee1.empFaceImg      = string.Empty;
                        }
                        subItem.employees.Add(employee1);
                    }
                    obj.updatesSubItems.Add(subItem);
                }
            }
            return(obj);
        }