Compare commits

...

3 Commits

Author SHA1 Message Date
lihanbo c18ee4036d Update
移除参考模块引用
增加版本管理模块
2024-10-16 15:22:58 +08:00
lihanbo de39bba323 Update
更新默认的增删改查仓储对象
增加通用的API返回结果包装
增加IModel转换为查询条件的工具类
IDataModel类增加默认主键
2024-10-16 15:22:09 +08:00
lihanbo e49fff6407 Move LFlow to LFlow.Base 2024-10-16 11:35:05 +08:00
41 changed files with 834 additions and 357 deletions

View File

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

View File

@ -0,0 +1,92 @@
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using SqlSugar;
namespace LFlow.Base.Default;
/// <summary>
/// 默认的增删改查仓储
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
public abstract class DefaultCurdRepo<T, K> : IRepo<T, K> where T : class, IDataModel, new()
{
private readonly ISqlSugarClient _client;
public DefaultCurdRepo(ISqlSugarClient client)
{
_client = client;
}
/// <summary>
/// 根据ID删除对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public virtual int DeleteById(K id)
{
if (Get(id) != null)
{
return _client.Deleteable<T>().In(id).ExecuteCommand();
}
else
{
throw new Exception("删除的对象不存在");
}
}
/// <summary>
/// 根据ID获取对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual T Get(K id)
{
return _client.Queryable<T>().InSingle(id);
}
/// <summary>
/// 批量查询(分页)
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="pageTotal"></param>
/// <returns></returns>
public List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal)
{
return _client.Queryable<T>().ToPageList(pageIndex, pageSize, ref pageTotal);
}
/// <summary>
/// 报错或是更新对象
/// </summary>
/// <param name="entity"></param>
/// <param name="isUpdate"></param>
/// <returns></returns>
public virtual T SaveOrUpdate(T entity, bool isUpdate)
{
if (isUpdate)
{
_client.Updateable(entity).ExecuteCommand();
}
else
{
_client.Insertable(entity).ExecuteCommand();
}
return entity;
}
/// <summary>
/// 搜索
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
public virtual List<T> Search(T whereObj)
{
return _client.Queryable<T>().Where(whereObj.ToWhereExp()).ToList();
}
/// <summary>
/// 查找ID
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
public virtual List<K> WhereSearchId(T whereObj)
{
return _client.Queryable<T>().Where(whereObj.ToWhereExp()).Select(x => (K)Convert.ChangeType(x.ID, typeof(K))).ToList();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,17 @@
using LFlow.Base.Utils;
namespace LFlow.Base.Interfaces;
/// <summary>
/// ·þÎñ½Ó¿Ú
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IService<T> where T : class, IModel, new()
{
T GetById(string id);
List<T> Search(T whereObj);
int DeleteById(string id);
T Save(T entity, bool isUpdate);
PagedApiResult<List<T>> GetAll(int pageIndex, int pageSize);
}

View File

@ -1,11 +1,6 @@
using System.Reflection;
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Npgsql.Replication;
using Serilog;
using Serilog.Events;
using SqlSugar;
@ -16,6 +11,7 @@ public static class Program
public static void Main(string[] args)
{
// 先用Serilog的BootstrapLogger
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
@ -23,7 +19,7 @@ public static class Program
.CreateBootstrapLogger();
var builder = WebApplication.CreateBuilder(args);
// 添加到Service中
builder.Services.AddSerilog((services, lc) => lc
.ReadFrom.Configuration(builder.Configuration)
.ReadFrom.Services(services)
@ -57,7 +53,7 @@ public static class Program
}
});
});
// 使用Serilog此处为了修复 `The logger is already frozen` 的问题重新配置Serilog
builder.Host.UseSerilog((context, services, config) =>
{
config.ReadFrom.Configuration(context.Configuration)
@ -70,6 +66,7 @@ public static class Program
var app = builder.Build();
app.UseSerilogRequestLogging(options =>
{
// 配置日志级别
options.GetLevel = (httpContext, elapsed, ex) => LogEventLevel.Information;
});
app.MapControllers();
@ -145,7 +142,7 @@ public static class Program
{
Log.Logger.Information($"\tFound IModule -> {type.FullName}");
var module = Activator.CreateInstance(type) as IModule;
module.ConfigureModule(services);
module?.ConfigureModule(services);
}
}
}

View File

@ -0,0 +1,35 @@
namespace LFlow.Base.Utils;
/// <summary>
/// 返回结果包装
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class ApiResult<T> where T : class, new()
{
public T? Data
{
get; set;
}
public ApiResult()
{
}
public ApiResult(bool success, string message, T data)
{
Success = success;
Message = message;
Data = data;
}
public bool Success
{
get; set;
}
public string? Message
{
get; set;
}
}

View File

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

View File

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

View File

@ -0,0 +1,55 @@
using LFlow.Base.Interfaces;
namespace LFlow.Base.Utils;
public static class ObjectToWhereExp
{
/// <summary>
/// 将IModel对象转换为where条件
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static string ToWhereExp(this IModel model)
{
var type = model.GetType();
var properties = type.GetProperties();
var whereExp = " 1=1 ";
foreach (var property in properties)
{
var value = property.GetValue(model);
if (value == null) continue;
if (property.PropertyType == typeof(string))
{
whereExp += $" and {property.Name} like '%{value}%'";
}
else if (property.PropertyType == typeof(DateTime) && value is DateTime dateTime)
{
if (dateTime != default(DateTime))
{
whereExp += $" and {property.Name} like '%{value}%'";
}
}
else if (property.PropertyType.IsEnum)
{
var enumValue = (int)value;
whereExp += $" and {property.Name} = '{enumValue}'";
}
else if (property.PropertyType == typeof(bool) && value is bool flag)
{
if (flag)
{
whereExp += $" and {property.Name} = 1";
}
else
{
whereExp += $" and {property.Name} = 0";
}
}
else if (value != null)
{
whereExp += $" and {property.Name} = '{value}'";
}
}
return whereExp;
}
}

View File

@ -0,0 +1,43 @@
namespace LFlow.Base.Utils;
/// <summary>
/// 返回结果包装 (分页)
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class PagedApiResult<T> : ApiResult<T> where T : class, new()
{
public new T? Data
{
get; set;
}
public int TotalCount
{
get; set;
}
public int PageIndex
{
get; set;
}
public int PageSize
{
get; set;
}
public PagedApiResult()
{
}
public PagedApiResult(bool success, string message, T data, int totalCount, int pageIndex, int pageSize)
{
Success = success;
Message = message;
Data = data;
TotalCount = totalCount;
PageIndex = pageIndex;
PageSize = pageSize;
}
}

View File

@ -1,11 +1,13 @@
using System;
using LFlow.Base.Interfaces;
namespace LFlow.Base.Utils;
public static class RegisterModule
{
public static void RegisterAllModule(this List<Type> types, IServiceCollection services)
/// <summary>
/// 注册所有模型
/// </summary>
/// <param name="types"></param>
/// <param name="services"></param>
public static void RegisterAllModel(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)
{
@ -24,6 +26,11 @@ public static class RegisterModule
}
}
}
/// <summary>
/// 注册所有服务
/// </summary>
/// <param name="types"></param>
/// <param name="services"></param>
public static void RegisterAllService(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)
@ -45,6 +52,11 @@ public static class RegisterModule
}
}
}
/// <summary>
/// 注册所有数据仓库
/// </summary>
/// <param name="types"></param>
/// <param name="services"></param>
public static void RegisterAllRepo(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)

View File

@ -9,19 +9,29 @@ using LFlow.Home.Services;
using Microsoft.Extensions.DependencyInjection;
namespace LFlow.Home;
/// <summary>
/// 首页模块
/// </summary>
public class HomeModule : IModule
{
/// <summary>
/// 配置模块
/// </summary>
/// <param name="services">启动前的IServiceCollection</param>
public void ConfigureModule(IServiceCollection services)
{
// 将HomeModel注册到CodeFirst将会在程序启动后自动创建表
CodeFirst.AddType(typeof(HomeModel));
// 注册服务、仓储、模型
var assembly = Assembly.GetAssembly(typeof(HomeService))!;
var types = assembly.GetTypes().ToList();
RegisterModule.RegisterAllService(types, services);
RegisterModule.RegisterAllRepo(types, services);
RegisterModule.RegisterAllModule(types, services);
RegisterModule.RegisterAllModel(types, services);
// 添加控制器
services.AddControllers().AddApplicationPart(assembly);
Console.WriteLine("HomeModule ConfigureModule");

View File

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

View File

@ -10,15 +10,29 @@ using Serilog;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Home.Services;
/// <summary>
/// 服务直接作为控制器
/// </summary>
/// <param name="repo"></param>
/// <param name="logger"></param>
public class HomeService(IRepo<HomeModel, string> repo, ILogger logger) : BaseController, IHomeService<HomeDto?, string>
{
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public HomeDto? DeleteById(string id)
{
var result = repo.Delete(id);
return Mapper.Map<HomeDto>(result);
}
/// <summary>
/// 获取
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public HomeDto? GetById(string id)
{
@ -26,12 +40,23 @@ public class HomeService(IRepo<HomeModel, string> repo, ILogger logger) : BaseCo
var result = repo.Get(id);
return Mapper.Map<HomeDto>(result);
}
/// <summary>
/// 保存 (修改或者新增,按主键判断)
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public HomeDto? Save(HomeDto entity)
{
var result = repo.SaveOrUpdate(Mapper.Map<HomeModel>(entity), false);
return Mapper.Map<HomeDto>(result);
}
/// <summary>
/// 搜索
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
[HttpGet]
public List<HomeDto>? Search(HomeDto whereObj)
{

View File

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

View File

@ -0,0 +1,12 @@
namespace LFlow.VersionManagement.Enums;
/// <summary>
/// 更新目标类型
/// </summary>
public enum UpgradeTargetType
{
// 鼎捷插件
SWI = 1,
// XH工具箱
XH_TOOL = 2,
}

View File

@ -0,0 +1,12 @@
namespace LFlow.VersionManagement.Enums;
/// <summary>
/// 更新通道
/// </summary>
public enum VersionChannel
{
// 正式
Official = 1,
// 预览
Preview = 2
}

View File

@ -0,0 +1,14 @@
namespace LFlow.VersionManagement.Enums;
/// <summary>
/// 更新类型
/// </summary>
public enum VersionType
{
// 优化
Optimize = 1,
// 新增
Add = 2,
// 修复
Fix = 3
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>../LFlow_Bin/Services/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controller\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,89 @@
using LFlow.Base.Interfaces;
using LFlow.VersionManagement.Enums;
namespace LFlow.VersionManagement.Model;
public class VersionDto : IModel
{
/// <summary>
/// ID
/// </summary>
public string? ID
{
get;
set;
}
/// <summary>
/// 版本号 eg:1.0.0.1
/// </summary>
public string? CurrentVersion
{
get; set;
}
/// <summary>
/// 更新说明
/// </summary>
public string? Description
{
get; set;
}
public DateTime LastPublishTime
{
get; set;
}
/// <summary>
/// 下载地址
/// </summary>
public string? DownloadUrl
{
get; set;
}
/// <summary>
/// 文件名
/// </summary>
public string? FileName
{
get; set;
}
/// <summary>
/// 文件大小
/// </summary>
public string? FileSize
{
get; set;
}
/// <summary>
/// MD5 校验码
/// </summary>
public string? Md5
{
get; set;
}
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsRequired
{
get; set;
}
/// <summary>
/// 更新通道
/// </summary>
public VersionChannel VersionChannel
{
get; set;
}
/// <summary>
/// 更新目标类型
/// </summary>
public UpgradeTargetType UpgradeTargetType
{
get; set;
}
/// <summary>
/// 更新类型
/// </summary>
public VersionType VersionType
{
get; set;
}
}

View File

@ -0,0 +1,97 @@
using LFlow.Base.Interfaces;
using LFlow.VersionManagement.Enums;
using SqlSugar;
namespace LFlow.VersionManagement.Model;
/// <summary>
/// 版本信息
/// </summary>
[SugarTable("T_P_VERSION")]
[Serializable]
public class VersionModel : IDataModel
{
/// <summary>
/// ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public string ID
{
get;
set;
}
/// <summary>
/// 版本号 eg:1.0.0.1
/// </summary>
public string? CurrentVersion
{
get; set;
}
/// <summary>
/// 更新说明
/// </summary>
public string? Description
{
get; set;
}
public DateTime LastPublishTime
{
get; set;
}
/// <summary>
/// 下载地址
/// </summary>
public string? DownloadUrl
{
get; set;
}
/// <summary>
/// 文件名
/// </summary>
public string? FileName
{
get; set;
}
/// <summary>
/// 文件大小
/// </summary>
public string? FileSize
{
get; set;
}
/// <summary>
/// MD5 校验码
/// </summary>
public string? Md5
{
get; set;
}
/// <summary>
/// 是否强制更新
/// </summary>
public bool IsRequired
{
get; set;
}
/// <summary>
/// 更新通道
/// </summary>
public VersionChannel VersionChannel
{
get; set;
}
/// <summary>
/// 更新目标类型
/// </summary>
public UpgradeTargetType UpgradeTargetType
{
get; set;
}
/// <summary>
/// 更新类型
/// </summary>
public VersionType VersionType
{
get; set;
}
}

View File

@ -0,0 +1,23 @@
using LFlow.Base.Default;
using LFlow.Base.Utils;
using LFlow.VersionManagement.Model;
using SqlSugar;
namespace LFlow.VersionManagement.Repository;
public class VersionManagementRepo(ISqlSugarClient db) : DefaultCurdRepo<VersionModel, string>(db)
{
public override List<VersionModel> Search(VersionModel whereObj)
{
return db.Queryable<VersionModel>()
.Where(whereObj.ToWhereExp())
.ToList();
}
public override List<string> WhereSearchId(VersionModel whereObj)
{
return db.Queryable<VersionModel>()
.Where(whereObj.ToWhereExp())
.Where(x => x.ID != null)
.Select(x => x.ID)
.ToList();
}
}

View File

@ -0,0 +1,7 @@
using LFlow.Base.Interfaces;
using LFlow.VersionManagement.Model;
namespace LFlow.VersionManagement.Service;
public interface IVersionManagementService : IService<VersionDto>
{
}

View File

@ -0,0 +1,60 @@
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.VersionManagement.Model;
using Mapster;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.VersionManagement.Service;
/// <summary>
/// 版本管理服务
/// </summary>
public class VersionManagementService : BaseController, IVersionManagementService
{
private readonly IRepo<VersionModel, string> _repo;
public VersionManagementService(IRepo<VersionModel, string> repo)
{
_repo = repo;
}
[HttpDelete]
public int DeleteById(string id)
{
return _repo.DeleteById(id);
}
[HttpGet]
public PagedApiResult<List<VersionDto>> GetAll(int pageIndex, int pageSize)
{
var total = 0;
var result = _repo.GetAll(pageIndex, pageSize, ref total);
return new PagedApiResult<List<VersionDto>>
{
Data = Mapper.Map<List<VersionDto>>(result),
PageIndex = pageIndex,
PageSize = pageSize,
Message = "获取成功",
Success = true,
TotalCount = total
};
}
[HttpGet]
public VersionDto GetById(string id)
{
return _repo.Get(id).Adapt<VersionDto>();
}
[HttpPost]
public VersionDto Save(VersionDto entity, bool isUpdate)
{
return _repo.SaveOrUpdate(entity.Adapt<VersionModel>(), isUpdate).Adapt<VersionDto>();
}
[HttpPost]
public List<VersionDto> Search(VersionDto whereObj)
{
return _repo.Search(whereObj.Adapt<VersionModel>()).Adapt<List<VersionDto>>();
}
[HttpPost]
public List<string> SearchAllId(VersionDto whereObj)
{
return _repo.WhereSearchId(whereObj.Adapt<VersionModel>());
}
}

View File

@ -0,0 +1,22 @@
using System.Reflection;
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.VersionManagement.Model;
using Microsoft.Extensions.DependencyInjection;
namespace LFlow.User;
public class VersionManagementModule : IModule
{
public void ConfigureModule(IServiceCollection services)
{
CodeFirst.AddType(typeof(VersionModel));
var assembly = Assembly.GetAssembly(typeof(VersionManagementModule))!;
var types = assembly.GetTypes().ToList();
RegisterModule.RegisterAllService(types, services);
RegisterModule.RegisterAllRepo(types, services);
RegisterModule.RegisterAllModel(types, services);
services.AddControllers().AddApplicationPart(assembly);
Console.WriteLine("UserModule ConfigureModule");
}
}

View File

@ -3,11 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.Base", "LFlow.Base\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.User", "LFlow.User\LFlow.User.csproj", "{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -19,14 +17,10 @@ Global
{C581AFB2-50BA-4357-AD0A-AF287194837D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C581AFB2-50BA-4357-AD0A-AF287194837D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C581AFB2-50BA-4357-AD0A-AF287194837D}.Release|Any CPU.Build.0 = Release|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.Build.0 = Release|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.Build.0 = Release|Any CPU
{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

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"
}
]
}

View File

@ -1,40 +0,0 @@
using System;
using System.Reflection;
using LFlow.Base.Interfaces;
namespace LFlow.Base.Default;
/// <summary>
/// 默认的CURD操作
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
public abstract class DefaultCurd<T, K> where T : IModel, IDataModel
{
private readonly IRepo<T, K> _repo;
public DefaultCurd(IRepo<T, K> repo)
{
_repo = repo;
}
public virtual T Add(T model)
{
return _repo.SaveOrUpdate(model, false);
}
public virtual int Delete(K id)
{
return _repo.Delete(id);
}
public virtual T Update(T model)
{
return _repo.SaveOrUpdate(model, true);
}
public virtual T Get(K id)
{
return _repo.Get(id);
}
public virtual List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal)
{
return _repo.GetAll(pageIndex, pageSize, ref pageTotal);
}
public abstract List<T> GetWhere(T WhereObject);
}

View File

@ -1,50 +0,0 @@
using System;
using LFlow.Base.Interfaces;
using SqlSugar;
namespace LFlow.Base.Default;
public abstract class DefaultCurdRepo<T, K> : IRepo<T, K> where T : class, IDataModel, new()
{
private readonly ISqlSugarClient _client;
public DefaultCurdRepo(ISqlSugarClient client)
{
_client = client;
}
public virtual int Delete(K id)
{
if (Get(id) != null)
{
return _client.Deleteable<T>().In(id).ExecuteCommand();
}
else
{
throw new Exception("删除的对象不存在");
}
}
public virtual T Get(K id)
{
return _client.Queryable<T>().InSingle(id);
}
public List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal)
{
return _client.Queryable<T>().ToPageList(pageIndex, pageSize, ref pageTotal);
}
public virtual T SaveOrUpdate(T entity, bool isUpdate)
{
if (isUpdate)
{
_client.Updateable(entity).ExecuteCommand();
}
else
{
_client.Insertable(entity).ExecuteCommand();
}
return entity;
}
public abstract List<T> Search(T whereObj);
public abstract List<K> WhereSearchId(T whereObj);
}

View File

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

View File

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

View File

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