Merge branch 'sqlsugar-dev' into sqlsugar

This commit is contained in:
陈淳
2023-01-04 13:40:58 +08:00
53 changed files with 1526 additions and 698 deletions

63
.gitattributes vendored
View File

@@ -1,63 +0,0 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

Binary file not shown.

View File

@@ -181,6 +181,40 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ERP.SupplierController.PageList(Yi.Framework.DtoModel.ERP.Supplier.SupplierCreateUpdateInput,Yi.Framework.Common.Models.PageParModel)">
<summary>
分页查
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ERP.SupplierController.GetById(System.Int64)">
<summary>
单查
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ERP.SupplierController.Create(Yi.Framework.DtoModel.ERP.Supplier.SupplierCreateUpdateInput)">
<summary>
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ERP.SupplierController.Update(System.Int64,Yi.Framework.DtoModel.ERP.Supplier.SupplierCreateUpdateInput)">
<summary>
</summary>
<param name="id"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ERP.SupplierController.Del(System.Collections.Generic.List{System.Int64})">
<summary>
</summary>
<param name="ids"></param>
<returns></returns>
</member>
<member name="T:Yi.Framework.ApiMicroservice.Controllers.AccountController">
<summary>
账户管理

View File

@@ -0,0 +1,81 @@
using Microsoft.AspNetCore.Mvc;
using Yi.Framework.Common.Models;
using Yi.Framework.DtoModel.ERP.Supplier;
using Yi.Framework.Interface.ERP;
namespace Yi.Framework.ApiMicroservice.Controllers.ERP
{
[ApiController]
[Route("api/[controller]/[action]")]
public class SupplierController : ControllerBase
{
private readonly ILogger<SupplierController> _logger;
private readonly ISupplierService _supplierService;
public SupplierController(ILogger<SupplierController> logger, ISupplierService supplierService)
{
_logger = logger;
_supplierService = supplierService;
}
/// <summary>
/// 分页查
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> PageList([FromQuery] SupplierCreateUpdateInput input, [FromQuery] PageParModel page)
{
var result = await _supplierService.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 _supplierService.GetByIdAsync(id);
return Result.Success().SetData(result);
}
/// <summary>
/// 增
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<Result> Create(SupplierCreateUpdateInput input)
{
var result = await _supplierService.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, SupplierCreateUpdateInput input)
{
var result = await _supplierService.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 _supplierService.DeleteAsync(ids);
return Result.Success();
}
}
}

View File

@@ -1,10 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Yi.Framework.Common.Models;
using Yi.Framework.DtoModel.RABC.Student;
using Yi.Framework.Interface.RABC;
namespace Brick.IFServer.Controllers
namespace Yi.Framework.ApiMicroservice.Controllers.ERP
{
[ApiController]
[Route("[controller]")]

View File

@@ -407,6 +407,84 @@ namespace Yi.Framework.Common.Helper
return folder.Select(x => x.Name).ToList();
}
/// <summary>
/// 文件内容替换
/// </summary>
public static string FileContentReplace(string path, string oldStr, string newStr)
{
var content = File.ReadAllText(path);
if (content.Contains(oldStr))
{
File.Delete(path);
File.WriteAllText(path, content.Replace(oldStr, newStr));
}
return path;
}
/// <summary>
/// 文件名称
/// </summary>
public static string FileNameReplace(string path, string oldStr, string newStr)
{
string fileName = Path.GetFileName(path);
if (!fileName.Contains(oldStr))
{
return path;
}
string? directoryName = Path.GetDirectoryName(path);
string newFileName = fileName.Replace(oldStr, newStr);
string newPath = Path.Combine(directoryName ?? "", newFileName);
File.Move(path, newPath);
return newPath;
}
/// <summary>
/// 目录名替换
/// </summary>
public static string DirectoryNameReplace(string path, string oldStr, string newStr)
{
string fileName = Path.GetFileName(path);
if (!fileName.Contains(oldStr))
{
return path;
}
string? directoryName = Path.GetDirectoryName(path);
string newFileName = fileName.Replace(oldStr, newStr);
string newPath = Path.Combine(directoryName ?? "", newFileName);
Directory.Move(path, newPath);
return newPath;
}
/// <summary>
/// 全部信息递归替换
/// </summary>
/// <param name="dirPath"></param>
/// <param name="oldStr"></param>
/// <param name="newStr"></param>
public static void AllInfoReplace(string dirPath, string oldStr, string newStr)
{
var path = DirectoryNameReplace(dirPath, oldStr, newStr);
var dirInfo = new DirectoryInfo(path);
var files = dirInfo.GetFiles();
var dirs = dirInfo.GetDirectories();
if (files.Length > 0)
{
foreach (var f in files)
{
FileContentReplace(f.FullName, oldStr, newStr);
FileNameReplace(f.FullName, oldStr, newStr);
}
}
if (dirs.Length > 0)
{
foreach (var d in dirs)
{
AllInfoReplace(d.FullName, oldStr, newStr);
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.DtoModel.ERP.Supplier.ConstConfig
{
public class SupplierConst
{
}
}

View File

@@ -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.ERP.Entitys;
namespace Yi.Framework.DtoModel.ERP.Supplier.MapperConfig
{
public class SupplierProfile:Profile
{
public SupplierProfile()
{
CreateMap<SupplierCreateUpdateInput, SupplierEntity>();
CreateMap<SupplierEntity, SupplierGetListOutput>();
}
}
}

View File

@@ -0,0 +1,41 @@
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.ERP.Supplier
{
public class SupplierCreateUpdateInput : EntityDto<long>
{
/// <summary>
/// 供应商编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 供应商名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 供应商地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 电话
/// </summary>
public long Phone { get; set; }
/// <summary>
/// 传真
/// </summary>
public string Fax { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string Email { get; set; }
}
}

View File

@@ -0,0 +1,40 @@
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.ERP.Supplier
{
public class SupplierGetListOutput: EntityDto<long>
{
/// <summary>
/// 供应商编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 供应商名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 供应商地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 电话
/// </summary>
public long Phone { get; set; }
/// <summary>
/// 传真
/// </summary>
public string Fax { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string Email { get; set; }
}
}

View File

@@ -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.ERP.Supplier;
using Yi.Framework.Interface.Base.Crud;
namespace Yi.Framework.Interface.ERP
{
public interface ISupplierService : ICrudAppService<SupplierGetListOutput, long, SupplierCreateUpdateInput>
{
Task<PageModel<List<SupplierGetListOutput>>> PageListAsync(SupplierCreateUpdateInput input, PageParModel page);
}
}

View File

@@ -54,7 +54,7 @@ namespace Yi.Framework.Model.RABC.SeedData
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "显示",
DictValue = "0",
DictValue = "true",
DictType = "sys_show_hide",
OrderNum = 100,
Remark = "显示菜单",
@@ -66,7 +66,7 @@ namespace Yi.Framework.Model.RABC.SeedData
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "隐藏",
DictValue = "1",
DictValue = "false",
DictType = "sys_show_hide",
OrderNum = 99,
Remark = "隐藏菜单",

View File

@@ -6,10 +6,6 @@
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
</ItemGroup>

View File

@@ -68,7 +68,8 @@ namespace Yi.Framework.Service.Base.Crud
TryToSetTenantId(entity);
await Repository.InsertAsync(entity);
//这边需要进行判断实体是什么guid还是雪花id
await Repository.InsertReturnSnowflakeIdAsync(entity);
var entitydto = await MapToGetOutputDtoAsync(entity);
return entitydto;
@@ -80,7 +81,7 @@ namespace Yi.Framework.Service.Base.Crud
/// <param name="ids"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual Task DeleteAsync(IEnumerable<TKey> ids)
public virtual Task DeleteAsync(IEnumerable<TKey> ids)
{
throw new NotImplementedException();
}
@@ -110,7 +111,7 @@ namespace Yi.Framework.Service.Base.Crud
/// <param name="idEntity"></param>
/// <param name="dto"></param>
/// <returns></returns>
protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
{
return Task.CompletedTask;
}

View File

@@ -0,0 +1,32 @@
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.ERP.Supplier;
using Yi.Framework.Interface.ERP;
using Yi.Framework.Model.ERP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base.Crud;
namespace Yi.Framework.Service.ERP
{
public class SupplierService : CrudAppService<SupplierEntity, SupplierGetListOutput, long, SupplierCreateUpdateInput>, ISupplierService
{
public SupplierService(IRepository<SupplierEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
public async Task<PageModel<List<SupplierGetListOutput>>> PageListAsync(SupplierCreateUpdateInput 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<SupplierGetListOutput>> { Total = totalNumber.Value, Data = await MapToGetListOutputDtosAsync(data) };
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Template.Abstract
{
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);
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Template.Abstract
{
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();
}
}

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,75 @@
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 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();
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Template.Const
{
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#";
}
}

View File

@@ -0,0 +1,31 @@
using Yi.Framework.Template;
using Yi.Framework.Template.Provider.Server;
using Yi.Framework.Template.Provider.Site;
TemplateFactory templateFactory = new();
//选择需要生成的模板提供者
string modelName = "ERP";
List<string> entityNames =new (){ "Supplier", "Purchase", "PurchaseDetails" };
foreach (var entityName in entityNames)
{
templateFactory.CreateTemplateProviders((option) =>
{
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:模板全部生成完成!");
Console.ReadKey();

View File

@@ -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";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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 IServceTemplateProvider : ProgramTemplateProvider
{
public IServceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
{
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.Interface\{TemplateConst.ModelName}\I{TemplateConst.EntityName}Service.cs";
TemplatePath = $@"..\..\..\Template\Server\IServiceTemplate.txt";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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 ServceTemplateProvider : ProgramTemplateProvider
{
public ServceTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
{
BuildPath = $@"..\..\..\Code_Server\Yi.Framework.Service\{TemplateConst.ModelName}\{TemplateConst.EntityName}Service.cs";
TemplatePath = $@"..\..\..\Template\Server\ServiceTemplate.txt";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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
{
}
}

View File

@@ -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();
}
}
}

View File

@@ -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#
}
}

View File

@@ -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#
}
}

View File

@@ -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#CreateUpdateInput input, PageParModel page);
}
}

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,32 @@
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 #EntityName#Service(IRepository<#EntityName#Entity> repository, IMapper mapper) : base(repository, mapper)
{
}
public async Task<PageModel<List<#EntityName#GetListOutput>>> PageListAsync(#EntityName#CreateUpdateInput 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) };
}
}
}

View File

@@ -1,18 +1,9 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".js" #>
<#
var entityName="article";
#>
import request from '@/utils/request'
// 分页查询
export function listData(query) {
return request({
url: '/<#= entityName #>/pageList',
url: '/#LowerEntityName#/pageList',
method: 'get',
params: query
})
@@ -21,7 +12,7 @@ export function listData(query) {
// id查询
export function getData(code) {
return request({
url: '/<#= entityName #>/getById/' + code,
url: '/#LowerEntityName#/getById/' + code,
method: 'get'
})
}
@@ -29,16 +20,16 @@ export function getData(code) {
// 新增
export function addData(data) {
return request({
url: '/<#= entityName #>/add',
url: '/#LowerEntityName#/create',
method: 'post',
data: data
})
}
// 修改
export function updateData(data) {
export function updateData(id,data) {
return request({
url: '/<#= entityName #>/update',
url: `/#LowerEntityName#/update/${id}`,
method: 'put',
data: data
})
@@ -47,7 +38,7 @@ export function updateData(data) {
// 删除
export function delData(code) {
return request({
url: '/<#= entityName #>/delList',
url: '/#LowerEntityName#/del',
method: 'delete',
data:"string"==typeof(code)?[code]:code
})

View File

@@ -0,0 +1,38 @@
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.Provider;
namespace Yi.Framework.Template
{
public class TemplateFactory
{
private List<ITemplateProvider> _templateProviders;
public void CreateTemplateProviders(Action<List<ITemplateProvider>> action)
{
_templateProviders=new List<ITemplateProvider>();
action(_templateProviders);
}
public void BuildTemplate()
{
foreach (var provider in _templateProviders)
{
provider.Build();
}
}
public void BakTemplate()
{
foreach (var provider in _templateProviders)
{
provider.Bak();
}
}
}
}

View File

@@ -4,47 +4,45 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="vue3-ruoyi\view.vue">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>view.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="vue3-ruoyi\view.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>view.tt</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<None Update="vue3-ruoyi\view.tt">
<LastGenOutput>view.vue</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
<None Update="vue3-ruoyi\api.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>api.js</LastGenOutput>
</None>
<None Update="vue3-ruoyi\api.js">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>api.tt</DependentUpon>
</None>
<None Update="vue3-ruoyi\view.vue">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>view.tt</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Const\" />
</ItemGroup>
<ItemGroup>
<None Update="Template\Server\ControllerTemplate.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Template\Server\ProfileTemplate.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</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>
</Project>

View File

@@ -1,315 +0,0 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".vue" #>
<#
var entityName="article";
var path="/business/articleApi";
var entityRemark="文章";
var perCode="business:article";
var dataDic=new Dictionary<string,string>(){
{"title","文章标题"},
};
var isStart=false;
#>
//
<#if(isStart){
#>
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<# foreach(var dic in dataDic) { #>
<el-form-item label="<#=dic.Value#>" prop="<#=dic.Key#>">
<el-input
v-model="queryParams.<#=dic.Key#>"
placeholder="请输入<#=dic.Value#>"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<#} #>
<el-form-item label="状态" prop="isDeleted">
<el-select
v-model="queryParams.isDeleted"
placeholder="状态"
clearable
style="width: 240px"
>
<el-option
v-for="dict in sys_normal_disable"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间" style="width: 308px">
<el-date-picker
v-model="dateRange"
value-format="YYYY-MM-DD"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['<#=perCode#>:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['<#=perCode#>:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['<#=perCode#>:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['<#=perCode#>:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="<#=entityName#>List" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="id" />
<# foreach(var dic in dataDic) { #>
<el-table-column label="<#=dic.Value#>" align="center" prop="<#=dic.Key#>" :show-overflow-tooltip="true"/>
<# }#>
<el-table-column label="状态" align="center" prop="isDeleted">
<template #default="scope">
<dict-tag :options="sys_normal_disable" :value="scope.row.isDeleted" />
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['<#=perCode#>:edit']"
>修改</el-button>
<el-button
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['<#=perCode#>:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="dataRef" :model="form" :rules="rules" label-width="80px">
<# foreach(var dic in dataDic) { #>
<el-form-item label="<#=dic.Value#>" prop="<#=dic.Key#>">
<el-input v-model="form.<#=dic.Key#>" placeholder="请输入<#=dic.Value#>" />
</el-form-item>
<# } #>
<el-form-item label="状态" prop="isDeleted">
<el-radio-group v-model="form.isDeleted">
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :label="JSON.parse(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { listData, getData, delData, addData, updateData } from "@/api<#=path#>";
const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const <#=entityName#>List = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
<# foreach(var dic in dataDic) { #>
<#=dic.Key#>: undefined,
<# }#>
isDeleted: undefined
},
rules: {
<# foreach(var dic in dataDic) { #>
<#=dic.Key#>: [{ required: true, message: "<#=dic.Value#>不能为空", trigger: "blur" }],
<# }#>
},
});
const { queryParams, form, rules } = toRefs(data);
/** 查询列表 */
function getList() {
loading.value = true;
listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
<#=entityName#>List.value = response.data.data;
total.value = response.data.total;
loading.value = false;
});
}
/** 取消按钮 */
function cancel() {
open.value = false;
reset();
}
/** 表单重置 */
function reset() {
form.value = {
id: undefined,
<# foreach(var dic in dataDic) { #>
<#=dic.Key#>: undefined,
<# }#>
isDeleted: false,
remark: undefined
};
proxy.resetForm("dataRef");
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
dateRange.value = [];
proxy.resetForm("queryRef");
handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
reset();
open.value = true;
title.value = "添加<#=entityRemark#>";
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
ids.value = selection.map(item => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const id = row.id || ids.value;
getData(id).then(response => {
form.value = response.data;
open.value = true;
title.value = "修改<#=entityRemark#>类型";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["dataRef"].validate(valid => {
if (valid) {
if (form.value.id != undefined) {
updateData(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addData(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
const delIds = row.id || ids.value;
proxy.$modal.confirm('是否确认删除字典编号为"' + delIds + '"的数据项?').then(function() {
return delData(delIds);
}).then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
/** 导出按钮操作 */
function handleExport() {
}
getList();
</script>
<#}
#>

View File

@@ -1,13 +0,0 @@
using System.Data;
namespace Yi.Framework.Uow
{
public interface IUnitOfWork : IDisposable
{
public void Init(bool isTransactional, IsolationLevel? isolationLevel, int? timeout);
public void BeginTran();
public void CommitTran();
public void RollbackTran();
}
}

View File

@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow.Interceptors
{
public class UnitOfWorkAttribute : Attribute// : AbstractInterceptorAttribute
{
public UnitOfWorkAttribute(bool isTransactional = true)
{
IsTransactional = isTransactional;
}
public UnitOfWorkAttribute(IsolationLevel isolationLevel, bool isTransactional = true) : this(isTransactional)
{
IsolationLevel = isolationLevel;
}
public UnitOfWorkAttribute(IsolationLevel isolationLevel, int timeout, bool isTransactional = true) : this(isolationLevel, isTransactional)
{
Timeout = timeout;
}
public bool IsTransactional { get; }
public IsolationLevel? IsolationLevel { get; }
/// <summary>
/// Milliseconds
/// </summary>
public int? Timeout { get; }
public bool IsDisabled { get; }
//public override Task Invoke(AspectContext context, AspectDelegate next)
//{
// if (IsTransactional)
// {
// ServiceLocator.in.getservice()
// }
//}
}
}

View File

@@ -1,78 +0,0 @@
using Castle.DynamicProxy;
using Nest;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow.Interceptors
{
public class UnitOfWorkInterceptor : IInterceptor
{
private readonly IUnitOfWork _unitOfWork;
public UnitOfWorkInterceptor(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void Intercept(IInvocation invocation)
{
if (!IsUnitOfWorkMethod(invocation.Method, out var uowAttr))
{
invocation.Proceed();
return;
}
try
{
_unitOfWork.BeginTran();
//执行被拦截的方法
invocation.Proceed();
_unitOfWork.CommitTran();
}
catch (Exception ex)
{
_unitOfWork.RollbackTran();
throw ex;
}
}
public static bool IsUnitOfWorkMethod( MethodInfo methodInfo,out UnitOfWorkAttribute unitOfWorkAttribute)
{
//Method declaration
var attrs = methodInfo.GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
if (attrs.Any())
{
unitOfWorkAttribute = attrs.First();
return !unitOfWorkAttribute.IsDisabled;
}
if (methodInfo.DeclaringType != null)
{
//Class declaration
attrs = methodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
if (attrs.Any())
{
unitOfWorkAttribute = attrs.First();
return !unitOfWorkAttribute.IsDisabled;
}
////Conventional classes
//if (typeof(IUnitOfWorkEnabled).GetTypeInfo().IsAssignableFrom(methodInfo.DeclaringType))
//{
// unitOfWorkAttribute = null;
// return true;
//}
}
unitOfWorkAttribute = null;
return false;
}
}
}

View File

@@ -1,21 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Uow;
using Yi.Framework.Uow.Interceptors;
namespace Microsoft.Extensions.DependencyInjection
{
public static class UowIServiceCollectionExtensions
{
public static void AddUnitOfWork(this IServiceCollection services)
{
services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
services.AddSingleton<UnitOfWorkInterceptor>();
}
}
}

View File

@@ -1,75 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow
{
public class UnitOfWork : IUnitOfWork
{
public bool IsTransactional { get; protected set; }
public IsolationLevel? IsolationLevel { get; protected set; }
/// <summary>
/// Milliseconds
/// </summary>
public int? Timeout { get; protected set; }
public void Init(bool isTransactional, IsolationLevel? isolationLevel, int? timeout)
{
IsTransactional = isTransactional;
IsolationLevel = isolationLevel;
Timeout = timeout;
}
public ISqlSugarClient SugarClient { get; set; }
/// <summary>
/// 因为sqlsugarclient的生命周期是作用域的也就是说一个请求线程内是共用一个client暂时先直接注入
/// </summary>
/// <param name="sqlSugarClient"></param>
public UnitOfWork(ISqlSugarClient sqlSugarClient)
{
this.SugarClient = sqlSugarClient;
}
public void Dispose()
{
SugarClient?.Dispose();
SugarClient?.Close();
}
public void BeginTran()
{
if (IsTransactional)
{
if (IsolationLevel.HasValue)
{
SugarClient.Ado.BeginTran(IsolationLevel.Value);
}
else
{
SugarClient.Ado.BeginTran();
}
}
}
public void CommitTran()
{
if (IsTransactional)
SugarClient.Ado.CommitTran();
}
public void RollbackTran()
{
if (IsTransactional)
SugarClient.Ado.RollbackTran();
}
}
}

View File

@@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Core" Version="5.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
</Project>

View File

@@ -118,6 +118,7 @@ namespace Yi.Framework.WebCore.AspNetCoreExtensions
{
sb.Append($"\r\n参数:{i.ParameterName},参数值:{i.Value}");
}
sb.Append( $"\r\n 完整SQL{UtilMethods.GetSqlString(DbType.MySql, s, p)}");
_logger?.LogInformation(sb.ToString());
}

View File

@@ -19,11 +19,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
public class ErrorHandExtension
{
private readonly RequestDelegate next;
private readonly ILogger<ErrorHandExtension> _logger;
//private readonly IErrorHandle _errorHandle;
public ErrorHandExtension(RequestDelegate next/*, IErrorHandle errorHandle*/)
public ErrorHandExtension(RequestDelegate next, ILoggerFactory loggerFactory /*, IErrorHandle errorHandle*/)
{
this.next = next;
//this._logger = loggerFactory.CreateLogger<ErrorHandExtension>();
this._logger = loggerFactory.CreateLogger<ErrorHandExtension>();
//_errorHandle = errorHandle;
}
@@ -40,6 +41,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
}
catch (Exception ex)
{
_logger.LogError("系统错误",ex);
//await _errorHandle.Invoer(context, ex);
var statusCode = context.Response.StatusCode;
if (ex is ArgumentException)

View File

@@ -258,7 +258,7 @@
<el-radio
v-for="dict in sys_show_hide"
:key="dict.value"
:label="dict.value"
:label="JSON.parse(dict.value)"
>{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>

View File

@@ -3,7 +3,7 @@
// 分页查询
export function listData(query) {
return request({
url: '/article/pageList',
url: '/supplier/pageList',
method: 'get',
params: query
})
@@ -12,7 +12,7 @@ export function listData(query) {
// id查询
export function getData(code) {
return request({
url: '/article/getById/' + code,
url: '/supplier/getById/' + code,
method: 'get'
})
}
@@ -20,16 +20,16 @@ export function getData(code) {
// 新增
export function addData(data) {
return request({
url: '/article/add',
url: '/supplier/create',
method: 'post',
data: data
})
}
// 修改
export function updateData(data) {
export function updateData(id,data) {
return request({
url: '/article/update',
url: `/supplier/update/${id}`,
method: 'put',
data: data
})
@@ -38,7 +38,7 @@ export function updateData(data) {
// 删除
export function delData(code) {
return request({
url: '/article/delList',
url: '/supplier/del',
method: 'delete',
data:"string"==typeof(code)?[code]:code
})

View File

@@ -0,0 +1,396 @@
<template>
<div class="app-container">
<el-form
:model="queryParams"
ref="queryRef"
:inline="true"
v-show="showSearch"
label-width="100px"
>
<el-form-item label="供应商名称" prop="title" >
<el-input
v-model="queryParams.name"
placeholder="请输入供应商名称"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
prop="name"
/>
</el-form-item>
<el-form-item label="供应商编号" prop="title" >
<el-input
v-model="queryParams.code"
placeholder="请输入供应商编号"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
prop="code"
/>
</el-form-item>
<!-- <el-form-item label="状态" prop="isDeleted">
<el-select
v-model="queryParams.isDeleted"
placeholder="状态"
clearable
style="width: 240px"
>
<el-option
v-for="dict in sys_normal_disable"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item> -->
<!-- <el-form-item label="创建时间" style="width: 308px">
<el-date-picker
v-model="dateRange"
value-format="YYYY-MM-DD"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item> -->
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery"
>搜索</el-button
>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['erp:supplier:add']"
>新增</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['erp:supplier:edit']"
>修改</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['erp:supplier:remove']"
>删除</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['erp:supplier:export']"
>导出</el-button
>
</el-col>
<right-toolbar
v-model:showSearch="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
<el-table
v-loading="loading"
:data="dataList"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<!-----------------------这里开始就是数据表单的全部列------------------------>
<el-table-column label="供应商编号" align="center" prop="code" />
<el-table-column label="供应商名称" align="center" prop="name" :show-overflow-tooltip="true"/>
<el-table-column label="详细地址" align="center" prop="address" :show-overflow-tooltip="true"/>
<el-table-column label="联系人" align="center" prop="name" :show-overflow-tooltip="true"/>
<el-table-column label="联系电话" align="center" prop="phone" :show-overflow-tooltip="true"/>
<el-table-column label="传真" align="center" prop="fax" :show-overflow-tooltip="true"/>
<el-table-column label="邮箱" align="center" prop="email" :show-overflow-tooltip="true"/>
<!-- <el-table-column label="状态" align="center" prop="isDeleted">
<template #default="scope">
<dict-tag
:options="sys_normal_disable"
:value="scope.row.isDeleted"
/>
</template>
</el-table-column> -->
<!-- <el-table-column
label="备注"
align="center"
prop="remark"
:show-overflow-tooltip="true"
/>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
>
<template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column> -->
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template #default="scope">
<el-button
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['business:article:edit']"
>修改</el-button
>
<el-button
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['business:article:remove']"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<!-- ---------------------这里是新增和更新的对话框--------------------- -->
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
<el-form ref="dataRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="供应商编码" prop="code">
<el-input v-model="form.code" placeholder="请输入供应商编码" />
</el-form-item>
<el-form-item label="供应商名称" prop="name">
<el-input v-model="form.name" placeholder="请输入供应商名称" />
</el-form-item>
<el-form-item label="地址" prop="address">
<el-input v-model="form.address" placeholder="请输入地址" />
</el-form-item>
<el-form-item label="供应商编码" prop="code">
<el-input v-model="form.code" placeholder="请输入供应商编码" />
</el-form-item>
<el-form-item label="联系电话" prop="phone">
<el-input v-model="form.phone" placeholder="请输入联系电话" />
</el-form-item>
<el-form-item label="传真" prop="fax">
<el-input v-model="form.fax" placeholder="请输入传真" />
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" placeholder="请输入邮箱" />
</el-form-item>
<!-- <el-form-item label="状态" prop="isDeleted">
<el-radio-group v-model="form.isDeleted">
<el-radio
v-for="dict in sys_normal_disable"
:key="dict.value"
:label="JSON.parse(dict.value)"
>{{ dict.label }}</el-radio
>
</el-radio-group>
</el-form-item> -->
<el-form-item label="备注" prop="remarks">
<el-input
v-model="form.remarks"
type="textarea"
placeholder="请输入内容"
></el-input>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup>
import {
listData,
getData,
delData,
addData,
updateData,
} from "@/api/erp/supplierApi";
import { ref } from "@vue/reactivity";
const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
name: undefined,
code: undefined,
},
rules: {
code: [{ required: true, message: "供应商编号不能为空", trigger: "blur" }],
name: [{ required: true, message: "供应商名称不能为空", trigger: "blur" }],
},
});
const { queryParams, form, rules } = toRefs(data);
/** 查询列表 */
function getList() {
loading.value = true;
listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(
(response) => {
dataList.value = response.data.data;
total.value = response.data.total;
loading.value = false;
}
);
}
/** 取消按钮 */
function cancel() {
open.value = false;
reset();
}
/** 表单重置 */
function reset() {
form.value = {
id: undefined,
title: undefined,
isDeleted: false,
remark: undefined,
};
proxy.resetForm("dataRef");
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
dateRange.value = [];
proxy.resetForm("queryRef");
handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
reset();
open.value = true;
title.value = "添加供应商";
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
ids.value = selection.map((item) => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const id = row.id || ids.value;
getData(id).then((response) => {
form.value = response.data;
open.value = true;
title.value = "修改供应商";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["dataRef"].validate((valid) => {
if (valid) {
if (form.value.id != undefined) {
updateData(form.value.id,form.value).then((response) => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addData(form.value).then((response) => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
const delIds = row.id || ids.value;
proxy.$modal
.confirm('是否确认删除字典编号为"' + delIds + '"的数据项?')
.then(function () {
return delData(delIds);
})
.then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
})
.catch(() => {});
}
/** 导出按钮操作 */
function handleExport() {}
getList();
</script>