Пример #1
0
        public async Task<IResultModel> Delete(Guid id)
        {
            var role = await _repository.GetAsync(id);
            if (role == null)
                return ResultModel.Failed("角色不存在");
            if (role.IsSpecified)
                return ResultModel.Failed("指定角色不允许删除");

            var exist = await _accountRoleRepository.ExistsByRole(id);
            if (exist)
                return ResultModel.Failed("有账户绑定了该角色,请先删除对应绑定关系");

            using (var uow = _dbContext.NewUnitOfWork())
            {
                var result = await _repository.SoftDeleteAsync(id, uow);
                if (result)
                {
                    result = await _roleMenuRepository.DeleteByRoleId(id, uow);
                    if (result)
                    {
                        result = await _roleMenuButtonRepository.DeleteByRole(id, uow);
                        if (result)
                        {
                            uow.Commit();
                        }
                    }
                }
                return ResultModel.Result(result);
            }
        }
Пример #2
0
        public async Task <IResultModel <Guid> > Add(AccountAddModel model, IUnitOfWork uow = null)
        {
            var result = new ResultModel <Guid>();

            var account = _mapper.Map <AccountEntity>(model);

            var exists = await Exists(account);

            if (!exists.Successful)
            {
                return(exists);
            }

            //设置默认密码
            if (account.Password.IsNull())
            {
                var config = _configProvider.Get <AdminConfig>();
                account.Password = config.DefaultPassword.NotNull() ? config.DefaultPassword : "******";
            }

            account.Password = _passwordHandler.Encrypt(account.UserName, account.Password);

            //如果uow参数为空,需要自动处理工作单元
            var noUow = uow == null;

            if (noUow)
            {
                uow = _dbContext.NewUnitOfWork();
            }

            if (await _accountRepository.AddAsync(account, uow))
            {
                if (model.Roles != null && model.Roles.Any())
                {
                    var accountRoleList = model.Roles.Select(m => new AccountRoleEntity {
                        AccountId = account.Id, RoleId = m
                    }).ToList();
                    if (await _accountRoleRepository.AddAsync(accountRoleList, uow))
                    {
                        if (noUow)
                        {
                            uow.Commit();
                        }

                        return(result.Success(account.Id));
                    }
                }
                else
                {
                    if (noUow)
                    {
                        uow.Commit();
                    }

                    return(result.Success(account.Id));
                }
            }

            return(result.Failed());
        }
Пример #3
0
        public async Task <IResultModel <Guid> > Add(AccountAddModel model)
        {
            var result = new ResultModel <Guid>();

            var account = _mapper.Map <AccountEntity>(model);

            var exists = await Exists(account);

            if (!exists.Successful)
            {
                return(exists);
            }

            //默认未激活状态,用户首次登录激活
            account.Status = AccountStatus.Inactive;

            //设置默认密码
            if (account.Password.IsNull())
            {
                account.Password = DefaultPassword;
            }

            account.Password = EncryptPassword(account.UserName, account.Password);

            using (var uow = _dbContext.NewUnitOfWork())
            {
                if (await _accountRepository.AddAsync(account, uow))
                {
                    if (model.Roles != null && model.Roles.Any())
                    {
                        var accountRoleList = model.Roles.Select(m => new AccountRoleEntity {
                            AccountId = account.Id, RoleId = m
                        }).ToList();
                        if (await _accountRoleRepository.AddAsync(accountRoleList, uow))
                        {
                            uow.Commit();
                            return(result.Success(account.Id));
                        }
                    }
                    else
                    {
                        uow.Commit();
                        return(result.Success(account.Id));
                    }
                }
            }

            return(result.Failed());
        }
        public void Save(List <ModuleOptionStorageModel> descriptors)
        {
            if (descriptors == null || !descriptors.Any())
            {
                return;
            }

            using var uow = _dbContext.NewUnitOfWork();
            foreach (var descriptor in descriptors)
            {
                var newEntity = new ConfigEntity
                {
                    Type    = ConfigType.Module,
                    Key     = descriptor.Key,
                    Value   = descriptor.Value,
                    Remarks = descriptor.Remarks
                };

                var entity = _repository.GetByKey(descriptor.Key, ConfigType.Module).Result;
                if (entity == null)
                {
                    _repository.AddAsync(newEntity, uow).GetAwaiter().GetResult();
                }
                else
                {
                    newEntity.Id = entity.Id;
                    _repository.UpdateAsync(newEntity, uow).GetAwaiter().GetResult();
                }
            }
        }
Пример #5
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            using var uow = _dbContext.NewUnitOfWork();

            //先清除已有权限信息
            await _repository.ClearAsync(uow);

            foreach (var permission in permissions)
            {
                if (!await _repository.AddAsync(permission, uow))
                {
                    uow.Rollback();
                    return(ResultModel.Failed("同步失败"));
                }
            }

            uow.Commit();

            return(ResultModel.Success());
        }
Пример #6
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var permission in permissions)
                {
                    if (!await _permissionRepository.Exists(permission, uow))
                    {
                        if (!await _permissionRepository.AddAsync(permission, uow))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed("同步失败"));
                        }
                    }
                    else
                    {
                        if (!await _permissionRepository.UpdateForSync(permission, uow))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed("同步失败"));
                        }
                    }
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
        public async Task Save(List <ModuleOptionDescriptor> descriptors)
        {
            if (descriptors == null || !descriptors.Any())
            {
                return;
            }

            using var uow = _dbContext.NewUnitOfWork();
            foreach (var descriptor in descriptors)
            {
                var newEntity = new ConfigEntity
                {
                    Type    = ConfigType.Module,
                    Key     = descriptor.Key,
                    Value   = descriptor.Value,
                    Remarks = descriptor.Remarks
                };

                var entity = await _repository.GetByKey(descriptor.Key, ConfigType.Module);

                if (entity == null)
                {
                    await _repository.AddAsync(newEntity, uow);
                }
                else
                {
                    newEntity.Id = entity.Id;
                    await _repository.UpdateAsync(newEntity, uow);
                }
            }
        }
Пример #8
0
        public IResultModel UpdateConfig(SystemConfigModel model)
        {
            if (model == null)
            {
                return(ResultModel.Failed());
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                Update(SystemConfigKey.Title, model.Title, "系统标题", uow).Wait();
                Update(SystemConfigKey.Logo, model.Logo, "系统Logo", uow).Wait();
                Update(SystemConfigKey.Home, model.Home, "系统首页", uow).Wait();
                Update(SystemConfigKey.UserInfoPage, model.UserInfoPage, "个人信息页", uow).Wait();
                Update(SystemConfigKey.ButtonPermission, model.ButtonPermission, "启用按钮权限", uow).Wait();
                Update(SystemConfigKey.PermissionValidate, model.PermissionValidate, "启用权限验证功能", uow).Wait();
                Update(SystemConfigKey.Auditing, model.Auditing, "启用审计日志", uow).Wait();
                Update(SystemConfigKey.LoginVerifyCode, model.LoginVerifyCode, "启用登录验证码功能", uow).Wait();
                Update(SystemConfigKey.ToolbarFullscreen, model.Toolbar.Fullscreen, "显示工具栏全屏按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarSkin, model.Toolbar.Skin, "显示工具栏皮肤按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarLogout, model.Toolbar.Logout, "显示工具栏退出按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarUserInfo, model.Toolbar.UserInfo, "显示工具栏用户信息按钮", uow).Wait();
                Update(SystemConfigKey.CustomCss, model.CustomCss, "自定义CSS样式", uow).Wait();

                uow.Commit();
            }

            _cache.RemoveAsync(CacheKeys.SystemConfigCacheKey).Wait();

            return(ResultModel.Success());
        }
Пример #9
0
        public IResultModel UpdateConfig(SystemConfigModel model)
        {
            if (model == null)
            {
                return(ResultModel.Failed());
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                Update(SystemConfigKey.Title, model.Title, "系统标题", uow).Wait();
                Update(SystemConfigKey.Logo, model.Logo, "系统Logo", uow).Wait();
                Update(SystemConfigKey.Home, model.Home, "系统首页", uow).Wait();
                Update(SystemConfigKey.UserInfoPage, model.UserInfoPage, "个人信息页", uow).Wait();
                Update(SystemConfigKey.ButtonPermission, model.ButtonPermission, "启用按钮权限", uow).Wait();
                Update(SystemConfigKey.PermissionValidate, model.PermissionValidate, "启用权限验证功能", uow).Wait();
                Update(SystemConfigKey.Auditing, model.Auditing, "启用审计日志", uow).Wait();
                Update(SystemConfigKey.ToolbarFullscreen, model.Toolbar.Fullscreen, "显示工具栏全屏按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarSkin, model.Toolbar.Skin, "显示工具栏皮肤按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarLogout, model.Toolbar.Logout, "显示工具栏退出按钮", uow).Wait();
                Update(SystemConfigKey.ToolbarUserInfo, model.Toolbar.UserInfo, "显示工具栏用户信息按钮", uow).Wait();
                Update(SystemConfigKey.CustomCss, model.CustomCss, "自定义CSS样式", uow).Wait();
                Update(SystemConfigKey.MenuUniqueOpened, model.MenuUniqueOpened, "菜单只能打开一个", uow).Wait();
                Update(SystemConfigKey.DialogCloseOnClickModal, model.DialogCloseOnClickModal, "点击模态框关闭对话框", uow).Wait();
                Update(SystemConfigKey.LoginOptionsType, model.LoginOptions.Type, "登录页类型", uow).Wait();
                Update(SystemConfigKey.LoginOptionsVerifyCode, model.LoginOptions.VerifyCode, "启用登录验证码功能", uow).Wait();
                Update(SystemConfigKey.Copyright, model.Copyright, "版权申明", uow).Wait();

                uow.Commit();
            }

            _cache.RemoveAsync(CacheKeys.SystemConfigCacheKey).Wait();

            return(ResultModel.Success());
        }
Пример #10
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            using var uow = _dbContext.NewUnitOfWork();

            //先清除已有权限信息
            if (await _repository.ClearAsync(uow))
            {
                foreach (var permission in permissions)
                {
                    if (!await _repository.AddAsync(permission, uow))
                    {
                        uow.Rollback();
                        return(ResultModel.Failed("同步失败"));
                    }
                }

                uow.Commit();

                //删除所有账户的缓存信息
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.AccountPermissions);

                return(ResultModel.Success());
            }
            return(ResultModel.Failed("同步失败"));
        }
Пример #11
0
        public async Task <IResultModel> UpdateSortList(SortUpdateModel <Guid> model)
        {
            if (model.Options == null || !model.Options.Any())
            {
                return(ResultModel.Failed("不包含数据"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var option in model.Options)
                {
                    var entity = await _menuRepository.GetAsync(option.Id, uow);

                    if (entity == null)
                    {
                        return(ResultModel.Failed());
                    }

                    entity.Sort = option.Sort;
                    if (!await _menuRepository.UpdateAsync(entity, uow))
                    {
                        return(ResultModel.Failed());
                    }
                }

                //清除账户菜单缓存
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_MENUS);

                uow.Commit();
            }

            return(ResultModel.Success());
        }
Пример #12
0
        public async Task <IResultModel> Sync()
        {
            if (!_options.RefreshModuleOrPermission)
            {
                return(ResultModel.Success());
            }

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Code    = m.Code,
                Name    = m.Name,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogDebug("Sync Module Info");

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var module in modules)
                {
                    if (!await _repository.Exists(module, uow))
                    {
                        if (!await _repository.AddAsync(module))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                    else
                    {
                        if (!await _repository.UpdateByCode(module))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
Пример #13
0
        public async Task <IResultModel> Add(MenuAddModel model)
        {
            var menu = _mapper.Map <MenuEntity>(model);

            //根据父节点的等级+1设置当前菜单的等级
            if (menu.ParentId != Guid.Empty)
            {
                var parentMenu = await _menuRepository.GetAsync(model.ParentId);

                if (parentMenu == null)
                {
                    return(ResultModel.Failed("父节点不存在"));
                }

                menu.Level = parentMenu.Level + 1;
            }

            if (menu.Type == MenuType.Node)
            {
                menu.Target = MenuTarget.UnKnown;
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                if (await _menuRepository.AddAsync(menu, uow))
                {
                    //同步菜单权限
                    if (await SyncPermission(menu, model.Permissions, uow))
                    {
                        //同步按钮
                        if (await SyncButton(menu, model.Buttons, uow))
                        {
                            uow.Commit();

                            await ClearAccountPermissionCache(menu);

                            return(ResultModel.Success());
                        }
                    }
                }
            }

            return(ResultModel.Failed());
        }
Пример #14
0
        public async Task <IResultModel> Sync()
        {
            using var uow = _dbContext.NewUnitOfWork();

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Name    = m.Name,
                Code    = m.Code,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogInformation("开始:同步模块信息");

            foreach (var module in modules)
            {
                if (!await _repository.Exists(module, uow))
                {
                    if (!await _repository.AddAsync(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
                else
                {
                    if (!await _repository.UpdateByCode(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
            }

            uow.Commit();

            _logger.LogInformation("结束:同步模块信息");

            return(ResultModel.Success());
        }
Пример #15
0
        private void Update <T>(T config)
        {
            var list = new List <ConfigEntity>();

            UpdateConfig(config, list);

            using var uow = _dbContext.NewUnitOfWork();
            var tasks = new Task[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                tasks[i] = _configRepository.UpdateAsync(list[i], uow);
            }

            Task.WaitAll(tasks);
            uow.Commit();
        }
Пример #16
0
        private void Update <T>(T config)
        {
            var list = new List <ConfigEntity>();

            UpdateConfig(config, list);

            using var uow = _dbContext.NewUnitOfWork();
            var tasks = new Task[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                tasks[i] = _configRepository.UpdateAsync(list[i], uow);
            }

            Task.WaitAll(tasks);
            uow.Commit();

            _cache.RemoveAsync(CacheKeys.SystemConfigCacheKey).GetAwaiter().GetResult();
        }
Пример #17
0
        public async Task <IResultModel> Delete(int id)
        {
            var employee = await _repository.GetAsync(id);

            if (employee == null)
            {
                return(ResultModel.Failed("员工信息不存在"));
            }

            var account = await _accountRepository.GetAsync(employee.AccountId);

            if (account == null)
            {
                return(ResultModel.Failed("账户信息不存在"));
            }

            using var uow      = _dbContext.NewUnitOfWork();
            using var adminUow = _adminDbContext.NewUnitOfWork();

            var result = await _repository.SoftDeleteAsync(id, uow);

            if (result)
            {
                result = await _accountRepository.SoftDeleteAsync(account.Id, adminUow);

                if (result)
                {
                    uow.Commit();
                    adminUow.Commit();

                    //清除缓存
                    await _cacheHandler.RemoveAsync(CacheKeys.EMPLOYEE_TREE);

                    await _cacheHandler.RemoveAsync($"{CacheKeys.EMPLOYEE_BASE_INFO}:{employee.Id}");

                    return(ResultModel.Success());
                }
            }
            return(ResultModel.Failed());
        }
Пример #18
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (!_options.RefreshModuleOrPermission)
            {
                return(ResultModel.Success());
            }

            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            _logger.LogDebug("Sync Permission Info");

            using var uow = _dbContext.NewUnitOfWork();

            //先清除已有权限信息
            if (await _repository.ClearAsync(uow))
            {
                foreach (var permission in permissions)
                {
                    if (!await _repository.AddAsync(permission, uow))
                    {
                        uow.Rollback();
                        return(ResultModel.Failed("同步失败"));
                    }
                }

                uow.Commit();

                //删除所有账户的权限缓存
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS);

                return(ResultModel.Success());
            }

            return(ResultModel.Failed("同步失败"));
        }
Пример #19
0
        public async Task <IResultModel> Sync()
        {
            var modules = _moduleCollection.Select(m => new ModuleInfoEntity
            {
                Name    = m.Name,
                Code    = m.Id,
                Icon    = m.Icon,
                Version = m.Version
            });

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var moduleInfo in modules)
                {
                    if (!await _repository.Exists(moduleInfo, uow))
                    {
                        if (!await _repository.AddAsync(moduleInfo))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                    else
                    {
                        if (!await _repository.UpdateByCode(moduleInfo))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
Пример #20
0
        public async Task <ResultModel <LoginResultModel> > Login(LoginModel model)
        {
            var result = new ResultModel <LoginResultModel>();

            //检测验证码
            if (!await CheckVerifyCode(result, model))
            {
                return(result);
            }

            //检测账户
            var account = await _accountRepository.GetByUserName(model.UserName, model.AccountType);

            var checkAccountResult = CheckAccount(account);

            if (!checkAccountResult.Successful)
            {
                return(result.Failed(checkAccountResult.Msg));
            }

            //检测密码
            if (!CheckPassword(result, model, account))
            {
                return(result);
            }

            using var uow = _dbContext.NewUnitOfWork();

            //判断是否激活,如果未激活需要修改为已激活状态
            if (account.Status == AccountStatus.Inactive)
            {
                if (!await _accountRepository.UpdateAccountStatus(account.Id, AccountStatus.Enabled, uow))
                {
                    return(result.Failed());
                }
            }

            //更新登录信息
            var loginInfo = await UpdateLoginInfo(account, model, uow);

            if (loginInfo != null)
            {
                uow.Commit();

                if (_systemConfig.Login.VerifyCode)
                {
                    //删除验证码缓存
                    await _cacheHandler.RemoveAsync(string.Format(CacheKeys.VerifyCodeKey, model.VerifyCode.Id));
                }

                //清除账户的认证信息缓存
                await _cacheHandler.RemoveAsync(string.Format(CacheKeys.AccountAuthInfo, account.Id, model.Platform.ToInt()));

                return(result.Success(new LoginResultModel
                {
                    Account = account,
                    AuthInfo = loginInfo
                }));
            }

            return(result.Failed());
        }
Пример #21
0
        public async Task <IResultModel <Guid> > Add(AccountAddModel model, IUnitOfWork uow = null)
        {
            var result = new ResultModel <Guid>();

            var account = _mapper.Map <AccountEntity>(model);

            var exists = await Exists(account);

            if (!exists.Successful)
            {
                return(exists);
            }

            //默认未激活状态,用户首次登录激活
            account.Status = AccountStatus.Inactive;

            //设置默认密码
            if (account.Password.IsNull())
            {
                if (_systemConfig != null && _systemConfig.Permission.DefaultPassword.NotNull())
                {
                    account.Password = _systemConfig.Permission.DefaultPassword;
                }
                else
                {
                    account.Password = "******";
                }
            }

            account.Password = _passwordHandler.Encrypt(account.UserName, account.Password);

            //如果uow参数为空,需要自动处理工作单元
            var noUow = uow == null;

            if (noUow)
            {
                uow = _dbContext.NewUnitOfWork();
            }

            if (await _accountRepository.AddAsync(account, uow))
            {
                if (model.Roles != null && model.Roles.Any())
                {
                    var accountRoleList = model.Roles.Select(m => new AccountRoleEntity {
                        AccountId = account.Id, RoleId = m
                    }).ToList();
                    if (await _accountRoleRepository.AddAsync(accountRoleList, uow))
                    {
                        if (noUow)
                        {
                            uow.Commit();
                        }

                        return(result.Success(account.Id));
                    }
                }
                else
                {
                    if (noUow)
                    {
                        uow.Commit();
                    }

                    return(result.Success(account.Id));
                }
            }

            return(result.Failed());
        }
Пример #22
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            using var uow = _dbContext.NewUnitOfWork();

            #region ==同步模块信息==

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Name    = m.Name,
                Code    = m.Code,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogDebug("Sync Module Info");

            foreach (var module in modules)
            {
                if (!await _repository.Exists(module, uow))
                {
                    if (!await _repository.AddAsync(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
                else
                {
                    if (!await _repository.UpdateByCode(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
            }

            #endregion

            #region ==同步权限信息=

            if (permissions != null && permissions.Any())
            {
                _logger.LogDebug("Sync Permission Info");

                //先清除已有权限信息
                if (await _permissionRepository.ClearAsync(uow))
                {
                    foreach (var permission in permissions)
                    {
                        if (!await _permissionRepository.AddAsync(permission, uow))
                        {
                            return(ResultModel.Failed("同步失败"));
                        }
                    }

                    //删除所有账户的权限缓存
                    await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS);
                }
            }

            #endregion

            uow.Commit();

            return(ResultModel.Success());
        }
Пример #23
0
        public async Task <IResultModel> Add(FileUploadModel model, FileInfo fileInfo)
        {
            var entity = new FileEntity
            {
                ModuleCode = model.ModuleCode,
                Group      = model.Group,
                AccessMode = model.AccessMode,
                FileName   = fileInfo.FileName,
                SaveId     = fileInfo.SaveName.Split('.')[0],
                Path       = fileInfo.Path,
                FullPath   = fileInfo.FullPath,
                Ext        = fileInfo.Ext,
                Size       = fileInfo.Size.Size,
                SizeName   = fileInfo.Size.ToString(),
                Md5        = fileInfo.Md5
            };

            var mime = await _mimeRepository.Get(fileInfo.Ext.ToLower());

            if (mime != null)
            {
                entity.Mime = mime.Value;
            }

            using var uow = _dbContext.NewUnitOfWork();
            var result = await _repository.AddAsync(entity, uow);

            if (result)
            {
                #region ==绑定文件拥有者==

                if (model.AccessMode == FileAccessMode.Auth && model.Accounts != null && model.Accounts.Any())
                {
                    var owners = model.Accounts.Split(',')
                                 .Select(accountId => new FileOwnerEntity
                    {
                        SaveId    = entity.SaveId,
                        AccountId = Guid.Parse(accountId)
                    }).ToList();
                    await _ownerRepository.AddAsync(owners, uow);
                }

                #endregion

                #region ==OSS上传==

                var fileObject = new FileObject
                {
                    ModuleCode   = entity.ModuleCode,
                    Group        = entity.Group,
                    AccessMode   = entity.AccessMode,
                    PhysicalPath = model.PhysicalPath,
                    FileInfo     = fileInfo
                };

                await _fileStorageProvider.Upload(fileObject);

                entity.Url = fileInfo.Url;

                #endregion

                uow.Commit();

                return(ResultModel.Success(entity));
            }
            return(ResultModel.Failed());
        }