增加在线管理模块

This commit is contained in:
lihanbo 2024-10-19 08:33:19 +08:00
parent 0a217e7b50
commit 250ba4a01a
11 changed files with 171 additions and 4 deletions

Binary file not shown.

View File

@ -0,0 +1,23 @@
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.OnlineManegement.Model;
using LFlow.OnlineManegement.Service;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.OnlineManegement.Controller;
public class OnlineManagementController(IOnlineManagementService service) : BaseController
{
[HttpGet]
public PagedApiResult<List<OnlineDto>> ListAll(int pageIndex, int pageSize)
{
int dataTotal = 0;
var result = service.GetAllOnlineUser(pageIndex, pageSize, ref dataTotal);
return PagedApiResult<List<OnlineDto>>.SuccessResult(result, dataTotal, pageIndex, pageSize);
}
[HttpPost]
public ApiResult<OnlineDto> OnlineRegistered(OnlineDto onlineInfo)
{
return ApiResult<OnlineDto>.SuccessResult(service.OnlineRegistered(onlineInfo));
}
}

View File

@ -0,0 +1,17 @@
<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>
</Project>

View File

@ -0,0 +1,15 @@
using LFlow.Base.Interfaces;
namespace LFlow.OnlineManegement.Model
{
public class OnlineDto : IModel
{
public string? ID { get; set; }
public string? HostName { get; set; }
public string? IPAddress { get; set; }
public string? MacAddress { get; set; }
public string? OS { get; set; }
public string? LastOnlineTime { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using LFlow.Base.Interfaces;
using SqlSugar;
namespace LFlow.OnlineManegement.Model
{
[SugarTable("T_U_ONLINE")]
public class OnlineModel : IDataModel
{
[SugarColumn(IsPrimaryKey = true)]
public string ID { get; set; }
public string HostName { get; set; }
public string IPAddress { get; set; }
public string MacAddress { get; set; }
public string OS { get; set; }
public string LastOnlineTime { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.OnlineManegement.Model;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System.Reflection;
namespace LFlow.OnlineManegement
{
public class OnlineManegementModule : IModule
{
public void ConfigureModule(IServiceCollection services)
{
// 将模型添加到需要初始化数据库表的队列中
CodeFirst.AddType(typeof(OnlineModel));
// 获取当前程序集
var assembly = Assembly.GetAssembly(typeof(OnlineManegementModule))!;
var types = assembly.GetTypes().ToList();
//注册服务
RegisterModule.RegisterAllService(types, services);
//注册仓储
RegisterModule.RegisterAllRepo(types, services);
//RegisterModule.RegisterAllModel(types, services);
services.AddControllers().AddApplicationPart(assembly);
Log.Logger?.Information("OnlineManegementModule ConfigureModule done");
}
}
}

View File

@ -0,0 +1,10 @@
using LFlow.Base.Default;
using LFlow.OnlineManegement.Model;
using SqlSugar;
namespace LFlow.OnlineManegement.Repository
{
public class OnlineManagementRepo(ISqlSugarClient db) : DefaultCurdRepo<OnlineModel, string>(db)
{
}
}

View File

@ -0,0 +1,10 @@
using LFlow.Base.Interfaces;
using LFlow.OnlineManegement.Model;
namespace LFlow.OnlineManegement.Service;
public interface IOnlineManagementService : IService//<VersionDto>
{
List<OnlineDto> GetAllOnlineUser(int pageIndex, int pageSize, ref int dataTotal);
OnlineDto OnlineRegistered(OnlineDto onlineInfo);
}

View File

@ -0,0 +1,38 @@
using LFlow.Base.Interfaces;
using LFlow.OnlineManegement.Model;
using Mapster;
namespace LFlow.OnlineManegement.Service;
/// <summary>
/// 在线管理服务
/// </summary>
public class OnlineManagementService(IRepo<OnlineModel, string> _repo) : IOnlineManagementService
{
public List<OnlineDto> GetAllOnlineUser(int pageIndex, int pageSize, ref int dataTotal)
{
var result = _repo.GetAll(pageIndex, pageSize, ref dataTotal).Adapt<List<OnlineDto>>();
return result;
}
public OnlineDto OnlineRegistered(OnlineDto onlineInfo)
{
bool isUpdate = false;
if (string.IsNullOrEmpty(onlineInfo.ID))
{
onlineInfo.ID = Guid.NewGuid().ToString();
}
else
{
if (_repo.Get(onlineInfo.ID) == null)
{
isUpdate = false;
}
else
{
isUpdate = true;
}
}
return _repo.SaveOrUpdate(onlineInfo.Adapt<OnlineModel>(), isUpdate).Adapt<OnlineDto>();
}
}

View File

@ -1,8 +1,9 @@
using System.Reflection;
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.VersionManagement.Model;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System.Reflection;
namespace LFlow.User;
@ -15,8 +16,9 @@ public class VersionManagementModule : IModule
var types = assembly.GetTypes().ToList();
RegisterModule.RegisterAllService(types, services);
RegisterModule.RegisterAllRepo(types, services);
RegisterModule.RegisterAllModel(types, services);
//RegisterModule.RegisterAllModel(types, services);
services.AddControllers().AddApplicationPart(assembly);
Console.WriteLine("UserModule ConfigureModule");
Log.Logger?.Information("VersionManagementModule ConfigureModule done");
//Console.WriteLine("UserModule ConfigureModule");
}
}

View File

@ -5,7 +5,9 @@ VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
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.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.OnlineManegement", "LFlow.OnlineManegement\LFlow.OnlineManegement.csproj", "{E849310F-64AD-453A-A2AA-557731508BF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{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
{E849310F-64AD-453A-A2AA-557731508BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E849310F-64AD-453A-A2AA-557731508BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE