|  | @@ -35,7 +35,7 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |      private readonly IRepositoryBase<RolePermissionEntity> _rolePermissionRepository;
 |  |      private readonly IRepositoryBase<RolePermissionEntity> _rolePermissionRepository;
 | 
											
												
													
														|  |      private IOrgRepository _orgRepository => LazyGetRequiredService<IOrgRepository>();
 |  |      private IOrgRepository _orgRepository => LazyGetRequiredService<IOrgRepository>();
 | 
											
												
													
														|  |      private IStaffRepository _staffRepository => LazyGetRequiredService<IStaffRepository>();
 |  |      private IStaffRepository _staffRepository => LazyGetRequiredService<IStaffRepository>();
 | 
											
												
													
														|  | -    private IRepositoryBase<UserOrgEntity> _empOrgRepository => LazyGetRequiredService<IRepositoryBase<UserOrgEntity>>();
 |  | 
 | 
											
												
													
														|  | 
 |  | +    private IRepositoryBase<UserOrgEntity> _userOrgRepository => LazyGetRequiredService<IRepositoryBase<UserOrgEntity>>();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      private AppConfig _appConfig => LazyGetRequiredService<AppConfig>();
 |  |      private AppConfig _appConfig => LazyGetRequiredService<AppConfig>();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -100,6 +100,16 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |      [Transaction]
 |  |      [Transaction]
 | 
											
												
													
														|  |      public virtual async Task<IResultOutput> AddAsync(TenantAddInput input)
 |  |      public virtual async Task<IResultOutput> AddAsync(TenantAddInput input)
 | 
											
												
													
														|  |      {
 |  |      {
 | 
											
												
													
														|  | 
 |  | +        if (await _tenantRepository.Select.AnyAsync(a => a.Name == input.Name))
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            return ResultOutput.NotOk($"企业名称已存在");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        if (await _tenantRepository.Select.AnyAsync(a => a.Code == input.Code))
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            return ResultOutput.NotOk($"企业编码已存在");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          //添加租户
 |  |          //添加租户
 | 
											
												
													
														|  |          var entity = Mapper.Map<TenantEntity>(input);
 |  |          var entity = Mapper.Map<TenantEntity>(input);
 | 
											
												
													
														|  |          var tenant = await _tenantRepository.InsertAsync(entity);
 |  |          var tenant = await _tenantRepository.InsertAsync(entity);
 | 
											
										
											
												
													
														|  | @@ -118,8 +128,9 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          //添加主管理员
 |  |          //添加主管理员
 | 
											
												
													
														|  |          var pwd = MD5Encrypt.Encrypt32(_appConfig.DefaultPassword);
 |  |          var pwd = MD5Encrypt.Encrypt32(_appConfig.DefaultPassword);
 | 
											
												
													
														|  | -        var user = new UserEntity { 
 |  | 
 | 
											
												
													
														|  | -            TenantId = tenantId, 
 |  | 
 | 
											
												
													
														|  | 
 |  | +        var user = new UserEntity
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            TenantId = tenantId,
 | 
											
												
													
														|  |              UserName = input.Phone,
 |  |              UserName = input.Phone,
 | 
											
												
													
														|  |              Password = pwd,
 |  |              Password = pwd,
 | 
											
												
													
														|  |              Name = input.RealName,
 |  |              Name = input.RealName,
 | 
											
										
											
												
													
														|  | @@ -145,10 +156,11 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |              UserId = userId,
 |  |              UserId = userId,
 | 
											
												
													
														|  |              OrgId = org.Id
 |  |              OrgId = org.Id
 | 
											
												
													
														|  |          };
 |  |          };
 | 
											
												
													
														|  | -        await _empOrgRepository.InsertAsync(userOrg);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        await _userOrgRepository.InsertAsync(userOrg);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          //添加角色
 |  |          //添加角色
 | 
											
												
													
														|  | -        var role = new RoleEntity { 
 |  | 
 | 
											
												
													
														|  | 
 |  | +        var role = new RoleEntity
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  |              TenantId = tenantId,
 |  |              TenantId = tenantId,
 | 
											
												
													
														|  |              Name = "主管理员",
 |  |              Name = "主管理员",
 | 
											
												
													
														|  |              Code = "admin"
 |  |              Code = "admin"
 | 
											
										
											
												
													
														|  | @@ -156,16 +168,15 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |          await _roleRepository.InsertAsync(role);
 |  |          await _roleRepository.InsertAsync(role);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          //添加用户角色
 |  |          //添加用户角色
 | 
											
												
													
														|  | -        var userRole = new UserRoleEntity() 
 |  | 
 | 
											
												
													
														|  | -        { 
 |  | 
 | 
											
												
													
														|  | -            UserId = userId, 
 |  | 
 | 
											
												
													
														|  | -            RoleId = role.Id 
 |  | 
 | 
											
												
													
														|  | 
 |  | +        var userRole = new UserRoleEntity()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            UserId = userId,
 | 
											
												
													
														|  | 
 |  | +            RoleId = role.Id
 | 
											
												
													
														|  |          };
 |  |          };
 | 
											
												
													
														|  |          await _userRoleRepository.InsertAsync(userRole);
 |  |          await _userRoleRepository.InsertAsync(userRole);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        //更新租户的用户和角色
 |  | 
 | 
											
												
													
														|  | 
 |  | +        //更新租户的用户
 | 
											
												
													
														|  |          tenant.UserId = userId;
 |  |          tenant.UserId = userId;
 | 
											
												
													
														|  | -        tenant.RoleId = role.Id;
 |  | 
 | 
											
												
													
														|  |          await _tenantRepository.UpdateAsync(tenant);
 |  |          await _tenantRepository.UpdateAsync(tenant);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          return ResultOutput.Ok();
 |  |          return ResultOutput.Ok();
 | 
											
										
											
												
													
														|  | @@ -208,6 +219,12 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 | 
											
												
													
														|  |          //删除用户角色
 |  |          //删除用户角色
 | 
											
												
													
														|  |          await _userRoleRepository.Where(a => a.User.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 |  |          await _userRoleRepository.Where(a => a.User.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +        //删除员工
 | 
											
												
													
														|  | 
 |  | +        await _staffRepository.Where(a => a.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //删除用户部门
 | 
											
												
													
														|  | 
 |  | +        await _userOrgRepository.Where(a => a.User.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          //删除用户
 |  |          //删除用户
 | 
											
												
													
														|  |          await _userRepository.Where(a => a.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 |  |          await _userRepository.Where(a => a.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
 | 
											
												
													
														|  |  
 |  |  
 |