|
|
|
|
@ -388,17 +388,101 @@ namespace Haoliang.Core.Services
|
|
|
|
|
#region ========== 模板服务 ==========
|
|
|
|
|
public class TemplateService : ITemplateService
|
|
|
|
|
{
|
|
|
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetAllTemplatesAsync() => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
|
|
|
public Task<CNCBrandTemplate?> GetTemplateByIdAsync(int templateId) => Task.FromResult<CNCBrandTemplate?>(null);
|
|
|
|
|
public Task<CNCBrandTemplate> CreateTemplateAsync(CNCBrandTemplate template) => Task.FromResult(template);
|
|
|
|
|
public Task<CNCBrandTemplate?> UpdateTemplateAsync(int templateId, CNCBrandTemplate template) => Task.FromResult<CNCBrandTemplate?>(null);
|
|
|
|
|
public Task<bool> DeleteTemplateAsync(int templateId) => Task.FromResult(true);
|
|
|
|
|
public Task<bool> EnableTemplateAsync(int templateId) => Task.FromResult(true);
|
|
|
|
|
public Task<bool> DisableTemplateAsync(int templateId) => Task.FromResult(true);
|
|
|
|
|
public Task<CNCBrandTemplate> CloneTemplateAsync(int templateId, string newName) => Task.FromResult<CNCBrandTemplate>(null);
|
|
|
|
|
private readonly ITemplateRepository _templateRepository;
|
|
|
|
|
|
|
|
|
|
public TemplateService(ITemplateRepository templateRepository)
|
|
|
|
|
{
|
|
|
|
|
_templateRepository = templateRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<CNCBrandTemplate>> GetAllTemplatesAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _templateRepository.GetAllAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<CNCBrandTemplate?> GetTemplateByIdAsync(int templateId)
|
|
|
|
|
{
|
|
|
|
|
return await _templateRepository.GetByIdAsync(templateId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<CNCBrandTemplate> CreateTemplateAsync(CNCBrandTemplate template)
|
|
|
|
|
{
|
|
|
|
|
template.CreatedAt = DateTime.Now;
|
|
|
|
|
template.UpdatedAt = DateTime.Now;
|
|
|
|
|
template.IsEnabled = true;
|
|
|
|
|
await _templateRepository.AddAsync(template);
|
|
|
|
|
await _templateRepository.SaveAsync();
|
|
|
|
|
return template;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<CNCBrandTemplate?> UpdateTemplateAsync(int templateId, CNCBrandTemplate template)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _templateRepository.GetByIdAsync(templateId);
|
|
|
|
|
if (existing == null) return null;
|
|
|
|
|
|
|
|
|
|
existing.BrandName = template.BrandName;
|
|
|
|
|
existing.Description = template.Description;
|
|
|
|
|
existing.FieldMappings = template.FieldMappings;
|
|
|
|
|
existing.UpdatedAt = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
_templateRepository.Update(existing);
|
|
|
|
|
await _templateRepository.SaveAsync();
|
|
|
|
|
return existing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DeleteTemplateAsync(int templateId)
|
|
|
|
|
{
|
|
|
|
|
var template = await _templateRepository.GetByIdAsync(templateId);
|
|
|
|
|
if (template == null) return false;
|
|
|
|
|
|
|
|
|
|
_templateRepository.Remove(template);
|
|
|
|
|
return await _templateRepository.SaveAsync() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> EnableTemplateAsync(int templateId)
|
|
|
|
|
{
|
|
|
|
|
await _templateRepository.UpdateTemplateEnabledAsync(templateId, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DisableTemplateAsync(int templateId)
|
|
|
|
|
{
|
|
|
|
|
await _templateRepository.UpdateTemplateEnabledAsync(templateId, false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<CNCBrandTemplate> CloneTemplateAsync(int templateId, string newName)
|
|
|
|
|
{
|
|
|
|
|
var original = await _templateRepository.GetByIdAsync(templateId);
|
|
|
|
|
if (original == null) return null;
|
|
|
|
|
|
|
|
|
|
var cloned = new CNCBrandTemplate
|
|
|
|
|
{
|
|
|
|
|
BrandName = newName,
|
|
|
|
|
Description = original.Description + " (Cloned)",
|
|
|
|
|
FieldMappings = original.FieldMappings,
|
|
|
|
|
IsEnabled = false,
|
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
|
UpdatedAt = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _templateRepository.AddAsync(cloned);
|
|
|
|
|
await _templateRepository.SaveAsync();
|
|
|
|
|
return cloned;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task TestTemplateAsync(int templateId) => Task.CompletedTask;
|
|
|
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetTemplatesByBrandAsync(string brandName) => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
|
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetActiveTemplatesAsync() => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<CNCBrandTemplate>> GetTemplatesByBrandAsync(string brandName)
|
|
|
|
|
{
|
|
|
|
|
return await _templateRepository.FindAsync(t => t.BrandName == brandName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<CNCBrandTemplate>> GetActiveTemplatesAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _templateRepository.GetEnabledTemplatesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<bool> ValidateTemplateAsync(CNCBrandTemplate template) => Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|