22 changed files with 414 additions and 16 deletions
@ -0,0 +1,14 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public class EnterpriseCreateDto : EnterpriseCreateOrUpdateDto |
|||
{ |
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
[Required] |
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using System; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public abstract class EnterpriseCreateOrUpdateDto |
|||
{ |
|||
/// <summary>
|
|||
/// 关联租户
|
|||
/// </summary>
|
|||
public Guid? TenantId { get; set; } |
|||
/// <summary>
|
|||
/// 英文名称
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxEnglishNameLength))] |
|||
public string EnglishName { get; set; } |
|||
/// <summary>
|
|||
/// Logo
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxLogoLength))] |
|||
public string Logo { get; set; } |
|||
/// <summary>
|
|||
/// 地址
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxAddressLength))] |
|||
public string Address { get; set; } |
|||
/// <summary>
|
|||
/// 法人代表
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxLegalManLength))] |
|||
public string LegalMan { get; set; } |
|||
/// <summary>
|
|||
/// 税务登记号
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxTaxCodeLength))] |
|||
public string TaxCode { get; set; } |
|||
/// <summary>
|
|||
/// 组织机构代码
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxOrganizationCodeLength))] |
|||
public string OrganizationCode { get; set; } |
|||
/// <summary>
|
|||
/// 注册代码
|
|||
/// </summary>
|
|||
[DynamicStringLength(typeof(EnterpriseConsts), nameof(EnterpriseConsts.MaxRegistrationCodeLength))] |
|||
public string RegistrationCode { get; set; } |
|||
/// <summary>
|
|||
/// 注册日期
|
|||
/// </summary>
|
|||
public DateTime? RegistrationDate { get; set; } |
|||
/// <summary>
|
|||
/// 过期日期
|
|||
/// </summary>
|
|||
public DateTime? ExpirationDate { get; set; } |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public class EnterpriseDto : ExtensibleAuditedEntityDto<Guid>, IHasConcurrencyStamp |
|||
{ |
|||
public Guid? TenantId { get; set; } |
|||
public string Name { get; set; } |
|||
public string EnglishName { get; set; } |
|||
public string Logo { get; set; } |
|||
public string Address { get; set; } |
|||
public string LegalMan { get; set; } |
|||
public string TaxCode { get; set; } |
|||
public string OrganizationCode { get; set; } |
|||
public string RegistrationCode { get; set; } |
|||
public DateTime? RegistrationDate { get; set; } |
|||
public DateTime? ExpirationDate { get; set; } |
|||
public string ConcurrencyStamp { get; set; } |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public class EnterpriseGetListInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public DateTime? BeginRegistrationDate { get; set; } |
|||
|
|||
public DateTime? EndRegistrationDate { get; set; } |
|||
|
|||
public DateTime? BeginExpirationDate { get; set; } |
|||
|
|||
public DateTime? EndExpirationDate { get; set; } |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public class EnterpriseUpdateDto : EnterpriseCreateOrUpdateDto, IHasConcurrencyStamp |
|||
{ |
|||
public string ConcurrencyStamp { get; set; } |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
public interface IEnterpriseAppService : |
|||
ICrudAppService< |
|||
EnterpriseDto, |
|||
Guid, |
|||
EnterpriseGetListInput, |
|||
EnterpriseCreateDto, |
|||
EnterpriseUpdateDto> |
|||
{ |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using LINGYUN.Platform.Localization; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Platform; |
|||
|
|||
public abstract class PlatformApplicationCurdAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput> : |
|||
CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput> |
|||
where TEntity : class, IEntity<TKey> |
|||
{ |
|||
protected PlatformApplicationCurdAppServiceBase( |
|||
IRepository<TEntity, TKey> repository) : base(repository) |
|||
{ |
|||
LocalizationResource = typeof(PlatformResource); |
|||
ObjectMapperContext = typeof(PlatformApplicationModule); |
|||
} |
|||
} |
|||
@ -0,0 +1,147 @@ |
|||
using LINGYUN.Platform.Permissions; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
[Authorize(PlatformPermissions.Enterprise.Default)] |
|||
public class EnterpriseAppService : |
|||
PlatformApplicationCurdAppServiceBase< |
|||
Enterprise, |
|||
EnterpriseDto, |
|||
Guid, |
|||
EnterpriseGetListInput, |
|||
EnterpriseCreateDto, |
|||
EnterpriseUpdateDto>, |
|||
IEnterpriseAppService |
|||
{ |
|||
protected IEnterpriseRepository EnterpriseRepository { get; } |
|||
|
|||
public EnterpriseAppService(IEnterpriseRepository repository) |
|||
: base(repository) |
|||
{ |
|||
EnterpriseRepository = repository; |
|||
|
|||
CreatePolicyName = PlatformPermissions.Enterprise.Create; |
|||
UpdatePolicyName = PlatformPermissions.Enterprise.Update; |
|||
DeletePolicyName = PlatformPermissions.Enterprise.Delete; |
|||
GetListPolicyName = PlatformPermissions.Enterprise.Default; |
|||
GetPolicyName = PlatformPermissions.Enterprise.Default; |
|||
} |
|||
|
|||
protected async override Task<Enterprise> MapToEntityAsync(EnterpriseCreateDto createInput) |
|||
{ |
|||
if (await EnterpriseRepository.FindByNameAsync(createInput.Name) != null) |
|||
{ |
|||
throw new BusinessException(PlatformErrorCodes.DuplicateEnterpriseName) |
|||
.WithData("Name", createInput.Name); |
|||
} |
|||
|
|||
if (!createInput.EnglishName.IsNullOrWhiteSpace()) |
|||
{ |
|||
if (await EnterpriseRepository.FindByNameAsync(createInput.EnglishName) != null) |
|||
{ |
|||
throw new BusinessException(PlatformErrorCodes.DuplicateEnterpriseName) |
|||
.WithData("Name", createInput.EnglishName); |
|||
} |
|||
} |
|||
|
|||
var enterprise = new Enterprise( |
|||
GuidGenerator.Create(), |
|||
createInput.Name, |
|||
createInput.Address, |
|||
createInput.TaxCode, |
|||
createInput.OrganizationCode, |
|||
createInput.RegistrationCode, |
|||
createInput.RegistrationDate, |
|||
createInput.ExpirationDate, |
|||
createInput.TenantId); |
|||
|
|||
UpdateByInput(enterprise, createInput); |
|||
|
|||
return enterprise; |
|||
} |
|||
|
|||
protected async override Task MapToEntityAsync(EnterpriseUpdateDto updateInput, Enterprise entity) |
|||
{ |
|||
if (!string.Equals(entity.EnglishName, updateInput.EnglishName, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
if (await EnterpriseRepository.FindByNameAsync(updateInput.EnglishName) != null) |
|||
{ |
|||
throw new BusinessException(PlatformErrorCodes.DuplicateEnterpriseName) |
|||
.WithData("Name", updateInput.EnglishName); |
|||
} |
|||
} |
|||
|
|||
UpdateByInput(entity, updateInput); |
|||
|
|||
entity.SetConcurrencyStampIfNotNull(updateInput.ConcurrencyStamp); |
|||
} |
|||
|
|||
protected override void TryToSetTenantId(Enterprise entity) |
|||
{ |
|||
// ignore tenant
|
|||
} |
|||
|
|||
protected async override Task DeleteByIdAsync(Guid id) |
|||
{ |
|||
var enterprise = await Repository.GetAsync(id); |
|||
|
|||
await Repository.DeleteAsync(enterprise); |
|||
} |
|||
|
|||
protected virtual void UpdateByInput(Enterprise enterprise, EnterpriseCreateOrUpdateDto input) |
|||
{ |
|||
if (!string.Equals(enterprise.EnglishName, input.EnglishName, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.EnglishName = input.EnglishName; |
|||
} |
|||
if (!string.Equals(enterprise.Logo, input.Logo, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.Logo = input.Logo; |
|||
} |
|||
if (!string.Equals(enterprise.Address, input.Address, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.Address = input.Address; |
|||
} |
|||
if (!string.Equals(enterprise.LegalMan, input.LegalMan, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.LegalMan = input.LegalMan; |
|||
} |
|||
if (!string.Equals(enterprise.TaxCode, input.TaxCode, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.TaxCode = input.TaxCode; |
|||
} |
|||
if (!string.Equals(enterprise.OrganizationCode, input.OrganizationCode, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.SetOrganization(input.OrganizationCode); |
|||
} |
|||
if (!string.Equals(enterprise.RegistrationCode, input.RegistrationCode, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
enterprise.SetRegistration(input.RegistrationCode, input.RegistrationDate, input.ExpirationDate); |
|||
} |
|||
} |
|||
|
|||
protected async override Task<IQueryable<Enterprise>> CreateFilteredQueryAsync(EnterpriseGetListInput input) |
|||
{ |
|||
var filteredQuery = await base.CreateFilteredQueryAsync(input); |
|||
|
|||
Expression<Func<Enterprise, bool>> expression = _ => true; |
|||
|
|||
expression = expression.AndIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Filter) || |
|||
x.EnglishName.Contains(input.Filter) || x.Address.Contains(input.Filter) || x.LegalMan.Contains(input.Filter) || |
|||
x.TaxCode.Contains(input.Filter)|| x.OrganizationCode.Contains(input.Filter) || x.RegistrationCode.Contains(input.Filter)); |
|||
|
|||
expression = expression.AndIf(input.BeginRegistrationDate.HasValue, x => x.RegistrationDate >= input.BeginRegistrationDate); |
|||
expression = expression.AndIf(input.EndRegistrationDate.HasValue, x => x.RegistrationDate <= input.EndRegistrationDate); |
|||
expression = expression.AndIf(input.BeginExpirationDate.HasValue, x => x.ExpirationDate >= input.BeginExpirationDate); |
|||
expression = expression.AndIf(input.EndExpirationDate.HasValue, x => x.ExpirationDate <= input.EndExpirationDate); |
|||
|
|||
return filteredQuery.Where(expression); |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using LINGYUN.Platform.Permissions; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Platform.Portal; |
|||
|
|||
[Area("platform")] |
|||
[Authorize(PlatformPermissions.Enterprise.Default)] |
|||
[RemoteService(Name = PlatformRemoteServiceConsts.RemoteServiceName)] |
|||
[Route($"api/{PlatformRemoteServiceConsts.ModuleName}/enterprise")] |
|||
public class EnterpriseController : AbpControllerBase, IEnterpriseAppService |
|||
{ |
|||
private readonly IEnterpriseAppService _service; |
|||
public EnterpriseController(IEnterpriseAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Authorize(PlatformPermissions.Enterprise.Create)] |
|||
public virtual Task<EnterpriseDto> CreateAsync(EnterpriseCreateDto input) |
|||
{ |
|||
return _service.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpDelete] |
|||
[Route("{id}")] |
|||
[Authorize(PlatformPermissions.Enterprise.Delete)] |
|||
public virtual Task DeleteAsync(Guid id) |
|||
{ |
|||
return _service.DeleteAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("{id}")] |
|||
public virtual Task<EnterpriseDto> GetAsync(Guid id) |
|||
{ |
|||
return _service.GetAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<PagedResultDto<EnterpriseDto>> GetListAsync(EnterpriseGetListInput input) |
|||
{ |
|||
return _service.GetListAsync(input); |
|||
} |
|||
|
|||
[HttpPut] |
|||
[Route("{id}")] |
|||
[Authorize(PlatformPermissions.Enterprise.Delete)] |
|||
public virtual Task<EnterpriseDto> UpdateAsync(Guid id, EnterpriseUpdateDto input) |
|||
{ |
|||
return _service.UpdateAsync(id, input); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue