mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-20 18:58:16 +08:00
refactor: ♻️ 框架&业务代码分离 (#185)
Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Api;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Api;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Cache;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Cache;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Captcha;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Captcha;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Config;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Config;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dept;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dept;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dev;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dev;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Catalog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.JobRecord;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.JobRecord;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.LoginLog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.LoginLog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Menu;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Menu;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.RequestLogDetail;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.RequestLogDetail;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.RequestLog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.RequestLog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Role;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgDept;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgDept;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgFlag;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsg;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsg;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgFlag;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgRole;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgUser;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgUser;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Tool;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Tool;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.User;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.User;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.VerifyCode;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
@ -1,11 +0,0 @@
|
||||
using NetAdmin.Domain.Dto.Tpl.Example;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Tpl;
|
||||
|
||||
/// <summary>
|
||||
/// 示例模块
|
||||
/// </summary>
|
||||
public interface IExampleModule : ICrudModule<CreateExampleReq, QueryExampleRsp // 创建类型
|
||||
, QueryExampleReq, QueryExampleRsp // 查询类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -1,9 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<DefineConstants>DBTYPE_SQLITE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)/build/code.quality.props"/>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../NetAdmin.Application/NetAdmin.Application.csproj"/>
|
||||
<ProjectReference Include="../NetAdmin.SysComponent.Domain/NetAdmin.SysComponent.Domain.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,9 +1,11 @@
|
||||
global using NetAdmin.Application.Modules;
|
||||
global using NetAdmin.Application.Modules;
|
||||
global using NetAdmin.Application.Repositories;
|
||||
global using NetAdmin.Application.Services;
|
||||
global using NetAdmin.Domain.DbMaps.Sys;
|
||||
global using NetAdmin.Domain.Dto.Dependency;
|
||||
global using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
global using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
global using NetAdmin.SysComponent.Domain.DbMaps.Sys;
|
||||
global using NetAdmin.SysComponent.Domain.Dto.Sys;
|
||||
global using NetAdmin.SysComponent.Domain.Enums.Sys;
|
||||
global using DynamicFilterInfo = NetAdmin.Domain.Dto.DynamicFilterInfo;
|
||||
global using DynamicFilterOperators = NetAdmin.Domain.Enums.DynamicFilterOperators;
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Api;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Api;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using NetAdmin.Domain.Dto.Sys.Cache;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Cache;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Captcha;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Captcha;
|
||||
using SixLabors.ImageSharp;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Config;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Config;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Api;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Api;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Catalog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.JobRecord;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Job;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgFlag;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.User;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.User;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.VerifyCode;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dept;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dept;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Api;
|
||||
using NetAdmin.Domain.Dto.Sys.Dev;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Api;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dev;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
@ -20,33 +20,32 @@ public sealed class DevService(IApiService apiService) : ServiceBase<DevService>
|
||||
public async Task GenerateCsCodeAsync(GenerateCsCodeReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
|
||||
// 模块类型(Sys、Adm、等)
|
||||
var moduleType = Enum.GetName(req.Type)!;
|
||||
var @namespace = req.Type.ToString();
|
||||
int index;
|
||||
var typeAbbr = req.Type[(index = req.Type.LastIndexOf('.') + 1)..(index + 3)];
|
||||
|
||||
// 模板层目录
|
||||
var tplHostDir = GetDir("SysComponent.Host");
|
||||
var tplCacheDir = GetDir("SysComponent.Cache");
|
||||
var tplAppDir = GetDir("SysComponent.Application");
|
||||
var tplHostDir = GetDir("NetAdmin.Host");
|
||||
var tplCacheDir = GetDir("NetAdmin.Cache");
|
||||
var tplDataDir = GetDir("NetAdmin.Domain");
|
||||
var tplAppDir = GetDir("NetAdmin.Application");
|
||||
|
||||
// 主机层目录
|
||||
var hostControllerDir = Path.Combine(GetDir($"{moduleType}.Host"), "Controllers", moduleType[..3]);
|
||||
var hostControllerDir = Path.Combine(GetDir($"{req.Type}.Host"), "Controllers", typeAbbr);
|
||||
|
||||
// 缓存层目录
|
||||
var cacheDir = Path.Combine(GetDir($"{moduleType}.Cache"), moduleType[..3]);
|
||||
var cacheDependencyDir = Path.Combine(cacheDir, "Dependency");
|
||||
var cacheDir = Path.Combine(GetDir($"{req.Type}.Cache"), typeAbbr);
|
||||
var cacheDependencyDir = Path.Combine(cacheDir, "Dependency");
|
||||
|
||||
// 业务逻辑层目录
|
||||
var appDir = GetDir($"{moduleType}.Application");
|
||||
var appModulesDir = Path.Combine(appDir, "Modules", moduleType[..3]);
|
||||
var appServicesDir = Path.Combine(appDir, "Services", moduleType[..3]);
|
||||
var appDir = GetDir($"{req.Type}.Application");
|
||||
var appModulesDir = Path.Combine(appDir, "Modules", typeAbbr);
|
||||
var appServicesDir = Path.Combine(appDir, "Services", typeAbbr);
|
||||
var appServicesDependencyDir = Path.Combine(appServicesDir, "Dependency");
|
||||
|
||||
// 数据契约层目录
|
||||
var dataDir = GetDir("NetAdmin.Domain");
|
||||
var dtoDir = Path.Combine(dataDir, "Dto", moduleType[..3], req.ModuleName);
|
||||
var entityDir = Path.Combine(dataDir, "DbMaps", moduleType[..3]);
|
||||
var dataDir = GetDir($"{req.Type}.Domain");
|
||||
var dtoDir = Path.Combine(dataDir, "Dto", typeAbbr, req.ModuleName);
|
||||
var entityDir = Path.Combine(dataDir, "DbMaps", typeAbbr);
|
||||
|
||||
// 创建缺少的目录
|
||||
CreateDir(hostControllerDir, cacheDir, cacheDependencyDir, appDir, appModulesDir, appServicesDir, appServicesDependencyDir, dataDir, dtoDir
|
||||
@ -54,52 +53,52 @@ public sealed class DevService(IApiService apiService) : ServiceBase<DevService>
|
||||
|
||||
// Controller
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplHostDir, "Controllers", "Tpl", "ExampleController.cs")
|
||||
, Path.Combine(hostControllerDir, $"{req.ModuleName}Controller.cs"), @namespace)
|
||||
, Path.Combine(hostControllerDir, $"{req.ModuleName}Controller.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// CreateReq
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "Dto", "Tpl", "Example", "CreateExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Create{req.ModuleName}Req.cs"), @namespace)
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplDataDir, "Dto", "Tpl", "Example", "CreateExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Create{req.ModuleName}Req.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// QueryReq
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "Dto", "Tpl", "Example", "QueryExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Query{req.ModuleName}Req.cs"), @namespace)
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplDataDir, "Dto", "Tpl", "Example", "QueryExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Query{req.ModuleName}Req.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// QueryRsp
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "Dto", "Tpl", "Example", "QueryExampleRsp.cs")
|
||||
, Path.Combine(dtoDir, $"Query{req.ModuleName}Rsp.cs"), @namespace)
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplDataDir, "Dto", "Tpl", "Example", "QueryExampleRsp.cs")
|
||||
, Path.Combine(dtoDir, $"Query{req.ModuleName}Rsp.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// ICache
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplCacheDir, "Tpl", "Dependency", "IExampleCache.cs")
|
||||
, Path.Combine(cacheDependencyDir, $"I{req.ModuleName}Cache.cs"), @namespace)
|
||||
, Path.Combine(cacheDependencyDir, $"I{req.ModuleName}Cache.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// Cache
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplCacheDir, "Tpl", "ExampleCache.cs"), Path.Combine(cacheDir, $"{req.ModuleName}Cache.cs")
|
||||
, @namespace)
|
||||
, typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// IModule
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplAppDir, "Modules", "Tpl", "IExampleModule.cs")
|
||||
, Path.Combine(appModulesDir, $"I{req.ModuleName}Module.cs"), @namespace)
|
||||
, Path.Combine(appModulesDir, $"I{req.ModuleName}Module.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// IService
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplAppDir, "Services", "Tpl", "Dependency", "IExampleService.cs")
|
||||
, Path.Combine(appServicesDependencyDir, $"I{req.ModuleName}Service.cs"), @namespace)
|
||||
, Path.Combine(appServicesDependencyDir, $"I{req.ModuleName}Service.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// Service
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplAppDir, "Services", "Tpl", "ExampleService.cs")
|
||||
, Path.Combine(appServicesDir, $"{req.ModuleName}Service.cs"), @namespace)
|
||||
, Path.Combine(appServicesDir, $"{req.ModuleName}Service.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// Entity
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "DbMaps", "Tpl", "Tpl_Example.cs")
|
||||
, Path.Combine(entityDir, $"{moduleType[..3]}_{req.ModuleName}.cs"), @namespace)
|
||||
await WriteCodeFileAsync(req, Path.Combine(tplDataDir, "DbMaps", "Tpl", "Tpl_Example.cs")
|
||||
, Path.Combine(entityDir, $"{typeAbbr}_{req.ModuleName}.cs"), typeAbbr)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@ -191,13 +190,10 @@ public sealed class DevService(IApiService apiService) : ServiceBase<DevService>
|
||||
return _projectDirs.First(x => x.EndsWith(key, true, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private static async Task WriteCodeFileAsync(GenerateCsCodeReq req, string tplFile, string writeFile, string @namespace = "SysComponent")
|
||||
private static async Task WriteCodeFileAsync(GenerateCsCodeReq req, string tplFile, string writeFile, string moduleAbbr)
|
||||
{
|
||||
var tplContent = await File.ReadAllTextAsync(tplFile).ConfigureAwait(false);
|
||||
tplContent = tplContent.Replace("Tpl", Enum.GetName(req.Type)![..3])
|
||||
.Replace("示例", req.ModuleRemark)
|
||||
.Replace("Example", req.ModuleName)
|
||||
.Replace("NetAdmin.SysComponent", $"NetAdmin.{@namespace}");
|
||||
tplContent = tplContent.Replace("Tpl", moduleAbbr).Replace("示例", req.ModuleRemark).Replace("Example", req.ModuleName);
|
||||
|
||||
await File.WriteAllTextAsync(writeFile, tplContent).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Catalog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.JobRecord;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
using Cronos;
|
||||
using FreeSql.Internal;
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.Domain.Enums.Sys;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Infrastructure.Constant;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
@ -299,13 +298,13 @@ public sealed class JobService(BasicRepository<Sys_Job, long> rpo, IJobRecordSer
|
||||
{
|
||||
var ret1 = await UpdateAsync( // 运行中,运行时间超过超时设定;置为空闲状态
|
||||
new Sys_Job { Status = JobStatues.Idle }, [nameof(Sys_Job.Status)], null
|
||||
, a => a.Status == JobStatues.Running && a.LastExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB), null, true)
|
||||
, a => a.Status == JobStatues.Running && a.LastExecTime < DateTime.Now.AddSeconds(-SysNumbers.SECS_TIMEOUT_JOB), null, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var ret2 = await UpdateAsync( // 空闲中,下次执行时间在当前时间减去超时时间以前;将下次执行时间调整到现在
|
||||
new Sys_Job { NextExecTime = DateTime.Now, NextTimeId = DateTime.Now.TimeUnixUtc() }
|
||||
, [nameof(Sys_Job.NextExecTime), nameof(Sys_Job.NextTimeId)], null
|
||||
, a => a.Status == JobStatues.Idle && a.NextExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB), null, true)
|
||||
, [nameof(Sys_Job.NextExecTime), nameof(Sys_Job.NextTimeId)], null
|
||||
, a => a.Status == JobStatues.Idle && a.NextExecTime < DateTime.Now.AddSeconds(-SysNumbers.SECS_TIMEOUT_JOB), null, true)
|
||||
.ConfigureAwait(false);
|
||||
return ret1 + ret2;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.LoginLog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.LoginLog;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Menu;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Menu;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.RequestLogDetail;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.RequestLogDetail;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.LoginLog;
|
||||
using NetAdmin.Domain.Dto.Sys.RequestLog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.LoginLog;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.RequestLog;
|
||||
using NetAdmin.SysComponent.Infrastructure.Constant;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
@ -40,7 +40,7 @@ public sealed class RequestLogService(BasicRepository<Sys_RequestLog, long> rpo,
|
||||
var ret = await Rpo.InsertAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 插入登录日志
|
||||
if (req.ApiPathCrc32 == Chars.FLG_PATH_API_SYS_USER_LOGIN_BY_PWD.Crc32()) {
|
||||
if (req.ApiPathCrc32 == SysChars.FLG_PATH_API_SYS_USER_LOGIN_BY_PWD.Crc32()) {
|
||||
_ = await loginLogService.CreateAsync(req.Adapt<CreateLoginLogReq>()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Role;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgDept;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgDept;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgFlag;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgRole;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
using NetAdmin.Domain.Contexts;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsg;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.Domain.Dto.Sys.User;
|
||||
using NetAdmin.Domain.Enums.Sys;
|
||||
using NetAdmin.SysComponent.Domain.Contexts;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsg;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.User;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
@ -295,7 +294,7 @@ public sealed class SiteMsgService(BasicRepository<Sys_SiteMsg, long> rpo, Conte
|
||||
|
||||
return Rpo.Orm.Select<Sys_SiteMsg, Sys_User, Sys_SiteMsgDept, Sys_SiteMsgRole, Sys_SiteMsgUser, Sys_SiteMsgFlag>()
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.LeftJoin((a, b, _, _, _, _) => a.CreatedUserId == b.Id)
|
||||
.LeftJoin((a, _, c, _, _, _) => a.Id == c.SiteMsgId)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgUser;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.SiteMsgUser;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Tool;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Tool;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using NetAdmin.Domain.Contexts;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Contexts;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Infrastructure.Constant;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
@ -178,10 +179,11 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp
|
||||
{
|
||||
#pragma warning disable CA1305,IDE0072
|
||||
var ret = Rpo.Orm.Select<Sys_UserProfile, Sys_DicContent, Sys_DicContent, Sys_DicContent, Sys_DicContent>()
|
||||
.LeftJoin((a, b, _, __, ___) => a.NationArea.ToString() == b.Value && b.CatalogId == Numbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, _, c, __, ___) => a.CompanyArea.ToString() == c.Value && c.CatalogId == Numbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, _, __, d, ___) => a.HomeArea.ToString() == d.Value && d.CatalogId == Numbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, _, __, ___, e) => a.EmergencyContactArea.ToString() == e.Value && e.CatalogId == Numbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, b, _, __, ___) => a.NationArea.ToString() == b.Value && b.CatalogId == SysNumbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, _, c, __, ___) => a.CompanyArea.ToString() == c.Value && c.CatalogId == SysNumbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin((a, _, __, d, ___) => a.HomeArea.ToString() == d.Value && d.CatalogId == SysNumbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.LeftJoin(
|
||||
(a, _, __, ___, e) => a.EmergencyContactArea.ToString() == e.Value && e.CatalogId == SysNumbers.ID_DIC_CATALOG_GEO_AREA)
|
||||
.WhereDynamicFilter(req.DynamicFilter);
|
||||
|
||||
return req.Order switch {
|
||||
|
@ -1,9 +1,9 @@
|
||||
using NetAdmin.Domain.Attributes.DataValidation;
|
||||
using NetAdmin.Domain.Contexts;
|
||||
using NetAdmin.Domain.Dto.Sys.User;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.Domain.Events.Sys;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.User;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.SysComponent.Domain.Events.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.Domain.Enums.Sys;
|
||||
using NetAdmin.Domain.Events.Sys;
|
||||
using NetAdmin.SysComponent.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.SysComponent.Domain.Events.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
using NetAdmin.SysComponent.Application.Modules.Tpl;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Tpl.Dependency;
|
||||
|
||||
/// <summary>
|
||||
/// 示例服务
|
||||
/// </summary>
|
||||
public interface IExampleService : IService, IExampleModule;
|
@ -1,126 +0,0 @@
|
||||
using NetAdmin.Domain.DbMaps.Tpl;
|
||||
using NetAdmin.Domain.Dto.Tpl.Example;
|
||||
using NetAdmin.SysComponent.Application.Services.Tpl.Dependency;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Tpl;
|
||||
|
||||
/// <inheritdoc cref="IExampleService" />
|
||||
public sealed class ExampleService(BasicRepository<Tpl_Example, long> rpo) //
|
||||
: RepositoryService<Tpl_Example, long, IExampleService>(rpo), IExampleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = 0;
|
||||
|
||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
foreach (var item in req.Items) {
|
||||
ret += await DeleteAsync(item).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<long> CountAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryExampleRsp> CreateAsync(CreateExampleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await Rpo.InsertAsync(req).ConfigureAwait(false);
|
||||
return ret.Adapt<QueryExampleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> DeleteAsync(DelReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return Rpo.DeleteAsync(a => a.Id == req.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IActionResult> ExportAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return ExportAsync<QueryExampleReq, QueryExampleRsp>(QueryInternal, req, Ln.示例导出);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryExampleRsp> GetAsync(QueryExampleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(new QueryReq<QueryExampleReq> { Filter = req, Order = Orders.None }).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<QueryExampleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PagedQueryRsp<QueryExampleRsp>> PagedQueryAsync(PagedQueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new PagedQueryRsp<QueryExampleRsp>(req.Page, req.PageSize, total, list.Adapt<IEnumerable<QueryExampleRsp>>());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<QueryExampleRsp>> QueryAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryExampleRsp>>();
|
||||
}
|
||||
|
||||
private ISelect<Tpl_Example> QueryInternal(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||
switch (req.Order) {
|
||||
case Orders.None:
|
||||
return ret;
|
||||
case Orders.Random:
|
||||
return ret.OrderByRandom();
|
||||
}
|
||||
|
||||
ret = ret.OrderByPropertyNameIf(req.Prop?.Length > 0, req.Prop, req.Order == Orders.Ascending);
|
||||
if (!req.Prop?.Equals(nameof(req.Filter.Id), StringComparison.OrdinalIgnoreCase) ?? true) {
|
||||
ret = ret.OrderByDescending(a => a.Id);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user