示例#1
0
 public InfoStatisticsDto GetBackInfoStatistics()
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var mgdb            = new MongoDbProvider <SceneItem>();
             var users           = db.FrontUsers.Count();
             var projects        = db.Projects.Where(x => !x.Deleted).Count();
             var scenes          = db.Scenes.Where(x => !x.Deleted).Count();
             var pictrues        = mgdb.GetAll(x => true).Select(n => n.Count).Sum();
             var sceneItemStatus = mgdb.GetAll(x => x.Status == ItemStatus.Redo && !x.IsExamine && !x.IsExamine).Count();
             return(new InfoStatisticsDto()
             {
                 Users = users,
                 Scenes = scenes,
                 Projects = projects,
                 Pictures = pictrues,
                 ItemStatus = sceneItemStatus
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#2
0
 public InfoStatisticsDto GetEnterpriseInfoStatistics(string enterpriseId)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var mgdb            = new MongoDbProvider <SceneItem>();
             var users           = db.FrontUsers.Where(x => x.EnterpiseID.Equals(enterpriseId)).Count();
             var projects        = db.Projects.Where(x => !x.Deleted && x.EnterpriseID.Equals(enterpriseId)).Count();
             var sceneIDlist     = db.Scenes.Where(x => !x.Deleted && x.EnterpriseID.Equals(enterpriseId)).Select(n => n.SceneID).ToList();
             var pictrues        = mgdb.GetAll(x => sceneIDlist.Contains(x.SceneID)).Select(n => n.Count).Sum();
             var sceneItemStatus = mgdb.GetAll(x => x.Status == ItemStatus.Redo && sceneIDlist.Contains(x.SceneID) && !x.IsExamine).Count();
             return(new InfoStatisticsDto()
             {
                 Users = users,
                 Scenes = sceneIDlist.Count(),
                 Projects = projects,
                 Pictures = pictrues,
                 ItemStatus = sceneItemStatus
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        //  可选优化,IEnumerable查询会加载所有结果,IQueryable只会加载分页结果
        //  controller已确保EnterpriseID的正确使用
        private static IEnumerable <OperationLog> SearchOperationLogsByMongo(SearchLogConditionDto condition)
        {
            try
            {
                IEnumerable <OperationLog> reList;
                List <string> uIDList = new List <string>();
                var           mgdb    = new MongoDbProvider <OperationLog>();

                //  不存在UserID时候查询过程
                if (string.IsNullOrEmpty(condition.UserID))
                {
                    using (var db = new BCEnterpriseContext())
                    {
                        uIDList = db.FrontUsers.Where(obj => (string.IsNullOrEmpty(condition.EnterpriseID) ? true : obj.EnterpiseID == condition.EnterpriseID) && (string.IsNullOrEmpty(condition.UserName) ? true : obj.Name.Contains(condition.UserName))).Select(o => o.UserID).ToList();
                    }
                    if (0 == uIDList.Count)
                    {
                        if (string.IsNullOrEmpty(condition.OperationID))
                        {
                            // 第一次显示操作日志判断
                            reList = mgdb.GetAll(obj => (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) && (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                                 (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                        }
                        else
                        {
                            //  UserID和UserName为空,仅根据企业ID和操作ID查询
                            reList = mgdb.GetAll(obj => (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                                 (obj.OperationID.ToLower().Contains(condition.OperationID.ToLower())) &&
                                                 (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                                 (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                        }
                    }
                    else
                    {
                        //  输入UserName查询得到uIDList模糊查询
                        var tempCondition = string.IsNullOrEmpty(condition.OperationID) ? "" : condition.OperationID.ToLower();
                        reList = mgdb.GetAll(obj => (uIDList.Contains(obj.UserID)) &&
                                             (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                             (string.IsNullOrEmpty(condition.OperationID) || obj.OperationID.ToLower().Contains(tempCondition)) &&
                                             (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                             (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                    }
                }

                //  指定UserID查询过程
                else
                {
                    //  指定了UserID查询
                    reList = mgdb.GetAll(obj => (obj.UserID == condition.UserID) &&
                                         (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                         (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                         (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                }
                return(reList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private DepartmentInfoFormDto GetDepartmentInfoFormOfMyDepartment(int?departmentId, string enterpriseId, DateTime?beginTime, DateTime?endTime, BCEnterpriseContext db)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                //get my sceneId
                var scenlist = (from scene in db.Scenes
                                join project in db.Projects on scene.ProjectID equals project.ProjectID
                                where project.EnterpriseID == enterpriseId
                                select new
                {
                    SceneId = scene.SceneID,
                    Deleted = scene.Deleted,
                    RegistDate = scene.RegistDate,
                    Departments = project.Departments
                }).ToList();
                //由原来获取当前部门下的所有部门的现场数 改为 获取当前部门的现场数
                var scenelist = scenlist.Where(o => o.Departments.Split("|".ToCharArray()).Any(x => x == (!departmentId.HasValue ? "" : departmentId.Value.ToString())));
                //get projectId in my department
                var projectlist = db.Projects.Where(x => !x.Deleted).ToList();
                //由原来获取当前部门下的所有部门的项目数 改为 获取当前部门的项目数
                var newprolist = projectlist.Where(x => x.Departments.Split("|".ToCharArray()).Any(n => n == (!departmentId.HasValue ? "" : departmentId.Value.ToString())));
                //get pictures of scene on my department
                var sceneIdlist = scenelist.Select(x => x.SceneId);

                var Picount = mgdb.GetAll(x => sceneIdlist.Contains(x.SceneID) && (x.CreateTime > (beginTime ?? DateTime.MinValue)) && (x.CreateTime < (endTime ?? DateTime.MaxValue))).Select(n => n.Count).Sum();
                var pByte   = mgdb.GetAll(x => sceneIdlist.Contains(x.SceneID) && (x.CreateTime > (beginTime ?? DateTime.MinValue)) && (x.CreateTime < (endTime ?? DateTime.MaxValue))).Select(n => n.TotalOrgImageBytes).Sum();
                //由原来获取属于当前部门及其子部门的人 改成只获取属于当前部门的人
                var userlist = db.FrontUsers.Where(x => x.DepartmentID == departmentId);


                var depart = db.Departments.FirstOrDefault(x => x.DepartmentID == departmentId.Value);

                return(new DepartmentInfoFormDto
                {
                    DepartmentName = depart.Name,
                    DepartmentID = depart.DepartmentID,
                    ParentID = depart.ParentID,
                    PictureByte = pByte,
                    //get users in my department
                    UsersCount = userlist.Where(n =>
                                                n.EnterpiseID.Equals(enterpriseId) &&
                                                n.RegistDate <(endTime ?? DateTime.MaxValue) &&
                                                              n.RegistDate> (beginTime ?? DateTime.MinValue)).Count(),
                    ProjectCount = newprolist.Where(n =>
                                                    n.RegistDate > (beginTime ?? DateTime.MinValue) &&
                                                    n.RegistDate < (endTime ?? DateTime.MaxValue)).Count(),
                    SceneCount = scenelist.Where(n =>
                                                 !n.Deleted &&
                                                 n.RegistDate > (beginTime ?? DateTime.MinValue) &&
                                                 n.RegistDate < (endTime ?? DateTime.MaxValue)).Count(),
                    PictureCount = Picount
                });
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#5
0
        public RectificationStatisticalDto GetRectificationStatistical(string enterpriseID, int?departmentID, string userID)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                using (var db = new BCEnterpriseContext())
                {
                    var itemAllList = new List <SceneItem>();
                    if (string.IsNullOrEmpty(userID))
                    {
                        var departmentlist = GetOwnerDepartment(departmentID ?? -1, db);

                        var tempscenelist = (from scene in db.Scenes
                                             join project in db.Projects on scene.ProjectID equals project.ProjectID
                                             where project.EnterpriseID == enterpriseID && !project.Deleted && !scene.Deleted
                                             select new
                        {
                            DepartmentIDs = project.Departments,
                            SceneID = scene.SceneID
                        }).ToList();

                        var scenelist =
                            tempscenelist.Where(
                                x => x.DepartmentIDs.Split("|".ToCharArray()).Contains(departmentID.ToString())).Select(n => n.SceneID).ToList();
                        //所有现场数据
                        itemAllList = mgdb.GetAll(x => scenelist.Contains(x.SceneID)).ToList();
                    }
                    else
                    {
                        //所有现场数据
                        itemAllList = mgdb.GetAll(x => x.UserID.Equals(userID)).ToList();
                    }

                    //当前需要整改现场数据
                    var itemRectificationList = itemAllList.Where(x => (x.Examines ?? new List <Examine>()).Any(n => n.ExamineStatus == ItemStatus.Redo));
                    var itemtemlist           = itemAllList.Where(x => x.Examines != null);
                    //在记录操作状态的Examine集合中,最后一个记录状态不为整改,但是在这个集合中至少有一个为需要整改,则记录该条为整改完成.整改完成的现场数据
                    var itemFinishList =
                        itemtemlist.Where(
                            x => (((x.Examines.OrderByDescending(n => n.Time).First()).ExamineStatus !=
                                   ItemStatus.Redo) && (x.Examines.Any(m => m.ExamineStatus == ItemStatus.Redo))));
                    var pictureCount = itemAllList.Select(x => x.Count).Sum();
                    var stallitem    = itemAllList.Where(x => "" == x.Relation);
                    return(new RectificationStatisticalDto()
                    {
                        FinishCount = itemFinishList.Count(),
                        RectificationCount = itemRectificationList.Count(),
                        AllCount = stallitem.Count(),
                        PictureCount = pictureCount
                    });
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#6
0
        public List <UserMessageQueueItem> PopupUserMessageQueueItem(string userId, string device)
        {
            if (userId == null)
            {
                throw new ArgumentNullException("userId");
            }
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            var db     = new MongoDbProvider <UserMessageQueueItem>();
            var list   = db.GetAll(n => n.State == AppSyncDataStateEnum.Normal && n.UserID == userId && n.Device == device).ToList();
            var result = list.ToArray().Clone() as UserMessageQueueItem[];

            foreach (var l in list)
            {
                l.Time = l.Time.ToLocalTime();
                var chatMessage = l.Data as ChatMessage;
                if (chatMessage == null)
                {
                    continue;
                }
                chatMessage.SendTime = chatMessage.SendTime.ToLocalTime();
                chatMessage.IsRead   = ReadStatus.Read;
            }
            list.ForEach(n =>
            {
                n.State      = AppSyncDataStateEnum.Sent;
                n.UpdateTime = DBTimeHelper.DBNowTime();
                db.Update(n);
            });

            return(null != result?result.ToList() : new List <UserMessageQueueItem>());
        }
示例#7
0
 public int GetMessageCount(string userId)
 {
     try
     {
         var mgdb  = new MongoDbProvider <UserMessageQueueItem>();
         var msg   = mgdb.GetAll(x => x.UserID == userId && ((ChatMessage)x.Data).SendUserID != userId && ((ChatMessage)x.Data).IsRead == ReadStatus.NoRead);
         var count = msg.Select(x => ((ChatMessage)x.Data).MessageID).Distinct().Count();
         return(count);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#8
0
        public List <ChatMessageDto> GetChatMessages(string userID, string deviceID, int pageSize, DateTime queryTime, out int count)
        {
            try
            {
                var mgdb  = new MongoDbProvider <UserMessageQueueItem>();
                var query = mgdb.GetAll(o => o.UserID == userID && o.Time < queryTime && ((ChatMessage)o.Data).Message != null)
                            .Select(o =>
                {
                    var temp = (ChatMessage)o.Data;
                    return(new ChatMessageDto
                    {
                        SendUserID = temp.SendUserID,
                        SendUserName = temp.SendUserName,
                        SendUserPicture = temp.SendUserPicture,
                        EnterpriseID = temp.EnterpriseID,
                        Recipients = temp.Recipients,
                        Message = temp.Message,
                        MessageID = temp.MessageID,
                        IsRead = temp.IsRead,
                        SendTime = temp.SendTime.ToLocalTime(),
                        Time = o.Time.ToLocalTime()
                    });
                }).Distinct();

                count = query.Count();
                if (0 == count)
                {
                    return(new List <ChatMessageDto>());
                }
                if (pageSize < 1)
                {
                    pageSize = 10;
                }
                var re = query.OrderByDescending(obj => obj.Time)
                         .Take(pageSize)
                         .ToList();

                return(re);
            }
            catch (Exception ex)
            {
                var logger = log4net.LogManager.GetLogger(typeof(ChatMessageService));
                logger.Error(ex.Message);
                throw;
            }
        }
        public bool DeleteSceneItem(string sceneItemID)
        {
            try
            {
                if (string.IsNullOrEmpty(sceneItemID))
                {
                    throw new KnownException("id为空,无法删除!");
                }
                var mgdb      = new MongoDbProvider <SceneItem>();
                var sceneItem = mgdb.GetAll(o => o.Id == sceneItemID).FirstOrDefault();
                if (null == sceneItem)
                {
                    return(true);
                }
                else if (sceneItem.Status == ItemStatus.Final)
                {
                    throw new KnownException("已经归档,不能删除!");
                }

                //  如果有图片,需要删除图片
                if (null != sceneItem.Images)
                {
                    foreach (var image in sceneItem.Images)
                    {
                        mgdb.DeleteFileByName(image.OriginalPicture, PictureDbName);
                        mgdb.DeleteFileByName(image.ThumbnailPicture, PictureDbName);
                    }
                }
                mgdb.Delete(sceneItemID);

                using (var db = new BCEnterpriseContext())
                {
                    var scene = db.Scenes.First(o => o.SceneID == sceneItem.SceneID);
                    if (scene.HasData && (null == mgdb.GetByCondition(o => o.SceneID == sceneItem.SceneID)))
                    {
                        scene.HasData = false;
                    }
                    db.SaveChanges();
                }
                return(Send2MsmqAsDelete(sceneItemID, OperationEnum.Deleted, sceneItem.SceneID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
 public bool ChangeReadStatus(Guid messageId, string userId)
 {
     try
     {
         var mgdb = new MongoDbProvider <UserMessageQueueItem>();
         var msg  = mgdb.GetAll(x => x.UserID == userId && ((ChatMessage)x.Data).IsRead == ReadStatus.NoRead && ((ChatMessage)x.Data).MessageID == messageId);
         foreach (var chat in msg)
         {
             ((ChatMessage)chat.Data).IsRead = EnterpriseData.Common.ReadStatus.Read;
             mgdb.Update(chat);
         }
         return(((ChatMessage)msg.FirstOrDefault().Data).IsRead == EnterpriseData.Common.ReadStatus.Read);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#11
0
 public List <PersonStatisDto> GetPersonStatisInfo(string enterpriseId, string userName, DateTime startTime, DateTime endTime, int pageSize, int pageIndex, out int amount)
 {
     try
     {
         if (startTime == null)
         {
             startTime = DateTime.MinValue;
         }
         if (endTime == null)
         {
             endTime = DateTime.MaxValue;
         }
         if (userName == null)
         {
             userName = "";
         }
         var mgdb = new MongoDbProvider <SceneItem>();
         using (var db = new BCEnterpriseContext())
         {
             var userQuery = db.FrontUsers.Where(u => u.EnterpiseID.Equals(enterpriseId) && !u.Closed && (userName.Equals("") || u.Name.Contains(userName)));
             amount = userQuery.Count();
             var userList = userQuery.OrderBy(u => u.UserID).Skip(pageSize * (pageIndex - 1)).Take(pageSize).Select(u => new { UserID = u.UserID, Name = u.Name }).ToList();
             List <PersonStatisDto> result = new List <PersonStatisDto>();
             foreach (var user in userList)
             {
                 PersonStatisDto dto = new PersonStatisDto();
                 dto.userName = user.Name;
                 var sceneProjList = db.Scenes.Where(s => s.EnterpriseID.Equals(enterpriseId) && !s.Deleted && s.Woker.Contains(user.UserID) && startTime <= s.RegistDate && s.RegistDate <= endTime).Select(s => s.ProjectID);
                 dto.projCount  = db.Projects.Where(p => p.EnterpriseID.Equals(enterpriseId) && !p.Deleted && (p.Managers.Contains(user.UserID) || sceneProjList.Contains(p.ProjectID)) && startTime <= p.RegistDate && p.RegistDate <= endTime).Count();
                 dto.sceneCount = sceneProjList.Count();
                 var imageCountTemp = mgdb.GetAll(si => si.UserID.Equals(user.UserID) && startTime <= si.CreateTime && si.CreateTime <= endTime).Select(si => new { count = si.Count, @byte = si.TotalOrgImageBytes });
                 dto.imageCount = imageCountTemp.Select(t => t.count).Sum();
                 dto.imageSize  = imageCountTemp.Select(t => t.@byte).Sum();
                 result.Add(dto);
             }
             return(result);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#12
0
 public void ChangeUserMessageQueueStatus(string userId, string devicId, DateTime?time)
 {
     try
     {
         var mgdb        = new MongoDbProvider <UserMessageQueueItem>();
         var messagelist = mgdb.GetAll(x => x.UserID.Equals(userId) &&
                                       x.Device.Equals(devicId) &&
                                       x.Time > (time ?? DateTime.MinValue));
         foreach (var user in messagelist)
         {
             user.State = AppSyncDataStateEnum.Overdue;
             mgdb.Update(user);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#13
0
 public PersonStatisDto GetPersonStatisSummaryInfo(string enterpriseId)
 {
     try
     {
         var mgdb = new MongoDbProvider <SceneItem>();
         using (var db = new BCEnterpriseContext())
         {
             PersonStatisDto dto         = new PersonStatisDto();
             var             userIdQuery = db.FrontUsers.Where(u => u.EnterpiseID.Equals(enterpriseId) && !u.Closed).Select(u => u.UserID).ToList();
             dto.userName   = "******" + userIdQuery.Count() + "个用户";
             dto.sceneCount = db.Scenes.Where(s => s.EnterpriseID.Equals(enterpriseId) && !s.Deleted).Count();
             dto.projCount  = db.Projects.Where(p => p.EnterpriseID.Equals(enterpriseId) && !p.Deleted).Count();
             var imageCountTemp = mgdb.GetAll(si => userIdQuery.Contains(si.UserID)).Select(si => new { count = si.Count, @byte = si.TotalOrgImageBytes });
             dto.imageCount = imageCountTemp.Select(t => t.count).Sum();
             dto.imageSize  = imageCountTemp.Select(t => t.@byte).Sum();
             return(dto);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public List <SceneItemDto> GetAllByStatus(string sceneID, ItemStatus status, int pageSize, int pageIndex,
                                                  out int count)
        {
            try
            {
                if (string.IsNullOrEmpty(sceneID))
                {
                    throw new ArgumentNullException("sceneID");
                }
                var mgdb = new MongoDbProvider <SceneItem>();

                var query = ItemStatus.All == status
                    ? mgdb.GetAll(o => (o.SceneID == sceneID))
                    : mgdb.GetAll(o => (o.SceneID == sceneID) && (o.Status == status));

                count = query.Count();
                int pageTotal;

                if (pageSize > 0)
                {
                    pageTotal = (count + pageSize - 1) / pageSize;
                }
                else
                {
                    pageSize  = 10;
                    pageTotal = (count + pageSize - 1) / pageSize;
                }

                if (pageIndex > pageTotal)
                {
                    pageIndex = pageTotal;
                }
                if (pageIndex < 1)
                {
                    pageIndex = 1;
                }

                var sceneItems = query
                                 .OrderByDescending(obj => obj.CreateTime)
                                 .Skip(pageSize * (pageIndex - 1))
                                 .Take(pageSize)
                                 .ToList();

                using (var db = new BCEnterpriseContext())
                {
                    if (0 == sceneItems.Count)
                    {
                        return(new List <SceneItemDto>());
                    }
                    var userIds    = sceneItems.Select(o => o.UserID).ToList();
                    var reUserInfo = db.FrontUsers.Where(obj => userIds.Contains(obj.UserID)).Select(o => new
                    {
                        uid     = o.UserID,
                        name    = o.Name,
                        picture = o.Picture
                    }).ToList();

                    var re = (from item in sceneItems
                              join r in reUserInfo on item.UserID equals r.uid into tempSU
                              from t in tempSU.DefaultIfEmpty()
                              select new SceneItemDto
                    {
                        Id = item.Id,
                        SceneID = item.SceneID,
                        PictureGuid = item.PictureGuid,
                        Count = item.Count,
                        Status = item.Status,
                        UserID = item.UserID,
                        CreateTime = item.CreateTime,
                        UpdateTime = item.UpdateTime,
                        Address = item.Address,
                        GPS = item.GPS,
                        Relation = item.Relation,
                        Description = item.Description,
                        Images = item.Images,
                        IsExamine = item.IsExamine,
                        Comments = item.Comments,
                        Type = item.Type,
                        Examines = item.Examines,
                        UserName = t == null ? string.Empty : t.name,
                        UserPicture = t == null ? string.Empty : UriExtensions.GetFullUrl(t.picture)
                    })
                             .ToList();
                    foreach (var r in re)
                    {
                        r.Images = MakeUrlWithPictureName(r.Images);
                    }
                    return(re);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
        public List <ChatDto> SearchChatMessages(string userId, DateTime?beginTime, DateTime?endTime, string objectiveName, EnterpriseData.Common.ReadStatus status, int pageSize, int pageNumber, out int amount)
        {
            try
            {
                if (string.IsNullOrEmpty(objectiveName))
                {
                    objectiveName = "";
                }
                //if (beginTime > endTime)
                //    throw new KnownException("起止时间不合法");
                using (var db = new BCEnterpriseContext())
                {
                    var mgdb = new MongoDbProvider <UserMessageQueueItem>();
                    var msg  = mgdb.GetAll(x => x.UserID == userId && ((ChatMessage)x.Data).IsRead == ReadStatus.NoRead);
                    foreach (var chat in msg)
                    {
                        ((ChatMessage)chat.Data).IsRead = EnterpriseData.Common.ReadStatus.Read;
                        mgdb.Update(chat);
                    }
                    var uidlist = db.FrontUsers.Where(x => x.Name.Contains(objectiveName)).Select(n => n.UserID).ToList();
                    List <ChatMessageDto> sendlist   = new List <ChatMessageDto>();
                    List <ChatMessageDto> recivelist = new List <ChatMessageDto>();
                    sendlist = mgdb.GetAll(o => o.UserID == userId &&
                                           ((ChatMessage)o.Data).SendTime <(endTime ?? DateTime.MaxValue) &&
                                                                           ((ChatMessage)o.Data).SendTime> (beginTime ?? DateTime.MinValue) &&
                                           (((ChatMessage)o.Data).IsRead == status || (status == EnterpriseData.Common.ReadStatus.All)) &&
                                           uidlist.Contains(((ChatMessage)o.Data).SendUserID)).Select(o =>
                    {
                        var temp = (ChatMessage)o.Data;
                        return(new ChatMessageDto
                        {
                            SendUserID = temp.SendUserID,
                            SendUserName = temp.SendUserName,
                            SendUserPicture = temp.SendUserPicture,
                            EnterpriseID = temp.EnterpriseID,
                            Recipients = temp.Recipients,
                            Message = temp.Message,
                            MessageID = temp.MessageID,
                            IsRead = temp.IsRead,
                            SendTime = temp.SendTime.ToLocalTime(),
                            Time = o.Time.ToLocalTime()
                        });
                    }).Distinct().ToList();
                    foreach (var chat in sendlist)
                    {
                        List <KeyValuePair <string, string> > userlist = new List <KeyValuePair <string, string> >();
                        var useridlist = mgdb.GetAll(x => ((ChatMessage)x.Data).MessageID == chat.MessageID)
                                         .Select(n => n.UserID).Distinct().ToList();
                        foreach (var user in useridlist)
                        {
                            var u = db.FrontUsers.FirstOrDefault(x => x.UserID.Equals(user));
                            userlist.Add(new KeyValuePair <string, string>((u ?? new FrontUser {
                                UserID = ""
                            }).UserID, (u ?? new FrontUser {
                                Name = ""
                            }).Name));
                        }
                        chat.UserList = userlist;
                    }
                    //var msgidlist = templist.Select(x => x.MessageID).ToList();
                    //var useridlist = mgdb.GetAll(x => msgidlist.Contains(((ChatMessage)x.Data).MessageID))
                    //        .Select(n => ((ChatMessage)n.Data).SendUserID)
                    //        .ToList();
                    recivelist = mgdb.GetAll(o => ((ChatMessage)o.Data).SendUserID == userId &&
                                             ((ChatMessage)o.Data).SendTime <(endTime ?? DateTime.MaxValue) &&
                                                                             ((ChatMessage)o.Data).SendTime> (beginTime ?? DateTime.MinValue) &&
                                             (((ChatMessage)o.Data).IsRead == status || (status == EnterpriseData.Common.ReadStatus.All)) &&
                                             uidlist.Contains(o.UserID)).Select(o =>
                    {
                        var temp = (ChatMessage)o.Data;
                        return(new ChatMessageDto
                        {
                            SendUserID = temp.SendUserID,
                            SendUserName = temp.SendUserName,
                            SendUserPicture = temp.SendUserPicture,
                            EnterpriseID = temp.EnterpriseID,
                            Recipients = temp.Recipients,
                            Message = temp.Message,
                            MessageID = temp.MessageID,
                            IsRead = temp.IsRead,
                            SendTime = temp.SendTime.ToLocalTime(),
                            Time = o.Time.ToLocalTime()
                        });
                    }).Distinct().ToList();
                    foreach (var chat in recivelist)
                    {
                        List <KeyValuePair <string, string> > userlist = new List <KeyValuePair <string, string> >();
                        var useridlist = mgdb.GetAll(x => ((ChatMessage)x.Data).MessageID == chat.MessageID)
                                         .Select(n => n.UserID).Distinct().ToList();
                        foreach (var user in useridlist)
                        {
                            var u = db.FrontUsers.FirstOrDefault(x => x.UserID.Equals(user));
                            userlist.Add(new KeyValuePair <string, string>((u ?? new FrontUser {
                                UserID = ""
                            }).UserID, (u ?? new FrontUser {
                                Name = ""
                            }).Name));
                        }
                        chat.UserList = userlist;
                    }
                    var templist = sendlist.Concat(recivelist);
                    //.Select(
                    //o => new ChatDto
                    //{
                    //    SendTime = ((ChatMessage)o.Data).SendTime.ToLocalTime(),
                    //    SenderName = ((ChatMessage)o.Data).SendUserID,
                    //    Message = ((ChatMessage)o.Data).Message,
                    //    IsRead = ((ChatMessage)o.Data).IsRead,
                    //    MessageID = ((ChatMessage)o.Data).MessageID
                    //}).Distinct();

                    var namelist = db.FrontUsers.Where(x => uidlist.Contains(x.UserID)).Select(x => new uidnameDto
                    {
                        UserId   = x.UserID,
                        UserName = x.Name
                    }).ToList();
                    var list = from user in namelist
                               join temp in templist on user.UserId equals temp.SendUserID
                               select new
                    {
                        SendTime   = temp.SendTime,
                        SenderName = user.UserName,
                        IsRead     = temp.IsRead,
                        Message    = temp.Message,
                        MessageID  = temp.MessageID,
                        UserList   = temp.UserList
                    };
                    //var list = templist.Where(x=>namelist.Any(n=>n.UserId.Equals(x.SenderName))).Select(m=>new ChatDto{
                    //SenderName = m.
                    //})
                    int pagecount;
                    amount = list.Count();
                    if (pageSize > 0)
                    {
                        // 获取总共页数
                        pagecount = (list.Count() + pageSize - 1) / pageSize;
                    }
                    else
                    {
                        pagecount = 0;
                    }
                    //页码判断,小于1则为1,大于最大页码则为最大页码
                    if (pageNumber > pagecount)
                    {
                        pageNumber = pagecount;
                    }
                    if (pageNumber < 1)
                    {
                        pageNumber = 1;
                    }

                    return(list.Select(x => new ChatDto
                    {
                        SendTime = x.SendTime,
                        SenderName = x.SenderName,
                        IsRead = x.IsRead,
                        Message = x.Message,
                        MessageID = x.MessageID,
                        UserList = x.UserList
                    }).OrderByDescending(x => x.SendTime).Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList().Distinct(new DistinctByMessageID()).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#16
0
        public List <ChatDto> SearchChatMessages(string userId, DateTime?beginTime, DateTime?endTime, string senderName, EnterpriseData.Common.ReadStatus status, int pageSize, int pageNumber, out int amount)
        {
            try
            {
                if (string.IsNullOrEmpty(senderName))
                {
                    senderName = "";
                }
                //if (beginTime > endTime)
                //    throw new KnownException("起止时间不合法");
                using (var db = new BCEnterpriseContext())
                {
                    var mgdb     = new MongoDbProvider <UserMessageQueueItem>();
                    var uidlist  = db.FrontUsers.Where(x => x.Name.Contains(senderName)).Select(n => n.UserID).ToList();
                    var templist = mgdb.GetAll(o => o.UserID == userId &&
                                               ((ChatMessage)o.Data).SendTime <(endTime ?? DateTime.MaxValue) &&
                                                                               ((ChatMessage)o.Data).SendTime> (beginTime ?? DateTime.MinValue) &&
                                               (((ChatMessage)o.Data).IsRead == status || (status == EnterpriseData.Common.ReadStatus.All)) &&
                                               uidlist.Contains(((ChatMessage)o.Data).SendUserID))
                                   .Select(o => new ChatDto
                    {
                        SendTime   = ((ChatMessage)o.Data).SendTime.ToLocalTime(),
                        SenderName = ((ChatMessage)o.Data).SendUserID,
                        Message    = ((ChatMessage)o.Data).Message,
                        IsRead     = ((ChatMessage)o.Data).IsRead,
                        MessageID  = ((ChatMessage)o.Data).MessageID
                    }).ToList();
                    var namelist = db.FrontUsers.Where(x => uidlist.Contains(x.UserID)).Select(x => new uidnameDto
                    {
                        UserId   = x.UserID,
                        UserName = x.Name
                    }).ToList();
                    var list = from user in namelist
                               join temp in templist on user.UserId equals temp.SenderName
                               select new
                    {
                        SendTime   = temp.SendTime,
                        SenderName = user.UserName,
                        IsRead     = temp.IsRead,
                        Message    = temp.Message,
                        MessageID  = temp.MessageID
                    };
                    //var list = templist.Where(x=>namelist.Any(n=>n.UserId.Equals(x.SenderName))).Select(m=>new ChatDto{
                    //SenderName = m.
                    //})
                    int pagecount;
                    amount = list.Count();
                    if (pageSize > 0)
                    {
                        // 获取总共页数
                        pagecount = (list.Count() + pageSize - 1) / pageSize;
                    }
                    else
                    {
                        pagecount = 0;
                    }
                    //页码判断,小于1则为1,大于最大页码则为最大页码
                    if (pageNumber > pagecount)
                    {
                        pageNumber = pagecount;
                    }
                    if (pageNumber < 1)
                    {
                        pageNumber = 1;
                    }

                    return(list.Select(x => new ChatDto
                    {
                        SendTime = x.SendTime,
                        SenderName = x.SenderName,
                        IsRead = x.IsRead,
                        Message = x.Message,
                        MessageID = x.MessageID
                    }).OrderBy(x => x.MessageID).Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public byte[] DownloadPicturePack(string sceneID)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                using (var db = new BCEnterpriseContext())
                {
                    string temp         = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    var    temppath     = temp + "DownLoad";
                    var    basepath     = string.Format("{0}/{1}", temppath, sceneID);
                    string Safepath     = string.Format("{0}/{1}", basepath, "Safe");
                    string Progresspath = string.Format("{0}/{1}", basepath, "Progress");
                    string Dliverpath   = string.Format("{0}/{1}", basepath, "Deliver");
                    string Visitingpath = string.Format("{0}/{1}", basepath, "Visting");
                    string Finishpath   = string.Format("{0}/{1}", basepath, "Finish");
                    if (!Directory.Exists(Safepath))
                    {
                        Directory.CreateDirectory(Safepath);
                    }
                    if (!Directory.Exists(Progresspath))
                    {
                        Directory.CreateDirectory(Progresspath);
                    }
                    if (!Directory.Exists(Dliverpath))
                    {
                        Directory.CreateDirectory(Dliverpath);
                    }
                    if (!Directory.Exists(Finishpath))
                    {
                        Directory.CreateDirectory(Dliverpath);
                    }
                    if (!Directory.Exists(Visitingpath))
                    {
                        Directory.CreateDirectory(Visitingpath);
                    }
                    var picturelist = mgdb.GetAll(x => x.SceneID.Equals(sceneID) && x.Images != null);
                    foreach (var piclist in picturelist)
                    {
                        foreach (var pic in piclist.Images)
                        {
                            var    picFile = mgdb.GetFileAsStream(pic.OriginalPicture, PictureDbName);
                            string path    = "";
                            switch (piclist.Type)
                            {
                            case SceneItemType.Safe: path = string.Format("{0}/{1}", Safepath, pic.OriginalPicture);;
                                break;

                            case SceneItemType.Progress: path = string.Format("{0}/{1}", Progresspath, pic.OriginalPicture);
                                break;

                            case SceneItemType.Deliver: path = string.Format("{0}/{1}", Dliverpath, pic.OriginalPicture);
                                break;

                            case SceneItemType.Visiting: path = string.Format("{0}/{1}", Visitingpath, pic.OriginalPicture);
                                break;

                            case SceneItemType.Finish: path = string.Format("{0}/{1}", Finishpath, pic.OriginalPicture);
                                break;
                            }
                            SavePictureFile(path, picFile);
                        }
                    }
                    var zipPath = string.Format("{0}/{1}", temppath, sceneID + ".zip");
                    Packaging(zipPath, basepath);
                    return(Download(zipPath));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public List <SceneItemDto> GetSceneItemForSync(string userId, string device)
        {
            lock (GETSCENEITEMFORSYNCLOCK)
            {
                using (var db = new BCEnterpriseContext())
                {
                    List <string> sceneIDs = new List <string>();

                    #region get sceneIDs

                    var userDepartmentID = db.FrontUsers.Where(o => o.UserID == userId).Select(o => o.DepartmentID).FirstOrDefault().ToString();
                    if (!string.IsNullOrEmpty(userDepartmentID))
                    {
                        sceneIDs = (from scene in db.Scenes
                                    join project in db.Projects on scene.ProjectID equals project.ProjectID into tPrj
                                    from prj in tPrj.DefaultIfEmpty()
                                    where prj.Departments.Contains(userDepartmentID)
                                    select scene.SceneID
                                    ).Distinct()
                                   .ToList();
                    }

                    if (!(db.SyncStates.Any(n => n.UserID == userId && n.DeviceID == device && n.ActionType == (int)ML.BC.Infrastructure.MsmqHelper.TypeEnum.SceneData)))
                    {
                        var syncSceneData = new SyncState()
                        {
                            UserID     = userId,
                            DeviceID   = device,
                            ActionType = (int)TypeEnum.SceneData,
                            SyncTime   = DBTimeHelper.DBNowTime(db)
                        };
                        db.SyncStates.Add(syncSceneData);
                        if (0 < db.SaveChanges())
                        {
                            return(new List <SceneItemDto>());
                        }
                        else
                        {
                            var logger = log4net.LogManager.GetLogger(typeof(SceneItemManagementService));
                            logger.Error("第一次写入同步现场数据的状态失败!");
                            return(new List <SceneItemDto>());
                        }
                    }

                    var lastSyncTime = (db.SyncStates.FirstOrDefault(
                                            n =>
                                            n.UserID == userId && n.DeviceID == device &&
                                            n.ActionType == (int)ML.BC.Infrastructure.MsmqHelper.TypeEnum.SceneData)
                                        ?? new SyncState {
                        SyncTime = DateTime.MinValue
                    }).SyncTime;

                    #endregion

                    var mgdb       = new MongoDbProvider <SceneItem>();
                    var sceneItems = mgdb.GetAll(n => (sceneIDs.Contains(n.SceneID)) && (n.UpdateTime >= lastSyncTime));

                    var userIds     = sceneItems.Select(n => n.UserID).ToList();
                    var relateUsers = db.FrontUsers.Where(obj => userIds.Contains(obj.UserID)).Select(o => new
                    {
                        uid     = o.UserID,
                        name    = o.Name,
                        picture = o.Picture
                    }).ToList();

                    var resultList = (from item in sceneItems
                                      join r in relateUsers on item.UserID equals r.uid into tempSU
                                      from t in tempSU.DefaultIfEmpty()
                                      select new SceneItemDto
                    {
                        Id = item.Id,
                        SceneID = item.SceneID,
                        PictureGuid = item.PictureGuid,
                        Count = item.Count,
                        Status = item.Status,
                        UserID = item.UserID,
                        CreateTime = item.CreateTime,
                        UpdateTime = item.UpdateTime,
                        Address = item.Address,
                        GPS = item.GPS,
                        Description = item.Description,
                        Images = item.Images,
                        Relation = item.Relation,
                        IsExamine = item.IsExamine,
                        Comments = item.Comments,
                        Type = item.Type,
                        UserName = t == null ? string.Empty : t.name,
                        UserPicture = t == null ? string.Empty : UriExtensions.GetFullUrl(t.picture)
                    })
                                     .OrderByDescending(o => o.UpdateTime)
                                     .ToList();
                    foreach (var r in resultList)
                    {
                        r.Images = MakeUrlWithPictureName(r.Images);
                    }
                    return(resultList);
                }
            }
        }
        public List <SceneItemDto> GetAllByStatus(string userID, string deviceID, string sceneID, ItemStatus status,
                                                  int pageSize, DateTime time, out int count)
        {
            if (string.IsNullOrEmpty(sceneID))
            {
                throw new ArgumentNullException("sceneID");
            }

            using (var db = new BCEnterpriseContext())
            {
                var iSsync =
                    db.SyncStates.Any(
                        n =>
                        n.UserID == userID && n.DeviceID == deviceID &&
                        n.ActionType == (int)ML.BC.Infrastructure.MsmqHelper.TypeEnum.SceneData);
                if (!iSsync)
                {
                    var syncSceneData = new SyncState()
                    {
                        UserID     = userID,
                        DeviceID   = deviceID,
                        ActionType = (int)TypeEnum.SceneData,
                        SyncTime   = DBTimeHelper.DBNowTime(db)
                    };

                    db.SyncStates.Add(syncSceneData);
                    if (!(0 < db.SaveChanges()))
                    {
                        var logger = log4net.LogManager.GetLogger(typeof(SceneItemManagementService));
                        logger.Error("第一次写入同步现场数据的状态失败!");
                    }
                }
            }

            var mgdb  = new MongoDbProvider <SceneItem>();
            var query = ItemStatus.All == status
                ? mgdb.GetAll(o => (o.SceneID == sceneID) && (o.UpdateTime < time))
                : mgdb.GetAll(o => (o.SceneID == sceneID) && (o.Status == status) && (o.UpdateTime < time));

            count = query.Count();
            if (pageSize < 1)
            {
                pageSize = 10;
            }
            var sceneItems = query
                             .OrderByDescending(obj => obj.CreateTime)
                             .Take(pageSize)
                             .ToList();

            using (var db = new BCEnterpriseContext())
            {
                if (0 == sceneItems.Count)
                {
                    return(new List <SceneItemDto>());
                }
                var userIds    = sceneItems.Select(o => o.UserID).ToList();
                var reUserInfo = db.FrontUsers.Where(obj => userIds.Contains(obj.UserID)).Select(o => new
                {
                    uid     = o.UserID,
                    name    = o.Name,
                    picture = o.Picture
                }).ToList();

                var re = (from item in sceneItems
                          join r in reUserInfo on item.UserID equals r.uid into tempSU
                          from t in tempSU.DefaultIfEmpty()
                          select new SceneItemDto
                {
                    Id = item.Id,
                    SceneID = item.SceneID,
                    PictureGuid = item.PictureGuid,
                    Count = item.Count,
                    Status = item.Status,
                    UserID = item.UserID,
                    CreateTime = item.CreateTime,
                    UpdateTime = item.UpdateTime,
                    Address = item.Address,
                    GPS = item.GPS,
                    Description = item.Description,
                    Images = item.Images,
                    Examines = item.Examines,
                    Comments = item.Comments,
                    Relation = item.Relation,
                    IsExamine = item.IsExamine,
                    Type = item.Type,
                    UserName = t == null ? string.Empty : t.name,
                    UserPicture = t == null ? string.Empty : UriExtensions.GetFullUrl(t.picture)
                })
                         .ToList();
                foreach (var r in re)
                {
                    r.Images = MakeUrlWithPictureName(r.Images);
                }
                return(re);
            }
        }
示例#20
0
        public ReviewStatisticsDto GetReviewStatistics(string userID, DateTime?beginTime, DateTime?endTime)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                using (var db = new BCEnterpriseContext())
                {
                    var roles = (from users in db.UserRoles
                                 join role in db.RFAAuthorizations on users.RoleID equals role.RoleID
                                 where users.UserID == userID && !users.Deleted && !role.Deleted && (role.FunctionID == ProjectFunction || role.FunctionID == SceneFunction)
                                 select new
                    {
                        funID = role.FunctionID
                    }).Distinct();
                    if (0 == roles.Count())
                    {
                        return(new ReviewStatisticsDto());
                    }
                    var user           = GetMyDepartment(userID, db);
                    var proflag        = roles.FirstOrDefault(x => x.Equals(ProjectFunction));
                    var sceneflag      = roles.FirstOrDefault(x => x.Equals(SceneFunction));
                    var department     = new List <int>();
                    var tempprojectAll = new List <string>();
                    var tempsceneAll   = new List <EnterpriseData.Model.Scene>();
                    //获取企业所有项目
                    var tempprojectlist = db.Projects.Where(x => x.EnterpriseID.Equals(user.EnterpiseID) && !x.Deleted && (beginTime ?? DateTime.MinValue) < x.UpdateTime && x.UpdateTime < (endTime ?? DateTime.MaxValue)).ToList();
                    if (null != proflag)
                    {
                        //没有查看全部权限时传入参数为级部门ID
                        department = GetNowDepartment(user.EnterpiseID, user.DepartmentID, db).Select(x => x.DepartmentID).ToList();
                    }
                    else
                    {
                        //拥有查看全部权限时候传入参数为Null
                        department = GetNowDepartment(user.EnterpiseID, null, db).Select(x => x.DepartmentID).ToList();
                    }
                    if (0 == department.Count())
                    {
                        department = new List <int>();
                    }
                    department.Add(user.DepartmentID ?? -1);

                    tempprojectAll = tempprojectlist.Where(x => x.Departments.Split("|".ToCharArray()).Any(n => department.Any(m => m.ToString() == n)))
                                     .Select(n => n.ProjectID).ToList();
                    if (null != sceneflag)
                    {
                        //没有查看全部权限时传入参数为级部门ID
                        department = GetNowDepartment(user.EnterpiseID, user.DepartmentID, db).Select(x => x.DepartmentID).ToList();
                    }
                    else
                    {
                        //拥有查看全部权限时候传入参数为Null
                        department = GetNowDepartment(user.EnterpiseID, null, db).Select(x => x.DepartmentID).ToList();
                    }
                    if (0 == department.Count())
                    {
                        department = new List <int>();
                    }
                    department.Add(user.DepartmentID ?? -1);

                    var tempprojAll = tempprojectlist.Where(x => x.Departments.Split("|".ToCharArray()).Any(n => department.Any(m => m.ToString() == n)))
                                      .Select(n => n.ProjectID).ToList();

                    department = GetOwnerDepartment(user.DepartmentID ?? -1, db).Select(x => x.DepartmentID).ToList();
                    if (0 == department.Count())
                    {
                        department = new List <int>();
                    }
                    department.Add(user.DepartmentID ?? -1);
                    tempsceneAll = db.Scenes.Where(x => tempprojAll.Contains(x.ProjectID) && !x.Deleted).ToList();
                    var templist  = tempsceneAll.Select(x => x.SceneID).ToList();
                    var scenelist =
                        mgdb.GetAll(
                            x => (null != x.Examines) && templist.Contains(x.SceneID))
                        .Select(m => m.SceneID).Distinct().ToList();
                    var proIDlist =
                        tempsceneAll.Where(x => scenelist.Contains(x.SceneID) && !x.Deleted).Select(n => n.ProjectID).ToList();
                    var projectlist = tempprojAll.Where(x => proIDlist.Contains(x)).ToList();
                    return(new ReviewStatisticsDto()
                    {
                        ProjectAll = tempprojectAll.Count(),
                        ProjectScan = projectlist.Count(),
                        SceneAll = tempsceneAll.Count(),
                        SceneScan = scenelist.Count()
                    });
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        private static IEnumerable <OperationLog> GetAllOperationLog()
        {
            var mgdb = new MongoDbProvider <OperationLog>();

            return(mgdb.GetAll().ToList());
        }