Skip to content

Commit

Permalink
应用层商户注释
Browse files Browse the repository at this point in the history
  • Loading branch information
boydg123 committed Jul 17, 2017
1 parent 382df88 commit 35c2076
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 36 deletions.
38 changes: 30 additions & 8 deletions zero/Derrick.Application/MultiTenancy/Dto/CreateTenantInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,56 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 创建商户Input
/// </summary>
public class CreateTenantInput
{
/// <summary>
/// 商户名称
/// </summary>
[Required]
[StringLength(AbpTenantBase.MaxTenancyNameLength)]
[RegularExpression(Tenant.TenancyNameRegex)]
public string TenancyName { get; set; }

/// <summary>
/// Name
/// </summary>
[Required]
[StringLength(Tenant.MaxNameLength)]
public string Name { get; set; }

/// <summary>
/// 管理员邮箱
/// </summary>
[Required]
[EmailAddress]
[StringLength(User.MaxEmailAddressLength)]
public string AdminEmailAddress { get; set; }

/// <summary>
/// 管理员密码
/// </summary>
[StringLength(User.MaxPasswordLength)]
public string AdminPassword { get; set; }

/// <summary>
/// 连接字符串
/// </summary>
[MaxLength(AbpTenantBase.MaxConnectionStringLength)]
public string ConnectionString { get; set; }

/// <summary>
/// 是否在下次登陆时修改密码
/// </summary>
public bool ShouldChangePasswordOnNextLogin { get; set; }

/// <summary>
/// 发送激活邮箱
/// </summary>
public bool SendActivationEmail { get; set; }

/// <summary>
/// 版本ID
/// </summary>
public int? EditionId { get; set; }

/// <summary>
/// 是否激活
/// </summary>
public bool IsActive { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 商户功能编辑Output
/// </summary>
public class GetTenantFeaturesForEditOutput
{
/// <summary>
/// 功能值列表
/// </summary>
public List<NameValueDto> FeatureValues { get; set; }

/// <summary>
/// 功能列表
/// </summary>
public List<FlatFeatureDto> Features { get; set; }
}
}
10 changes: 9 additions & 1 deletion zero/Derrick.Application/MultiTenancy/Dto/GetTenantsInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 获取商户Input
/// </summary>
public class GetTenantsInput : PagedAndSortedInputDto, IShouldNormalize
{
/// <summary>
/// 过滤条件
/// </summary>
public string Filter { get; set; }

/// <summary>
/// 标准化
/// </summary>
public void Normalize()
{
if (string.IsNullOrEmpty(Sorting))
Expand Down
22 changes: 18 additions & 4 deletions zero/Derrick.Application/MultiTenancy/Dto/TenantEditDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 商户编辑Dto
/// </summary>
[AutoMap(typeof (Tenant))]
public class TenantEditDto : EntityDto
{
/// <summary>
/// 商户名称
/// </summary>
[Required]
[StringLength(Tenant.MaxTenancyNameLength)]
public string TenancyName { get; set; }

/// <summary>
/// Name
/// </summary>
[Required]
[StringLength(Tenant.MaxNameLength)]
public string Name { get; set; }

/// <summary>
/// 连接字符串
/// </summary>
public string ConnectionString { get; set; }

/// <summary>
/// 版本ID
/// </summary>
public int? EditionId { get; set; }

/// <summary>
/// 是否激活
/// </summary>
public bool IsActive { get; set; }
}
}
26 changes: 21 additions & 5 deletions zero/Derrick.Application/MultiTenancy/Dto/TenantListDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 商户列表Dto
/// </summary>
[AutoMapFrom(typeof (Tenant))]
public class TenantListDto : EntityDto, IPassivable, IHasCreationTime
{
/// <summary>
/// 商户名称
/// </summary>
public string TenancyName { get; set; }

/// <summary>
/// Name
/// </summary>
public string Name { get; set; }

/// <summary>
/// 版本显示名
/// </summary>
public string EditionDisplayName { get; set; }

/// <summary>
/// 连接字符串
/// </summary>
public string ConnectionString { get; set; }

/// <summary>
/// 是否激活
/// </summary>
public bool IsActive { get; set; }

/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

namespace Derrick.MultiTenancy.Dto
{
/// <summary>
/// 更新商户功能Input
/// </summary>
public class UpdateTenantFeaturesInput
{
/// <summary>
/// ID
/// </summary>
[Range(1, int.MaxValue)]
public int Id { get; set; }

/// <summary>
/// 功能值列表
/// </summary>
[Required]
public List<NameValueDto> FeatureValues { get; set; }
}
Expand Down
50 changes: 43 additions & 7 deletions zero/Derrick.Application/MultiTenancy/ITenantAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,58 @@

namespace Derrick.MultiTenancy
{
/// <summary>
/// 商户服务
/// </summary>
public interface ITenantAppService : IApplicationService
{
/// <summary>
/// 获取商户列表(带分页)
/// </summary>
/// <param name="input">获取商户Input</param>
/// <returns></returns>
Task<PagedResultDto<TenantListDto>> GetTenants(GetTenantsInput input);

/// <summary>
/// 创建商户
/// </summary>
/// <param name="input">创建商户Input</param>
/// <returns></returns>
Task CreateTenant(CreateTenantInput input);

/// <summary>
/// 获取编辑商户
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
Task<TenantEditDto> GetTenantForEdit(EntityDto input);

/// <summary>
/// 更新商户
/// </summary>
/// <param name="input">商户编辑Dto</param>
/// <returns></returns>
Task UpdateTenant(TenantEditDto input);

/// <summary>
/// 删除商户
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
Task DeleteTenant(EntityDto input);

/// <summary>
/// 获取编辑时商户功能
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
Task<GetTenantFeaturesForEditOutput> GetTenantFeaturesForEdit(EntityDto input);

/// <summary>
/// 更新商户功能
/// </summary>
/// <param name="input">更新商户功能Input</param>
/// <returns></returns>
Task UpdateTenantFeatures(UpdateTenantFeaturesInput input);

/// <summary>
/// 重置商户指定的功能
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
Task ResetTenantSpecificFeatures(EntityDto input);
}
}
59 changes: 50 additions & 9 deletions zero/Derrick.Application/MultiTenancy/TenantAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,30 @@

namespace Derrick.MultiTenancy
{
/// <summary>
/// 商户服务实现
/// </summary>
[AbpAuthorize(AppPermissions.Pages_Tenants)]
public class TenantAppService : AbpZeroTemplateAppServiceBase, ITenantAppService
{
/// <summary>
/// 商户管理器
/// </summary>
private readonly TenantManager _tenantManager;

/// <summary>
/// 构造函数
/// </summary>
/// <param name="tenantManager"></param>
public TenantAppService(
TenantManager tenantManager)
{
_tenantManager = tenantManager;
}

/// <summary>
/// 获取商户列表(带分页)
/// </summary>
/// <param name="input">获取商户Input</param>
/// <returns></returns>
public async Task<PagedResultDto<TenantListDto>> GetTenants(GetTenantsInput input)
{
var query = TenantManager.Tenants
Expand All @@ -47,7 +60,11 @@ public async Task<PagedResultDto<TenantListDto>> GetTenants(GetTenantsInput inpu
tenants.MapTo<List<TenantListDto>>()
);
}

/// <summary>
/// 创建商户
/// </summary>
/// <param name="input">创建商户Input</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_Create)]
[UnitOfWork(IsDisabled = true)]
public async Task CreateTenant(CreateTenantInput input)
Expand All @@ -62,15 +79,23 @@ await _tenantManager.CreateWithAdminUserAsync(input.TenancyName,
input.ShouldChangePasswordOnNextLogin,
input.SendActivationEmail);
}

/// <summary>
/// 获取编辑商户
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_Edit)]
public async Task<TenantEditDto> GetTenantForEdit(EntityDto input)
{
var tenantEditDto = (await TenantManager.GetByIdAsync(input.Id)).MapTo<TenantEditDto>();
tenantEditDto.ConnectionString = SimpleStringCipher.Instance.Decrypt(tenantEditDto.ConnectionString);
return tenantEditDto;
}

/// <summary>
/// 更新商户
/// </summary>
/// <param name="input">商户编辑Dto</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_Edit)]
public async Task UpdateTenant(TenantEditDto input)
{
Expand All @@ -79,14 +104,22 @@ public async Task UpdateTenant(TenantEditDto input)
input.MapTo(tenant);
CheckErrors(await TenantManager.UpdateAsync(tenant));
}

/// <summary>
/// 删除商户
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_Delete)]
public async Task DeleteTenant(EntityDto input)
{
var tenant = await TenantManager.GetByIdAsync(input.Id);
CheckErrors(await TenantManager.DeleteAsync(tenant));
}

/// <summary>
/// 获取编辑时商户功能
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_ChangeFeatures)]
public async Task<GetTenantFeaturesForEditOutput> GetTenantFeaturesForEdit(EntityDto input)
{
Expand All @@ -99,13 +132,21 @@ public async Task<GetTenantFeaturesForEditOutput> GetTenantFeaturesForEdit(Entit
FeatureValues = featureValues.Select(fv => new NameValueDto(fv)).ToList()
};
}

/// <summary>
/// 更新商户功能
/// </summary>
/// <param name="input">更新商户功能Input</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_ChangeFeatures)]
public async Task UpdateTenantFeatures(UpdateTenantFeaturesInput input)
{
await TenantManager.SetFeatureValuesAsync(input.Id, input.FeatureValues.Select(fv => new NameValue(fv.Name, fv.Value)).ToArray());
}

/// <summary>
/// 重置商户指定的功能
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
[AbpAuthorize(AppPermissions.Pages_Tenants_ChangeFeatures)]
public async Task ResetTenantSpecificFeatures(EntityDto input)
{
Expand Down

0 comments on commit 35c2076

Please sign in to comment.