diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN.Abp.PrintDesigner.Application.Contracts.csproj b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN.Abp.PrintDesigner.Application.Contracts.csproj new file mode 100644 index 000000000..55b93d3fe --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN.Abp.PrintDesigner.Application.Contracts.csproj @@ -0,0 +1,26 @@ + + + + + + + netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0 + LINGYUN.Abp.PrintDesigner.Application.Contracts + LINGYUN.Abp.PrintDesigner.Application.Contracts + false + false + false + True + + + + + + + + + + + + + diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationContractsModule.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationContractsModule.cs new file mode 100644 index 000000000..b4fa966e6 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationContractsModule.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Application; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.PrintDesigner; + +[DependsOn( + typeof(AbpDddApplicationContractsModule), + typeof(AbpPrintDesignerDomainSharedModule))] +public class AbpPrintDesignerApplicationContractsModule : AbpModule +{ +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateDto.cs new file mode 100644 index 000000000..1f3b6b387 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateDto.cs @@ -0,0 +1,5 @@ +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementCreateDto : CustomElementCreateOrUpdateDto +{ +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateOrUpdateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateOrUpdateDto.cs new file mode 100644 index 000000000..ef56305d0 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementCreateOrUpdateDto.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public abstract class CustomElementCreateOrUpdateDto +{ + /// + /// 元素名称 + /// + [Required] + [DynamicStringLength(typeof(CustomElementConsts), nameof(CustomElementConsts.MaxNameLength))] + public string Name { get; set; } = default!; + /// + /// 描述 + /// + [DynamicStringLength(typeof(CustomElementConsts), nameof(CustomElementConsts.MaxDescriptionLength))] + public string? Description { get; set; } + /// + /// 元素定义 + /// + [Required] + public Dictionary Element { get; set; } = new Dictionary(); + /// + /// 元素扩展参数 + /// + public Dictionary Ext { get; set; } = new Dictionary(); +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDeleteDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDeleteDto.cs new file mode 100644 index 000000000..ec67b1036 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDeleteDto.cs @@ -0,0 +1,6 @@ +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementDeleteDto +{ + public bool Success { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDto.cs new file mode 100644 index 000000000..a62349621 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementDto.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementDto : AuditedEntityDto, IHasConcurrencyStamp +{ + /// + /// 名称 + /// + public string Name { get; set; } = default!; + /// + /// 描述 + /// + public string? Description { get; set; } + /// + /// 时间戳(毫秒) + /// + public long? UpdatedAt { get; set; } + /// + /// 元素数据 + /// + public Dictionary? Element { get; set; } + /// + /// 扩展数据容器 + /// + public Dictionary Ext { get; set; } = new Dictionary(); + /// + /// 用于控制前端操作按钮权限 + /// + public CustomElementPermissionDto? Permissions { get; set; } + /// + /// 并发令牌 + /// + public string ConcurrencyStamp { get; set; } = default!; +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementGetPagedListInput.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementGetPagedListInput.cs new file mode 100644 index 000000000..0d23210f4 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementGetPagedListInput.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementGetPagedListInput : PagedAndSortedResultRequestDto +{ + public string? Filter { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementPermissionDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementPermissionDto.cs new file mode 100644 index 000000000..84624bcd4 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementPermissionDto.cs @@ -0,0 +1,8 @@ +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementPermissionDto +{ + public bool Editable { get; set; } + public bool Deletable { get; set; } + public bool Copyable { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpdateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpdateDto.cs new file mode 100644 index 000000000..7703fa908 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpdateDto.cs @@ -0,0 +1,6 @@ +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementUpdateDto : CustomElementCreateOrUpdateDto +{ + public string? ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpsertDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpsertDto.cs new file mode 100644 index 000000000..121c3615e --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/Dtos/CustomElementUpsertDto.cs @@ -0,0 +1,10 @@ +using System; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; + +public class CustomElementUpsertDto : CustomElementCreateOrUpdateDto +{ + public Guid? Id { get; set; } + + public string? ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/ICustomElementAppService.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/ICustomElementAppService.cs new file mode 100644 index 000000000..4ff6fc387 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/CustomElements/ICustomElementAppService.cs @@ -0,0 +1,56 @@ +using LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements; + +public interface ICustomElementAppService : IApplicationService +{ + /// + /// 获取全部自定义元素列表 + /// + /// + Task> GetAllAsync(); + /// + /// 获取自定义元素列表 + /// + /// 查询过滤参数 + /// + Task> GetListAsync(CustomElementGetPagedListInput input); + /// + /// 获取自定义元素详情 + /// + /// 自定义元素Id + /// + Task GetAsync(Guid id); + /// + /// 新增自定义元素 + /// + /// + /// + Task CreateAsync(CustomElementCreateDto input); + /// + /// 编辑自定义元素 + /// + /// 自定义元素Id + /// + /// + Task UpdateAsync(Guid id, CustomElementUpdateDto input); + /// + /// 新增或编辑自定义元素 + /// + /// + /// 兼容upsert接口 + /// + /// + /// + Task UpsertAsync(CustomElementUpsertDto input); + /// + /// 删除自定义元素 + /// + /// 自定义元素Id + /// + Task DeleteAsync(Guid id); +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissionDefinitionProvider.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissionDefinitionProvider.cs new file mode 100644 index 000000000..91dd66968 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissionDefinitionProvider.cs @@ -0,0 +1,50 @@ +using LINGYUN.Abp.PrintDesigner.Localization; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.PrintDesigner.Permissions; + +public class PrintDesignerPermissionDefinitionProvider : PermissionDefinitionProvider +{ + public override void Define(IPermissionDefinitionContext context) + { + var group = context.AddGroup(PrintDesignerPermissions.GroupName, L("Permission:PrintDesigner")); + + var customElement = group.AddPermission( + PrintDesignerPermissions.CustomElement.Default, + L("Permission:CustomElement")); + customElement.AddChild( + PrintDesignerPermissions.CustomElement.Create, + L("Permission:Create")); + customElement.AddChild( + PrintDesignerPermissions.CustomElement.Delete, + L("Permission:Delete")); + customElement.AddChild( + PrintDesignerPermissions.CustomElement.Update, + L("Permission:Update")); + customElement.AddChild( + PrintDesignerPermissions.CustomElement.Copy, + L("Permission:Copy")); + + var template = group.AddPermission( + PrintDesignerPermissions.Template.Default, + L("Permission:Template")); + template.AddChild( + PrintDesignerPermissions.Template.Create, + L("Permission:Create")); + template.AddChild( + PrintDesignerPermissions.Template.Delete, + L("Permission:Delete")); + template.AddChild( + PrintDesignerPermissions.Template.Update, + L("Permission:Update")); + template.AddChild( + PrintDesignerPermissions.Template.Copy, + L("Permission:Copy")); + } + + private static LocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissions.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissions.cs new file mode 100644 index 000000000..0b6ed45c0 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Permissions/PrintDesignerPermissions.cs @@ -0,0 +1,24 @@ +namespace LINGYUN.Abp.PrintDesigner.Permissions; + +public static class PrintDesignerPermissions +{ + public const string GroupName = "PrintDesigner"; + + public static class CustomElement + { + public const string Default = GroupName + ".CustomElements"; + public const string Create = Default + ".Create"; + public const string Update = Default + ".Update"; + public const string Delete = Default + ".Delete"; + public const string Copy = Default + ".Copy"; + } + + public static class Template + { + public const string Default = GroupName + ".Templates"; + public const string Create = Default + ".Create"; + public const string Update = Default + ".Update"; + public const string Delete = Default + ".Delete"; + public const string Copy = Default + ".Copy"; + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/PrintDesignerRemoteServiceConsts.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/PrintDesignerRemoteServiceConsts.cs new file mode 100644 index 000000000..d0d9ebf07 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/PrintDesignerRemoteServiceConsts.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.PrintDesigner; + +public static class PrintDesignerRemoteServiceConsts +{ + public const string RemoteServiceName = "PrintDesigner"; + public const string ModuleName = "print-designer"; +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateDto.cs new file mode 100644 index 000000000..91ee2b736 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateDto.cs @@ -0,0 +1,5 @@ +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateCreateDto : TemplateCreateOrUpdateDto +{ +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateOrUpdateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateOrUpdateDto.cs new file mode 100644 index 000000000..0e3ddc1c5 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateCreateOrUpdateDto.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public abstract class TemplateCreateOrUpdateDto +{ + /// + /// 名称 + /// + [Required] + [DynamicStringLength(typeof(TemplateConsts), nameof(TemplateConsts.MaxNameLength))] + public string Name { get; set; } = default!; + /// + /// 描述 + /// + [DynamicStringLength(typeof(TemplateConsts), nameof(TemplateConsts.MaxDescriptionLength))] + public string? Description { get; set; } + /// + /// 模板设计数据 + /// + [Required] + public Dictionary Data { get; set; } = new Dictionary(); + /// + /// 模板扩展参数容器 + /// + public Dictionary Ext { get; set; } = new Dictionary(); +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDeleteDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDeleteDto.cs new file mode 100644 index 000000000..3dcde9353 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDeleteDto.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateDeleteDto +{ + public bool Success { get; set; } +} + diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDto.cs new file mode 100644 index 000000000..a0e1c68b6 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateDto.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateDto : AuditedEntityDto, IHasConcurrencyStamp +{ + /// + /// 名称 + /// + public string Name { get; set; } = default!; + /// + /// 描述 + /// + public string? Description { get; set; } + /// + /// 时间戳(毫秒) + /// + public long? UpdatedAt { get; set; } + /// + /// 模板设计数据 + /// + public Dictionary? Data { get; set; } + /// + /// 扩展数据容器 + /// + public Dictionary Ext { get; set; } = new Dictionary(); + /// + /// 用于控制前端操作按钮权限 + /// + public TemplatePermissionDto? Permissions { get; set; } + /// + /// 并发令牌 + /// + public string ConcurrencyStamp { get; set; } = default!; +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateGetPagedListInput.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateGetPagedListInput.cs new file mode 100644 index 000000000..0adf06314 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateGetPagedListInput.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateGetPagedListInput : PagedAndSortedResultRequestDto +{ + public string? Filter { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplatePermissionDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplatePermissionDto.cs new file mode 100644 index 000000000..5a0db342a --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplatePermissionDto.cs @@ -0,0 +1,8 @@ +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplatePermissionDto +{ + public bool Editable { get; set; } + public bool Deletable { get; set; } + public bool Copyable { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpdateDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpdateDto.cs new file mode 100644 index 000000000..8856bfb2e --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpdateDto.cs @@ -0,0 +1,6 @@ +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateUpdateDto : TemplateCreateOrUpdateDto +{ + public string? ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpsertDto.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpsertDto.cs new file mode 100644 index 000000000..e11c75f0b --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/Dtos/TemplateUpsertDto.cs @@ -0,0 +1,10 @@ +using System; + +namespace LINGYUN.Abp.PrintDesigner.Templates.Dtos; + +public class TemplateUpsertDto : TemplateCreateOrUpdateDto +{ + public Guid? Id { get; set; } + + public string? ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/ITemplateAppService.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/ITemplateAppService.cs new file mode 100644 index 000000000..478ba1561 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application.Contracts/LINGYUN/Abp/PrintDesigner/Templates/ITemplateAppService.cs @@ -0,0 +1,61 @@ +using LINGYUN.Abp.PrintDesigner.Templates.Dtos; +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.PrintDesigner.Templates; + +public interface ITemplateAppService : IApplicationService +{ + /// + /// 获取全部模板列表 + /// + /// + Task> GetAllAsync(); + /// + /// 获取模板列表 + /// + /// + Task> GetListAsync(TemplateGetPagedListInput input); + /// + /// 获取模板详情 + /// + /// 模板Id + /// + Task GetAsync(Guid id); + /// + /// 获取模板详情 + /// + /// 模板名称 + /// + Task GetByNameAsync(string name); + /// + /// 新增模板 + /// + /// + /// + Task CreateAsync(TemplateCreateDto input); + /// + /// 编辑模板 + /// + /// 模板Id + /// + /// + Task UpdateAsync(Guid id, TemplateUpdateDto input); + /// + /// 新增或编辑模板 + /// + /// + /// 兼容upsert接口 + /// + /// + /// + Task UpsertAsync(TemplateUpsertDto input); + /// + /// 删除模板 + /// + /// 模板Id + /// + Task DeleteAsync(Guid id); +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN.Abp.PrintDesigner.Application.csproj b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN.Abp.PrintDesigner.Application.csproj new file mode 100644 index 000000000..140a8733d --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN.Abp.PrintDesigner.Application.csproj @@ -0,0 +1,25 @@ + + + + + + + net10.0 + LINGYUN.Abp.PrintDesigner.Application + LINGYUN.Abp.PrintDesigner.Application + false + false + false + + + + + + + + + + + + + diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationModule.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationModule.cs new file mode 100644 index 000000000..035b21432 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/AbpPrintDesignerApplicationModule.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Application; +using Volo.Abp.Authorization; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.PrintDesigner; + +[DependsOn( + typeof(AbpAuthorizationModule), + typeof(AbpDddApplicationModule), + typeof(AbpPrintDesignerDomainModule), + typeof(AbpPrintDesignerApplicationContractsModule))] +public class AbpPrintDesignerApplicationModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddMapperlyObjectMapper(); + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementAppService.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementAppService.cs new file mode 100644 index 000000000..33be885dd --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementAppService.cs @@ -0,0 +1,208 @@ +using LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; +using LINGYUN.Abp.PrintDesigner.Permissions; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Data; +using Volo.Abp.Json; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements; + +[Authorize(PrintDesignerPermissions.CustomElement.Default)] +public class CustomElementAppService : PrintDesignerAppServiceBase, ICustomElementAppService +{ + private readonly IJsonSerializer _jsonSerializer; + private readonly ICustomElementRepository _customElementRepository; + + public CustomElementAppService( + IJsonSerializer jsonSerializer, + ICustomElementRepository customElementRepository) + { + _jsonSerializer = jsonSerializer; + _customElementRepository = customElementRepository; + } + + [Authorize(PrintDesignerPermissions.CustomElement.Create)] + public async virtual Task CreateAsync(CustomElementCreateDto input) + { + if (await _customElementRepository.FindByNameAsync(input.Name) != null) + { + throw new BusinessException( + PrintDesignerErrorCodes.CustomElement.NameAlreadyExists, + $"A custom element definition named {input.Name} already exists.!") + .WithData("Name", input.Name); + } + + var customElement = new CustomElement( + GuidGenerator.Create(), + input.Name, + input.Description, + CurrentTenant.Id); + + var elementData = _jsonSerializer.Serialize(input.Element); + var extendedData = _jsonSerializer.Serialize(input.Ext); + customElement.SetData(elementData, extendedData); + + customElement = await _customElementRepository.InsertAsync(customElement); + + await CurrentUnitOfWork!.SaveChangesAsync(); + + var customElementDto = ObjectMapper.Map(customElement); + + await SetCustomElementPermissions(customElementDto); + + return customElementDto; + } + + [Authorize(PrintDesignerPermissions.CustomElement.Delete)] + public async virtual Task DeleteAsync(Guid id) + { + bool success; + try + { + var customElement = await _customElementRepository.GetAsync(id); + + await _customElementRepository.DeleteAsync(customElement); + + success = true; + } + catch (Exception ex) + { + Logger.LogWarning(ex, "Deleting custom element: {id} failed: {message}!", id, ex.Message); + success = false; + } + + return new CustomElementDeleteDto + { + Success = success, + }; + } + + public async virtual Task GetAsync(Guid id) + { + var customElement = await _customElementRepository.GetAsync(id); + + var customElementDto = ObjectMapper.Map(customElement); + + await SetCustomElementPermissions(customElementDto); + + return customElementDto; + } + + public async virtual Task> GetAllAsync() + { + var customElements = await _customElementRepository.GetListAsync(); + + var customElementDtos = ObjectMapper.Map, List>(customElements); + + await SetCustomElementsPermissions(customElementDtos); + + return new ListResultDto(customElementDtos); + } + + public async virtual Task> GetListAsync(CustomElementGetPagedListInput input) + { + var specification = new CustomElementGetPagedListSpecification(input); + + var totalCount = await _customElementRepository.GetCountAsync(specification); + var customElements = await _customElementRepository.GetListAsync(specification, + input.Sorting, input.MaxResultCount, input.SkipCount); + + var customElementDtos = ObjectMapper.Map, List>(customElements); + + await SetCustomElementsPermissions(customElementDtos); + + return new PagedResultDto(totalCount, customElementDtos); + } + + [Authorize(PrintDesignerPermissions.CustomElement.Update)] + public async virtual Task UpdateAsync(Guid id, CustomElementUpdateDto input) + { + var customElement = await _customElementRepository.GetAsync(id); + if (!string.Equals(customElement.Name, input.Name, StringComparison.CurrentCultureIgnoreCase)) + { + if (await _customElementRepository.FindByNameAsync(input.Name) != null) + { + throw new BusinessException( + PrintDesignerErrorCodes.CustomElement.NameAlreadyExists, + $"A custom element definition named {input.Name} already exists.!") + .WithData("Name", input.Name); + } + customElement.SetName(input.Name); + } + var elementData = _jsonSerializer.Serialize(input.Element); + var extendedData = _jsonSerializer.Serialize(input.Ext); + customElement.SetData(elementData, extendedData); + customElement.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); + + customElement = await _customElementRepository.UpdateAsync(customElement); + + await CurrentUnitOfWork!.SaveChangesAsync(); + + var customElementDto = ObjectMapper.Map(customElement); + + await SetCustomElementPermissions(customElementDto); + + return customElementDto; + } + + public async virtual Task UpsertAsync(CustomElementUpsertDto input) + { + if (input.Id.HasValue && + await _customElementRepository.FindAsync(input.Id.Value) != null) + { + await AuthorizationService.CheckAsync(PrintDesignerPermissions.CustomElement.Update); + + return await UpdateAsync( + input.Id.Value, + new CustomElementUpdateDto + { + Name = input.Name, + Description = input.Description, + Element = input.Element, + Ext = input.Ext, + ConcurrencyStamp = input.ConcurrencyStamp, + }); + } + else + { + await AuthorizationService.CheckAsync(PrintDesignerPermissions.CustomElement.Create); + + return await CreateAsync( + new CustomElementCreateDto + { + Name = input.Name, + Description = input.Description, + Element = input.Element, + Ext = input.Ext, + }); + } + } + + protected async virtual Task SetCustomElementPermissions(CustomElementDto customElementDto) + { + customElementDto.Permissions ??= new CustomElementPermissionDto(); + customElementDto.Permissions.Editable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Update); + customElementDto.Permissions.Deletable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Delete); + customElementDto.Permissions.Copyable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Copy); + } + + protected async virtual Task SetCustomElementsPermissions(List customElementDtos) + { + var editable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Update); + var deletable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Delete); + var copyable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.CustomElement.Copy); + + foreach (var customElementDto in customElementDtos) + { + customElementDto.Permissions ??= new CustomElementPermissionDto(); + customElementDto.Permissions.Editable = editable; + customElementDto.Permissions.Deletable = deletable; + customElementDto.Permissions.Copyable = copyable; + } + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementGetPagedListSpecification.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementGetPagedListSpecification.cs new file mode 100644 index 000000000..fcb11f141 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/CustomElements/CustomElementGetPagedListSpecification.cs @@ -0,0 +1,24 @@ +using LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; +using System; +using System.Linq.Expressions; +using Volo.Abp.Specifications; + +namespace LINGYUN.Abp.PrintDesigner.CustomElements; + +public class CustomElementGetPagedListSpecification : Specification +{ + protected CustomElementGetPagedListInput Input { get; } + public CustomElementGetPagedListSpecification(CustomElementGetPagedListInput input) + { + Input = input; + } + public override Expression> ToExpression() + { + Expression> expression = _ => true; + + return expression + .AndIf(!Input.Filter.IsNullOrWhiteSpace(), x => + x.Name.Contains(Input.Filter!) || + (x.Description != null && x.Description.Contains(Input.Filter!))); + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerAppServiceBase.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerAppServiceBase.cs new file mode 100644 index 000000000..8fada0294 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerAppServiceBase.cs @@ -0,0 +1,13 @@ +using LINGYUN.Abp.PrintDesigner.Localization; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.PrintDesigner; + +public abstract class PrintDesignerAppServiceBase : ApplicationService +{ + protected PrintDesignerAppServiceBase() + { + LocalizationResource = typeof(PrintDesignerResource); + ObjectMapperContext = typeof(AbpPrintDesignerApplicationModule); + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerApplicationMappers.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerApplicationMappers.cs new file mode 100644 index 000000000..356fd7621 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/PrintDesignerApplicationMappers.cs @@ -0,0 +1,94 @@ +using LINGYUN.Abp.PrintDesigner.CustomElements.Dtos; +using LINGYUN.Abp.PrintDesigner.Templates.Dtos; +using LINGYUN.Abp.PrintDesigner.CustomElements; +using LINGYUN.Abp.PrintDesigner.Templates; +using Riok.Mapperly.Abstractions; +using System; +using System.Collections.Generic; +using Volo.Abp.Json; +using Volo.Abp.Mapperly; +using Volo.Abp.ObjectExtending; + +namespace LINGYUN.Abp.PrintDesigner.Admin; + +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] +[MapExtraProperties(DefinitionChecks = MappingPropertyDefinitionChecks.None)] +public partial class CustomElementToCustomElementDtoMapper : MapperBase +{ + private readonly IJsonSerializer _jsonSerializer; + public CustomElementToCustomElementDtoMapper(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } + + [MapperIgnoreTarget(nameof(CustomElementDto.Ext))] + [MapperIgnoreTarget(nameof(CustomElementDto.Element))] + [MapperIgnoreTarget(nameof(CustomElementDto.UpdatedAt))] + [MapperIgnoreTarget(nameof(CustomElementDto.Permissions))] + public override partial CustomElementDto Map(CustomElement source); + + [MapperIgnoreTarget(nameof(CustomElementDto.Ext))] + [MapperIgnoreTarget(nameof(CustomElementDto.Element))] + [MapperIgnoreTarget(nameof(CustomElementDto.UpdatedAt))] + [MapperIgnoreTarget(nameof(CustomElementDto.Permissions))] + public override partial void Map(CustomElement source, CustomElementDto destination); + + public override void AfterMap(CustomElement source, CustomElementDto destination) + { + destination.UpdatedAt = new DateTimeOffset(source.CreationTime).ToUnixTimeMilliseconds(); + destination.Element = new Dictionary(); + destination.Ext = new Dictionary(); + if (source.Data != null) + { + if (!source.Data.ElementData.IsNullOrWhiteSpace()) + { + destination.Element = _jsonSerializer.Deserialize>(source.Data.ElementData); + } + if (!source.Data.ExtendedData.IsNullOrWhiteSpace()) + { + destination.Ext = _jsonSerializer.Deserialize>(source.Data.ExtendedData); + } + } + } +} + +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] +[MapExtraProperties(DefinitionChecks = MappingPropertyDefinitionChecks.None)] +public partial class TemplateToTemplateDtoMapper : MapperBase +{ + private readonly IJsonSerializer _jsonSerializer; + public TemplateToTemplateDtoMapper(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } + + [MapperIgnoreTarget(nameof(TemplateDto.Data))] + [MapperIgnoreTarget(nameof(TemplateDto.Ext))] + [MapperIgnoreTarget(nameof(TemplateDto.UpdatedAt))] + [MapperIgnoreTarget(nameof(TemplateDto.Permissions))] + public override partial TemplateDto Map(Template source); + + [MapperIgnoreTarget(nameof(TemplateDto.Data))] + [MapperIgnoreTarget(nameof(TemplateDto.Ext))] + [MapperIgnoreTarget(nameof(TemplateDto.UpdatedAt))] + [MapperIgnoreTarget(nameof(TemplateDto.Permissions))] + public override partial void Map(Template source, TemplateDto destination); + + public override void AfterMap(Template source, TemplateDto destination) + { + destination.UpdatedAt = new DateTimeOffset(source.CreationTime).ToUnixTimeMilliseconds(); + destination.Data = new Dictionary(); + destination.Ext = new Dictionary(); + if (source.Data != null) + { + if (!source.Data.DesignerData.IsNullOrWhiteSpace()) + { + destination.Data = _jsonSerializer.Deserialize>(source.Data.DesignerData); + } + if (!source.Data.ExtendedData.IsNullOrWhiteSpace()) + { + destination.Ext = _jsonSerializer.Deserialize>(source.Data.ExtendedData); + } + } + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateAppService.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateAppService.cs new file mode 100644 index 000000000..0534a8b20 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateAppService.cs @@ -0,0 +1,221 @@ +using LINGYUN.Abp.PrintDesigner.Permissions; +using LINGYUN.Abp.PrintDesigner.Templates.Dtos; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Data; +using Volo.Abp.Json; + +namespace LINGYUN.Abp.PrintDesigner.Templates; + +[Authorize(PrintDesignerPermissions.Template.Default)] +public class TemplateAppService : PrintDesignerAppServiceBase, ITemplateAppService +{ + private readonly IJsonSerializer _jsonSerializer; + private readonly ITemplateRepository _templateRepository; + + public TemplateAppService( + IJsonSerializer jsonSerializer, + ITemplateRepository templateRepository) + { + _jsonSerializer = jsonSerializer; + _templateRepository = templateRepository; + } + + [Authorize(PrintDesignerPermissions.Template.Create)] + public async virtual Task CreateAsync(TemplateCreateDto input) + { + if (await _templateRepository.FindByNameAsync(input.Name) != null) + { + throw new BusinessException( + PrintDesignerErrorCodes.Template.NameAlreadyExists, + $"A template definition named {input.Name} already exists.!") + .WithData("Name", input.Name); + } + + var template = new Template( + GuidGenerator.Create(), + input.Name, + input.Description, + CurrentTenant.Id); + + var elementData = _jsonSerializer.Serialize(input.Data); + var extendedData = _jsonSerializer.Serialize(input.Ext); + template.SetData(elementData, extendedData); + + template = await _templateRepository.InsertAsync(template); + + await CurrentUnitOfWork!.SaveChangesAsync(); + + var templateDto = ObjectMapper.Map(template); + + await SetTemplatePermissions(templateDto); + + return templateDto; + } + + [Authorize(PrintDesignerPermissions.Template.Delete)] + public async virtual Task DeleteAsync(Guid id) + { + bool success; + try + { + var template = await _templateRepository.GetAsync(id); + + await _templateRepository.DeleteAsync(template); + + success = true; + } + catch (Exception ex) + { + Logger.LogWarning(ex, "Delete template: {id} failed: {message}!", id, ex.Message); + success = false; + } + + return new TemplateDeleteDto + { + Success = success, + }; + } + + public async virtual Task GetAsync(Guid id) + { + var template = await _templateRepository.GetAsync(id); + + var templateDto = ObjectMapper.Map(template); + + await SetTemplatePermissions(templateDto); + + return templateDto; + } + + public async virtual Task GetByNameAsync(string name) + { + var template = await _templateRepository.FindByNameAsync(name, includeDetails: true) + ?? throw new BusinessException(PrintDesignerErrorCodes.Template.NameNotFound) + .WithData("Name", name); + + var templateDto = ObjectMapper.Map(template); + + await SetTemplatePermissions(templateDto); + + return templateDto; + } + + public async virtual Task> GetAllAsync() + { + var templates = await _templateRepository.GetListAsync(); + + var templateDtos = ObjectMapper.Map, List>(templates); + + await SetTemplatesPermissions(templateDtos); + + return new ListResultDto(templateDtos); + } + + public async virtual Task> GetListAsync(TemplateGetPagedListInput input) + { + var specification = new TemplateGetPagedListSpecification(input); + + var totalCount = await _templateRepository.GetCountAsync(specification); + var templates = await _templateRepository.GetListAsync(specification, + input.Sorting, input.MaxResultCount, input.SkipCount); + + var templateDtos = ObjectMapper.Map, List>(templates); + + await SetTemplatesPermissions(templateDtos); + + return new PagedResultDto(totalCount, templateDtos); + } + + [Authorize(PrintDesignerPermissions.Template.Update)] + public async virtual Task UpdateAsync(Guid id, TemplateUpdateDto input) + { + var template = await _templateRepository.GetAsync(id); + if (!string.Equals(template.Name, input.Name, StringComparison.CurrentCultureIgnoreCase)) + { + if (await _templateRepository.FindByNameAsync(input.Name) != null) + { + throw new BusinessException( + PrintDesignerErrorCodes.Template.NameAlreadyExists, + $"A template definition named {input.Name} already exists.!") + .WithData("Name", input.Name); + } + template.SetName(input.Name); + } + var elementData = _jsonSerializer.Serialize(input.Data); + var extendedData = _jsonSerializer.Serialize(input.Ext); + template.SetData(elementData, extendedData); + template.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); + + template = await _templateRepository.UpdateAsync(template); + + await CurrentUnitOfWork!.SaveChangesAsync(); + + var templateDto = ObjectMapper.Map(template); + + await SetTemplatePermissions(templateDto); + + return templateDto; + } + + public async virtual Task UpsertAsync(TemplateUpsertDto input) + { + if (input.Id.HasValue && + await _templateRepository.FindAsync(input.Id.Value) != null) + { + await AuthorizationService.CheckAsync(PrintDesignerPermissions.Template.Update); + + return await UpdateAsync( + input.Id.Value, + new TemplateUpdateDto + { + Name = input.Name, + Data = input.Data, + Ext = input.Ext, + Description = input.Description, + ConcurrencyStamp = input.ConcurrencyStamp, + }); + } + else + { + await AuthorizationService.CheckAsync(PrintDesignerPermissions.Template.Create); + + return await CreateAsync( + new TemplateCreateDto + { + Name = input.Name, + Data = input.Data, + Ext = input.Ext, + Description = input.Description, + }); + } + } + + protected async virtual Task SetTemplatePermissions(TemplateDto templateDto) + { + templateDto.Permissions ??= new TemplatePermissionDto(); + templateDto.Permissions.Editable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Update); + templateDto.Permissions.Deletable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Delete); + templateDto.Permissions.Copyable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Copy); + } + + protected async virtual Task SetTemplatesPermissions(List templateDtos) + { + var editable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Update); + var deletable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Delete); + var copyable = await AuthorizationService.IsGrantedAsync(PrintDesignerPermissions.Template.Copy); + + foreach (var templateDto in templateDtos) + { + templateDto.Permissions ??= new TemplatePermissionDto(); + templateDto.Permissions.Editable = editable; + templateDto.Permissions.Deletable = deletable; + templateDto.Permissions.Copyable = copyable; + } + } +} diff --git a/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateGetPagedListSpecification.cs b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateGetPagedListSpecification.cs new file mode 100644 index 000000000..d9605a528 --- /dev/null +++ b/aspnet-core/modules/print-designer/LINGYUN.Abp.PrintDesigner.Application/LINGYUN/Abp/PrintDesigner/Templates/TemplateGetPagedListSpecification.cs @@ -0,0 +1,24 @@ +using LINGYUN.Abp.PrintDesigner.Templates.Dtos; +using System; +using System.Linq.Expressions; +using Volo.Abp.Specifications; + +namespace LINGYUN.Abp.PrintDesigner.Templates; + +public class TemplateGetPagedListSpecification : Specification