添加代码生成模块
This commit is contained in:
@@ -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