Esempio n. 1
0
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键</param>
 /// <param name="entity">实体</param>
 public void SaveEntity(string keyValue, FolderEntity entity)
 {
     try
     {
         folderService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
Esempio n. 2
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);
                }
            }
        }