Files
Yi.Admin/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application/TemplateGenService.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2024-06-02 13:09:25 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;
using Microsoft.AspNetCore.Mvc;
2024-06-02 13:27:41 +08:00
using Volo.Abp.Application.Services;
2024-06-02 13:09:25 +08:00
using Volo.Abp.DependencyInjection;
using Yi.Abp.Tool.Application.Contracts;
using Yi.Abp.Tool.Application.Contracts.Dtos;
using Yi.Abp.Tool.Domain;
using Yi.Abp.Tool.Domain.Shared.Dtos;
using Yi.Framework.Core.Helper;
namespace Yi.Abp.Tool.Application
{
2024-11-07 17:35:22 +08:00
public class TemplateGenService : ApplicationService, ITemplateGenService
2024-06-02 13:09:25 +08:00
{
private readonly TemplateGenManager _templateGenManager;
2024-11-07 17:35:22 +08:00
public TemplateGenService(TemplateGenManager templateGenManager)
{
_templateGenManager = templateGenManager;
}
2024-06-02 13:09:25 +08:00
/// <summary>
/// 下载模块文件
/// </summary>
/// <returns></returns>
2024-06-02 14:12:37 +08:00
public async Task<byte[]> CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto)
2024-06-02 13:09:25 +08:00
{
moduleCreateInputDto.SetNameReplace();
2024-11-07 17:35:22 +08:00
//模块类型,就是分支小写
2024-06-02 13:09:25 +08:00
var input = moduleCreateInputDto.Adapt<TemplateGenCreateDto>();
2024-11-07 17:35:22 +08:00
input.SetTemplateGiteeRef(moduleCreateInputDto.ModuleSoure);
2024-06-02 13:09:25 +08:00
var filePath = await _templateGenManager.CreateTemplateAsync(input);
2024-06-02 14:12:37 +08:00
////考虑从路径中获取
//var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath));
2024-06-02 13:09:25 +08:00
//设置附件下载,下载名称
2024-06-02 14:12:37 +08:00
return await File.ReadAllBytesAsync(filePath);
2024-06-02 13:09:25 +08:00
}
2024-11-07 17:35:22 +08:00
2024-06-02 13:09:25 +08:00
/// <summary>
2024-11-07 17:35:22 +08:00
/// 获取全部模板列表
2024-06-02 13:09:25 +08:00
/// </summary>
/// <returns></returns>
2024-11-07 17:35:22 +08:00
[HttpGet("template-gen/template")]
public async Task<List<string>> GetAllTemplatesAsync()
2024-06-02 13:09:25 +08:00
{
2024-11-07 17:35:22 +08:00
return await _templateGenManager.GetAllTemplatesAsync();
2024-06-02 13:09:25 +08:00
}
}
2024-11-07 17:35:22 +08:00
}