6 changed files with 301 additions and 2 deletions
-
25src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/CreateGiveUpCheckTemplateDto.cs
-
27src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateDto.cs
-
14src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/GiveUpCheckTemplateIdInputDto.cs
-
27src/Shentun.Peis.Application.Contracts/GiveUpCheckTemplates/UpdateGiveUpCheckTemplateDto.cs
-
206src/Shentun.Peis.Application/GiveUpCheckTemplates/GiveUpCheckTemplateAppService.cs
-
4src/Shentun.Peis.Domain/GiveUpCheckTemplates/GiveUpCheckTemplate.cs
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.GiveUpCheckTemplates |
|||
{ |
|||
public class CreateGiveUpCheckTemplateDto |
|||
{ |
|||
/// <summary>
|
|||
/// 模板名称
|
|||
/// </summary>
|
|||
public string DisplayName { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 模板内容
|
|||
/// </summary>
|
|||
public string InformedConsentTemplateFileContent { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public char IsActive { get; set; } |
|||
} |
|||
} |
|||
@ -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 |
|||
{ |
|||
/// <summary>
|
|||
/// 模板名称
|
|||
/// </summary>
|
|||
public string DisplayName { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 模板内容
|
|||
/// </summary>
|
|||
public string GiveUpCheckTemplateFileFileContent { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用 只能启用一个
|
|||
/// </summary>
|
|||
public char IsActive { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.GiveUpCheckTemplates |
|||
{ |
|||
public class GiveUpCheckTemplateIdInputDto |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public Guid GiveUpCheckTemplateId { get; set; } |
|||
} |
|||
} |
|||
@ -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; } |
|||
|
|||
/// <summary>
|
|||
/// 模板名称
|
|||
/// </summary>
|
|||
public string DisplayName { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 模板内容
|
|||
/// </summary>
|
|||
public string GiveUpCheckTemplateFileContent { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public char IsActive { get; set; } |
|||
} |
|||
} |
|||
@ -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 |
|||
{ |
|||
/// <summary>
|
|||
/// 弃检模板
|
|||
/// </summary>
|
|||
[ApiExplorerSettings(GroupName = "Work")] |
|||
[Authorize] |
|||
public class GiveUpCheckTemplateAppService : ApplicationService |
|||
{ |
|||
private readonly IRepository<GiveUpCheckTemplate, Guid> _giveUpCheckTemplateRepository; |
|||
private readonly CacheService _cacheService; |
|||
|
|||
|
|||
public GiveUpCheckTemplateAppService( |
|||
IRepository<GiveUpCheckTemplate, Guid> giveUpCheckTemplateRepository, |
|||
CacheService cacheService |
|||
) |
|||
{ |
|||
_giveUpCheckTemplateRepository = giveUpCheckTemplateRepository; |
|||
_cacheService = cacheService; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取通过主键
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/GiveUpCheckTemplate/Get")] |
|||
public async Task<GiveUpCheckTemplateDto> 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; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取列表
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/GiveUpCheckTemplate/GetList")] |
|||
public async Task<List<GiveUpCheckTemplateDto>> 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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/GiveUpCheckTemplate/Create")] |
|||
public async Task<GiveUpCheckTemplateDto> 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; |
|||
|
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/GiveUpCheckTemplate/Update")] |
|||
public async Task<GiveUpCheckTemplateDto> 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; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 删除
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/GiveUpCheckTemplate/Delete")] |
|||
public async Task DeleteAsync(GiveUpCheckTemplateIdInputDto input) |
|||
{ |
|||
await _giveUpCheckTemplateRepository.DeleteAsync(input.GiveUpCheckTemplateId); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue