添加各个木块代码生成
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using Brick.IFServer.Controllers;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.DtoModel.ERP.Supplier;
|
using Yi.Framework.DtoModel.ERP.Supplier;
|
||||||
using Yi.Framework.Interface.ERP;
|
using Yi.Framework.Interface.ERP;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.DtoModel.RABC.Student;
|
using Yi.Framework.DtoModel.RABC.Student;
|
||||||
using Yi.Framework.Interface.RABC;
|
using Yi.Framework.Interface.RABC;
|
||||||
|
|
||||||
namespace Brick.IFServer.Controllers
|
namespace Yi.Framework.ApiMicroservice.Controllers.ERP
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Abstract
|
||||||
|
{
|
||||||
|
public abstract class ModelTemplateProvider : ProgramTemplateProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
public ModelTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
AddIgnoreEntityField("Id", "TenantId");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string entityPath;
|
||||||
|
|
||||||
|
/// <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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//拼接实体字段
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ namespace Yi.Framework.Template.Abstract
|
|||||||
EntityName = entityName;
|
EntityName = entityName;
|
||||||
base.AddTemplateDic(TemplateConst.EntityName, EntityName);
|
base.AddTemplateDic(TemplateConst.EntityName, EntityName);
|
||||||
base.AddTemplateDic(TemplateConst.ModelName, ModelName);
|
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>
|
||||||
/// 实体名称
|
/// 实体名称
|
||||||
@@ -34,12 +36,22 @@ namespace Yi.Framework.Template.Abstract
|
|||||||
get => base.BuildPath;
|
get => base.BuildPath;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
value = value!.Replace(TemplateConst.EntityName, EntityName);
|
value = ReplaceTemplateDic(value!);
|
||||||
value = value.Replace(TemplateConst.ModelName, ModelName);
|
|
||||||
base.BuildPath = 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()
|
public override void Build()
|
||||||
{
|
{
|
||||||
if (BuildPath is null)
|
if (BuildPath is null)
|
||||||
@@ -47,12 +59,9 @@ namespace Yi.Framework.Template.Abstract
|
|||||||
throw new ArgumentNullException(nameof(BuildPath));
|
throw new ArgumentNullException(nameof(BuildPath));
|
||||||
}
|
}
|
||||||
var templateData = GetTemplateData();
|
var templateData = GetTemplateData();
|
||||||
foreach (var ky in TemplateDic)
|
templateData = ReplaceTemplateDic(templateData);
|
||||||
{
|
|
||||||
templateData = templateData.Replace(ky.Key, ky.Value);
|
|
||||||
}
|
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(BuildPath)))
|
if (!Directory.Exists(Path.GetDirectoryName(BuildPath)))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(BuildPath)!);
|
Directory.CreateDirectory(Path.GetDirectoryName(BuildPath)!);
|
||||||
}
|
}
|
||||||
File.WriteAllText(BuildPath, templateData);
|
File.WriteAllText(BuildPath, templateData);
|
||||||
|
|||||||
@@ -9,13 +9,28 @@ namespace Yi.Framework.Template.Const
|
|||||||
public class TemplateConst
|
public class TemplateConst
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模块名称
|
/// 模块名称大写
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string ModelName = "#ModelName#";
|
public const string ModelName = "#ModelName#";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体名称
|
/// 模块名称小写
|
||||||
|
/// </summary>
|
||||||
|
public const string LowerModelName = "#LowerModelName#";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体名称大驼峰
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string EntityName = "#EntityName#";
|
public const string EntityName = "#EntityName#";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体名称小驼峰
|
||||||
|
/// </summary>
|
||||||
|
public const string LowerEntityName = "#LowerEntityName#";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体字段
|
||||||
|
/// </summary>
|
||||||
|
public const string EntityField = "#EntityField#";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
using Yi.Framework.Template;
|
using Yi.Framework.Template;
|
||||||
using Yi.Framework.Template.Provider;
|
using Yi.Framework.Template.Provider.Server;
|
||||||
|
using Yi.Framework.Template.Provider.Site;
|
||||||
|
|
||||||
TemplateFactory templateFactory = new();
|
TemplateFactory templateFactory = new();
|
||||||
|
|
||||||
//选择需要生成的模板提供者
|
//选择需要生成的模板提供者
|
||||||
|
|
||||||
string modelName = "ERP";
|
string modelName = "ERP";
|
||||||
string entityName = "Test";
|
List<string> entityNames =new (){ "Supplier", "Purchase", "PurchaseDetails" };
|
||||||
|
|
||||||
templateFactory.CreateTemplateProviders((option) =>
|
foreach (var entityName in entityNames)
|
||||||
{
|
{
|
||||||
option.Add(new ServceTemplateProvider(modelName, entityName));
|
templateFactory.CreateTemplateProviders((option) =>
|
||||||
option.Add(new IServceTemplateProvider(modelName, entityName));
|
{
|
||||||
});
|
option.Add(new ServceTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new IServceTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new CreateUpdateInputTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new GetListOutputTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new ConstTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new ProfileTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new ControllerTemplateProvider(modelName, entityName));
|
||||||
|
option.Add(new ApiTemplateProvider(modelName, entityName));
|
||||||
|
});
|
||||||
|
//开始构建模板
|
||||||
|
templateFactory.BuildTemplate();
|
||||||
|
Console.WriteLine($"Yi.Framework.Template:{entityName}构建完成!");
|
||||||
|
}
|
||||||
|
|
||||||
//开始构建模板
|
Console.WriteLine("Yi.Framework.Template:模板全部生成完成!");
|
||||||
templateFactory.BuildTemplate();
|
|
||||||
Console.WriteLine("Yi.Framework.Template模板生成完成!");
|
|
||||||
Console.ReadKey();
|
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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
|
{
|
||||||
|
internal class ConstTemplateProvider : ProgramTemplateProvider
|
||||||
|
{
|
||||||
|
public ConstTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\ConstConfig\{TemplateConst.EntityName}Const.cs";
|
||||||
|
TemplatePath = $@"..\..\..\Template\Server\ConstTemplate.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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
|
{
|
||||||
|
public class ControllerTemplateProvider : ProgramTemplateProvider
|
||||||
|
{
|
||||||
|
public ControllerTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.ApiMicroservice\Controllers\{TemplateConst.ModelName}\{TemplateConst.EntityName}Controller.cs";
|
||||||
|
TemplatePath = $@"..\..\..\Template\Server\ControllerTemplate.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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
|
{
|
||||||
|
public class CreateUpdateInputTemplateProvider : ModelTemplateProvider
|
||||||
|
{
|
||||||
|
public CreateUpdateInputTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}CreateUpdateInput.cs";
|
||||||
|
TemplatePath = $@"..\..\..\Template\Server\CreateUpdateInputTemplate.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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
|
{
|
||||||
|
public class GetListOutputTemplateProvider : ModelTemplateProvider
|
||||||
|
{
|
||||||
|
public GetListOutputTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
BuildPath = $@"..\..\..\Code_Server\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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,14 +6,14 @@ using System.Threading.Tasks;
|
|||||||
using Yi.Framework.Template.Abstract;
|
using Yi.Framework.Template.Abstract;
|
||||||
using Yi.Framework.Template.Const;
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
namespace Yi.Framework.Template.Provider
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
{
|
{
|
||||||
public class IServceTemplateProvider : ProgramTemplateProvider
|
public class IServceTemplateProvider : ProgramTemplateProvider
|
||||||
{
|
{
|
||||||
public IServceTemplateProvider(string modelName, string entityName) : base( modelName,entityName)
|
public IServceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
{
|
{
|
||||||
BuildPath = $@"..\..\..\Code\Yi.Framework.Interface\{TemplateConst.ModelName}\I{TemplateConst.EntityName}Service.cs";
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.Interface\{TemplateConst.ModelName}\I{TemplateConst.EntityName}Service.cs";
|
||||||
TemplatePath = $@"..\..\..\Template\IServiceTemplate.txt";
|
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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
|
{
|
||||||
|
public class ProfileTemplateProvider : ProgramTemplateProvider
|
||||||
|
{
|
||||||
|
public ProfileTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
|
{
|
||||||
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\MapperConfig\{TemplateConst.EntityName}Profile.cs";
|
||||||
|
TemplatePath = $@"..\..\..\Template\Server\ProfileTemplate.txt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,14 +6,14 @@ using System.Threading.Tasks;
|
|||||||
using Yi.Framework.Template.Abstract;
|
using Yi.Framework.Template.Abstract;
|
||||||
using Yi.Framework.Template.Const;
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
namespace Yi.Framework.Template.Provider
|
namespace Yi.Framework.Template.Provider.Server
|
||||||
{
|
{
|
||||||
public class ServceTemplateProvider : ProgramTemplateProvider
|
public class ServceTemplateProvider : ProgramTemplateProvider
|
||||||
{
|
{
|
||||||
public ServceTemplateProvider(string modelName, string entityName) : base( modelName,entityName)
|
public ServceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
|
||||||
{
|
{
|
||||||
BuildPath = $@"..\..\..\Code\Yi.Framework.Service\{TemplateConst.ModelName}\{TemplateConst.EntityName}Service.cs";
|
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.Service\{TemplateConst.ModelName}\{TemplateConst.EntityName}Service.cs";
|
||||||
TemplatePath = $@"..\..\..\Template\ServiceTemplate.txt";
|
TemplatePath = $@"..\..\..\Template\Server\ServiceTemplate.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.Abstract;
|
||||||
|
using Yi.Framework.Template.Const;
|
||||||
|
|
||||||
|
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.ModelName}\{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,81 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Yi.Framework.Common.Models;
|
||||||
|
using Yi.Framework.DtoModel.#ModelName#.#EntityName#;
|
||||||
|
using Yi.Framework.Interface.#ModelName#;
|
||||||
|
|
||||||
|
namespace Yi.Framework.ApiMicroservice.Controllers.#ModelName#
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
public class #EntityName#Controller : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<#EntityName#Controller> _logger;
|
||||||
|
private readonly I#EntityName#Service _#LowerEntityName#Service;
|
||||||
|
public #EntityName#Controller(ILogger<#EntityName#Controller> logger, I#EntityName#Service #LowerEntityName#Service)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_#LowerEntityName#Service = #LowerEntityName#Service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Result> PageList([FromQuery] #EntityName#CreateUpdateInput input, [FromQuery] PageParModel page)
|
||||||
|
{
|
||||||
|
var result = await _#LowerEntityName#Service.PageListAsync(input, page);
|
||||||
|
return Result.Success().SetData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单查
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{id}")]
|
||||||
|
public async Task<Result> GetById(long id)
|
||||||
|
{
|
||||||
|
var result = await _#LowerEntityName#Service.GetByIdAsync(id);
|
||||||
|
return Result.Success().SetData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<Result> Create(#EntityName#CreateUpdateInput input)
|
||||||
|
{
|
||||||
|
var result = await _#LowerEntityName#Service.CreateAsync(input);
|
||||||
|
return Result.Success().SetData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
[Route("{id}")]
|
||||||
|
public async Task<Result> Update(long id, #EntityName#CreateUpdateInput input)
|
||||||
|
{
|
||||||
|
var result = await _#LowerEntityName#Service.UpdateAsync(id, input);
|
||||||
|
return Result.Success().SetData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete]
|
||||||
|
public async Task<Result> Del(List<long> ids)
|
||||||
|
{
|
||||||
|
await _#LowerEntityName#Service.DeleteAsync(ids);
|
||||||
|
return Result.Success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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#GetListOutput: EntityDto<long>
|
||||||
|
{
|
||||||
|
#EntityField#
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,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
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -7,22 +7,42 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Code\" />
|
|
||||||
<Folder Include="Const\" />
|
<Folder Include="Const\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Template\IServiceTemplate.txt">
|
<None Update="Template\Server\ControllerTemplate.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Template\ServiceTemplate.txt">
|
<None Update="Template\Server\ProfileTemplate.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Template\Server\CreateUpdateInputTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Template\Server\ConstTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Template\Server\IServiceTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Template\Server\ServiceTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
|
||||||
|
<None Update="Template\Server\GetListOutputTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
|
||||||
|
<None Update="Template\Site\ApiTemplate.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user