Пример #1
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <param name="entity">实体数据</param>
        public bool SaveEntity(string keyValue, FileAuthEntity entity)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (string.IsNullOrEmpty(keyValue))
                {
                    var entityTmp = db.FindEntity <FileAuthEntity>(" select * from lr_base_fileauth where F_ObjId = @objId AND F_FileInfoId = @Id AND F_Type = 0 ", new { objId = entity.F_ObjId, Id = entity.F_FileInfoId });
                    if (entityTmp != null)
                    {
                        db.Rollback();
                        return(false);
                    }
                    entity.Create();
                    db.Insert(entity);
                }
                else
                {
                    entity.Modify(keyValue);
                    db.Update(entity);
                }

                db.ExecuteBySql(" delete from lr_base_fileauth where F_from =@fromId ", new { fromId = entity.F_Id });
                int deep = 1;
                if (entity.F_IsFolder == 1)// 文件夹
                {
                    if (entity.F_FileInfoId != "0")
                    {
                        var folderEntity = db.FindEntity <FolderEntity>(entity.F_FileInfoId);
                        SaveSJEntity(folderEntity.F_PId, entity.F_Id, entity, deep, db);
                    }

                    // 授权子文件夹和文件
                    SaveXJEntity(entity.F_FileInfoId, entity.F_Id, entity, deep, db);
                }
                else
                {
                    var fileEntity = db.FindEntity <FileBInfoEntity>(entity.F_FileInfoId);
                    SaveSJEntity(fileEntity.F_Folder, entity.F_Id, entity, deep, db);
                }

                db.Commit();
                return(true);
            }
            catch (System.Exception)
            {
                db.Rollback();
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// 保存下级目录权限设置
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="fromId"></param>
        /// <param name="fromEntity"></param>
        /// <param name="deep"></param>
        /// <param name="db"></param>
        private void SaveXJEntity(string folderId, string fromId, FileAuthEntity fromEntity, int deep, IRepository db)
        {
            // 获取文件
            var fileList = db.FindList <FileBInfoEntity>(" select * from lr_base_fileinfo where F_IsPublish = 1 AND F_Folder = @folderId ", new { folderId });

            foreach (var item in fileList)
            {
                FileAuthEntity fileAuth = new FileAuthEntity()
                {
                    F_Id         = Guid.NewGuid().ToString(),
                    F_AuthType   = fromEntity.F_AuthType,
                    F_FileInfoId = item.F_Id,
                    F_from       = fromId,
                    F_ObjId      = fromEntity.F_ObjId,
                    F_ObjName    = fromEntity.F_ObjName,
                    F_ObjType    = fromEntity.F_ObjType,
                    F_Time       = fromEntity.F_Time,
                    F_Type       = 1,
                    F_IsFolder   = 0,
                    F_Level      = deep
                };
                db.Insert(fileAuth);
            }

            // 获取文件夹
            var folderList = db.FindList <FolderEntity>(" select * from lr_base_folder where  F_PId = @folderId ", new { folderId });

            foreach (var item in folderList)
            {
                FileAuthEntity folderAuth = new FileAuthEntity()
                {
                    F_Id         = Guid.NewGuid().ToString(),
                    F_AuthType   = fromEntity.F_AuthType,
                    F_FileInfoId = item.F_Id,
                    F_from       = fromId,
                    F_ObjId      = fromEntity.F_ObjId,
                    F_ObjName    = fromEntity.F_ObjName,
                    F_ObjType    = fromEntity.F_ObjType,
                    F_Time       = fromEntity.F_Time,
                    F_Type       = 1,
                    F_IsFolder   = 1,
                    F_Level      = deep
                };
                db.Insert(folderAuth);
                SaveXJEntity(item.F_Id, fromId, fromEntity, deep + 1, db);
            }
        }
Пример #3
0
 /// <summary>
 /// 保存上级目录权限设置
 /// </summary>
 /// <param name="folderId"></param>
 /// <param name="fromId"></param>
 /// <param name="fromEntity"></param>
 /// <param name="deep"></param>
 /// <param name="db"></param>
 private void SaveSJEntity(string folderId, string fromId, FileAuthEntity fromEntity, int deep, IRepository db)
 {
     if (folderId != "0")
     {
         FileAuthEntity entity = new FileAuthEntity()
         {
             F_Id         = Guid.NewGuid().ToString(),
             F_AuthType   = "1",
             F_FileInfoId = folderId,
             F_from       = fromId,
             F_ObjId      = fromEntity.F_ObjId,
             F_ObjName    = fromEntity.F_ObjName,
             F_ObjType    = fromEntity.F_ObjType,
             F_Time       = fromEntity.F_Time,
             F_Type       = 2,
             F_IsFolder   = 1,
             F_Level      = deep
         };
         db.Insert(entity);
         var folderEntity = db.FindEntity <FolderEntity>(folderId);
         SaveSJEntity(folderEntity.F_PId, fromId, fromEntity, deep + 1, db);
     }
 }
Пример #4
0
        /// <summary>
        /// 更新文件发布状态
        /// </summary>
        /// <param name="processId"></param>
        public void UpdateEntity(string processId)
        {
            var fileList = this.BaseRepository().FindEntity <FilelistEntity>(processId);

            var db = this.BaseRepository().BeginTrans();

            try
            {
                db.ExecuteBySql(" update lr_base_filelist set F_IsPublish = 0 where F_FileInfoId=@id ", new { id = fileList.F_FileInfoId });

                FilelistEntity filelistEntity = new FilelistEntity()
                {
                    F_Id          = fileList.F_Id,
                    F_IsPublish   = 1,
                    F_PublishTime = DateTime.Now
                };
                FileBInfoEntity fileBInfoEntity = new FileBInfoEntity
                {
                    F_Id         = fileList.F_FileInfoId,
                    F_IsPublish  = 1,
                    F_DeleteMark = 0,
                    F_KeyWord    = fileList.F_KeyWord,
                    F_Name       = fileList.F_Name,
                    F_Folder     = fileList.F_Folder
                };

                db.Update(filelistEntity);
                db.Update(fileBInfoEntity);

                // 更新权限
                // 删除上从层文件夹继承的权限
                var authList = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId ", new { F_FileInfoId = fileList.F_FileInfoId });
                foreach (var item in authList)
                {
                    if (item.F_Type != 0)
                    {
                        db.ExecuteBySql(" delete from lr_base_fileauth where F_Id =@id", new { id = item.F_Id });
                    }
                    else
                    {
                        db.ExecuteBySql(" delete from lr_base_fileauth where F_from =@fromId ", new { fromId = item.F_Id });
                    }
                }
                // 添加
                var authList2 = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId AND F_Type != 2 ", new { F_FileInfoId = fileList.F_Folder });
                foreach (var item in authList2)
                {
                    if (item.F_Type == 0)
                    {
                        item.F_from = item.F_Id;
                    }
                    FileAuthEntity authEntity = new FileAuthEntity()
                    {
                        F_Id         = Guid.NewGuid().ToString(),
                        F_AuthType   = item.F_AuthType,
                        F_FileInfoId = fileList.F_FileInfoId,
                        F_from       = item.F_from,
                        F_ObjId      = item.F_ObjId,
                        F_ObjName    = item.F_ObjName,
                        F_ObjType    = item.F_ObjType,
                        F_Time       = item.F_Time,
                        F_Type       = 1,
                        F_IsFolder   = 0,
                        F_Level      = item.F_Level + 1
                    };
                    db.Insert(authEntity);
                }

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 保存数据
 /// </summary>
 /// <param name="keyValue">主键</param>
 /// <param name="entity">实体数据</param>
 public bool SaveEntity(string keyValue, FileAuthEntity entity)
 {
     return(fileAuthService.SaveEntity(keyValue, entity));
 }
Пример #6
0
        /// <summary>
        /// 保存实体数据(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <param name="entity">实体</param>
        public void SaveEntity(string keyValue, FolderEntity entity)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    entity.Modify(keyValue);

                    var entityTmp = db.FindEntity <FolderEntity>("select * from lr_base_folder where F_Id = @keyValue", new { keyValue });
                    if (entityTmp.F_PId != entity.F_PId) // 修改了上级了目录需要调整权限
                    {
                        if (entityTmp.F_PId != "0")      // 需要删除原先继承过来的权限
                        {
                            var authList = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId ", new { F_FileInfoId = keyValue });
                            foreach (var item in authList)
                            {
                                if (item.F_Type == 1)// 来自上级文件夹的需要删除
                                {
                                    db.ExecuteBySql(" delete from lr_base_fileauth where F_Id =@id ", new { id = item.F_Id });
                                    db.ExecuteBySql(" delete from lr_base_fileauth where F_from =@fromId AND F_Level > @deep AND F_Type = 1 ", new { fromId = item.F_from, deep = item.F_Level });
                                }
                                else
                                {
                                    if (item.F_Type == 0)
                                    {
                                        item.F_from = item.F_Id;
                                    }
                                    db.ExecuteBySql(" delete from lr_base_fileauth where F_from =@fromId AND F_Level > @deep AND F_Type = 2 ", new { fromId = item.F_from, deep = item.F_Level });
                                }
                            }
                        }

                        if (entity.F_PId != "0")   // 添加新的权限
                        {
                            var authList2 = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId AND F_Type != 2 ", new { F_FileInfoId = entity.F_PId });
                            foreach (var item in authList2)
                            {
                                if (item.F_Type == 0)
                                {
                                    item.F_from = item.F_Id;
                                }
                                FileAuthEntity authEntity = new FileAuthEntity()
                                {
                                    F_Id         = Guid.NewGuid().ToString(),
                                    F_AuthType   = "1",
                                    F_FileInfoId = entity.F_Id,
                                    F_from       = item.F_from,
                                    F_ObjId      = item.F_ObjId,
                                    F_ObjName    = item.F_ObjName,
                                    F_ObjType    = item.F_ObjType,
                                    F_Time       = item.F_Time,
                                    F_Type       = 1,
                                    F_IsFolder   = 1,
                                    F_Level      = item.F_Level + 1
                                };
                                db.Insert(authEntity);
                                SaveXJEntity(entity.F_Id, item.F_from, item, authEntity.F_Level + 1, db);
                            }

                            // 将自己的权限赋值给上级目录
                            var authList3 = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId  AND F_Type != 1 ", new { F_FileInfoId = entity.F_Id });
                            foreach (var item in authList3)
                            {
                                if (item.F_Type == 0)
                                {
                                    item.F_from = item.F_Id;
                                }
                                SaveSJEntity(entity.F_PId, item.F_from, item, item.F_Level + 1, db);
                            }
                        }
                    }


                    db.Update(entity);
                }
                else
                {
                    entity.Create();
                    db.Insert(entity);

                    if (entity.F_PId != "0")
                    {
                        // 继承上级文件夹的权限
                        var authList = db.FindList <FileAuthEntity>(" select * from lr_base_fileauth t where t.F_FileInfoId = @F_FileInfoId ", new { F_FileInfoId = entity.F_PId });
                        foreach (var item in authList)
                        {
                            if (item.F_Type != 2)
                            {
                                if (item.F_Type == 0)
                                {
                                    item.F_from = item.F_Id;
                                }
                                FileAuthEntity authEntity = new FileAuthEntity()
                                {
                                    F_Id         = Guid.NewGuid().ToString(),
                                    F_AuthType   = "1",
                                    F_FileInfoId = entity.F_Id,
                                    F_from       = item.F_from,
                                    F_ObjId      = item.F_ObjId,
                                    F_ObjName    = item.F_ObjName,
                                    F_ObjType    = item.F_ObjType,
                                    F_Time       = item.F_Time,
                                    F_Type       = 1,
                                    F_IsFolder   = 1,
                                    F_Level      = item.F_Level + 1
                                };
                                db.Insert(authEntity);
                            }
                        }
                    }
                }

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }