Files
Yi.Admin/Yi.Furion.Net6/Yi.Framework.Module/WebFirstManager/Impl/WebFirstService.cs

110 lines
3.4 KiB
C#
Raw Normal View History

2023-06-10 13:53:00 +08:00
using System;
using System.Collections.Generic;
2023-09-27 18:01:10 +08:00
using System.Diagnostics;
2023-06-10 13:53:00 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-09-24 00:42:09 +08:00
using Furion.DatabaseAccessor;
2023-09-19 23:48:37 +08:00
using Furion.DependencyInjection;
using Furion.DynamicApiController;
2023-06-10 13:53:00 +08:00
using Mapster;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
2023-09-19 23:48:37 +08:00
using Microsoft.AspNetCore.Mvc;
2023-06-10 13:53:00 +08:00
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Ddd.Services;
2023-09-21 19:55:55 +08:00
using Yi.Framework.Module.WebFirstManager.Domain;
2023-09-19 23:48:37 +08:00
using Yi.Framework.Module.WebFirstManager.Dtos.WebFirst;
2023-06-10 13:53:00 +08:00
using Yi.Framework.Module.WebFirstManager.Entities;
namespace Yi.Framework.Module.WebFirstManager.Impl
{
2023-10-05 15:26:33 +08:00
/// <summary>
/// WebFirst
/// </summary>
2023-09-19 23:48:37 +08:00
[ApiDescriptionSettings("WebFirstManager")]
2023-09-21 00:04:55 +08:00
public class WebFirstService : ApplicationService, IWebFirstService, IDynamicApiController, ITransient
2023-06-10 13:53:00 +08:00
{
2023-09-24 00:42:09 +08:00
private IRepository<TableAggregateRoot> _tableRepository;
private CodeFileManager _codeFileManager;
private WebTemplateManager _webTemplateManager;
public WebFirstService(IRepository<TableAggregateRoot> tableRepository, CodeFileManager codeFileManager, WebTemplateManager webTemplateManager)
2023-09-21 00:04:55 +08:00
{
2023-09-21 19:55:55 +08:00
_tableRepository = tableRepository;
2023-09-24 00:42:09 +08:00
_codeFileManager = codeFileManager;
2023-09-27 18:01:10 +08:00
_webTemplateManager = webTemplateManager;
2023-09-21 00:04:55 +08:00
}
2023-06-10 13:53:00 +08:00
2023-10-05 15:54:42 +08:00
/// <summary>
/// 测试
/// </summary>
/// <returns></returns>
2023-10-05 16:23:43 +08:00
public async Task<string> GetTest2()
2023-10-05 15:54:42 +08:00
{
return "hello";
}
2023-06-10 13:53:00 +08:00
/// <summary>
2023-09-22 10:25:05 +08:00
/// Web To Code
2023-06-10 13:53:00 +08:00
/// </summary>
/// <returns></returns>
2023-09-27 18:01:10 +08:00
public async Task PostWebBuildCodeAsync(List<long> ids)
2023-06-10 13:53:00 +08:00
{
2023-09-21 19:55:55 +08:00
//获取全部表
2023-09-27 18:01:10 +08:00
var tables = await _tableRepository._DbQueryable.Where(x => ids.Contains(x.Id)).Includes(x => x.Fields).ToListAsync();
2023-09-21 19:55:55 +08:00
foreach (var table in tables)
{
2023-09-24 00:42:09 +08:00
await _codeFileManager.BuildWebToCodeAsync(table);
2023-09-21 19:55:55 +08:00
}
2023-06-10 13:53:00 +08:00
}
2023-09-21 19:55:55 +08:00
/// <summary>
2023-09-22 10:25:05 +08:00
/// Web To Db
2023-09-21 19:55:55 +08:00
/// </summary>
/// <returns></returns>
2023-09-22 10:25:05 +08:00
public async Task PostWebBuildDbAsync()
{
}
/// <summary>
/// Code To Web
/// </summary>
/// <returns></returns>
2023-09-24 00:42:09 +08:00
[UnitOfWork]
2023-09-22 10:25:05 +08:00
public async Task PostCodeBuildWebAsync()
{
2023-09-27 18:01:10 +08:00
var tableAggregateRoots = await _webTemplateManager.BuildCodeToWebAsync();
2023-09-24 00:42:09 +08:00
//覆盖数据库,将聚合根保存到数据库
_tableRepository._Db.DbMaintenance.TruncateTable<TableAggregateRoot>();
_tableRepository._Db.DbMaintenance.TruncateTable<FieldEntity>();
//导航插入即可
await _tableRepository._Db.InsertNav(tableAggregateRoots).Include(x => x.Fields).ExecuteCommandAsync();
2023-09-27 18:01:10 +08:00
2023-09-22 10:25:05 +08:00
}
/// <summary>
/// Code To Db
/// </summary>
/// <returns></returns>
public async Task PostCodeBuildDbAsync()
2023-09-21 00:04:55 +08:00
{
2023-09-21 19:55:55 +08:00
}
2023-09-27 18:01:10 +08:00
/// <summary>
/// 打开目录
/// </summary>
/// <returns></returns>
public async Task PostDir(string path)
{
path = Uri.UnescapeDataString(path);
//去除包含@的目录
path = string.Join("\\", path.Split("\\").Where(x => !x.Contains("@")).ToList());
Process.Start("explorer.exe", path);
}
2023-06-10 13:53:00 +08:00
}
}