Move LFlow to LFlow.Base

This commit is contained in:
lihanbo 2024-10-16 11:35:05 +08:00
parent 1a362319d0
commit e49fff6407
24 changed files with 210 additions and 241 deletions

View File

@ -1,15 +1,15 @@
using System; using System;
namespace LFlow.Base; namespace LFlow.Base;
/// <summary> /// <summary>
/// 程序对象 /// 程序对象
/// </summary> /// </summary>
public class App public class App
{ {
public static IServiceCollection? services; public static IServiceCollection? services;
private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider(); private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider();
public static T? GetService<T>() public static T? GetService<T>()
{ {
return ServiceProvider!.GetService<T>(); return ServiceProvider!.GetService<T>();
} }
} }

View File

@ -1,18 +1,18 @@
using System; using System;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
/// <summary> /// <summary>
/// 基础控制器 /// 基础控制器
/// </summary> /// </summary>
/// <example> /// <example>
/// [Route("api/[controller]/[action]")] /// [Route("api/[controller]/[action]")]
/// [ApiController] /// [ApiController]
/// </example> /// </example>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public abstract class BaseController : ControllerBase, IController public abstract class BaseController : ControllerBase, IController
{ {
} }

View File

@ -1,16 +1,16 @@
using System; using System;
using LFlow.Base.Interfaces; using LFlow.Base.Interfaces;
namespace LFlow.Base.BusinessInterface; namespace LFlow.Base.BusinessInterface;
/// <summary> /// <summary>
/// Home service interface /// Home service interface
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam> /// <typeparam name="K"></typeparam>
public interface IHomeService<T, K> : IService<T> where T : IModel public interface IHomeService<T, K> : IService<T> where T : IModel
{ {
T DeleteById(K id); T DeleteById(K id);
T GetById(K id); T GetById(K id);
} }

View File

@ -1,8 +1,8 @@
using System; using System;
namespace LFlow.Base.Interfaces.BusinessInterface; namespace LFlow.Base.Interfaces.BusinessInterface;
public interface IUserService<T> : IService<T> where T : IModel public interface IUserService<T> : IService<T> where T : IModel
{ {
} }

View File

@ -1,11 +1,11 @@
using System; using System;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
/// <summary> /// <summary>
/// 控制器接口 /// 控制器接口
/// </summary> /// </summary>
public interface IController public interface IController
{ {
} }

View File

@ -1,11 +1,11 @@
using System; using System;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
/// <summary> /// <summary>
/// 数据模型接口 Repo层用 /// 数据模型接口 Repo层用
/// </summary> /// </summary>
public interface IDataModel : IModel public interface IDataModel : IModel
{ {
} }

View File

@ -1,11 +1,11 @@
using System; using System;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
/// <summary> /// <summary>
/// 模型顶层接口 Service层用 /// 模型顶层接口 Service层用
/// </summary> /// </summary>
public interface IModel public interface IModel
{ {
} }

View File

@ -1,51 +1,51 @@
using System; using System;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
/// <summary> /// <summary>
/// 通用的仓库对象接口 /// 通用的仓库对象接口
/// </summary> /// </summary>
/// <typeparam name="T">数据模型</typeparam> /// <typeparam name="T">数据模型</typeparam>
/// <typeparam name="K">主键</typeparam> /// <typeparam name="K">主键</typeparam>
public interface IRepo<T, K> where T : IDataModel public interface IRepo<T, K> where T : IDataModel
{ {
/// <summary> /// <summary>
/// 获取单个对象 /// 获取单个对象
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
T Get(K id); T Get(K id);
/// <summary> /// <summary>
/// 删除单个对象 /// 删除单个对象
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
int Delete(K id); int Delete(K id);
/// <summary> /// <summary>
/// 保存与更新 /// 保存与更新
/// </summary> /// </summary>
/// <param name="entity"></param> /// <param name="entity"></param>
/// <returns></returns> /// <returns></returns>
T SaveOrUpdate(T entity, bool isUpdate); T SaveOrUpdate(T entity, bool isUpdate);
/// <summary> /// <summary>
/// 获取所有对象列表(默认分页) /// 获取所有对象列表(默认分页)
/// </summary> /// </summary>
/// <param name="pageIndex"></param> /// <param name="pageIndex"></param>
/// <param name="pageSize"></param> /// <param name="pageSize"></param>
/// <returns></returns> /// <returns></returns>
List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal); List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal);
/// <summary> /// <summary>
/// 根据条件搜索对象列表 /// 根据条件搜索对象列表
/// </summary> /// </summary>
/// <param name="whereObj"></param> /// <param name="whereObj"></param>
/// <returns></returns> /// <returns></returns>
List<T> Search(T whereObj); List<T> Search(T whereObj);
/// <summary> /// <summary>
/// 根据条件搜索主键列表 /// 根据条件搜索主键列表
/// </summary> /// </summary>
/// <param name="whereObj"></param> /// <param name="whereObj"></param>
/// <returns></returns> /// <returns></returns>
List<K> WhereSearchId(T whereObj); List<K> WhereSearchId(T whereObj);
} }

View File

@ -1,12 +1,12 @@
using System; using System;
namespace LFlow.Base.Interfaces; namespace LFlow.Base.Interfaces;
public interface IService<T> where T : IModel public interface IService<T> where T : IModel
{ {
T GetById(string id); T GetById(string id);
List<T> Search(T whereObj); List<T> Search(T whereObj);
T DeleteById(string id); T DeleteById(string id);
T Save(T entity); T Save(T entity);
} }

View File

@ -1,32 +1,32 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Net; using System.Net;
using Serilog; using Serilog;
using SqlSugar; using SqlSugar;
namespace LFlow.Base.Utils; namespace LFlow.Base.Utils;
public static class CodeFirst public static class CodeFirst
{ {
// 线程安全的类型列表 // 线程安全的类型列表
private static readonly ConcurrentBag<Type> _types = new(); private static readonly ConcurrentBag<Type> _types = new();
public static void AddType(Type type) public static void AddType(Type type)
{ {
_types.Add(type); _types.Add(type);
} }
internal static void InitTable() internal static void InitTable()
{ {
var logger = App.GetService<Serilog.ILogger>()!; var logger = App.GetService<Serilog.ILogger>()!;
var db = App.GetService<ISqlSugarClient>()!; var db = App.GetService<ISqlSugarClient>()!;
foreach (var type in _types) foreach (var type in _types)
{ {
db.CodeFirst.InitTables(type); db.CodeFirst.InitTables(type);
logger.Information($"Init table {type.Name} success"); logger.Information($"Init table {type.Name} success");
} }
} }
internal static void InitDBSeed() internal static void InitDBSeed()
{ {
//TODO: Seed data //TODO: Seed data
} }
} }

View File

@ -1,22 +1,22 @@
using System; using System;
using Mapster; using Mapster;
namespace LFlow.Base.Utils; namespace LFlow.Base.Utils;
public class Mapper public class Mapper
{ {
/// <summary> /// <summary>
/// 将一个对象映射到另一个对象 /// 将一个对象映射到另一个对象
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="source"></param> /// <param name="source"></param>
/// <returns></returns> /// <returns></returns>
public static T? Map<T>(object source) public static T? Map<T>(object source)
{ {
if (source == null) if (source == null)
{ {
return default; return default;
} }
return source.Adapt<T>(); return source.Adapt<T>();
} }
} }

View File

@ -20,7 +20,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" /> <ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" /> <ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.5.002.0 VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow.Base\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}"
EndProject EndProject

View File

@ -1,19 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build",
"program": "${workspaceFolder}/bin/Debug/net8.0/LFlow.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
]
}

View File

@ -1,12 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build",
"group": "build",
"problemMatcher": [],
"label": "dotnet: build"
}
]
}