添加代码生成模块
This commit is contained in:
@@ -5,23 +5,23 @@ VisualStudioVersion = 17.4.33103.184
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{EEF5F221-0E32-4A3D-B647-B4B5E7305806}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{32A813F5-13B2-4DCA-8B59-F27F1B0D5678}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{32A813F5-13B2-4DCA-8B59-F27F1B0D5678}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "framework", "framework", "{5F2B846D-96CE-400A-878E-220498F4EE31}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Core", "src\framework\Yi.Framework.Core\Yi.Framework.Core.csproj", "{83B2D7AD-ED8E-4392-B0AE-4227498CD75F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Application", "test\Yi.Framework.Application\Yi.Framework.Application.csproj", "{456835D1-4968-4195-9993-B2A580E85056}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Application", "src\project\Yi.Framework.Application\Yi.Framework.Application.csproj", "{456835D1-4968-4195-9993-B2A580E85056}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Application.Contracts", "test\Yi.Framework.Application.Contracts\Yi.Framework.Application.Contracts.csproj", "{D2378C23-2CFE-468A-924A-B8C9D4A3A8ED}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Application.Contracts", "src\project\Yi.Framework.Application.Contracts\Yi.Framework.Application.Contracts.csproj", "{D2378C23-2CFE-468A-924A-B8C9D4A3A8ED}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Domain", "test\Yi.Framework.Domain\Yi.Framework.Domain.csproj", "{C02A954D-CCCB-41BD-ADAD-9D7ECBF1A828}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Domain", "src\project\Yi.Framework.Domain\Yi.Framework.Domain.csproj", "{C02A954D-CCCB-41BD-ADAD-9D7ECBF1A828}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Domain.Shared", "test\Yi.Framework.Domain.Shared\Yi.Framework.Domain.Shared.csproj", "{26171153-1784-455B-9582-0558AEEC03CF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Domain.Shared", "src\project\Yi.Framework.Domain.Shared\Yi.Framework.Domain.Shared.csproj", "{26171153-1784-455B-9582-0558AEEC03CF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Sqlsugar", "test\Yi.Framework.Sqlsugar\Yi.Framework.Sqlsugar.csproj", "{3C3A7BAC-F27F-433E-BF91-289FA42E4995}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Sqlsugar", "src\project\Yi.Framework.Sqlsugar\Yi.Framework.Sqlsugar.csproj", "{3C3A7BAC-F27F-433E-BF91-289FA42E4995}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Web", "test\Yi.Framework.Web\Yi.Framework.Web.csproj", "{01CC7B62-F42C-45CE-BACA-F450593A1AF2}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Web", "src\project\Yi.Framework.Web\Yi.Framework.Web.csproj", "{01CC7B62-F42C-45CE-BACA-F450593A1AF2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.BackgroundJobs.Quartz", "src\module\Yi.Framework.BackgroundJobs.Quartz\Yi.Framework.BackgroundJobs.Quartz.csproj", "{1879A863-9864-4E16-8492-504055807684}"
|
||||
EndProject
|
||||
@@ -51,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Data", "src\fr
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Auth.JwtBearer", "src\framework\Yi.Framework.Auth.JwtBearer\Yi.Framework.Auth.JwtBearer.csproj", "{D40C583D-58BE-422D-9A57-94DECB751EB4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Template", "src\module\Yi.Framework.Template\Yi.Framework.Template.csproj", "{134C4AB9-2AFE-4383-84DE-825DF9499CB4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -141,6 +143,10 @@ Global
|
||||
{D40C583D-58BE-422D-9A57-94DECB751EB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D40C583D-58BE-422D-9A57-94DECB751EB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D40C583D-58BE-422D-9A57-94DECB751EB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{134C4AB9-2AFE-4383-84DE-825DF9499CB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{134C4AB9-2AFE-4383-84DE-825DF9499CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{134C4AB9-2AFE-4383-84DE-825DF9499CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{134C4AB9-2AFE-4383-84DE-825DF9499CB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -167,6 +173,7 @@ Global
|
||||
{588D0DA9-303A-4FF0-A2D1-83037E2B269F} = {EEF5F221-0E32-4A3D-B647-B4B5E7305806}
|
||||
{DEE07142-32CE-4B5F-A5A3-452064EBF4A2} = {5F2B846D-96CE-400A-878E-220498F4EE31}
|
||||
{D40C583D-58BE-422D-9A57-94DECB751EB4} = {5F2B846D-96CE-400A-878E-220498F4EE31}
|
||||
{134C4AB9-2AFE-4383-84DE-825DF9499CB4} = {EEF5F221-0E32-4A3D-B647-B4B5E7305806}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6C1A3808-0F4F-43FB-A9FE-5F27A3BB2ECF}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Template.Abstracts
|
||||
{
|
||||
public abstract class AbstractTemplateProvider : ITemplateProvider
|
||||
{
|
||||
public virtual string? BuildPath { get; set; }
|
||||
public string? TemplatePath { get; set; }
|
||||
public string? BakPath { get; set; }
|
||||
protected Dictionary<string, string> TemplateDic { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
public abstract void Bak();
|
||||
|
||||
public abstract void Build();
|
||||
|
||||
|
||||
protected virtual string GetTemplateData()
|
||||
{
|
||||
if (TemplatePath is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(TemplatePath));
|
||||
}
|
||||
return File.ReadAllText(TemplatePath);
|
||||
}
|
||||
|
||||
protected void AddTemplateDic(string oldStr, string newStr)
|
||||
{
|
||||
|
||||
TemplateDic.Add(oldStr, newStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Template.Abstracts
|
||||
{
|
||||
public interface ITemplateProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建生成路径
|
||||
/// </summary>
|
||||
string? BuildPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板文件路径
|
||||
/// </summary>
|
||||
string? TemplatePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备份文件路径
|
||||
/// </summary>
|
||||
string? BakPath { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开始构建
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
void Build();
|
||||
|
||||
/// <summary>
|
||||
/// 生成备份
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
void Bak();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Abstracts
|
||||
{
|
||||
public abstract class ModelTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
|
||||
public ModelTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
AddIgnoreEntityField("Id", "TenantId");
|
||||
}
|
||||
|
||||
private string entityPath=string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 实体路径,该类生成需要实体与模板两个同时构建成
|
||||
/// </summary>
|
||||
public string EntityPath
|
||||
{
|
||||
get => this.entityPath;
|
||||
set
|
||||
{
|
||||
value = value!.Replace(TemplateConst.EntityName, EntityName);
|
||||
value = value.Replace(TemplateConst.ModelName, ModelName);
|
||||
this.entityPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成模板忽略实体字段
|
||||
/// </summary>
|
||||
private List<string> IgnoreEntityFields { get; set; } = new();
|
||||
|
||||
public override void Build()
|
||||
{
|
||||
if (BuildPath is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(BuildPath));
|
||||
}
|
||||
//模板信息
|
||||
var templateData = GetTemplateData();
|
||||
|
||||
//实体信息
|
||||
var enetityDatas = GetEntityData().ToList();
|
||||
|
||||
//获取全部属性字段
|
||||
for (var i = enetityDatas.Count() - 1; i >= 0; i--)
|
||||
{
|
||||
//不是字段属性直接删除跳过
|
||||
if (!enetityDatas[i].Contains("{ get; set; }"))
|
||||
{
|
||||
enetityDatas.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
//是字段属性,同时还包含忽略字段
|
||||
foreach (var IgnoreEntityField in IgnoreEntityFields)
|
||||
{
|
||||
if (enetityDatas[i].Contains(IgnoreEntityField))
|
||||
{
|
||||
enetityDatas.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//以}结尾,不包含get不是属性,代表类结尾
|
||||
if (enetityDatas[i].EndsWith("}") && !enetityDatas[i].Contains("get"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//拼接实体字段
|
||||
var entityFieldsbuild = string.Join("\r\n", enetityDatas);
|
||||
|
||||
|
||||
//模板替换属性字段
|
||||
templateData = templateData.Replace(TemplateConst.EntityField, entityFieldsbuild);
|
||||
|
||||
templateData = base.ReplaceTemplateDic(templateData);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(BuildPath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(BuildPath)!);
|
||||
}
|
||||
File.WriteAllText(BuildPath, templateData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public virtual string[] GetEntityData()
|
||||
{
|
||||
if (TemplatePath is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(entityPath));
|
||||
}
|
||||
if (!File.Exists(entityPath))
|
||||
{
|
||||
throw new FileNotFoundException($"请检查路径:{entityPath}\r\n未包含实体:{EntityName}");
|
||||
}
|
||||
|
||||
return File.ReadAllLines(entityPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加忽略实体字段
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
public void AddIgnoreEntityField(params string[] field)
|
||||
{
|
||||
IgnoreEntityFields.AddRange(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Abstracts
|
||||
{
|
||||
|
||||
public abstract class ProgramTemplateProvider : AbstractTemplateProvider
|
||||
{
|
||||
public ProgramTemplateProvider(string modelName, string entityName)
|
||||
{
|
||||
ModelName = modelName;
|
||||
EntityName = entityName;
|
||||
base.AddTemplateDic(TemplateConst.EntityName, EntityName);
|
||||
base.AddTemplateDic(TemplateConst.ModelName, ModelName);
|
||||
base.AddTemplateDic(TemplateConst.LowerEntityName, EntityName.Substring(0, 1).ToLower() + EntityName.Substring(1));
|
||||
base.AddTemplateDic(TemplateConst.LowerModelName, ModelName.ToLower());
|
||||
}
|
||||
/// <summary>
|
||||
/// 实体名称
|
||||
/// </summary>
|
||||
public string EntityName { get; set; }
|
||||
/// <summary>
|
||||
/// 模块名称
|
||||
/// </summary>
|
||||
public string ModelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 重写构建路径,替换实体名称与模块名称
|
||||
/// </summary>
|
||||
public override string? BuildPath
|
||||
{
|
||||
get => base.BuildPath;
|
||||
set
|
||||
{
|
||||
value = ReplaceTemplateDic(value!);
|
||||
|
||||
base.BuildPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ReplaceTemplateDic(string str)
|
||||
{
|
||||
foreach (var ky in TemplateDic)
|
||||
{
|
||||
str = str.Replace(ky.Key, ky.Value);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
public override void Build()
|
||||
{
|
||||
if (BuildPath is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(BuildPath));
|
||||
}
|
||||
var templateData = GetTemplateData();
|
||||
templateData = ReplaceTemplateDic(templateData);
|
||||
if (!Directory.Exists(Path.GetDirectoryName(BuildPath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(BuildPath)!);
|
||||
}
|
||||
File.WriteAllText(BuildPath, templateData);
|
||||
}
|
||||
|
||||
public override void Bak()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Template.ConstClasses
|
||||
{
|
||||
public class TemplateConst
|
||||
{
|
||||
/// <summary>
|
||||
/// 模块名称大写
|
||||
/// </summary>
|
||||
public const string ModelName = "#ModelName#";
|
||||
|
||||
/// <summary>
|
||||
/// 模块名称小写
|
||||
/// </summary>
|
||||
public const string LowerModelName = "#LowerModelName#";
|
||||
|
||||
/// <summary>
|
||||
/// 实体名称大驼峰
|
||||
/// </summary>
|
||||
public const string EntityName = "#EntityName#";
|
||||
|
||||
/// <summary>
|
||||
/// 实体名称小驼峰
|
||||
/// </summary>
|
||||
public const string LowerEntityName = "#LowerEntityName#";
|
||||
|
||||
/// <summary>
|
||||
/// 实体字段
|
||||
/// </summary>
|
||||
public const string EntityField = "#EntityField#";
|
||||
|
||||
public const string BuildRootPath = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Yi.Framework.Template;
|
||||
using Yi.Framework.Template.Provider.Server;
|
||||
using Yi.Framework.Template.Provider.Site;
|
||||
|
||||
TemplateFactory templateFactory = new();
|
||||
|
||||
//选择需要生成的模板提供者
|
||||
|
||||
string modelName = "";
|
||||
List<string> entityNames = new() { "_" };
|
||||
|
||||
foreach (var entityName in entityNames)
|
||||
{
|
||||
templateFactory.CreateTemplateProviders((option) =>
|
||||
{
|
||||
option.Add(new ServiceTemplateProvider(modelName, entityName));
|
||||
option.Add(new IServiceTemplateProvider(modelName, entityName));
|
||||
|
||||
|
||||
option.Add(new CreateInputVoTemplateProvider(modelName, entityName));
|
||||
option.Add(new UpdateInputVoTemplateProvider(modelName, entityName));
|
||||
option.Add(new GetListInputVoTemplateProvider(modelName, entityName));
|
||||
option.Add(new GetListOutputDtoTemplateProvider(modelName, entityName));
|
||||
|
||||
option.Add(new ConstTemplateProvider(modelName, entityName));
|
||||
option.Add(new ProfileTemplateProvider(modelName, entityName));
|
||||
|
||||
|
||||
option.Add(new ApiTemplateProvider(modelName, entityName));
|
||||
});
|
||||
//开始构建模板
|
||||
templateFactory.BuildTemplate();
|
||||
Console.WriteLine($"Yi.Framework.Template:{entityName}构建完成!");
|
||||
}
|
||||
|
||||
Console.WriteLine("Yi.Framework.Template:模板全部生成完成!");
|
||||
Console.ReadKey();
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
internal class ConstTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
public ConstTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\ConstConfig\{TemplateConst.EntityName}Const.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\ConstTemplate.txt";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class CreateInputVoTemplateProvider : ModelTemplateProvider
|
||||
{
|
||||
public CreateInputVoTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}CreateInput.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\CreateInputTemplate.txt";
|
||||
EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class GetListInputTemplateProvider : ModelTemplateProvider
|
||||
{
|
||||
public GetListInputTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}GetListInput.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\GetListInputTemplate.txt";
|
||||
EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class GetListOutputTemplateProvider : ModelTemplateProvider
|
||||
{
|
||||
public GetListOutputTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}GetListOutput.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\GetListOutputTemplate.txt";
|
||||
EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class GetOutputDtoTemplateProvider : ModelTemplateProvider
|
||||
{
|
||||
public GetOutputDtoTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}GetOutputDto.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\GetOutputDtoTemplate.txt";
|
||||
EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class IServiceTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
public IServiceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.Interface\{TemplateConst.ModelName}\I{TemplateConst.EntityName}Service.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\IServiceTemplate.txt";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class ProfileTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
public ProfileTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\MapperConfig\{TemplateConst.EntityName}Profile.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\ProfileTemplate.txt";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class ServiceTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
public ServiceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.Service\{TemplateConst.ModelName}\{TemplateConst.EntityName}Service.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\ServiceTemplate.txt";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Server
|
||||
{
|
||||
public class UpdateInputVoTemplateProvider : ModelTemplateProvider
|
||||
{
|
||||
public UpdateInputVoTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}UpdateInputVo.cs";
|
||||
TemplatePath = $@"..\..\..\Template\Server\UpdateInputVoTemplate.txt";
|
||||
EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.ConstClasses;
|
||||
|
||||
namespace Yi.Framework.Template.Provider.Site
|
||||
{
|
||||
public class ApiTemplateProvider : ProgramTemplateProvider
|
||||
{
|
||||
public ApiTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||
{
|
||||
BuildPath = $@"..\..\..\Code_Site\src\api\{TemplateConst.LowerModelName}\{TemplateConst.LowerEntityName}Api.js";
|
||||
TemplatePath = $@"..\..\..\Template\Site\ApiTemplate.txt";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#.ConstConfig
|
||||
{
|
||||
public class #EntityName#Const
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
|
||||
{
|
||||
public class #EntityName#CreateUpdateInput : EntityDto<long>
|
||||
{
|
||||
#EntityField#
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
|
||||
{
|
||||
public class #EntityName#GetListInput
|
||||
{
|
||||
#EntityField#
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
|
||||
{
|
||||
public class #EntityName#GetListOutput: EntityDto<long>
|
||||
{
|
||||
#EntityField#
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
|
||||
{
|
||||
public class #EntityName#GetListOutput: EntityDto<long>
|
||||
{
|
||||
#EntityField#
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DtoModel.#ModelName#.#EntityName#;
|
||||
using Yi.Framework.Interface.Base.Crud;
|
||||
|
||||
namespace Yi.Framework.Interface.#ModelName#
|
||||
{
|
||||
public interface I#EntityName#Service : ICrudAppService<#EntityName#GetListOutput, long, #EntityName#CreateUpdateInput>
|
||||
{
|
||||
Task<PageModel<List<#EntityName#GetListOutput>>> PageListAsync(#EntityName#GetListInput input, PageParModel page);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.#ModelName#.Entitys;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#.MapperConfig
|
||||
{
|
||||
public class Suppli#ModelName#rofile:Profile
|
||||
{
|
||||
public Suppli#ModelName#rofile()
|
||||
{
|
||||
CreateMap<#EntityName#CreateUpdateInput, #EntityName#Entity>();
|
||||
CreateMap<#EntityName#Entity, #EntityName#GetListOutput>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using AutoMapper;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DtoModel.#ModelName#.#EntityName#;
|
||||
using Yi.Framework.Interface.#ModelName#;
|
||||
using Yi.Framework.Model.#ModelName#.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service.Base.Crud;
|
||||
|
||||
namespace Yi.Framework.Service.#ModelName#
|
||||
{
|
||||
public class #EntityName#Service : CrudAppService<#EntityName#Entity, #EntityName#GetListOutput, long, #EntityName#CreateUpdateInput>, I#EntityName#Service
|
||||
{
|
||||
public async Task<PageModel<List<#EntityName#GetListOutput>>> PageListAsync(#EntityName#GetListInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var data = await Repository._DbQueryable
|
||||
.WhereIF(input.Code is not null,u=>u.Code.Contains(input.Code))
|
||||
.WhereIF(input.Name is not null, u => u.Name.Contains(input.Name))
|
||||
.ToPageListAsync(page.PageNum, page.PageSize, totalNumber);
|
||||
return new PageModel<List<#EntityName#GetListOutput>> { Total = totalNumber.Value, Data = await MapToGetListOutputDtosAsync(data) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
|
||||
{
|
||||
public class #EntityName#CreateUpdateInput : EntityDto<long>
|
||||
{
|
||||
#EntityField#
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 分页查询
|
||||
export function listData(query) {
|
||||
return request({
|
||||
url: '/#LowerEntityName#/pageList',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// id查询
|
||||
export function getData(code) {
|
||||
return request({
|
||||
url: '/#LowerEntityName#/getById/' + code,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增
|
||||
export function addData(data) {
|
||||
return request({
|
||||
url: '/#LowerEntityName#/create',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改
|
||||
export function updateData(id,data) {
|
||||
return request({
|
||||
url: `/#LowerEntityName#/update/${id}`,
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除
|
||||
export function delData(code) {
|
||||
return request({
|
||||
url: '/#LowerEntityName#/del',
|
||||
method: 'delete',
|
||||
data:"string"==typeof(code)?[code]:code
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Template.Abstracts;
|
||||
using Yi.Framework.Template.Provider;
|
||||
|
||||
namespace Yi.Framework.Template
|
||||
{
|
||||
public class TemplateFactory
|
||||
{
|
||||
private List<ITemplateProvider> _templateProviders=new List<ITemplateProvider>();
|
||||
|
||||
public void CreateTemplateProviders(Action<List<ITemplateProvider>> action)
|
||||
{
|
||||
action(_templateProviders);
|
||||
}
|
||||
|
||||
public void BuildTemplate()
|
||||
{
|
||||
foreach (var provider in _templateProviders)
|
||||
{
|
||||
provider.Build();
|
||||
}
|
||||
}
|
||||
|
||||
public void BakTemplate()
|
||||
{
|
||||
foreach (var provider in _templateProviders)
|
||||
{
|
||||
provider.Bak();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Template\Server\ConstTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\ControllerTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\CreateUpdateInputTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\GetListInputTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\GetListOutputTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\IServiceTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\ProfileTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Server\ServiceTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Site\ApiTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user