public DepartmentDto GetParentDepartment(int departmentId)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var myDepartment = db.Departments.FirstOrDefault(x => x.DepartmentID == departmentId && !x.Deleted);
             return(db.Departments.Where(x => x.DepartmentID == myDepartment.ParentID && !x.Deleted).Select(n => new DepartmentDto
             {
                 Available = n.Available,
                 Deleted = n.Deleted,
                 DepartmentID = n.DepartmentID,
                 Description = n.Description,
                 EnterpriseID = n.EnterpriseID,
                 Name = n.Name,
                 ParentID = n.ParentID
             }).ToList().FirstOrDefault());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 2
0
 private static bool SetSceneHasData(string sceneID)
 {
     try
     {
         if (string.IsNullOrEmpty(sceneID))
         {
             return(false);
         }
         using (var db = new BCEnterpriseContext())
         {
             var scene = db.Scenes.First(o => o.SceneID == sceneID);
             if (!scene.HasData)
             {
                 scene.HasData = true;
                 return(0 < db.SaveChanges());
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
 private static bool SetSceneHasData(IMongoDbProvider <SceneItem, string> mgdb, string sceneID)
 {
     try
     {
         if (null != mgdb.GetAll(o => o.SceneID == sceneID))
         {
             return(true);
         }
         using (var db = new BCEnterpriseContext())
         {
             var scene = db.Scenes.First(o => o.SceneID == sceneID);
             if (!scene.HasData)
             {
                 return(true);
             }
             scene.HasData = false;
             return(0 < db.SaveChanges());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public bool Delete(int departmentId, string enterpriseId)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var mydepartments = GetOwnerDepartment(departmentId, db).Select(x => x.DepartmentID).ToList();
             mydepartments.Add(departmentId);
             var users = db.FrontUsers.FirstOrDefault(x => mydepartments.Contains(x.DepartmentID ?? -5) && x.EnterpiseID.Equals(enterpriseId));
             if (null == users)
             {
                 return(0 != DeleteDepartment(departmentId, db));
             }
             else
             {
                 throw new KnownException("该部门存在人员,无法删除");
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public EnterpriseSyncDto GetEnterpriseForSync(string enterpriseID, string userID, string deviceID)
        {
            using (var db = new BCEnterpriseContext())
            {
                //  同步表中无此用户和设备ID时,创建此记录并将Organization数据初始化发送给APP
                if (null == db.SyncStates.FirstOrDefault(o => (o.UserID == userID) && (o.DeviceID == deviceID) &&
                                                         ((o.ActionType == (byte)TypeEnum.User) || (o.ActionType == (byte)TypeEnum.Role) || (o.ActionType == (byte)TypeEnum.Department))))
                {
                    var syncDepartment = new SyncState()
                    {
                        ActionType = (byte)TypeEnum.Department, DeviceID = deviceID, UserID = userID
                    };
                    var syncUser = new SyncState()
                    {
                        ActionType = (byte)TypeEnum.User, DeviceID = deviceID, UserID = userID
                    };
                    var syncRole = new SyncState()
                    {
                        ActionType = (byte)TypeEnum.Role, DeviceID = deviceID, UserID = userID
                    };
                    AddSyncState(syncDepartment, syncUser, syncRole);
                    return(GetEnterpriseForSync(enterpriseID));
                }

                var tempData = (from ep in db.Enterprises
                                where ep.EnterpriseID == enterpriseID
                                join dp in db.Departments on ep.EnterpriseID equals dp.EnterpriseID into tempDP
                                join user in db.FrontUsers on ep.EnterpriseID equals user.EnterpiseID into tempUser
                                join rl in db.RFARoles on ep.EnterpriseID equals rl.OwnerID into tempRL
                                select new
                {
                    EnterpriseID = ep.EnterpriseID,
                    Departments = (
                        from tdp in tempDP.DefaultIfEmpty()
                        //where !tdp.Deleted
                        from st in db.SyncStates
                        where st.UserID == userID && st.DeviceID == deviceID && st.ActionType == (byte)TypeEnum.Department && st.SyncTime <= tdp.UpdateTime
                        select tdp),
                    FrontUsers = (
                        from tusr in tempUser.DefaultIfEmpty()
                        from st in db.SyncStates
                        where st.UserID == userID && st.DeviceID == deviceID && st.ActionType == (byte)TypeEnum.User && st.SyncTime <= tusr.UpdateTime
                        select new
                    {
                        tusr.UserID,
                        tusr.Name,
                        tusr.DepartmentID,
                        tusr.Closed,
                    }
                        ),
                    UserRoles = (
                        from tul in tempRL.DefaultIfEmpty()
                        join ur in db.UserRoles on tul.RoleID equals ur.RoleID into tempUR
                        from tur in tempUR.DefaultIfEmpty()
                        //where tul.Available && (tur == null || !tur.Deleted)
                        from st in db.SyncStates
                        where st.UserID == userID && st.DeviceID == deviceID && st.ActionType == (byte)TypeEnum.Role && (st.SyncTime <= tul.UpdateTime || tur == null || st.SyncTime <= tur.UpdateTime)
                        select new
                    {
                        RoleId = tul.RoleID,
                        RoleName = tul.Name,
                        Available = tul.Available,
                        UserID = tur.UserID,
                        Deleted = tur != null && tur.Deleted
                    }
                        ).Union(
                        from tul in db.RFARoles
                        where tul.OwnerID == null
                        join ur in db.UserRoles on tul.RoleID equals ur.RoleID into tempUR
                        from tur in tempUR.DefaultIfEmpty()
                        join user in tempUser on tur.UserID equals user.UserID into tempUser2
                        from tuser in tempUser2.DefaultIfEmpty()
                        where tul.Available && (tur == null || !tur.Deleted) && tuser != null
                        from st in db.SyncStates
                        where st.UserID == userID && st.DeviceID == deviceID && st.ActionType == 3 && (st.SyncTime <= tul.UpdateTime || (tur == null || st.SyncTime <= tur.UpdateTime))
                        select new
                    {
                        RoleId = tul.RoleID,
                        RoleName = tul.Name,
                        Available = tul.Available,
                        UserID = tur.UserID,
                        Deleted = tur != null && tur.Deleted
                    }
                        )
                }).FirstOrDefault();
                if (tempData == null)
                {
                    return(new EnterpriseSyncDto());
                }

                var result = new EnterpriseSyncDto
                {
                    EnterpriseID = tempData.EnterpriseID,
                    Departments  = tempData.Departments.Select(obj => (DepartmentSyncDto)obj).ToArray(),
                    FrontUsers   = tempData.FrontUsers.Select(n => new FrontUserSyncDto
                    {
                        EnterpriseID = tempData.EnterpriseID,
                        UserID       = n.UserID,
                        Name         = n.Name,
                        Closed       = n.Closed,
                        DepartmentID = n.DepartmentID
                    }).ToArray(),
                    UserRoles = tempData.UserRoles.Select(n => new UserRoleSyncDto
                    {
                        EnterpriseID = tempData.EnterpriseID,
                        UserID       = n.UserID,
                        RoleID       = n.RoleId,
                        RoleName     = n.RoleName,
                        Deleted      = n.Deleted || !n.Available
                    }).ToArray()
                };

                return(result);
            }
        }
 public string AddEnterprise(EnterpriseDto enterprise)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var idGenerator  = ML.BC.Infrastructure.Ioc.GetService <IUniqeIdGenerator>();
             var enterpriseId = idGenerator.GeneratorEnterpriseID(enterprise.ProfessionID, enterprise.PropertyID);
             //为null则行业ID和性质ID长度有误
             if (null == enterpriseId)
             {
                 throw new KnownException("企业ID生成失败");
             }
             else
             {
                 enterprise.EnterpriseID = enterpriseId;
             }
             // 设置注册和更新时间为当前时间
             enterprise.RegistDate = DateTime.Now;
             enterprise.UpdateTime = DateTime.Now;
             // 判断不允许为空的字段是否为空
             if (
                 string.IsNullOrEmpty(enterprise.EnterpriseID) ||
                 string.IsNullOrEmpty(enterprise.Name) ||
                 string.IsNullOrEmpty(enterprise.ProfessionID) ||
                 string.IsNullOrEmpty(enterprise.PropertyID) ||
                 null == enterprise.UpdateTime ||
                 null == enterprise.RegistDate)
             {
                 throw new KnownException("不允许非空字段为空");
             }
             var prof = db.EnterpriseProfessions.FirstOrDefault(x => x.EnterpriseProfessionID.Equals(enterprise.ProfessionID));
             if (null == prof)
             {
                 throw new KnownException("行业ID无效");
             }
             var prop = db.EnterprisePropertys.FirstOrDefault(x => x.EnterprisePropertyID.Equals(enterprise.PropertyID));
             if (null == prop)
             {
                 throw new KnownException("性质ID无效");
             }
             db.Enterprises.Add(enterprise);
             //添加企业超级管理员
             var uid = AddEnterpriseAdmin(db, enterpriseId);
             //添加企业超级管理员用户角色关系
             AddEnterpriseAdaminRole(db, enterpriseId, uid);
             if (db.SaveChanges() > 0)
             {
                 return(enterprise.EnterpriseID);
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        private List <FrontUserDto> GetUserByDepartmentIDsAndEnterpriseID(string enterpriseID, List <int> departIDs, int pageSize, int pageIndex, out int count)
        {
            try
            {
                if (null == departIDs)
                {
                    throw new KnownException("部门ID信息缺失!");
                }
                using (var db = new BCEnterpriseContext())
                {
                    var query = db.FrontUsers.Where(obj => (obj.EnterpiseID == enterpriseID) && (departIDs.Contains(obj.DepartmentID ?? 0)));

                    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;
                    }

                    return(query
                           .OrderBy(obj => obj.UserID)
                           .Skip(pageSize * (pageIndex - 1))
                           .Take(pageSize)
                           .Select(obj => new FrontUserDto()
                    {
                        UserID = obj.UserID,
                        Name = obj.Name,
                        EnterpiseID = obj.EnterpiseID,
                        DepartmentID = obj.DepartmentID,
                        Mobile = obj.Mobile,
                        LastIP = obj.LastIP,
                        LastDate = obj.LastDate,
                        Password = obj.Password,
                        UpdateTime = obj.UpdateTime,
                        Closed = obj.Closed,
                        RegistDate = obj.RegistDate,
                        LoginByDesktop = obj.LoginByDesktop,
                        LoginByMobile = obj.LoginByMobile
                    }).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <FrontUserDto> SearchUser(string enterpriseID, string departmentKeyword,
                                              string nameKeyword, int pageIndex, int pageSize, out int count)
        {
            try
            {
                if (string.IsNullOrEmpty(enterpriseID))
                {
                    throw new KnownException("企业ID信息缺失!");
                }

                using (var db = new BCEnterpriseContext())
                {
                    var departmentIDList = db.Departments.Where(obj => string.IsNullOrEmpty(departmentKeyword) ? true : obj.Name.Contains(departmentKeyword) && !obj.Deleted)
                                           .Select(o => o.DepartmentID)
                                           .ToList();
                    if (departmentIDList.Count <= 0)
                    {
                        throw new KnownException("部门没有任何数据");
                    }
                    var query = db.FrontUsers.Where(obj => (obj.Name.Contains(nameKeyword)) &&
                                                    (string.IsNullOrEmpty(enterpriseID) ? true : obj.EnterpiseID.Equals(enterpriseID)) &&
                                                    (departmentIDList.Contains(obj.DepartmentID.Value) || obj.DepartmentID == null) &&
                                                    !obj.Closed);

                    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;
                    }

                    return(query
                           .OrderBy(obj => obj.UserID)
                           .Skip(pageSize * (pageIndex - 1))
                           .Take(pageSize)
                           .Select(obj => new FrontUserDto()
                    {
                        UserID = obj.UserID,
                        Name = obj.Name,
                        EnterpiseID = obj.EnterpiseID,
                        DepartmentID = obj.DepartmentID,
                        Mobile = obj.Mobile,
                        LastIP = obj.LastIP,
                        LastDate = obj.LastDate,
                        Password = obj.Password,
                        UpdateTime = obj.UpdateTime,
                        Closed = obj.Closed,
                        RegistDate = obj.RegistDate,
                        LoginByDesktop = obj.LoginByDesktop,
                        LoginByMobile = obj.LoginByMobile
                    }).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <FrontUserDto> GetFrontUserByPartialInfo(FrontUserDto model, int pageSize, int pageIndex, out int count)
        {
            try
            {
                if (null == model)
                {
                    model = new FrontUserDto();
                }
                using (var db = new BCEnterpriseContext())
                {
                    var query = db.FrontUsers.Where(
                        obj => (string.IsNullOrEmpty(model.EnterpiseID) ? true : obj.EnterpiseID == model.EnterpiseID) &&
                        (string.IsNullOrEmpty(model.Name) ? true : obj.Name.Contains(model.Name)));
                    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 list = query
                               .OrderBy(obj => obj.UserID)
                               .Skip(pageSize * (pageIndex - 1))
                               .Take(pageSize)
                               .Select(obj => new FrontUserDto()
                    {
                        UserID         = obj.UserID,
                        Name           = obj.Name,
                        EnterpiseID    = obj.EnterpiseID,
                        DepartmentID   = obj.DepartmentID,
                        Mobile         = obj.Mobile,
                        LastIP         = obj.LastIP,
                        LastDate       = obj.LastDate,
                        Password       = obj.Password,
                        UpdateTime     = obj.UpdateTime,
                        Closed         = obj.Closed,
                        RegistDate     = obj.RegistDate,
                        LoginByDesktop = obj.LoginByDesktop,
                        LoginByMobile  = obj.LoginByMobile
                    }).ToList();
                    return(list);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public Account.Dtos.SessionUserDto GetSessionUser(string userId, string device)
        {
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    throw new KnownException("用户名称不能为空!");
                }
                using (var db = new BCEnterpriseContext())
                {
                    ClearUserLoginState(db);

                    var user = (from u in db.FrontUsers
                                where u.UserID == userId
                                join ls in db.UserLoginStates on u.UserID equals ls.UserID
                                where ls.Device == device
                                join ep in db.Enterprises on u.EnterpiseID equals ep.EnterpriseID into tempEP
                                join ur in db.UserRoles on u.UserID equals ur.UserID into tempUR
                                select new
                    {
                        u,
                        ls,
                        ep = tempEP.DefaultIfEmpty().FirstOrDefault(),
                        roles = tempUR.DefaultIfEmpty().Where(n => !n.Deleted).Select(n => n.RoleID),
                        functions = (from tur in tempUR.DefaultIfEmpty()
                                     where tur.Deleted == false
                                     join r in db.RFARoles on tur.RoleID equals r.RoleID
                                     where r.Available
                                     join rf in db.RFAAuthorizations on tur.RoleID equals rf.RoleID into tempRF
                                     from trf in tempRF.DefaultIfEmpty()
                                     where !trf.Deleted
                                     select trf.FunctionID)
                    }).FirstOrDefault();

                    if (user == null)
                    {
                        throw new KnownException("用户名不存在或用户当前登录状态丢失请重新登录。");
                    }

                    #region get functionIds
                    //TODO:get it from the cache
                    var functions   = db.RFAFunctions.ToList();
                    var functionIds = new List <string>();

                    Action <string> recursionFunctions = null;
                    recursionFunctions = (functionId) =>
                    {
                        if (functionIds.Contains(functionId))
                        {
                            return;
                        }
                        functionIds.Add(functionId);

                        var tempParent = (from fun in functions
                                          where fun.FunctionID == functionId
                                          join tfun in functions on fun.ParentID equals tfun.FunctionID
                                          select tfun).FirstOrDefault();
                        if (tempParent != null)
                        {
                            recursionFunctions(tempParent.FunctionID);
                        }
                    };
                    user.functions.ToList().ForEach(recursionFunctions);
                    #endregion

                    var sessionUserDto = new Account.Dtos.SessionUserDto
                    {
                        UserID         = user.u.UserID,
                        UserName       = user.u.Name,
                        LastLoginTime  = user.u.LastDate ?? DateTime.Now,
                        LastIP         = user.u.LastIP,
                        Picture        = UriExtensions.GetFullUrl(user.u.Picture),
                        Device         = user.ls.Device,
                        Token          = user.ls.LoginToken,
                        EnterpriseID   = user.u.EnterpiseID,
                        EnterpriseName = user.ep == null ? string.Empty : user.ep.Name,
                        DepartmentID   = user.u.DepartmentID,
                        RoleIDs        = user.roles.ToArray(),
                        FunctionIDs    = functionIds.ToArray()
                    };
                    return(sessionUserDto);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        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 SceneItem Add(SceneItem sceneItem)
        {
            try
            {
                if (null == sceneItem)
                {
                    throw new KnownException("现场数据为空,不能添加!");
                }
                if (null == sceneItem.Relation)
                {
                    sceneItem.Relation = "";
                }
                if (string.IsNullOrEmpty(sceneItem.SceneID) && string.IsNullOrEmpty(sceneItem.UserID) &&
                    string.IsNullOrEmpty(sceneItem.GPS) && (string.IsNullOrEmpty(sceneItem.Address)))
                {
                    throw new KnownException("必要的现场数据缺失,无法保存!");
                }
                using (var db = new BCEnterpriseContext())
                {
                    if (db.Scenes.Any(o => o.ParentSceneID == sceneItem.SceneID &&
                                      o.Status == (byte)ML.BC.EnterpriseData.Common.Status.End))
                    {
                        throw new KnownException("当前现场不是叶子现场,或者该现场已完工,不能添加现场数据!");
                    }
                }
                sceneItem.UpdateTime = DBTimeHelper.DBNowTime();
                var mgdb = new MongoDbProvider <SceneItem>();
                if (sceneItem.Count == 0)
                {
                    var si = mgdb.Insert(sceneItem);
                    if (!string.IsNullOrEmpty(sceneItem.Relation))
                    {
                        var item = mgdb.GetById(sceneItem.Relation);
                        if (null != item)
                        {
                            item.IsExamine  = true;
                            item.UpdateTime = DBTimeHelper.DBNowTime();
                            mgdb.Update(item);
                        }
                    }
                    return(SetSceneHasData(si.SceneID) ? si : null);
                }

                var sessionDatas = HttpContext.Current.Session[sceneItem.PictureGuid.ToString()] as List <ImageInfo>;
                sessionDatas = sessionDatas ?? new List <ImageInfo>();

                var listUrl = new List <ImageUrl>();
                if (sceneItem.Count != sessionDatas.Count)
                {
                    throw new KnownException("图片还未上传完成!");
                }
                foreach (var info in sessionDatas)
                {
                    sceneItem.TotalOrgImageBytes += info.OrgImageBytes;
                    sceneItem.TotalThuImageBytes += info.ThuImageBytes;
                    listUrl.Add(new ImageUrl()
                    {
                        OriginalPicture = info.OriginalPicture, ThumbnailPicture = info.ThumbnailPicture
                    });
                }
                sceneItem.Images = listUrl;

                var re = mgdb.Insert(sceneItem);
                if (null == re)
                {
                    throw new KnownException("保存失败!");
                }
                if (!SetSceneHasData(re.SceneID))
                {
                    return(null);
                }
                HttpContext.Current.Session[sceneItem.PictureGuid.ToString()] = null;
                re.Images = MakeUrlWithPictureName(re.Images);
                if (!string.IsNullOrEmpty(sceneItem.Relation))
                {
                    var item = mgdb.GetById(sceneItem.Relation);
                    if (null != item)
                    {
                        item.IsExamine  = true;
                        item.UpdateTime = DBTimeHelper.DBNowTime();
                        mgdb.Update(item);
                    }
                }
                return(re);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        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);
            }
        }
        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;
            }
        }
Esempio n. 15
0
 public ProjectSceneCompletionStatisticsDto GetReportForm(string enterpriseId, DateTime?beginTime, DateTime?endTime, List <int> departments, string address)
 {
     try
     {
         List <Department>       dtmt     = new List <Department>();
         List <Department>       dtmtlist = new List <Department>();
         IQueryable <Department> temp;
         if (string.IsNullOrEmpty(address))
         {
             address = "";
         }
         //                List<Project> tempprojectlist = new List<Project>();
         using (var db = new BCEnterpriseContext())
         {
             if (0 == departments.Count())
             {
                 temp = db.Departments.Where(x => x.EnterpriseID == enterpriseId && x.ParentID == 0 && !x.Deleted);
                 if (temp.Count() <= 0)
                 {
                     throw new KnownException("没有相关信息");
                 }
                 foreach (var d in temp)
                 {
                     dtmtlist = GetOwnerDepartment(d.DepartmentID, db);
                     dtmt.Add(d);
                     dtmt = dtmt.Concat(dtmtlist).ToList();
                 }
                 departments = dtmt.Select(x => x.DepartmentID).ToList();
             }
             var project = db.Projects.Where(x =>
                                             x.EnterpriseID.Equals(enterpriseId) &&
                                             !x.Deleted).ToList();
             var            projectlist     = project.Where(x => x.Departments.Split("|".ToCharArray()).Any(n => departments.Any(m => m.ToString() == n))).ToList();
             List <string>  scenelist       = new List <string>();
             List <Project> listprojectdata = new List <Project>();
             if (!string.IsNullOrEmpty(address))
             {
                 scenelist = db.Scenes.Where(x =>
                                             x.EnterpriseID.Equals(enterpriseId) &&
                                             x.Address.Contains(address) &&
                                             !x.Deleted).Select(n => n.ProjectID).ToList();
                 listprojectdata = projectlist.Where(x => (scenelist ?? new List <string>()).Contains(x.ProjectID) &&
                                                     !((x.BeginDate > (endTime ?? DateTime.MaxValue)) ||
                                                       (x.EndDate < (beginTime ?? DateTime.MinValue)))).ToList();
             }
             else
             {
                 listprojectdata = projectlist.Where(x => !((x.BeginDate > (endTime ?? DateTime.MaxValue)) ||
                                                            (x.EndDate < (beginTime ?? DateTime.MinValue)))).ToList();
             }
             var prolist = projectlist.Select(x => x.ProjectID).ToList();
             if (0 >= prolist.Count())
             {
                 prolist = new List <string>();
             }
             var listscenedata = db.Scenes.Where(x =>
                                                 x.EnterpriseID.Equals(enterpriseId) &&
                                                 x.Address.Contains(address) &&
                                                 !x.Deleted &&
                                                 prolist.Contains(x.ProjectID) &&
                                                 !((x.BeginDate > (endTime ?? DateTime.MaxValue)) || (x.EndDate < (beginTime ?? DateTime.MinValue)))).ToList();
             var endCount        = listprojectdata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.End).Count();
             var ingCount        = listprojectdata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.Begin).Count();
             var readyCount      = listprojectdata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.Ready).Count();
             var endCountscene   = listscenedata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.End).Count();
             var ingCountscene   = listscenedata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.Begin).Count();
             var readyCountscene = listscenedata.Where(x => x.Status == (byte)EnterpriseData.Common.Status.Ready).Count();
             return(new ProjectSceneCompletionStatisticsDto()
             {
                 ProjectData = new CompletionStatistics()
                 {
                     EndCount = endCount,
                     IngCount = ingCount,
                     ReadyCount = readyCount,
                 },
                 SceneData = new CompletionStatistics()
                 {
                     EndCount = endCountscene,
                     IngCount = ingCountscene,
                     ReadyCount = readyCountscene,
                 }
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 16
0
        private DepartmentInfoFormDto GetDepartmentInfoFormOfMyDepartment(int?departmentId, string enterpriseId, DateTime?beginTime, DateTime?endTime, BCEnterpriseContext db)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                //get my departments
                var dpartmentlist = GetMyDepartment(enterpriseId, departmentId, db);
                //get my sceneId
                var scenlist = (from scene in db.Scenes
                                join project in db.Projects on scene.ProjectID equals project.ProjectID
                                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 => (dpartmentlist.Any(n => n.DepartmentID.ToString().Equals(x)))));
                //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 => (dpartmentlist.Any(m => m.DepartmentID.ToString().Equals(n)))));
                //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();
                //get users of my department
                var templist = dpartmentlist.Select(n => n.DepartmentID).ToList();
                var userlist = db.FrontUsers.Where(x => null != x.DepartmentID && templist.Contains(x.DepartmentID.Value));
                var depart   = db.Departments.FirstOrDefault(x => x.DepartmentID == departmentId.Value);
                return(new DepartmentInfoFormDto
                {
                    DepartmentName = depart.Name,
                    //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,
                    PictureByte = pByte
                });
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 17
0
        private List <DepartmentDto> GetMyDepartment(string enterpriseId, int?departmentId, BCEnterpriseContext db)
        {
            try
            {
                IEnumerable <Department> dtmt = null;
                if (departmentId.HasValue)
                {
                    dtmt = db.Departments.Where(x => x.EnterpriseID == enterpriseId && x.DepartmentID == departmentId.Value && !x.Deleted);
                }
                else
                {
                    dtmt = db.Departments.Where(x => x.EnterpriseID == enterpriseId && x.ParentID == 0 && !x.Deleted);
                }

                if (0 == dtmt.Count())
                {
                    return(dtmt.Select(x => new DepartmentDto
                    {
                        DepartmentID = x.DepartmentID,
                        Name = x.Name,
                    }).ToList());
                }
                foreach (var deptmt in dtmt)
                {
                    dtmt = dtmt.Concat(GetOwnerDepartment(deptmt.DepartmentID, db));
                }
                return(dtmt.Select(x => new DepartmentDto
                {
                    DepartmentID = x.DepartmentID,
                    Name = x.Name,
                }).ToList());
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        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 bool UpdateFrontUser(FrontUserDto frontUserDto)
        {
            try
            {
                if (null == frontUserDto)
                {
                    throw new KnownException("用户信息为空,无法更新!");
                }
                if (string.IsNullOrEmpty(frontUserDto.EnterpiseID) || null == frontUserDto.UserRoleIDs)
                {
                    throw new KnownException("关键信息缺失,无法更新用户!");
                }

                using (var db = new BCEnterpriseContext())
                {
                    if (!db.Enterprises.Any(obj => obj.EnterpriseID == frontUserDto.EnterpiseID && !obj.Deleted))
                    {
                        throw new KnownException("没有相关企业信息或企业已被禁用!,不能更新用户,请尝试刷新后重试!");
                    }
                    if (null != frontUserDto.DepartmentID &&
                        (!db.Departments.Any(obj => obj.EnterpriseID == frontUserDto.EnterpiseID && obj.DepartmentID == frontUserDto.DepartmentID && !obj.Deleted)))
                    {
                        throw new KnownException("此企业下不存在该部门信息或已被删除,无法更新用户,请尝试刷新后重试!");
                    }
                    if (frontUserDto.UserRoleIDs.Count == 0)
                    {
                        throw new KnownException("必须为用户指定角色");
                    }
                    var r = (db.RFARoles.Where(o => frontUserDto.UserRoleIDs.Contains(o.RoleID) ? o.Available : true)).Select(o => o.RoleID).ToList();
                    if (!frontUserDto.UserRoleIDs.All(o => (r.Contains(o))))
                    {
                        throw new KnownException("指定的角色不存在,或已被删除,请尝试刷新后重试!");
                    }

                    using (TransactionScope transaction = new TransactionScope())
                    {
                        var query = db.FrontUsers.FirstOrDefault(obj => obj.UserID == frontUserDto.UserID);
                        if (!db.FrontUsers.Any(obj => obj.UserID == frontUserDto.UserID))
                        {
                            throw new KnownException("不存在该记录无法更新!");
                        }
                        if (!string.IsNullOrEmpty(frontUserDto.Password))
                        {
                            query.Password = CryptoService.MD5Encrypt(frontUserDto.Password);
                        }
                        query.Name         = frontUserDto.Name;
                        query.EnterpiseID  = frontUserDto.EnterpiseID;
                        query.DepartmentID = frontUserDto.DepartmentID;
                        query.Mobile       = frontUserDto.Mobile;
                        query.UpdateTime   = DateTime.Now;
                        query.Closed       = frontUserDto.Closed;
                        db.SaveChanges();

                        var result = SetFrontUserRoles(frontUserDto.UserID, frontUserDto.UserRoleIDs);
                        if (!result)
                        {
                            throw new KnownException("更新用户角色失败!");
                        }
                        else
                        {
                            transaction.Complete();
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 20
0
 public List <UserLoginLogDto> SearchUserLoginLog(DateTime?beginTime, DateTime?endTime, string userName, string enterpriseName, EnterpriseData.Common.LoginStatus status, int pageNumber, int pageSize, out int amount)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var temp = new Department()
             {
                 Name = "",
             };
             var entlist  = db.Enterprises.Where(x => x.Name.Contains(enterpriseName) || (enterpriseName ?? "") == "").Select(n => n.EnterpriseID).ToList();
             var userlist = db.FrontUsers.Where(x => entlist.Contains(x.EnterpiseID) && (x.Name.Contains(userName) || (userName ?? "") == "")).Select(n => new EnterpriseUsers
             {
                 DepartmentName = "",
                 EnterpriseName = "",
                 UserID         = n.UserID,
                 UserName       = n.Name,
                 DepartmentID   = n.DepartmentID,
                 EnterpriseID   = n.EnterpiseID
             }).ToList();
             foreach (var user in userlist)
             {
                 user.DepartmentName = (db.Departments.FirstOrDefault(m => m.DepartmentID == (user.DepartmentID ?? -5)) ?? temp).Name;
                 user.EnterpriseName = db.Enterprises.FirstOrDefault(m => m.EnterpriseID == user.EnterpriseID).Name;
             }
             var uidlist = userlist.Select(x => x.UserID).ToList();
             var list    = db.UserLoginLogs.Where(x => x.Time <(endTime ?? DateTime.MaxValue) &&
                                                               x.Time> (beginTime ?? DateTime.MinValue) &&
                                                  uidlist.Contains(x.UserID) &&
                                                  ((int)status == x.Status || status == EnterpriseData.Common.LoginStatus.GetAll));
             int pagecount;
             amount = list.Count();
             if (pageSize > 0)
             {
                 pagecount = (list.Count() + pageSize - 1) / pageSize;
             }
             else
             {
                 pagecount = 0;
             }
             if (pageNumber > pagecount)
             {
                 pageNumber = pagecount;
             }
             if (pageNumber < 1)
             {
                 pageNumber = 1;
             }
             var relist = list.OrderByDescending(x => x.Time).Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList().Select(m => new UserLoginLogDto
             {
                 UserLoginLogID = m.UserLoginLogID,
                 EnterpriseName = userlist.FirstOrDefault(x => x.UserID == m.UserID).EnterpriseName,
                 DepartmentName = userlist.FirstOrDefault(x => x.UserID == m.UserID).DepartmentName,
                 UserID         = m.UserID,
                 Status         = (LoginStatus)m.Status,
                 Description    = m.Description,
                 Time           = m.Time,
                 UserName       = userlist.FirstOrDefault(x => x.UserID == m.UserID).UserName,
                 IP             = m.IP,
                 Device         = m.Device
             }).ToList();
             return(relist);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public List <FrontUserDto> SearchUserByName(string enterpriseNameKeyword, string userNameKeyword, int pageIndex, int pageSize,
                                                    out int count)
        {
            try
            {
                using (var db = new BCEnterpriseContext())
                {
                    var entIDList = db.Enterprises.Where(
                        obj => string.IsNullOrEmpty(enterpriseNameKeyword) ? true : obj.Name.Contains(enterpriseNameKeyword))
                                    .Select(o => o.EnterpriseID)
                                    .ToList();

                    var query = db.FrontUsers.Where(obj => (string.IsNullOrEmpty(userNameKeyword) ? true : obj.Name.Contains(userNameKeyword)) &&
                                                    (entIDList.Contains(obj.EnterpiseID)));

                    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;
                    }

                    return(query
                           .OrderBy(obj => obj.UserID)
                           .Skip(pageSize * (pageIndex - 1))
                           .Take(pageSize)
                           .Select(obj => new FrontUserDto()
                    {
                        UserID = obj.UserID,
                        Name = obj.Name,
                        EnterpiseID = obj.EnterpiseID,
                        DepartmentID = obj.DepartmentID,
                        DepartmentName = db.Departments.FirstOrDefault(x => x.DepartmentID == obj.DepartmentID).Name.ToString(),
                        Mobile = obj.Mobile,
                        LastIP = obj.LastIP,
                        LastDate = obj.LastDate,
                        Password = obj.Password,
                        UpdateTime = obj.UpdateTime,
                        Closed = obj.Closed,
                        RegistDate = obj.RegistDate,
                        LoginByDesktop = obj.LoginByDesktop,
                        LoginByMobile = obj.LoginByMobile
                    }).ToList());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 22
0
        public List <KnowlegeDto> GetKnowlegeList(string name, EnterpriseData.Common.FileType filetype, int?knowlegeType, string enterpriseID, int pageSize, int pageNumber, out int amount)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    name = "";
                }
                using (var db = new BCEnterpriseContext())
                {
                    IQueryable <KnowledgeBase> list;
                    if (filetype == EnterpriseData.Common.FileType.All)
                    {
                        list = db.KnowledgeBase.Where(x =>
                                                      !x.Deleted && x.Name.Contains(name) && x.EnterpriseID.Equals(enterpriseID) &&
                                                      (knowlegeType ?? x.KnowledgeType) == x.KnowledgeType);
                    }
                    else
                    {
                        list =
                            db.KnowledgeBase.Where(x =>
                                                   !x.Deleted && x.Name.Contains(name) && x.EnterpriseID.Equals(enterpriseID) &&
                                                   (knowlegeType ?? x.KnowledgeType) == x.KnowledgeType &&
                                                   (int)filetype == x.DocumentType);
                    }
                    int pagecount;
                    amount = list.Count();
                    if (pageSize > 0)
                    {
                        pagecount = (list.Count() + pageSize - 1) / pageSize;
                    }
                    else
                    {
                        pagecount = 0;
                    }
                    if (pageNumber > pagecount)
                    {
                        pageNumber = pagecount;
                    }
                    if (pageNumber < 1)
                    {
                        pageNumber = 1;
                    }

                    var retlist = list.Select(n => new KnowlegeDto()
                    {
                        ID            = n.ID,
                        Name          = n.Name,
                        EnterpriseID  = n.EnterpriseID,
                        Deleted       = n.Deleted,
                        DocumentSize  = n.DocumentSize,
                        DocumentType  = (EnterpriseData.Common.FileType)n.DocumentType,
                        KnowledgeType = n.KnowledgeType,
                        UpdateTime    = n.UpdateTime,
                        FileAllSize   = n.FileAllSize,
                        FileGUID      = n.FileGUID,
                        FileNumber    = n.FileNumber
                    }).ToList().Distinct(new DistinctByFileGuid()).OrderByDescending(x => x.UpdateTime).ToList();
                    amount = retlist.Count;

                    return(retlist.Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public string AddFrontUser(FrontUserDto frontUserDto)
        {
            try
            {
                if (null == frontUserDto)
                {
                    throw new KnownException("用户信息为空,无法添加!");
                }
                if (string.IsNullOrEmpty(frontUserDto.EnterpiseID) || string.IsNullOrEmpty(frontUserDto.Password) || null == frontUserDto.UserRoleIDs)
                {
                    throw new KnownException("关键信息缺失,无法新增用户!");
                }

                var makeId = Ioc.GetService <IUniqeIdGenerator>().GeneratorFrontUserID();
                frontUserDto.UserID     = makeId;
                frontUserDto.Password   = CryptoService.MD5Encrypt(frontUserDto.Password);
                frontUserDto.RegistDate = DateTime.Now;
                frontUserDto.LastDate   = DateTime.Now;
                frontUserDto.UpdateTime = DateTime.Now;

                using (var db = new BCEnterpriseContext())
                {
                    if (!db.Enterprises.Any(obj => obj.EnterpriseID == frontUserDto.EnterpiseID && !obj.Deleted))
                    {
                        throw new KnownException("没有相关企业信息或企业已被禁用!,不能添加用户,请尝试刷新后重试!");
                    }
                    if (null != frontUserDto.DepartmentID &&
                        (!db.Departments.Any(obj => obj.EnterpriseID == frontUserDto.EnterpiseID && obj.DepartmentID == frontUserDto.DepartmentID && !obj.Deleted)))
                    {
                        throw new KnownException("此企业下不存在该部门信息或已被删除,无法添加用户,请尝试刷新后重试!");
                    }
                    if (frontUserDto.UserRoleIDs.Count == 0)
                    {
                        throw new KnownException("必须为用户指定角色");
                    }
                    var r = (db.RFARoles.Where(o => frontUserDto.UserRoleIDs.Contains(o.RoleID) ? o.Available : true)).Select(o => o.RoleID).ToList();
                    if (!frontUserDto.UserRoleIDs.All(o => (r.Contains(o))))
                    {
                        throw new KnownException("指定的角色不存在,或已被删除,请尝试刷新后重试!");
                    }
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        db.FrontUsers.Add(frontUserDto);
                        db.SaveChanges();
                        var result = SetFrontUserRoles(frontUserDto.UserID, frontUserDto.UserRoleIDs);
                        if (!result)
                        {
                            throw new KnownException("保存用户角色失败!");
                        }
                        else
                        {
                            transaction.Complete();
                            return(frontUserDto.UserID);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public List <FunctionDto> GetAllFunctions(string nameKeyword, int psize, int pageidx)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             if (psize <= 0 || pageidx <= 0)
             {
                 return(new List <FunctionDto>());
             }
             IEnumerable <RFAFunction> tResult;
             if (nameKeyword == null || nameKeyword.Equals(""))
             {
                 tResult = db.RFAFunctions;
             }
             else
             {
                 tResult = db.RFAFunctions.Where(obj => obj.Name.Contains(nameKeyword));
             }
             //tResult.c
             int count     = tResult.Count();
             int pageCount = (count + psize - 1) / psize;
             if (pageCount < pageidx)
             {
                 //if pageidx is overflow return the last page
                 return(tResult.AsEnumerable().Skip((pageCount - 1) * psize).Select(n => new FunctionDto
                 {
                     FunctionID = n.FunctionID,
                     MyID = n.MyID,
                     ParentID = n.ParentID,
                     Name = n.Name,
                     Desription = n.Desription,
                     Available = n.Available
                 }).ToList());;
             }
             else
             {
                 //return tResult.
                 return(tResult.AsEnumerable().Skip((pageidx - 1) * psize).Take(psize).Select(n => new FunctionDto
                 {
                     FunctionID = n.FunctionID,
                     MyID = n.MyID,
                     ParentID = n.ParentID,
                     Name = n.Name,
                     Desription = n.Desription,
                     Available = n.Available
                 }).ToList());;
             }
             //var list = db.RFAFunctions.Where(lambda).AsEnumerable().Select(n => new FunctionDto
             //{
             //    FunctionID = n.FunctionID,
             //    MyID = n.MyID,
             //    ParentID = n.ParentID,
             //    Name = n.Name,
             //    Desription = n.Desription,
             //    Available = n.Available
             //}).ToList();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public List <UserRolesDto> SetFrontUserRoles(string frontUserID, List <int> enterpriseRoleIDs)
        {
            try
            {
                if (string.IsNullOrEmpty(frontUserID) || null == enterpriseRoleIDs)
                {
                    throw new KnownException("用于设置的参数信息不正确!");
                }

                var list = new List <UserRolesDto>();
                using (var db = new BCEnterpriseContext())
                {
                    if (!db.FrontUsers.Any(obj => obj.UserID == frontUserID))
                    {
                        throw new KnownException("不存在相关的用户,无法更新用户角色!");
                    }

                    var isFresh = (from rid in enterpriseRoleIDs
                                   join rl in db.RFARoles on rid equals rl.RoleID into tempRL
                                   from trl in tempRL.DefaultIfEmpty()
                                   where trl == null || !trl.Available
                                   select trl).Any();
                    if (isFresh)
                    {
                        throw new KnownException("指定的角色不存在,或已被删除,请刷新后重试!");
                    }

                    foreach (var set in enterpriseRoleIDs.Select(roleID => new UserRole()
                    {
                        UserID = frontUserID, RoleID = roleID, UpdateTime = DateTime.Now
                    }))
                    {
                        db.UserRoles.AddOrUpdate(set);
                    }

                    var del = db.UserRoles.Where(obj => (obj.UserID == frontUserID) && (!enterpriseRoleIDs.Contains(obj.RoleID))).ToList();
                    foreach (var d in del)
                    {
                        db.UserRoles.Remove(d);
                    }

                    if (0 < db.SaveChanges())
                    {
                        list = db.UserRoles.Where(obj => (obj.UserID == frontUserID) && (enterpriseRoleIDs.Contains(obj.RoleID)))
                               .Select(obj => new UserRolesDto
                        {
                            UserID     = obj.UserID,
                            RoleID     = obj.RoleID,
                            UpdateTime = DateTime.Now
                        }).ToList();

                        ForceLogout(db, frontUserID, EnterpriseData.Common.LoginStatus.Logout, "用户权限更改,系统强制登出");
                    }

                    return(list);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 26
0
 public List <ProjectStatisDto> GetProjectStatisInfo(string enterpriseId, string projName, int pageSize, int pageIndex, out int amount)
 {
     try
     {
         if (projName == null)
         {
             projName = "";
         }
         if (pageIndex < 1)
         {
             pageIndex = 1;
         }
         if (pageSize < 1)
         {
             pageSize = 10;
         }
         using (var db = new BCEnterpriseContext())
         {
             var result      = new List <ProjectStatisDto>();
             var allProjList = db.Projects.Where(p => (projName.Equals("") || p.Name.Contains(projName)) && p.EnterpriseID.Equals(enterpriseId) && p.Deleted == false);
             if ((amount = allProjList.Count()) < 1)
             {
                 amount = 0;
                 return(result);
             }
             else
             {
                 List <Project> specProjList;
                 int            totalPage = (amount + pageSize - 1) / pageSize;
                 if (pageIndex > totalPage)
                 {
                     specProjList = allProjList.OrderBy(p => p.ProjectID).Skip((totalPage - 1) * pageSize).Take(pageSize).ToList();
                 }
                 else
                 {
                     specProjList = allProjList.OrderBy(p => p.ProjectID).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                 }
                 var mgdb = new MongoDbProvider <SceneItem>();
                 foreach (var proj in specProjList)
                 {
                     var stat = new ProjectStatisDto();
                     stat.projectId   = proj.ProjectID;
                     stat.projectName = proj.Name;
                     //计算各类型数量
                     for (int i = 0; i < 7; i++)
                     {
                         int idx      = (int)Math.Pow(2, i);
                         var sceneIDs = db.Scenes.Where(s => s.ProjectID.Equals(proj.ProjectID) && s.Deleted == false).Select(s => s.SceneID).ToList();
                         if (sceneIDs.Count() < 1)
                         {
                             stat.typeCount[i] = 0;
                         }
                         else
                         {
                             try
                             {
                                 stat.typeCount[i] = (int)mgdb.Count(s => sceneIDs.Contains(s.SceneID) && s.Type.Equals(idx));
                             }
                             catch (Exception)
                             {
                                 stat.typeCount[i] = -1;
                             }
                         }
                     }
                     result.Add(stat);
                 }
                 return(result);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public List <EnterpriseDto> SearchEnterpriseByCondition(string professionId, string propertyId, string enterpriseName, int pSize, int pNum, out int amount)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             if (string.IsNullOrEmpty(enterpriseName))
             {
                 enterpriseName = "";
             }
             var list = db.Enterprises.Where(x => x.Name.Contains(enterpriseName));
             if (!string.IsNullOrEmpty(professionId))
             {
                 list = list.Where(x => x.ProfessionID.Equals(professionId));
             }
             if (!string.IsNullOrEmpty(propertyId))
             {
                 list = list.Where(x => x.PropertyID.Equals(propertyId));
             }
             amount = list.Count();
             int count;
             //每页信息量判断
             if (pSize > 0)
             {
                 // 获取总共页数
                 count = (amount + pSize - 1) / pSize;
             }
             else
             {
                 count = 0;
             }
             //页码判断,小于1则为1,大于最大页码则为最大页码
             if (pNum > count)
             {
                 pNum = count;
             }
             if (pNum < 1)
             {
                 pNum = 1;
             }
             return(list.Select(obj => new EnterpriseDto
             {
                 ProfessionName = db.EnterpriseProfessions.FirstOrDefault(x => x.EnterpriseProfessionID == obj.ProfessionID && x.Available).Name,
                 EnterpriseID = obj.EnterpriseID,
                 Name = obj.Name,
                 ProfessionID = obj.ProfessionID,
                 Province = obj.Province,
                 City = obj.City,
                 Address = obj.Address,
                 Telephone = obj.Telephone,
                 Fax = obj.Fax,
                 Status = obj.Status,
                 RegistDate = obj.RegistDate,
                 UpdateTime = obj.UpdateTime,
                 Deleted = obj.Deleted,
                 PropertyID = obj.PropertyID,
                 PropertyName = db.EnterprisePropertys.FirstOrDefault(x => x.EnterprisePropertyID == obj.PropertyID && x.Available).Name
             }).OrderBy(x => x.EnterpriseID).Skip(pSize * (pNum - 1)).Take(pSize).ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 28
0
        private List <DepartmentDto> GetNowDepartment(string enterpriseId, int?departmentId, BCEnterpriseContext db)
        {
            try
            {
                IEnumerable <Department> dtmt = null;
                if (departmentId.HasValue)
                {
                    dtmt = db.Departments.Where(x => x.EnterpriseID == enterpriseId && x.DepartmentID == departmentId.Value && x.Deleted == false);
                }
                else
                {
                    dtmt = db.Departments.Where(x => x.EnterpriseID == enterpriseId && x.ParentID == 0 && x.Deleted == false);
                }

                if (0 == dtmt.Count())
                {
                    return(dtmt.Select(x => new DepartmentDto
                    {
                        DepartmentID = x.DepartmentID,
                        ParentID = x.ParentID,
                        Name = x.Name,
                        EnterpriseID = x.EnterpriseID,
                        Description = x.Description,
                        Available = x.Available,
                        Deleted = x.Deleted
                    }).ToList());
                }
                //var templist = dtmt.ToList();
                //for (int i = 0; i < dtmt.Count();i++ )
                //{
                //    dtmt = dtmt.Concat(GetOwnerDepartment(templist[i].DepartmentID, db));
                //}
                foreach (var deptmt in dtmt)
                {
                    dtmt = dtmt.Concat(GetOwnerDepartment(deptmt.DepartmentID, db));
                }
                return(dtmt.Select(x => new DepartmentDto
                {
                    DepartmentID = x.DepartmentID,
                    ParentID = x.ParentID,
                    Name = x.Name,
                    EnterpriseID = x.EnterpriseID,
                    Description = x.Description,
                    Available = x.Available,
                    Deleted = x.Deleted
                }).ToList());
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public EnterpriseSyncDto GetEnterpriseForSync(string enterpriseId)
        {
            using (var db = new BCEnterpriseContext())
            {
                var tempData = (from ep in db.Enterprises
                                where ep.EnterpriseID == enterpriseId
                                join dp in db.Departments on ep.EnterpriseID equals dp.EnterpriseID into tempDP
                                join user in db.FrontUsers on ep.EnterpriseID equals user.EnterpiseID into tempUser
                                join rl in db.RFARoles on ep.EnterpriseID equals rl.OwnerID into tempRL
                                select new
                {
                    EnterpriseID = ep.EnterpriseID,
                    Departments = (
                        from tdp in tempDP.DefaultIfEmpty()
                        where !tdp.Deleted
                        select tdp),
                    FrontUsers = (
                        from tur in tempUser.DefaultIfEmpty()
                        select new
                    {
                        tur.UserID,
                        tur.Name,
                        tur.DepartmentID,
                        tur.Closed
                    }
                        ),
                    UserRoles = (
                        from tul in tempRL.DefaultIfEmpty()
                        join ur in db.UserRoles on tul.RoleID equals ur.RoleID into tempUR
                        from tur in tempUR.DefaultIfEmpty()
                        where tul.Available && (tur == null || !tur.Deleted)
                        select new
                    {
                        RoleId = tul.RoleID,
                        RoleName = tul.Name,
                        Available = tul.Available,
                        UserID = tur.UserID,
                        Deleted = tur != null && tur.Deleted
                    }
                        ).Union(
                        from tul in db.RFARoles
                        where tul.OwnerID == null
                        join ur in db.UserRoles on tul.RoleID equals ur.RoleID into tempUR
                        from tur in tempUR.DefaultIfEmpty()
                        join user in tempUser on tur.UserID equals user.UserID into tempUser2
                        from tuser in tempUser2.DefaultIfEmpty()
                        where tul.Available && (tur == null || !tur.Deleted) && tuser != null
                        select new
                    {
                        RoleId = tul.RoleID,
                        RoleName = tul.Name,
                        Available = tul.Available,
                        UserID = tur.UserID,
                        Deleted = tur != null && tur.Deleted
                    }
                        )
                }).FirstOrDefault();
                if (tempData == null)
                {
                    return(new EnterpriseSyncDto());
                }

                var result = new EnterpriseSyncDto
                {
                    EnterpriseID = tempData.EnterpriseID,
                    Departments  = tempData.Departments.Select(obj => (DepartmentSyncDto)obj).ToArray(),
                    FrontUsers   = tempData.FrontUsers.Select(n => new FrontUserSyncDto
                    {
                        EnterpriseID = tempData.EnterpriseID,
                        UserID       = n.UserID,
                        Name         = n.Name,
                        Closed       = n.Closed,
                        DepartmentID = n.DepartmentID
                    }).ToArray(),
                    UserRoles = tempData.UserRoles.Select(n => new UserRoleSyncDto
                    {
                        EnterpriseID = tempData.EnterpriseID,
                        UserID       = n.UserID,
                        RoleID       = n.RoleId,
                        RoleName     = n.RoleName,
                        Deleted      = n.Deleted || !n.Available
                    }).ToArray()
                };

                return(result);
            }
        }
Esempio n. 30
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;
            }
        }