diff --git a/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/CreateGiveUpCheckTemplateDto.cs b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/CreateGiveUpCheckTemplateDto.cs new file mode 100644 index 00000000..cff60da6 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/CreateGiveUpCheckTemplateDto.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.GiveUpCheckTemplates +{ + public class CreateGiveUpCheckTemplateDto + { + /// + /// 模板名称 + /// + public string DisplayName { get; set; } + + + /// + /// 模板内容 + /// + public string InformedConsentTemplateFileContent { get; set; } + + /// + /// 是否启用 + /// + public char IsActive { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateDto.cs b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateDto.cs new file mode 100644 index 00000000..e29b8405 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateDto.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace Shentun.Peis.GiveUpCheckTemplates +{ + public class GiveUpCheckTemplateDto : AuditedEntityDtoName + { + /// + /// 模板名称 + /// + public string DisplayName { get; set; } + + + /// + /// 模板内容 + /// + public string GiveUpCheckTemplateFileFileContent { get; set; } + + /// + /// 是否启用 只能启用一个 + /// + public char IsActive { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateIdInputDto.cs new file mode 100644 index 00000000..43879f9d --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateIdInputDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.GiveUpCheckTemplates +{ + public class GiveUpCheckTemplateIdInputDto + { + /// + /// + /// + public Guid GiveUpCheckTemplateId { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/UpdateGiveUpCheckTemplateDto.cs b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/UpdateGiveUpCheckTemplateDto.cs new file mode 100644 index 00000000..f6d2e6ca --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/UpdateGiveUpCheckTemplateDto.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.GiveUpCheckTemplates +{ + public class UpdateGiveUpCheckTemplateDto + { + public Guid Id { get; set; } + + /// + /// 模板名称 + /// + public string DisplayName { get; set; } + + + /// + /// 模板内容 + /// + public string GiveUpCheckTemplateFileContent { get; set; } + + /// + /// 是否启用 + /// + public char IsActive { get; set; } + } +} diff --git a/src/Shentun.Peis.Application/GiveUpCheckTemplates/GiveUpCheckTemplateAppService.cs b/src/Shentun.Peis.Application/GiveUpCheckTemplates/GiveUpCheckTemplateAppService.cs new file mode 100644 index 00000000..bf63c4d5 --- /dev/null +++ b/src/Shentun.Peis.Application/GiveUpCheckTemplates/GiveUpCheckTemplateAppService.cs @@ -0,0 +1,206 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.Peis.InformedConsentTemplates; +using Shentun.Peis.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace Shentun.Peis.GiveUpCheckTemplates +{ + /// + /// 弃检模板 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class GiveUpCheckTemplateAppService : ApplicationService + { + private readonly IRepository _giveUpCheckTemplateRepository; + private readonly CacheService _cacheService; + + + public GiveUpCheckTemplateAppService( + IRepository giveUpCheckTemplateRepository, + CacheService cacheService + ) + { + _giveUpCheckTemplateRepository = giveUpCheckTemplateRepository; + _cacheService = cacheService; + } + + + /// + /// 获取通过主键 + /// + /// + /// + [HttpPost("api/app/GiveUpCheckTemplate/Get")] + public async Task GetAsync(GiveUpCheckTemplateIdInputDto input) + { + //模板存储html文件 + + var giveUpCheckTemplateEnt = await _giveUpCheckTemplateRepository.GetAsync(input.GiveUpCheckTemplateId); + + string giveUpCheckTemplateFileContent = ""; + if (!string.IsNullOrWhiteSpace(giveUpCheckTemplateEnt.GiveUpCheckTemplateFile)) + { + + string fileName = giveUpCheckTemplateEnt.GiveUpCheckTemplateFile.TrimStart('/'); // 去除开头的 / + // fileName: SignatureTemplate/3a209c4d-cad9-ad05-62af-c7824067d8f7.html + + string physicalPath = Path.Combine(Directory.GetCurrentDirectory(), fileName); + + + + + if (File.Exists(physicalPath)) + { + giveUpCheckTemplateFileContent = await File.ReadAllTextAsync(physicalPath, Encoding.UTF8); + } + + + } + var entDto = new GiveUpCheckTemplateDto + { + CreationTime = giveUpCheckTemplateEnt.CreationTime, + CreatorId = giveUpCheckTemplateEnt.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(giveUpCheckTemplateEnt.CreatorId).GetAwaiter().GetResult(), + DisplayName = giveUpCheckTemplateEnt.DisplayName, + Id = giveUpCheckTemplateEnt.Id, + GiveUpCheckTemplateFileFileContent = giveUpCheckTemplateFileContent, + IsActive = giveUpCheckTemplateEnt.IsActive, + LastModificationTime = giveUpCheckTemplateEnt.LastModificationTime, + LastModifierId = giveUpCheckTemplateEnt.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(giveUpCheckTemplateEnt.LastModifierId).GetAwaiter().GetResult() + }; + return entDto; + } + + + /// + /// 获取列表 + /// + /// + [HttpPost("api/app/GiveUpCheckTemplate/GetList")] + public async Task> GetListAsync() + { + var entListDto = (await _giveUpCheckTemplateRepository.GetListAsync()).Select(s => new GiveUpCheckTemplateDto + { + CreationTime = s.CreationTime, + CreatorId = s.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).GetAwaiter().GetResult(), + DisplayName = s.DisplayName, + Id = s.Id, + GiveUpCheckTemplateFileFileContent = "", + IsActive = s.IsActive, + LastModificationTime = s.LastModificationTime, + LastModifierId = s.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).GetAwaiter().GetResult() + }).ToList(); + + return entListDto; + } + + /// + /// 创建 + /// + /// + /// + [HttpPost("api/app/GiveUpCheckTemplate/Create")] + public async Task CreateAsync(CreateGiveUpCheckTemplateDto input) + { + Guid giveUpCheckTemplateId = GuidGenerator.Create(); + + // 4. 完整的文件路径 + string fullFilePath = System.IO.Path.Combine("SignatureTemplate", $"{giveUpCheckTemplateId.ToString()}.html"); + // 5. 写入HTML内容到文件 + await File.WriteAllTextAsync(fullFilePath, input.InformedConsentTemplateFileContent, System.Text.Encoding.UTF8); + + var giveUpCheckTemplateEntity = new GiveUpCheckTemplate(giveUpCheckTemplateId) + { + DisplayName = input.DisplayName, + GiveUpCheckTemplateFile = $"/SignatureTemplate/{giveUpCheckTemplateId.ToString()}.html", + IsActive = input.IsActive + }; + + if (input.IsActive == 'Y') + { + var upList = await _giveUpCheckTemplateRepository.GetListAsync(); + foreach (var item in upList) + { + item.IsActive = 'N'; + } + await _giveUpCheckTemplateRepository.UpdateManyAsync(upList, true); + } + + await _giveUpCheckTemplateRepository.InsertAsync(giveUpCheckTemplateEntity, true); + + var entDto = await GetAsync(new GiveUpCheckTemplateIdInputDto { GiveUpCheckTemplateId = giveUpCheckTemplateId }); + + return entDto; + + + } + + /// + /// 更新 + /// + /// + /// + [HttpPost("api/app/GiveUpCheckTemplate/Update")] + public async Task UpdateAsync(UpdateGiveUpCheckTemplateDto input) + { + var giveUpCheckTemplateEntity = await _giveUpCheckTemplateRepository.FirstOrDefaultAsync(f => f.Id == input.Id); + if (giveUpCheckTemplateEntity == null) + { + throw new UserFriendlyException("数据不存在"); + } + + giveUpCheckTemplateEntity.DisplayName = input.DisplayName; + + // 4. 完整的文件路径 + string fullFilePath = Path.Combine("SignatureTemplate", $"{giveUpCheckTemplateEntity.Id.ToString()}.html"); + // 5. 写入HTML内容到文件 + await File.WriteAllTextAsync(fullFilePath, input.GiveUpCheckTemplateFileContent, System.Text.Encoding.UTF8); + + + giveUpCheckTemplateEntity.GiveUpCheckTemplateFile = $"/SignatureTemplate/{giveUpCheckTemplateEntity.Id.ToString()}.html"; + + if (input.IsActive == 'Y') + { + var upList = await _giveUpCheckTemplateRepository.GetListAsync(m => m.Id != input.Id); + foreach (var item in upList) + { + item.IsActive = 'N'; + } + await _giveUpCheckTemplateRepository.UpdateManyAsync(upList, true); + } + + await _giveUpCheckTemplateRepository.UpdateAsync(giveUpCheckTemplateEntity, true); + + var entDto = await GetAsync(new GiveUpCheckTemplateIdInputDto { GiveUpCheckTemplateId = input.Id }); + + return entDto; + } + + + /// + /// 删除 + /// + /// + /// + [HttpPost("api/app/GiveUpCheckTemplate/Delete")] + public async Task DeleteAsync(GiveUpCheckTemplateIdInputDto input) + { + await _giveUpCheckTemplateRepository.DeleteAsync(input.GiveUpCheckTemplateId); + } + + + } +} diff --git a/src/Shentun.Peis.Domain/GiveUpCheckTemplates/GiveUpCheckTemplate.cs b/src/Shentun.Peis.Domain/GiveUpCheckTemplates/GiveUpCheckTemplate.cs index cc99c3cb..1de88f77 100644 --- a/src/Shentun.Peis.Domain/GiveUpCheckTemplates/GiveUpCheckTemplate.cs +++ b/src/Shentun.Peis.Domain/GiveUpCheckTemplates/GiveUpCheckTemplate.cs @@ -34,9 +34,9 @@ namespace Shentun.Peis.Models /// /// 模板路径 /// - [Column("informed_consent_template_file")] + [Column("give_up_check_template_file")] [StringLength(200)] - public string InformedConsentTemplateFile { get; set; } + public string GiveUpCheckTemplateFile { get; set; } ///