增加视图模型引擎模块
This commit is contained in:
@@ -140,6 +140,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tnb.PerMgr.Entities", "PerM
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tnb.PerMgr.Interfaces", "PerMgr\Tnb.PerMgr.Interfaces\Tnb.PerMgr.Interfaces.csproj", "{F3656494-27D3-4BD7-B831-8D909DFBD7B9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tnb.VmodelEngine", "visualdev\Tnb.Vmodel\Tnb.VmodelEngine.csproj", "{437AE0E4-66AE-4627-9ACD-29F5BB9E6642}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -338,6 +340,10 @@ Global
|
||||
{F3656494-27D3-4BD7-B831-8D909DFBD7B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3656494-27D3-4BD7-B831-8D909DFBD7B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F3656494-27D3-4BD7-B831-8D909DFBD7B9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{437AE0E4-66AE-4627-9ACD-29F5BB9E6642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{437AE0E4-66AE-4627-9ACD-29F5BB9E6642}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{437AE0E4-66AE-4627-9ACD-29F5BB9E6642}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{437AE0E4-66AE-4627-9ACD-29F5BB9E6642}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -390,6 +396,7 @@ Global
|
||||
{D41946CF-09C6-4CA4-A1F4-42E7E1538BF7} = {74AB6486-1090-4CC9-9D1A-F1245E3ECFC3}
|
||||
{42AD083D-D199-4B09-ADD8-89251011C959} = {74AB6486-1090-4CC9-9D1A-F1245E3ECFC3}
|
||||
{F3656494-27D3-4BD7-B831-8D909DFBD7B9} = {74AB6486-1090-4CC9-9D1A-F1245E3ECFC3}
|
||||
{437AE0E4-66AE-4627-9ACD-29F5BB9E6642} = {161853F8-ADB9-4281-B706-E2E23D40D0F1}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {646DDD1C-F143-42C2-894F-F5C7B3A0CE74}
|
||||
|
||||
@@ -30,37 +30,43 @@ public static class ConfigureSqlSugarExtensions
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
IsAutoRemoveDataCache = true // 自动清理缓存
|
||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
||||
IsAutoToUpper = false,
|
||||
//PgSqlIsAutoToLower = false,
|
||||
DisableNvarchar = true
|
||||
},
|
||||
});
|
||||
|
||||
services.AddSqlSugar(connectConfigList, client =>
|
||||
{
|
||||
connectConfigList.ForEach(config =>
|
||||
{
|
||||
var db = ((SqlSugarScope)client).GetConnectionScope((string)config.ConfigId);
|
||||
//connectConfigList.ForEach(config =>
|
||||
//{
|
||||
// var db = ((SqlSugarScope)client).GetConnectionScope((string)config.ConfigId);
|
||||
|
||||
// 设置超时时间
|
||||
db.Ado.CommandTimeOut = 30;
|
||||
//db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
//{
|
||||
// var oldColor = Console.ForegroundColor;
|
||||
// Console.ForegroundColor = ConsoleColor.Green;
|
||||
// var finalSql = UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars);
|
||||
// Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss.fff")}——SQL执行完成】{db.Ado.SqlExecutionTime.TotalMilliseconds} ms");
|
||||
// Console.WriteLine(finalSql);
|
||||
// Console.ForegroundColor = oldColor;
|
||||
// if (db.Ado.SqlExecutionTime.TotalMilliseconds > 3000)
|
||||
// {
|
||||
// Log.Warning($"慢查询: {db.Ado.SqlExecutionTime.TotalMilliseconds}ms, SQL: " + finalSql);
|
||||
// }
|
||||
// Console.WriteLine();
|
||||
//};
|
||||
//db.Aop.OnError = (ex) =>
|
||||
//{
|
||||
// Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||
//};
|
||||
});
|
||||
// // 设置超时时间
|
||||
// db.Ado.CommandTimeOut = 30;
|
||||
// db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
// {
|
||||
// var oldColor = Console.ForegroundColor;
|
||||
// Console.ForegroundColor = ConsoleColor.Green;
|
||||
// var finalSql = UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars);
|
||||
// Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss.fff")}——SQL执行完成】{db.Ado.SqlExecutionTime.TotalMilliseconds} ms");
|
||||
// if (db.Ado.SqlExecutionTime.TotalMilliseconds > 3000)
|
||||
// {
|
||||
// Log.Warning($"慢查询: {db.Ado.SqlExecutionTime.TotalMilliseconds}ms, SQL: " + finalSql);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine(finalSql);
|
||||
// Console.ForegroundColor = oldColor;
|
||||
// Console.WriteLine();
|
||||
// }
|
||||
// };
|
||||
// db.Aop.OnError = (ex) =>
|
||||
// {
|
||||
// Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||
// };
|
||||
//});
|
||||
});
|
||||
services.AddUnitOfWork<SqlSugarUnitOfWork>();
|
||||
services.AddConfigurableOptions<ConnectionStringsOptions>();
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
|
||||
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev\Tnb.VisualDev.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.Vmodel\Tnb.VmodelEngine.csproj" />
|
||||
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" />
|
||||
<ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -12,14 +12,14 @@ public class LoginInput
|
||||
/// <summary>
|
||||
/// 用户名.
|
||||
/// </summary>
|
||||
/// <example>13459475357</example>
|
||||
/// <example>admin</example>
|
||||
[Required(ErrorMessage = "用户名不能为空")]
|
||||
public string? account { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码.
|
||||
/// </summary>
|
||||
/// <example>e10adc3949ba59abbe56e057f20f883e</example>
|
||||
/// <example>f5252ff163e76623601a9a84d275c842</example>
|
||||
[Required(ErrorMessage = "密码不能为空")]
|
||||
public string? password { get; set; }
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace JNPF.Systems.Common;
|
||||
[Route("api")]
|
||||
public class TestService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<UserEntity> _repository;
|
||||
//private readonly ISqlSugarRepository<UserEntity> _repository;
|
||||
private readonly SqlSugarScope _sugar;
|
||||
private readonly IDataBaseManager _databaseService;
|
||||
|
||||
public TestService(ISqlSugarRepository<UserEntity> repository, IDataBaseManager databaseService)
|
||||
public TestService(ISqlSugarClient db, IDataBaseManager databaseService)
|
||||
{
|
||||
_repository = repository;
|
||||
_sugar = (SqlSugarScope)repository.AsSugarClient();
|
||||
//_repository = repository;
|
||||
_sugar = (SqlSugarScope)db;
|
||||
_databaseService = databaseService;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TestService : IDynamicApiController, ITransient
|
||||
//var xx = App.HttpContext.Request.Host.ToString();
|
||||
//var sql = "SELECT TOP 1 [F_PARENTID],[F_PROCESSID],[F_ENCODE],[F_FULLNAME],[F_FLOWURGENT],[F_FLOWID],[F_FLOWCODE],[F_FLOWNAME],[F_FLOWTYPE],[F_FLOWCATEGORY],[F_FLOWFORM],[F_FLOWFORMCONTENTJSON],[F_FLOWTEMPLATEJSON],[F_FLOWVERSION],[F_STARTTIME],[F_ENDTIME],[F_THISSTEP],[F_THISSTEPID],[F_GRADE],[F_STATUS],[F_COMPLETION],[F_DESCRIPTION],[F_SORTCODE],[F_ISASYNC],[F_ISBATCH],[F_TASKNODEID],[F_TEMPLATEID],[F_REJECTDATAID],[F_DELEGATEUSER],[F_CREATORTIME],[F_CREATORUSERID],[F_ENABLEDMARK],[F_LastModifyTime],[F_LastModifyUserId],[F_DeleteMark],[F_DeleteTime],[F_DeleteUserId],[F_Id] FROM [FLOW_TASK] WHERE (( [F_DeleteMark] IS NULL ) AND ( [F_Id] = N'367536153122855173' ))";
|
||||
//var darta = _sqlSugarRepository.AsSugarClient().Ado.SqlQuery<dynamic>(sql);
|
||||
var data = await _repository.GetFirstAsync(a => true);
|
||||
var data = await _sugar.Queryable<UserEntity>().FirstAsync(a => true);
|
||||
var json = App.GetService<IJsonSerializerProvider>();
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace JNPF.TaskScheduler.Entitys;
|
||||
/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com)
|
||||
/// 日 期:2021-06-01 .
|
||||
/// </summary>
|
||||
[SugarTable("BASE_TIMETASK")]
|
||||
[SugarTable("base_timetask")]
|
||||
public class TimeTaskEntity : CLDEntityBase
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
16
visualdev/Tnb.Vmodel/BaseAppService.cs
Normal file
16
visualdev/Tnb.Vmodel/BaseAppService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 增删改查基类
|
||||
/// </summary>
|
||||
public class BaseAppService : IDynamicApiController, ITransient
|
||||
{
|
||||
}
|
||||
70
visualdev/Tnb.Vmodel/Constants/DbConsts.cs
Normal file
70
visualdev/Tnb.Vmodel/Constants/DbConsts.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public static class DbConsts
|
||||
{
|
||||
public const string DefaultDbCode = "totedp";
|
||||
public const string ConnectNameDapper = "Dapper";
|
||||
public const string ConnectNameMySql = "MySql";
|
||||
public const string ConnectNameSqlServer = "SqlServer";
|
||||
public const string ConnectNameSqlite = "Sqlite";
|
||||
public const string ConnectNamePostgreSql = "PostgreSql";
|
||||
public const string ConnectNameOracle = "Oracle";
|
||||
public const string ConnectNameMongoDb = "MongoDb";
|
||||
|
||||
public const string DbCode = "totemp";
|
||||
public const string DbTablePrefix = "app";
|
||||
public const string DbSchema = null;
|
||||
public const string DbSystemPrefix = "sys";
|
||||
public const string DbMESPrefix = "mes";
|
||||
public const string DbWMSPrefix = "wms";
|
||||
public const string DbBasePrefix = "bas";
|
||||
public const string DbConfigPrefix = "cfg";
|
||||
public const string DbEqpPrefix = "eqp";
|
||||
public const string DbQCPrefix = "qc";
|
||||
|
||||
public const string OneToOne = "OneToOne";
|
||||
public const string OneToMany = "OneToMany";
|
||||
public const string ManyToMany = "ManyToMany";
|
||||
|
||||
public static string[] HiddenFields = new string[] { "Id", "CreationTime", "CreatorId", "LastModificationTime", "LastModifierId" };
|
||||
|
||||
public const string CsString = "string";
|
||||
public const string CsInt = "int";
|
||||
public const string CsShort = "short";
|
||||
public const string CsBool = "bool";
|
||||
public const string CsFloat = "float";
|
||||
public const string CsDouble = "double";
|
||||
public const string CsGuid = "Guid";
|
||||
public const string CsDateTime = "DateTime";
|
||||
public const string CsClass = "class";
|
||||
public const string CsJson = "json";
|
||||
public const string CsEnum = "enum";
|
||||
public const string CsCustomer = "customer";
|
||||
|
||||
public const int LengthXXS = 10;
|
||||
public const int LengthXS = 25;
|
||||
public const int LengthS = 50;
|
||||
public const int LengthM = 100;
|
||||
public const int LengthL = 250;
|
||||
public const int LengthXL = 1000;
|
||||
public const int LengthXXL = 2000;
|
||||
public const int LengthXXXL = 3000;
|
||||
public const int LengthXXXXL = 4000;
|
||||
public const int LengthPassword = 32;
|
||||
public const int LengthNodePath = 742; //20组GUID
|
||||
public const int LengthText = -1;
|
||||
|
||||
public const string SuperAdminName = "admin";
|
||||
public static Guid SuperAdminId = Guid.Parse("39fe9e87-4659-05a7-99ce-9a23d84875df");
|
||||
public static Guid SuperRoleId = Guid.Parse("39fea2c5-088a-32c1-2c2c-b814700aee7e");
|
||||
public static Guid UserAdminId = Guid.Parse("39fe9e87-4695-8eb7-273c-e49b0524aea8");
|
||||
public static Guid RoleAdminId = Guid.Parse("39fea2c8-01a4-75cd-026f-2f0349a94098");
|
||||
public static Guid EventDefaultCategoryId = Guid.Parse("39ffae5d-13d2-1e43-3f0e-98f774f71c8a");
|
||||
public static Guid DefaultViewId = Guid.Parse("39fea2c1-b2dd-cfae-1c3d-89de77f94709");
|
||||
|
||||
}
|
||||
7
visualdev/Tnb.Vmodel/Constants/ModuleConst.cs
Normal file
7
visualdev/Tnb.Vmodel/Constants/ModuleConst.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public class ModuleConst
|
||||
{
|
||||
public const string Tag = "Tnb";
|
||||
public const string Area = "tnb";
|
||||
}
|
||||
109
visualdev/Tnb.Vmodel/Constants/VmodelEnum.cs
Normal file
109
visualdev/Tnb.Vmodel/Constants/VmodelEnum.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public enum eCsType
|
||||
{
|
||||
[Description("string")]
|
||||
String = 10,
|
||||
[Description("bool")]
|
||||
Bool = 12,
|
||||
[Description("uuid")]
|
||||
Guid = 14,
|
||||
[Description("int")]
|
||||
Int = 20,
|
||||
[Description("short")]
|
||||
Short = 22,
|
||||
[Description("long")]
|
||||
Long = 24,
|
||||
[Description("float")]
|
||||
Float = 30,
|
||||
[Description("double")]
|
||||
Double = 32,
|
||||
[Description("decimal")]
|
||||
Decimal = 34,
|
||||
[Description("date")]
|
||||
Date = 40,
|
||||
[Description("time")]
|
||||
Time = 42,
|
||||
[Description("datetime")]
|
||||
DateTime = 44,
|
||||
[Description("timestamp")]
|
||||
Timestamp = 46,
|
||||
[Description("enum")]
|
||||
Enum = 50,
|
||||
[Description("dictionary")]
|
||||
Dictionary = 52,
|
||||
[Description("json")]
|
||||
Json = 60,
|
||||
[Description("entity")]
|
||||
Entity = 70,
|
||||
[Description("customer")]
|
||||
Customer = 80,
|
||||
}
|
||||
public enum eDbType
|
||||
{
|
||||
MySql,
|
||||
SqlServer,
|
||||
PostgreSQL,
|
||||
Oracle,
|
||||
Sqlite,
|
||||
MsAccess,
|
||||
Dameng,
|
||||
ClickHouse,
|
||||
Redis,
|
||||
InfluxDb
|
||||
}
|
||||
public enum eResourceType
|
||||
{
|
||||
[Description("菜单")]
|
||||
Menu = 10,
|
||||
[Description("页面")]
|
||||
Page = 20,
|
||||
[Description("按钮")]
|
||||
Button = 30,
|
||||
[Description("接口")]
|
||||
Interface = 40,
|
||||
[Description("视图")]
|
||||
View = 50,
|
||||
}
|
||||
public enum eSearchType
|
||||
{
|
||||
[Description("无")]
|
||||
None = 0,
|
||||
[Description("精准查询")]
|
||||
Exact = 1,
|
||||
[Description("模糊查询")]
|
||||
Fuzzy = 2,
|
||||
[Description("范围查询")]
|
||||
Range = 3,
|
||||
}
|
||||
public enum eNavigateType
|
||||
{
|
||||
[Description("无")]
|
||||
None = 0,
|
||||
[Description("一对一")]
|
||||
OneToOne = 1,
|
||||
[Description("一对多")]
|
||||
OneToMany = 2,
|
||||
[Description("多对多")]
|
||||
ManyToMany = 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模型属性类型
|
||||
/// </summary>
|
||||
public enum ePropType
|
||||
{
|
||||
[Description("表字段")]
|
||||
DbTable = 0,
|
||||
[Description("计算属性")]
|
||||
Calculate = 1,
|
||||
[Description("导航属性")]
|
||||
Navigate = 2,
|
||||
}
|
||||
422
visualdev/Tnb.Vmodel/DataAccess/DataAccess.cs
Normal file
422
visualdev/Tnb.Vmodel/DataAccess/DataAccess.cs
Normal file
@@ -0,0 +1,422 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using JNPF;
|
||||
using JNPF.DependencyInjection;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using Tnb.VmodelEngine;
|
||||
|
||||
namespace Tnb.DataAccess;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
{
|
||||
const int MAX_PAGE_SIZE = 1000;
|
||||
private ISqlSugarClient? sugar;
|
||||
protected ISqlSugarClient Db
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sugar == null)
|
||||
{
|
||||
ConnectionStringsOptions conn = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
//var DBType = (DbType)Enum.Parse(typeof(DbType), conn.DBType);
|
||||
sugar = new SqlSugarScope(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = conn.ConnectString,
|
||||
DbType = conn.DBType.Adapt<DbType>(),
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = conn.ConfigId,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
||||
IsAutoToUpper = false,
|
||||
PgSqlIsAutoToLower = false,
|
||||
DisableNvarchar = true
|
||||
},
|
||||
}, SugarHelper.ConfigSugar);
|
||||
}
|
||||
return sugar;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局缓存
|
||||
/// </summary>
|
||||
static ConcurrentDictionary<string, ISqlSugarClient> DbCache = new ConcurrentDictionary<string, ISqlSugarClient>();
|
||||
|
||||
/// <summary>
|
||||
/// 构造
|
||||
/// </summary>
|
||||
public DataAccess()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var item in DbCache)
|
||||
{
|
||||
item.Value.Dispose();
|
||||
}
|
||||
DbCache.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 ISqlSugarClient
|
||||
/// </summary>
|
||||
public ISqlSugarClient GetSqlSugar(string? dbCode = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbCode) || dbCode == DbConsts.DefaultDbCode)
|
||||
{
|
||||
return Db;
|
||||
}
|
||||
if (DbCache.ContainsKey(dbCode))
|
||||
{
|
||||
return DbCache[dbCode];
|
||||
}
|
||||
|
||||
var dblink = GetVmLink(dbCode);
|
||||
if (dblink == null)
|
||||
{
|
||||
throw new Exception($"没有此数据库{dbCode}连接信息");
|
||||
}
|
||||
var dbType = Enum.Parse<DbType>(dblink.dbType.ToString(), true);
|
||||
var sugar = new SqlSugarScope(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = dblink.dbConnection,
|
||||
DbType = dbType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = dblink.dbCode,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
||||
IsAutoToUpper = false,
|
||||
PgSqlIsAutoToLower = false,
|
||||
DisableNvarchar = true
|
||||
},
|
||||
}, SugarHelper.ConfigSugar);
|
||||
if (sugar.Ado.IsValidConnection())
|
||||
{
|
||||
DbCache[dbCode] = sugar;
|
||||
}
|
||||
else
|
||||
{
|
||||
sugar.Dispose();
|
||||
throw new Exception($"无法连接到数据库{dbCode}");
|
||||
}
|
||||
return DbCache[dbCode];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 DbLink
|
||||
/// </summary>
|
||||
public VmodelLink GetVmLink(string dbCode)
|
||||
{
|
||||
var model = Db.Queryable<VmodelLink>().First(a => a.dbCode == dbCode);
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时不抛异常
|
||||
/// </summary>
|
||||
public async Task<Vmodel?> TryGetVmodelAsync(string id, bool loadNavigate = false)
|
||||
{
|
||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.id == id && a.deleted == 0);
|
||||
if (vm != null && loadNavigate)
|
||||
{
|
||||
await LoadVmodelNavigateAsync(vm);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时抛异常
|
||||
/// </summary>
|
||||
public async Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false)
|
||||
{
|
||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.id == id && a.deleted == 0);
|
||||
ArgumentNullException.ThrowIfNull(vm, $"找不到vmid={id}的模型");
|
||||
if (loadNavigate)
|
||||
{
|
||||
await LoadVmodelNavigateAsync(vm);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时不抛异常
|
||||
/// </summary>
|
||||
public async Task<Vmodel?> TryGetVmodelAsync(string area, string vmCode, bool loadNavigate = false)
|
||||
{
|
||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.area == area && a.vmCode == vmCode && a.deleted == 0);
|
||||
if (vm != null && loadNavigate)
|
||||
{
|
||||
await LoadVmodelNavigateAsync(vm);
|
||||
}
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时抛异常
|
||||
/// </summary>
|
||||
public async Task<Vmodel> GetVmodelAsync(string area, string vmCode, bool loadNavigate = false)
|
||||
{
|
||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.area == area && a.vmCode == vmCode && a.deleted == 0);
|
||||
ArgumentNullException.ThrowIfNull(vm, $"找不到area={area}, vmCode={vmCode}的模型");
|
||||
if (loadNavigate)
|
||||
{
|
||||
await LoadVmodelNavigateAsync(vm);
|
||||
}
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 获取 Vmodel
|
||||
///// </summary>
|
||||
//public async Task<Vmodel?> GetVmodelAsync(string tableName, string? dbCode)
|
||||
//{
|
||||
// Vmodel vm = await _db.Queryable<Vmodel>().FirstAsync(a => a.tableName == tableName && a.dbCode == dbCode && a.deleted == 0);
|
||||
// return vm;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 加载模型的导航属性
|
||||
/// </summary>
|
||||
/// <param name="vm"></param>
|
||||
/// <returns></returns>
|
||||
private async Task LoadVmodelNavigateAsync(Vmodel vm)
|
||||
{
|
||||
Dictionary<string, Vmodel> dictVm = new();
|
||||
foreach (var navProp in vm.navProps)
|
||||
{
|
||||
if (!dictVm.ContainsKey(navProp.vmid))
|
||||
{
|
||||
var navModel = await GetVmodelAsync(navProp.vmid);
|
||||
dictVm.Add(navProp.vmid, navModel);
|
||||
}
|
||||
navProp.naviModel = dictVm[navProp.vmid];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<VmPagedOutput> QueryDataAsync(Vmodel vm, VmQueryInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
var query = db.Queryable<object>().AS(vm.tableName, VmSelectProp.MAIN_ALIES);
|
||||
var selProps = vm.GetVmSelectProps(input.o);
|
||||
//处理导航属性联表
|
||||
List<JoinInfoParameter> joins = vm.GetJoinInfos(selProps);
|
||||
query.AddJoinInfo(joins);
|
||||
List<IConditionalModel> wheres = vm.GetConditionalModels(input.q);
|
||||
if (!string.IsNullOrEmpty(input.k))
|
||||
{
|
||||
var lsCondition = new List<KeyValuePair<WhereType, ConditionalModel>>();
|
||||
var wType = WhereType.And;
|
||||
foreach (var prop in vm.dbProps.Where(a => a.fuzzy))
|
||||
{
|
||||
lsCondition.Add(new(wType, new ConditionalModel() { FieldName = prop.field, ConditionalType = ConditionalType.Like, FieldValue = input.k }));
|
||||
wType = WhereType.Or;
|
||||
}
|
||||
wheres.Add(new ConditionalCollections() { ConditionalList = lsCondition });
|
||||
}
|
||||
//处理查询参数
|
||||
query.Where(wheres);
|
||||
if (!string.IsNullOrEmpty(input.sort))
|
||||
{
|
||||
query.OrderBy(input.sort);
|
||||
}
|
||||
//处理输出字段
|
||||
List<SelectModel> selects = vm.GetSelectModels(selProps);
|
||||
query.Select(selects);
|
||||
//查询数据
|
||||
VmPagedOutput result = new();
|
||||
List<Dictionary<string, object>> ls = new();
|
||||
int skip = input.pnum > 0 ? (input.pnum - 1) * input.psize : 0;
|
||||
int take = input.psize == 0 ? MAX_PAGE_SIZE : input.psize;
|
||||
if (input.pnum > 0) { result.total = await query.CountAsync(); }
|
||||
ls = await query.Skip(skip).Take(take).ToDictionaryListAsync();
|
||||
//组装输出对象
|
||||
foreach (var data in ls)
|
||||
{
|
||||
DObject ret = await NestedOutputAsync(vm, data, selProps);
|
||||
result.items.Add(ret);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 组装子模型对象
|
||||
/// </summary>
|
||||
/// <param name="vm"></param>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="selProps"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<DObject> NestedOutputAsync(Vmodel vm, Dictionary<string, object> src, List<VmSelectProp> selProps)
|
||||
{
|
||||
DObject ret = new();
|
||||
foreach (var prop in selProps)
|
||||
{
|
||||
if (prop.navType == eNavigateType.None || prop.navCode == VmSelectProp.MAIN_ALIES)
|
||||
{
|
||||
if (src.ContainsKey(prop.code))
|
||||
{
|
||||
ret.Add(prop.code, src[prop.code]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prop.navType == eNavigateType.OneToOne)
|
||||
{
|
||||
var key = prop.navCode + "_" + prop.code;
|
||||
ret.Add(key, src[key]);
|
||||
//if (!ret.ContainsKey(prop.navCode))
|
||||
//{
|
||||
// ret.Add(prop.navCode, new DObject());
|
||||
//}
|
||||
//var key = prop.navCode + "_" + prop.code;
|
||||
//if (src.ContainsKey(key))
|
||||
//{
|
||||
// ((DObject)ret[prop.navCode]).Add(prop.code, src[key]);
|
||||
//}
|
||||
}
|
||||
else if (prop.navType == eNavigateType.OneToMany)
|
||||
{
|
||||
if (!ret.ContainsKey(prop.navCode))
|
||||
{
|
||||
ret.Add(prop.navCode, new List<DObject>());
|
||||
}
|
||||
var navProp = vm.navProps.First(a => a.code == prop.navCode);
|
||||
if (navProp != null && navProp.naviModel != null && src.ContainsKey(navProp.refField))
|
||||
{
|
||||
VmQueryInput input = new VmQueryInput();
|
||||
input.q = new DObject(navProp.refField, src[navProp.refField]);
|
||||
input.o = string.Join(',', selProps.Where(a => a.navCode == prop.navCode).Select(a => a.code));
|
||||
ret[prop.navCode] = (await QueryDataAsync(navProp.naviModel, input)).items;
|
||||
}
|
||||
}
|
||||
else if (prop.navType == eNavigateType.ManyToMany)
|
||||
{
|
||||
if (!ret.ContainsKey(prop.navCode))
|
||||
{
|
||||
ret.Add(prop.navCode, new List<DObject>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
int num = 0;
|
||||
if (input.data != null)
|
||||
{
|
||||
var model = vm.PropToField(input.data);
|
||||
num = await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
||||
return input.data;
|
||||
}
|
||||
else if (input.items != null)
|
||||
{
|
||||
List<DObject> lst = new List<DObject>();
|
||||
foreach (var item in input.items)
|
||||
{
|
||||
lst.Add(vm.PropToField(item));
|
||||
}
|
||||
num = await db.Insertable(lst).AS(vm.tableName).ExecuteCommandAsync();
|
||||
return input.items;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.data = vm.GetDefaultDObject();
|
||||
var model = vm.PropToField(input.data);
|
||||
num = await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
||||
return input.data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<dynamic> UpdateDataAsync(Vmodel vm, VmUpdateInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
var pk = vm.GetPrimary();
|
||||
int num = 0;
|
||||
if (input.data != null)
|
||||
{
|
||||
var model = vm.PropToField(input.data);
|
||||
if (!model.ContainsKey(pk.field))
|
||||
{
|
||||
throw new Exception($"更新数据时主键({pk.code})不可为空");
|
||||
}
|
||||
//if (!model.ContainsKey(pk.field) && input.id != null)
|
||||
//{
|
||||
// model.Add(pk.field, input.id);
|
||||
//}
|
||||
num = await db.Updateable(model).AS(vm.tableName).WhereColumns(pk.field).ExecuteCommandAsync();
|
||||
}
|
||||
else if (input.items != null)
|
||||
{
|
||||
List<DObject> lst = new();
|
||||
foreach (var item in input.items)
|
||||
{
|
||||
var model = vm.PropToField(item);
|
||||
if (model.ContainsKey(pk.field))
|
||||
{
|
||||
lst.Add(model);
|
||||
}
|
||||
}
|
||||
num = await db.Updateable(lst).AS(vm.tableName).WhereColumns(pk.field).ExecuteCommandAsync();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<int> DeleteDataAsync(Vmodel vm, VmDeleteInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
var pk = vm.GetPrimary();
|
||||
int num = 0;
|
||||
List<Dictionary<string, object>> ids = new();
|
||||
if (input.id != null)
|
||||
{
|
||||
ids.Add(new DObject(pk.field, input.id));
|
||||
}
|
||||
else if (input.ids != null)
|
||||
{
|
||||
ids.AddRange(input.ids.Select(a => new DObject(pk.field, a)));
|
||||
}
|
||||
if (ids.Count > 0)
|
||||
{
|
||||
num = await db.Deleteable<object>().AS(vm.tableName).WhereColumns(ids).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
}
|
||||
71
visualdev/Tnb.Vmodel/DataAccess/IDataAccess.cs
Normal file
71
visualdev/Tnb.Vmodel/DataAccess/IDataAccess.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.DependencyInjection;
|
||||
using SqlSugar;
|
||||
using Tnb.VmodelEngine;
|
||||
|
||||
namespace Tnb.DataAccess;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IDataAccess : ITransient
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 SqlSugar
|
||||
/// </summary>
|
||||
/// <param name="dbCode"></param>
|
||||
/// <returns></returns>
|
||||
ISqlSugarClient GetSqlSugar(string? dbCode = null);
|
||||
|
||||
/// <summary>
|
||||
/// 获取DbLink
|
||||
/// </summary>
|
||||
/// <param name="dbCode"></param>
|
||||
/// <returns></returns>
|
||||
VmodelLink GetVmLink(string dbCode);
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时不抛异常
|
||||
/// </summary>
|
||||
Task<Vmodel?> TryGetVmodelAsync(string id, bool loadNavigate = false);
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时抛异常
|
||||
/// </summary>
|
||||
Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false);
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时不抛异常
|
||||
/// </summary>
|
||||
Task<Vmodel?> TryGetVmodelAsync(string area, string vmCode, bool loadNavigate = false);
|
||||
/// <summary>
|
||||
/// 获取 Vmodel, 为空时抛异常
|
||||
/// </summary>
|
||||
Task<Vmodel> GetVmodelAsync(string area, string vmCode, bool loadNavigate = false);
|
||||
//Task<VmPagedOutput> QueryDataAsync(VmBaseInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 查询数据 默认方法
|
||||
/// </summary>
|
||||
Task<VmPagedOutput> QueryDataAsync(Vmodel vm, VmQueryInput input);
|
||||
|
||||
//Task<dynamic> CreateDataAsync(VmCreateInput input);
|
||||
/// <summary>
|
||||
/// 新增数据 默认方法
|
||||
/// </summary>
|
||||
Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input);
|
||||
|
||||
//Task<dynamic> UpdateDataAsync(VmUpdateInput input);
|
||||
/// <summary>
|
||||
/// 更新数据 默认方法
|
||||
/// </summary>
|
||||
Task<dynamic> UpdateDataAsync(Vmodel vm, VmUpdateInput input);
|
||||
|
||||
//Task<int> DeleteDataAsync(VmDeleteInput input);
|
||||
/// <summary>
|
||||
/// 删除数据 默认方法
|
||||
/// </summary>
|
||||
Task<int> DeleteDataAsync(Vmodel vm, VmDeleteInput input);
|
||||
}
|
||||
34
visualdev/Tnb.Vmodel/DataAccess/SugarHelper.cs
Normal file
34
visualdev/Tnb.Vmodel/DataAccess/SugarHelper.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using JNPF.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public class SugarHelper
|
||||
{
|
||||
public static void ConfigSugar(ISqlSugarClient db)
|
||||
{
|
||||
// 设置超时时间
|
||||
db.Ado.CommandTimeOut = 30;
|
||||
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
var finalSql = UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars);
|
||||
if (db.Ado.SqlExecutionTime.TotalMilliseconds > 3000)
|
||||
{
|
||||
Log.Warning($"慢查询: {db.Ado.SqlExecutionTime.TotalMilliseconds}ms, SQL: " + finalSql);
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss.fff")}——SQL执行完成】{db.Ado.SqlExecutionTime.TotalMilliseconds} ms");
|
||||
Console.WriteLine(finalSql);
|
||||
Console.ForegroundColor = oldColor;
|
||||
Console.WriteLine();
|
||||
}
|
||||
};
|
||||
db.Aop.OnError = (ex) =>
|
||||
{
|
||||
Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||
};
|
||||
}
|
||||
}
|
||||
198
visualdev/Tnb.Vmodel/Dtos/VmDto.cs
Normal file
198
visualdev/Tnb.Vmodel/Dtos/VmDto.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 字典对象
|
||||
/// </summary>
|
||||
public class DObject : Dictionary<string, object>
|
||||
{
|
||||
public DObject() { }
|
||||
public DObject(string key, object value)
|
||||
{
|
||||
Add(key, value);
|
||||
}
|
||||
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
|
||||
{
|
||||
}
|
||||
public void AddCascade(string code, object value)
|
||||
{
|
||||
var keys = code.Split('.');
|
||||
if(keys.Length == 1 )
|
||||
{
|
||||
Add(code, value);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < keys.Length; i++)
|
||||
{
|
||||
DObject temp = this;
|
||||
if(i < keys.Length - 1)
|
||||
{
|
||||
if (!ContainsKey(keys[i]))
|
||||
{
|
||||
temp = new DObject();
|
||||
Add(keys[i], temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = (DObject)temp[keys[i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.Add(keys[i], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class VmBaseInput
|
||||
{
|
||||
///// <summary>
|
||||
///// 视图模型id
|
||||
///// </summary>
|
||||
//public string vmid { get; set; } = string.Empty;
|
||||
}
|
||||
public class VmGetInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 要获取数据的id
|
||||
/// </summary>
|
||||
public string? id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过滤条件
|
||||
/// </summary>
|
||||
public string? q { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 输出字段
|
||||
/// </summary>
|
||||
public string o { get; set; } = "*";
|
||||
}
|
||||
|
||||
public class VmGetListInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前页数
|
||||
/// </summary>
|
||||
public int pnum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 每页记录数
|
||||
/// </summary>
|
||||
public int psize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public string? sort { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 模糊查询
|
||||
/// </summary>
|
||||
public string? k { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过滤条件
|
||||
/// </summary>
|
||||
public string? q { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 输出字段
|
||||
/// </summary>
|
||||
public string o { get; set; } = "*";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条数据输入参数
|
||||
/// </summary>
|
||||
public class VmQueryInput : VmGetListInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public new DObject? q { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 高级查询
|
||||
/// </summary>
|
||||
public DObject? adv { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增数据输入参数
|
||||
/// </summary>
|
||||
public class VmCreateInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
public DObject? data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
public List<DObject>? items { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改数据输入参数
|
||||
/// </summary>
|
||||
public class VmUpdateInput : VmCreateInput
|
||||
{
|
||||
///// <summary>
|
||||
///// 要更新的数据id
|
||||
///// </summary>
|
||||
//public string? id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除数据输入参数
|
||||
/// </summary>
|
||||
public class VmDeleteInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 要删除的数据id
|
||||
/// </summary>
|
||||
public string? id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 要删除的id列表
|
||||
/// </summary>
|
||||
public List<string>? ids { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页列表输出对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class PagedOutput<T>
|
||||
{
|
||||
public int total { get; set; }
|
||||
public List<T> items { get; set; } = new List<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态分页列表输出对象
|
||||
/// </summary>
|
||||
public class VmPagedOutput : PagedOutput<dynamic>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询属性信息
|
||||
/// </summary>
|
||||
public class VmSelectProp
|
||||
{
|
||||
public const string MAIN_ALIES = "m";
|
||||
public string code { get; set; } = string.Empty;
|
||||
public string field { get; set; } = string.Empty;
|
||||
public string navCode { get; set; } = MAIN_ALIES;
|
||||
public ePropType propType { get; set; }
|
||||
public eNavigateType navType { get; set; }
|
||||
}
|
||||
34
visualdev/Tnb.Vmodel/Dtos/VmodelDto.cs
Normal file
34
visualdev/Tnb.Vmodel/Dtos/VmodelDto.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public class VmodelCreateFromTableInput
|
||||
{
|
||||
public string? dbCode { get; set; }
|
||||
|
||||
public string tableName { get; set; } = string.Empty;
|
||||
|
||||
public string? removePrefix { get; set; }
|
||||
public string area { get; set; } = "edp";
|
||||
}
|
||||
|
||||
public class CreatePageFromVmodelInput
|
||||
{
|
||||
public Guid? viewId { get; set; }
|
||||
public string? vmid { get; set; }
|
||||
}
|
||||
|
||||
public class VmodelGetInput
|
||||
{
|
||||
public long? id { get; set; }
|
||||
public string? moduleCode { get; set; }
|
||||
public string? vmCode { get; set; }
|
||||
public string? dbCode { get; set; }
|
||||
public string? tableName { get; set; }
|
||||
public bool drill { get; set; }
|
||||
|
||||
}
|
||||
|
||||
30
visualdev/Tnb.Vmodel/Entities/Entity.cs
Normal file
30
visualdev/Tnb.Vmodel/Entities/Entity.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.Common.Contracts;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
[Serializable]
|
||||
public abstract class Entity : IEntity
|
||||
{
|
||||
protected Entity()
|
||||
{
|
||||
//EntityHelper.TrySetTenantId(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[ENTITY: {GetType().Name}] Keys = {string.Join(", ", GetKeys())}";
|
||||
}
|
||||
|
||||
public abstract object[] GetKeys();
|
||||
|
||||
//public bool EntityEquals(IEntity other)
|
||||
//{
|
||||
// return EntityHelper.EntityEquals(this, other);
|
||||
//}
|
||||
}
|
||||
444
visualdev/Tnb.Vmodel/Entities/Vmodel.cs
Normal file
444
visualdev/Tnb.Vmodel/Entities/Vmodel.cs
Normal file
@@ -0,0 +1,444 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using Tnb.DataAccess;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型
|
||||
/// </summary>
|
||||
[SugarTable("sys_vmodel")]
|
||||
public partial class Vmodel : Entity
|
||||
{
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 主键标识
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string id { get; set; } = YitIdHelper.NextId().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 模块代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "area", Length = DbConsts.LengthS)]
|
||||
public string area { get; set; } = "edp";
|
||||
|
||||
/// <summary>
|
||||
/// 视图代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "vm_code", IsNullable = false, Length = DbConsts.LengthM)]
|
||||
public string vmCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 视图名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "vm_name", IsNullable = false, Length = DbConsts.LengthM)]
|
||||
public string vmName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库连接
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "db_code", Length = DbConsts.LengthS)]
|
||||
public string? dbCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主表名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "table_name", IsNullable = false, Length = DbConsts.LengthS)]
|
||||
public string tableName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 表字段属性
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "db_props", IsNullable = false, IsJson = true)]
|
||||
public List<VmDbProp> dbProps { get; set; } = new List<VmDbProp>();
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "nav_props", IsNullable = true, IsJson = true)]
|
||||
public List<VmNavProp> navProps { get; set; } = new List<VmNavProp>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算属性
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "cal_props", IsNullable = true, IsJson = true)]
|
||||
public List<VmCalProp> calProps { get; set; } = new List<VmCalProp>();
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "ordinal", IsNullable = false)]
|
||||
public int ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 软删除
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "soft_delete", IsNullable = false)]
|
||||
public short softDelete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否激活
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "enabled", IsNullable = false)]
|
||||
public short enabled { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "deleted", IsNullable = false)]
|
||||
public short deleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "descrip", Length = DbConsts.LengthL)]
|
||||
public string? descrip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "create_time", IsNullable = false)]
|
||||
public DateTime createTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "create_id", Length = DbConsts.LengthS)]
|
||||
public string? createId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "modify_time", Length = DbConsts.LengthS)]
|
||||
public DateTime? modifyTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "modify_id", Length = DbConsts.LengthS)]
|
||||
public string? modifyId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public override object[] GetKeys()
|
||||
{
|
||||
return new object[] { id };
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 通过实体创建模型
|
||||
/// </summary>
|
||||
/// <param name="tpEntity"></param>
|
||||
/// <param name="dbCode"></param>
|
||||
/// <returns></returns>
|
||||
public static Vmodel CreateByEntity(Type tpEntity, string? dbCode = null)
|
||||
{
|
||||
Vmodel model = new() { dbCode = dbCode, vmCode = tpEntity.Name };
|
||||
var sugarTableAttr = tpEntity.GetCustomAttribute<SugarTable>();
|
||||
if (sugarTableAttr != null)
|
||||
{
|
||||
model.tableName = sugarTableAttr.TableName;
|
||||
model.vmName = sugarTableAttr.TableDescription;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.tableName))
|
||||
{
|
||||
model.tableName = tpEntity.GetCustomAttribute<TableAttribute>()?.Name ?? tpEntity.Name;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.vmName))
|
||||
{
|
||||
model.vmName = tpEntity.GetCustomAttribute<DisplayAttribute>()?.Name ?? tpEntity.GetCustomAttribute<DescriptionAttribute>()?.Description ?? model.vmCode;
|
||||
}
|
||||
var props = tpEntity.GetProperties(BindingFlags.Public);
|
||||
int n = 1;
|
||||
foreach (var p in props)
|
||||
{
|
||||
VmDbProp prop = new();
|
||||
var sugarColumn = p.GetCustomAttribute<SugarColumn>();
|
||||
if (sugarColumn != null)
|
||||
{
|
||||
prop = sugarColumn.Adapt<VmDbProp>();
|
||||
}
|
||||
prop.code = p.Name;
|
||||
prop.ordinal = n++;
|
||||
model.dbProps.Add(prop);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型的主键字段属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmDbProp GetPrimary()
|
||||
{
|
||||
return dbProps.First(a => a.pkey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据属性名获取字段名
|
||||
/// </summary>
|
||||
/// <param name="propCode"></param>
|
||||
/// <returns></returns>
|
||||
public string? PropCodeToFieldCode(string propCode)
|
||||
{
|
||||
return dbProps.Where(a => a.code == propCode).Select(a => a.field).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字段名获取属性名
|
||||
/// </summary>
|
||||
/// <param name="fieldCode"></param>
|
||||
/// <returns></returns>
|
||||
public string? FieldCodeToPropCode(string fieldCode)
|
||||
{
|
||||
return dbProps.Where(a => a.field == fieldCode).Select(a => a.code).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 属性代码转换为字段代码
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="ignoreNotMapped"></param>
|
||||
/// <returns></returns>
|
||||
public DObject PropToField(DObject input, bool ignoreNotMapped = true)
|
||||
{
|
||||
DObject ret = new();
|
||||
foreach (var item in input)
|
||||
{
|
||||
var fcode = PropCodeToFieldCode(item.Key);
|
||||
if (!string.IsNullOrEmpty(fcode))
|
||||
{
|
||||
ret.Add(fcode, item.Value);
|
||||
}
|
||||
else if (!ignoreNotMapped)
|
||||
{
|
||||
ret.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字段代码转换为属性代码
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="ignoreNotMapped"></param>
|
||||
/// <returns></returns>
|
||||
public DObject FieldToProp(DObject input, bool ignoreNotMapped = true)
|
||||
{
|
||||
DObject ret = new();
|
||||
foreach (var item in input)
|
||||
{
|
||||
var pcode = FieldCodeToPropCode(item.Key);
|
||||
if (!string.IsNullOrEmpty(pcode))
|
||||
{
|
||||
ret.Add(pcode, item.Value);
|
||||
}
|
||||
else if (!ignoreNotMapped)
|
||||
{
|
||||
ret.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取查询字段的属性信息
|
||||
/// </summary>
|
||||
/// <param name="outputProps"></param>
|
||||
/// <returns></returns>
|
||||
public List<VmSelectProp> GetVmSelectProps(string? outputProps)
|
||||
{
|
||||
if (string.IsNullOrEmpty(outputProps) || outputProps == "*")
|
||||
{
|
||||
return dbProps.Select(a => new VmSelectProp { code = a.code, field = a.field }).ToList();
|
||||
}
|
||||
List<VmSelectProp> selProps = new();
|
||||
var outputs = outputProps.Split(',').Distinct().ToList();
|
||||
foreach (var propCode in outputs)
|
||||
{
|
||||
if (!propCode.Contains("."))
|
||||
{
|
||||
var fieldCode = PropCodeToFieldCode(propCode);
|
||||
if (!string.IsNullOrEmpty(fieldCode))
|
||||
{
|
||||
selProps.Add(new VmSelectProp { code = propCode, field = fieldCode });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
var codes = propCode.Split('.');
|
||||
if (codes.Length != 2) continue;
|
||||
if (codes[0] == VmSelectProp.MAIN_ALIES)
|
||||
{
|
||||
var fieldCode = PropCodeToFieldCode(propCode);
|
||||
if (!string.IsNullOrEmpty(fieldCode))
|
||||
{
|
||||
selProps.Add(new VmSelectProp { code = propCode, field = fieldCode });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
var navProp = navProps.FirstOrDefault(a => a.code == codes[0]);
|
||||
if (navProp?.naviModel != null)
|
||||
{
|
||||
var fieldCode = navProp.naviModel.PropCodeToFieldCode(codes[1]);
|
||||
if (!string.IsNullOrEmpty(fieldCode))
|
||||
{
|
||||
selProps.Add(new VmSelectProp { code = codes[1], field = fieldCode, navCode = codes[0], propType = ePropType.Navigate, navType = navProp.navType });
|
||||
}
|
||||
}
|
||||
}
|
||||
return selProps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联表配置信息
|
||||
/// </summary>
|
||||
/// <param name="selProps"></param>
|
||||
/// <returns></returns>
|
||||
public List<JoinInfoParameter> GetJoinInfos(List<VmSelectProp> selProps)
|
||||
{
|
||||
var navigates = selProps.Where(a => a.propType == ePropType.Navigate).Select(a => a.navCode).Distinct().ToList();
|
||||
List<JoinInfoParameter> joins = new();
|
||||
foreach (var navCode in navigates)
|
||||
{
|
||||
if (navCode == VmSelectProp.MAIN_ALIES) continue;
|
||||
var navProp = navProps.First(a => a.code == navCode);
|
||||
if (navProp.naviModel == null || navProp.navType != eNavigateType.OneToOne) continue;
|
||||
JoinInfoParameter join = new JoinInfoParameter { TableName = navProp.naviModel.tableName, ShortName = navCode, Type = JoinType.Inner };
|
||||
var fkField = navProp.naviModel.PropCodeToFieldCode(navProp.fkField);
|
||||
var refField = navProp.refField;
|
||||
if (navProp.refCode != VmSelectProp.MAIN_ALIES)
|
||||
{
|
||||
var refProp = navProps.First(a => a.code == navProp.refCode);
|
||||
refField = refProp.naviModel!.PropCodeToFieldCode(navProp.refField);
|
||||
}
|
||||
join.Models = ObjectFuncModel.Create("Equals", $"{navCode}.{fkField}", $"{navProp.refCode}.{refField}");
|
||||
joins.Add(join);
|
||||
}
|
||||
return joins;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为查询过滤条件
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public List<IConditionalModel> GetConditionalModels(DObject? filter)
|
||||
{
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>();
|
||||
if (filter == null) return wheres;
|
||||
foreach (var item in filter)
|
||||
{
|
||||
// TODO 按子表条件查询
|
||||
if (item.Key.Contains("."))
|
||||
{
|
||||
|
||||
}
|
||||
var prop = dbProps.FirstOrDefault(a => a.code == item.Key);
|
||||
if (prop == null) continue;
|
||||
if (item.Value is JArray val)
|
||||
{
|
||||
var op = val[0].ToString();
|
||||
switch (op)
|
||||
{
|
||||
case "><":
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan });
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan });
|
||||
break;
|
||||
case ">=<":
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual });
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan });
|
||||
break;
|
||||
case "><=":
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan });
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual });
|
||||
break;
|
||||
case ">=<=":
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual });
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual });
|
||||
break;
|
||||
case "in":
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val.Skip(1).ToString(), ConditionalType = ConditionalType.In });
|
||||
break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (item.Value == null) continue;
|
||||
var conditionalType = ConditionalType.Equal;
|
||||
string? value = item.Value?.ToString();
|
||||
if (string.IsNullOrEmpty(value)) continue;
|
||||
if (value.Length >= 2)
|
||||
{
|
||||
var op = value.Substring(0, 2);
|
||||
switch (op)
|
||||
{
|
||||
case "%%": conditionalType = ConditionalType.Like; break;
|
||||
case ">>": conditionalType = ConditionalType.GreaterThan; break;
|
||||
case "<<": conditionalType = ConditionalType.LessThan; break;
|
||||
case ">=": conditionalType = ConditionalType.GreaterThanOrEqual; break;
|
||||
case "<=": conditionalType = ConditionalType.LessThanOrEqual; break;
|
||||
case "==": conditionalType = ConditionalType.Equal; break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(op))
|
||||
{
|
||||
value = value.RemovePreFix(op);
|
||||
if (value.ToLower() == "null")
|
||||
{
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = value, ConditionalType = conditionalType });
|
||||
}
|
||||
}
|
||||
return wheres;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为查询字段列表
|
||||
/// </summary>
|
||||
/// <param name="selProps"></param>
|
||||
/// <returns></returns>
|
||||
public List<SelectModel> GetSelectModels(List<VmSelectProp> selProps)
|
||||
{
|
||||
return selProps.Where(a => a.navType != eNavigateType.OneToMany && a.navType != eNavigateType.ManyToMany).Select(a => new SelectModel
|
||||
{
|
||||
FiledName = (a.navCode == VmSelectProp.MAIN_ALIES ? "" : a.navCode + ".") + a.field,
|
||||
AsName = (a.navCode == VmSelectProp.MAIN_ALIES ? "" : a.navCode + "_") + a.code
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DObject GetDefaultDObject()
|
||||
{
|
||||
DObject obj = new();
|
||||
foreach (var p in dbProps)
|
||||
{
|
||||
obj.Add(p.code, p.GetDefaultValue()!);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
50
visualdev/Tnb.Vmodel/Entities/VmodelLink.cs
Normal file
50
visualdev/Tnb.Vmodel/Entities/VmodelLink.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.Common.Contracts;
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库连接
|
||||
/// </summary>
|
||||
[SugarTable("sys_vmodel_link")]
|
||||
public partial class VmodelLink : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键标识
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string id { get; set; } = YitIdHelper.NextId().ToString();
|
||||
/// <summary>
|
||||
/// 数据库连接
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "db_code", Length = DbConsts.LengthS)]
|
||||
public string? dbCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "db_type", IsNullable = false)]
|
||||
public eDbType dbType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接串
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "db_connection", IsNullable = false, Length = DbConsts.LengthXL)]
|
||||
public string dbConnection { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public override object[] GetKeys()
|
||||
{
|
||||
return new object[] { id };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
107
visualdev/Tnb.Vmodel/Entities/VmodelPage.cs
Normal file
107
visualdev/Tnb.Vmodel/Entities/VmodelPage.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 功能页面
|
||||
/// </summary>
|
||||
[SugarTable("sys_vmodel_page")]
|
||||
public partial class VmodelPage : Entity
|
||||
{
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 主键标识
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string id { get; set; } = YitIdHelper.NextId().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 模型id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "vmid", Length = DbConsts.LengthS)]
|
||||
public string? vmid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 页面代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "code", Length = DbConsts.LengthS)]
|
||||
public string code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 页面名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "name", Length = DbConsts.LengthM)]
|
||||
public string name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 页面类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "page_type", Length = DbConsts.LengthS)]
|
||||
public string pageType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 页面配置
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "page_schema", Length = DbConsts.LengthS, IsJson = true)]
|
||||
public JObject pageSchema { get; set; } = new JObject();
|
||||
|
||||
/// <summary>
|
||||
/// 页面配置
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "option", Length = DbConsts.LengthS)]
|
||||
public string? option { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "enabled")]
|
||||
public short enabled { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "deleted")]
|
||||
public short deleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "create_time")]
|
||||
public DateTime createTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "create_id", Length = DbConsts.LengthS)]
|
||||
public string? createId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "modify_time", Length = DbConsts.LengthS)]
|
||||
public DateTime? modifyTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "modify_id", Length = DbConsts.LengthS)]
|
||||
public string? modifyId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public override object[] GetKeys()
|
||||
{
|
||||
return new object[] { id };
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
231
visualdev/Tnb.Vmodel/Entities/VmodelProp.cs
Normal file
231
visualdev/Tnb.Vmodel/Entities/VmodelProp.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Tnb.DataAccess;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型属性
|
||||
/// </summary>
|
||||
public class VmProp
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性代码
|
||||
/// </summary>
|
||||
public string code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string name { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字段属性
|
||||
/// </summary>
|
||||
public class VmDbProp : VmProp
|
||||
{
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 字段名称
|
||||
/// </summary>
|
||||
public string field { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string dataType { get; set; } = "varchar";
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string? csType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 长度
|
||||
/// </summary>
|
||||
public int length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 精度
|
||||
/// </summary>
|
||||
public int digit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 非空
|
||||
/// </summary>
|
||||
public bool required { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否主键
|
||||
/// </summary>
|
||||
public bool pkey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否模糊搜索
|
||||
/// </summary>
|
||||
public bool fuzzy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
public string? defValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string? descrip { get; set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object? GetDefaultValue()
|
||||
{
|
||||
object? val = null;
|
||||
if (string.IsNullOrEmpty(defValue))
|
||||
{
|
||||
val = defValue switch
|
||||
{
|
||||
"@@snowid" => YitIdHelper.NextId().ToString(),
|
||||
"@@now" => DateTime.Now,
|
||||
"@@userid" => YitIdHelper.NextId().ToString(),
|
||||
"@@orgid" => YitIdHelper.NextId().ToString(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
val = csType switch
|
||||
{
|
||||
"string" => string.Empty,
|
||||
"short" or "int" or "long" => 0,
|
||||
"float" or "double" or "decimal" => 0f,
|
||||
"DateTime" => DateTime.Now,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认宽度
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetDefaultWidth()
|
||||
{
|
||||
return csType switch
|
||||
{
|
||||
"string" => "\"width\": \"auto\"",
|
||||
"int" or "short" or "long" => "\"width\": 80",
|
||||
"DateTime" => "\"width\": 150",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认组件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public CompOption GetDefaultComp()
|
||||
{
|
||||
CompOption comp = new CompOption();
|
||||
if (pkey)
|
||||
{
|
||||
comp.attr.Add("disabled", true);
|
||||
return comp;
|
||||
}
|
||||
switch (csType)
|
||||
{
|
||||
case "string":
|
||||
comp.attr.Add("clearable", true);
|
||||
comp.attr.Add("maxlength", length);
|
||||
comp.attr.Add("showWordLimit", true);
|
||||
break;
|
||||
case "int":
|
||||
case "short":
|
||||
case "long":
|
||||
comp.type = "el-input-number";
|
||||
break;
|
||||
case "DateTime":
|
||||
comp.type = "el-date-picker";
|
||||
break;
|
||||
};
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性
|
||||
/// </summary>
|
||||
public class VmNavProp : VmProp
|
||||
{
|
||||
/// <summary>
|
||||
/// 导航属性模型id
|
||||
/// </summary>
|
||||
public string vmid { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 导航关联类型
|
||||
/// </summary>
|
||||
public eNavigateType navType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 源表字段
|
||||
/// </summary>
|
||||
public string refCode { get; set; } = VmSelectProp.MAIN_ALIES;
|
||||
|
||||
/// <summary>
|
||||
/// 被引用字段
|
||||
/// </summary>
|
||||
public string refField { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 源表字段
|
||||
/// </summary>
|
||||
public string fkField { get; set; } = string.Empty;
|
||||
|
||||
///// <summary>
|
||||
///// 关联表表名
|
||||
///// </summary>
|
||||
//[JsonIgnore]
|
||||
//public string refTable { get; set; } = string.Empty;
|
||||
|
||||
///// <summary>
|
||||
///// 被引用表(中间表)
|
||||
///// </summary>
|
||||
//[JsonIgnore]
|
||||
//public string? midTable { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Vmodel? naviModel { get; set; }
|
||||
}
|
||||
|
||||
public class VmCalProp : VmProp
|
||||
{
|
||||
public string calculate { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class DictOption
|
||||
{
|
||||
public string dictTypeId { get; set; } = string.Empty;
|
||||
public string refField { get; set; } = "id";
|
||||
}
|
||||
|
||||
public class CompOption
|
||||
{
|
||||
public string type { get; set; } = "el-input";
|
||||
public JObject attr { get; set; } = new JObject();
|
||||
}
|
||||
573
visualdev/Tnb.Vmodel/Extension/StringExtensions.cs
Normal file
573
visualdev/Tnb.Vmodel/Extension/StringExtensions.cs
Normal file
@@ -0,0 +1,573 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using Tnb.VmodelEngine;
|
||||
|
||||
namespace System;
|
||||
|
||||
/// <summary>
|
||||
/// 字符串扩展类,来自Abp
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a char to end of given string if it does not ends with the char.
|
||||
/// </summary>
|
||||
public static string EnsureEndsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
|
||||
{
|
||||
ThrowIf.IsNull(str, nameof(str));
|
||||
|
||||
if (str.EndsWith(c.ToString(), comparisonType))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str + c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a char to beginning of given string if it does not starts with the char.
|
||||
/// </summary>
|
||||
public static string EnsureStartsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
|
||||
{
|
||||
ThrowIf.IsNull(str, nameof(str));
|
||||
|
||||
if (str.StartsWith(c.ToString(), comparisonType))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return c + str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this string is null or an System.String.Empty string.
|
||||
/// </summary>
|
||||
public static bool IsNullOrEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// indicates whether this string is null, empty, or consists only of white-space characters.
|
||||
/// </summary>
|
||||
public static bool IsNullOrWhiteSpace(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from beginning of the string.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
||||
public static string Left(this string str, int len)
|
||||
{
|
||||
ThrowIf.IsNull(str, nameof(str));
|
||||
|
||||
if (str.Length < len)
|
||||
{
|
||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
||||
}
|
||||
|
||||
return str.Substring(0, len);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts line endings in the string to <see cref="Environment.NewLine"/>.
|
||||
/// </summary>
|
||||
public static string NormalizeLineEndings(this string str)
|
||||
{
|
||||
return str.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets index of nth occurrence of a char in a string.
|
||||
/// </summary>
|
||||
/// <param name="str">source string to be searched</param>
|
||||
/// <param name="c">Char to search in <paramref name="str"/></param>
|
||||
/// <param name="n">Count of the occurrence</param>
|
||||
public static int NthIndexOf(this string str, char c, int n)
|
||||
{
|
||||
ThrowIf.IsNull(str, nameof(str));
|
||||
|
||||
var count = 0;
|
||||
for (var i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (str[i] != c)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((++count) == n)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <param name="postFixes">one or more postfix.</param>
|
||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
||||
public static string RemovePostFix(this string str, params string[] postFixes)
|
||||
{
|
||||
return str.RemovePostFix(StringComparison.Ordinal, postFixes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <param name="comparisonType">String comparison type</param>
|
||||
/// <param name="postFixes">one or more postfix.</param>
|
||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
||||
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
|
||||
{
|
||||
if (str.IsNullOrEmpty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (postFixes.IsNullOrEmpty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
foreach (var postFix in postFixes)
|
||||
{
|
||||
if (str.EndsWith(postFix, comparisonType))
|
||||
{
|
||||
return str.Left(str.Length - postFix.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <param name="preFixes">one or more prefix.</param>
|
||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
||||
public static string RemovePreFix(this string str, params string[] preFixes)
|
||||
{
|
||||
return str.RemovePreFix(StringComparison.Ordinal, preFixes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <param name="comparisonType">String comparison type</param>
|
||||
/// <param name="preFixes">one or more prefix.</param>
|
||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
||||
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
|
||||
{
|
||||
if (str.IsNullOrEmpty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (preFixes.IsNullOrEmpty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
foreach (var preFix in preFixes)
|
||||
{
|
||||
if (str.StartsWith(preFix, comparisonType))
|
||||
{
|
||||
return str.Right(str.Length - preFix.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public static string ReplaceFirst(this string str, string search, string replace, StringComparison comparisonType = StringComparison.Ordinal)
|
||||
{
|
||||
|
||||
var pos = str.IndexOf(search, comparisonType);
|
||||
if (pos < 0)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.Substring(0, pos) + replace + str.Substring(pos + search.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from end of the string.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
||||
public static string Right(this string str, int len)
|
||||
{
|
||||
|
||||
if (str.Length < len)
|
||||
{
|
||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
||||
}
|
||||
|
||||
return str.Substring(str.Length - len, len);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses string.Split method to split given string by given separator.
|
||||
/// </summary>
|
||||
public static string[] Split(this string str, string separator)
|
||||
{
|
||||
return str.Split(new[] { separator }, StringSplitOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses string.Split method to split given string by given separator.
|
||||
/// </summary>
|
||||
public static string[] Split(this string str, string separator, StringSplitOptions options)
|
||||
{
|
||||
return str.Split(new[] { separator }, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
|
||||
/// </summary>
|
||||
public static string[] SplitToLines(this string str)
|
||||
{
|
||||
return str.Split(Environment.NewLine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
|
||||
/// </summary>
|
||||
public static string[] SplitToLines(this string str, StringSplitOptions options)
|
||||
{
|
||||
return str.Split(Environment.NewLine, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts PascalCase string to camelCase string.
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
/// <param name="handleAbbreviations">set true to if you want to convert 'XYZ' to 'xyz'.</param>
|
||||
/// <returns>camelCase of the string</returns>
|
||||
public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str.Length == 1)
|
||||
{
|
||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
||||
}
|
||||
|
||||
if (handleAbbreviations && IsAllUpperCase(str))
|
||||
{
|
||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
||||
}
|
||||
|
||||
return (useCurrentCulture ? char.ToLower(str[0]) : char.ToLowerInvariant(str[0])) + str.Substring(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts given PascalCase/camelCase string to sentence (by splitting words by space).
|
||||
/// Example: "ThisIsSampleSentence" is converted to "This is a sample sentence".
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert.</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
public static string ToSentenceCase(this string str, bool useCurrentCulture = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return useCurrentCulture
|
||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]))
|
||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLowerInvariant(m.Value[1]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts given PascalCase/camelCase string to kebab-case.
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert.</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
public static string ToKebabCase(this string str, bool useCurrentCulture = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
str = str.ToCamelCase();
|
||||
|
||||
return useCurrentCulture
|
||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLower(m.Value[1]))
|
||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLowerInvariant(m.Value[1]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts given PascalCase/camelCase string to snake case.
|
||||
/// Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence".
|
||||
/// https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert.</param>
|
||||
/// <returns></returns>
|
||||
public static string ToSnakeCase(this string str)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5));
|
||||
var previousCategory = default(UnicodeCategory?);
|
||||
|
||||
for (var currentIndex = 0; currentIndex < str.Length; currentIndex++)
|
||||
{
|
||||
var currentChar = str[currentIndex];
|
||||
if (currentChar == '_')
|
||||
{
|
||||
builder.Append('_');
|
||||
previousCategory = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentCategory = char.GetUnicodeCategory(currentChar);
|
||||
switch (currentCategory)
|
||||
{
|
||||
case UnicodeCategory.UppercaseLetter:
|
||||
case UnicodeCategory.TitlecaseLetter:
|
||||
if (previousCategory == UnicodeCategory.SpaceSeparator ||
|
||||
previousCategory == UnicodeCategory.LowercaseLetter ||
|
||||
previousCategory != UnicodeCategory.DecimalDigitNumber &&
|
||||
previousCategory != null &&
|
||||
currentIndex > 0 &&
|
||||
currentIndex + 1 < str.Length &&
|
||||
char.IsLower(str[currentIndex + 1]))
|
||||
{
|
||||
builder.Append('_');
|
||||
}
|
||||
|
||||
currentChar = char.ToLower(currentChar);
|
||||
break;
|
||||
|
||||
case UnicodeCategory.LowercaseLetter:
|
||||
case UnicodeCategory.DecimalDigitNumber:
|
||||
if (previousCategory == UnicodeCategory.SpaceSeparator)
|
||||
{
|
||||
builder.Append('_');
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (previousCategory != null)
|
||||
{
|
||||
previousCategory = UnicodeCategory.SpaceSeparator;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.Append(currentChar);
|
||||
previousCategory = currentCategory;
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts string to enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of enum</typeparam>
|
||||
/// <param name="value">String value to convert</param>
|
||||
/// <returns>Returns enum object</returns>
|
||||
public static T ToEnum<T>(this string value)
|
||||
where T : struct
|
||||
{
|
||||
ThrowIf.IsNull(value, nameof(value));
|
||||
return (T)Enum.Parse(typeof(T), value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts string to enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of enum</typeparam>
|
||||
/// <param name="value">String value to convert</param>
|
||||
/// <param name="ignoreCase">Ignore case</param>
|
||||
/// <returns>Returns enum object</returns>
|
||||
public static T ToEnum<T>(this string value, bool ignoreCase)
|
||||
where T : struct
|
||||
{
|
||||
ThrowIf.IsNull(value, nameof(value));
|
||||
return (T)Enum.Parse(typeof(T), value, ignoreCase);
|
||||
}
|
||||
|
||||
public static string ToMd5(this string str)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
var inputBytes = Encoding.UTF8.GetBytes(str);
|
||||
var hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var hashByte in hashBytes)
|
||||
{
|
||||
sb.Append(hashByte.ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts camelCase string to PascalCase string.
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
/// <returns>PascalCase of the string</returns>
|
||||
public static string ToPascalCase(this string str, bool useCurrentCulture = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str.Length == 1)
|
||||
{
|
||||
return useCurrentCulture ? str.ToUpper() : str.ToUpperInvariant();
|
||||
}
|
||||
|
||||
return (useCurrentCulture ? char.ToUpper(str[0]) : char.ToUpperInvariant(str[0])) + str.Substring(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
||||
/// </summary>
|
||||
public static string Truncate(this string str, int maxLength)
|
||||
{
|
||||
if (str.Length <= maxLength)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.Left(maxLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from Ending of the string if it exceeds maximum length.
|
||||
/// </summary>
|
||||
public static string TruncateFromBeginning(this string str, int maxLength)
|
||||
{
|
||||
if (str.Length <= maxLength)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.Right(maxLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
||||
/// It adds a "..." postfix to end of the string if it's truncated.
|
||||
/// Returning string can not be longer than maxLength.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||
public static string TruncateWithPostfix(this string str, int maxLength)
|
||||
{
|
||||
return TruncateWithPostfix(str, maxLength, "...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
||||
/// It adds given <paramref name="postfix"/> to end of the string if it's truncated.
|
||||
/// Returning string can not be longer than maxLength.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||
public static string TruncateWithPostfix(this string str, int maxLength, string postfix)
|
||||
{
|
||||
if (str == string.Empty || maxLength == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (str.Length <= maxLength)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (maxLength <= postfix.Length)
|
||||
{
|
||||
return postfix.Left(maxLength);
|
||||
}
|
||||
|
||||
return str.Left(maxLength - postfix.Length) + postfix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts given string to a byte array using <see cref="Encoding.UTF8"/> encoding.
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(this string str)
|
||||
{
|
||||
return str.GetBytes(Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts given string to a byte array using the given <paramref name="encoding"/>
|
||||
/// </summary>
|
||||
public static byte[] GetBytes([NotNull] this string str, [NotNull] Encoding encoding)
|
||||
{
|
||||
ThrowIf.IsNull(str, nameof(str));
|
||||
ThrowIf.IsNull(encoding, nameof(encoding));
|
||||
|
||||
return encoding.GetBytes(str);
|
||||
}
|
||||
|
||||
private static bool IsAllUpperCase(string input)
|
||||
{
|
||||
for (int i = 0; i < input.Length; i++)
|
||||
{
|
||||
if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts snake_case string to PascalCase string.
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
/// <returns>PascalCase of the string</returns>
|
||||
public static string SnakeToPascalCase(this string str, bool useCurrentCulture = false)
|
||||
{
|
||||
var sArr = str.Split(new char[] { '-', '_' }).Select(a => a.ToPascalCase(useCurrentCulture));
|
||||
return string.Join("", sArr);
|
||||
}
|
||||
/// <summary>
|
||||
/// Converts snake_case string to PascalCase string.
|
||||
/// </summary>
|
||||
/// <param name="str">String to convert</param>
|
||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
||||
/// <returns>PascalCase of the string</returns>
|
||||
public static string SnakeToCamelCase(this string str, bool useCurrentCulture = false)
|
||||
{
|
||||
return SnakeToPascalCase(str, useCurrentCulture).ToCamelCase();
|
||||
}
|
||||
|
||||
}
|
||||
16
visualdev/Tnb.Vmodel/IVmodelAppService.cs
Normal file
16
visualdev/Tnb.Vmodel/IVmodelAppService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.DependencyInjection;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型服务接口
|
||||
/// </summary>
|
||||
public interface IVmodelAppService : ITransient
|
||||
{
|
||||
|
||||
}
|
||||
16
visualdev/Tnb.Vmodel/IVmodelPageAppService.cs
Normal file
16
visualdev/Tnb.Vmodel/IVmodelPageAppService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.DependencyInjection;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型服务接口
|
||||
/// </summary>
|
||||
public interface IVmodelPageAppService : ITransient
|
||||
{
|
||||
|
||||
}
|
||||
25
visualdev/Tnb.Vmodel/Mapper/TypeAdapter.cs
Normal file
25
visualdev/Tnb.Vmodel/Mapper/TypeAdapter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public class TypeAdapter
|
||||
{
|
||||
public static TypeAdapterConfig IgnoreNull { get; }
|
||||
static TypeAdapter()
|
||||
{
|
||||
TypeAdapterConfig.GlobalSettings.Default.PreserveReference(true);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JToken, JToken>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JObject, JObject>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JArray, JArray>().MapWith(json => json);
|
||||
IgnoreNull = TypeAdapterConfig.GlobalSettings.Clone();
|
||||
IgnoreNull.Default.IgnoreNullValues(true);
|
||||
}
|
||||
|
||||
}
|
||||
46
visualdev/Tnb.Vmodel/Mapper/VmodelMapper.cs
Normal file
46
visualdev/Tnb.Vmodel/Mapper/VmodelMapper.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using JNPF.Common.Security;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public class VmodelMapper : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<VmGetInput, VmQueryInput>()
|
||||
.Map(dest => dest.psize, src => 1)
|
||||
.Map(dest => dest.pnum, src => 0)
|
||||
.Map(dest => dest.q, src => string.IsNullOrEmpty(src.q) ? null : src.q.ToObject<DObject>());
|
||||
config.ForType<VmGetListInput, VmQueryInput>()
|
||||
.Map(dest => dest.q, src => string.IsNullOrEmpty(src.q) ? null : src.q.ToObject<DObject>());
|
||||
config.ForType<DbColumnInfo, VmDbProp>()
|
||||
.Map(dest => dest.code, src => src.DbColumnName.SnakeToCamelCase(false))
|
||||
.Map(dest => dest.name, src => src.ColumnDescription)
|
||||
.Map(dest => dest.field, src => src.DbColumnName)
|
||||
.Map(dest => dest.dataType, src => src.DataType)
|
||||
//.Map(dest => dest.csType, src => src.DbColumnName)
|
||||
//.Map(dest => dest.propType, src => ePropType.DbTable)
|
||||
.Map(dest => dest.length, src => src.Length)
|
||||
.Map(dest => dest.digit, src => src.DecimalDigits)
|
||||
//.Map(dest => dest.ordinal, src => src.i)
|
||||
.Map(dest => dest.required, src => !src.IsNullable)
|
||||
.Map(dest => dest.pkey, src => src.IsPrimarykey)
|
||||
//.Map(dest => dest.descrip, src => src.DbColumnName)
|
||||
.Map(dest => dest.defValue, src => src.DefaultValue);
|
||||
config.ForType<SugarColumn, VmDbProp>()
|
||||
//.Map(dest => dest.code, src => src.DbColumnName.SnakeToCamelCase(false))
|
||||
.Map(dest => dest.name, src => src.ColumnDescription)
|
||||
.Map(dest => dest.field, src => src.ColumnName)
|
||||
.Map(dest => dest.dataType, src => src.ColumnDataType)
|
||||
//.Map(dest => dest.csType, src => src.DbColumnName)
|
||||
//.Map(dest => dest.propType, src => ePropType.DbTable)
|
||||
.Map(dest => dest.length, src => src.Length)
|
||||
.Map(dest => dest.digit, src => src.DecimalDigits)
|
||||
//.Map(dest => dest.ordinal, src => src.i)
|
||||
.Map(dest => dest.required, src => !src.IsNullable)
|
||||
.Map(dest => dest.pkey, src => src.IsPrimaryKey);
|
||||
//.Map(dest => dest.descrip, src => src.DbColumnName)
|
||||
//.Map(dest => dest.defValue, src => src.DefaultValue);
|
||||
}
|
||||
}
|
||||
13
visualdev/Tnb.Vmodel/Tnb.VmodelEngine.csproj
Normal file
13
visualdev/Tnb.Vmodel/Tnb.VmodelEngine.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\common\Tnb.Common\Tnb.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
168
visualdev/Tnb.Vmodel/Util/ThrowIf.cs
Normal file
168
visualdev/Tnb.Vmodel/Util/ThrowIf.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
public static class ThrowIf
|
||||
{
|
||||
public static void When(bool isMatch, string message)
|
||||
{
|
||||
if (isMatch)
|
||||
{
|
||||
throw new ArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static T IsNull<T>([NotNull] T? value, string parameterName, string? message = null)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(parameterName, message);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static T IsNullOrDefault<T>([NotNull] T? value, string parameterName) where T : struct
|
||||
{
|
||||
if (!value.HasValue)
|
||||
{
|
||||
throw new ArgumentException(parameterName + " is null!", parameterName);
|
||||
}
|
||||
|
||||
if (value.Value.Equals(default(T)))
|
||||
{
|
||||
throw new ArgumentException(parameterName + " has a default value!", parameterName);
|
||||
}
|
||||
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
|
||||
public static string IsNullOrWhiteSpace(string value, string parameterName, int maxLength = int.MaxValue, int minLength = 0)
|
||||
{
|
||||
if (value.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new ArgumentException(parameterName + " can not be null, empty or white space!", parameterName);
|
||||
}
|
||||
|
||||
if (value.Length > maxLength)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName);
|
||||
}
|
||||
|
||||
if (minLength > 0 && value.Length < minLength)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static string IsNullOrEmpty(string value, string parameterName, int maxLength = int.MaxValue, int minLength = 0)
|
||||
{
|
||||
if (value.IsNullOrEmpty())
|
||||
{
|
||||
throw new ArgumentException(parameterName + " can not be null or empty!", parameterName);
|
||||
}
|
||||
|
||||
if (value.Length > maxLength)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName);
|
||||
}
|
||||
|
||||
if (minLength > 0 && value.Length < minLength)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> value, string parameterName)
|
||||
//{
|
||||
// if (value.IsNullOrEmpty())
|
||||
// {
|
||||
// throw new ArgumentException(parameterName + " can not be null or empty!", parameterName);
|
||||
// }
|
||||
|
||||
// return value;
|
||||
//}
|
||||
|
||||
//public static Type AssignableTo<TBaseType>(Type type, string parameterName)
|
||||
//{
|
||||
// NotNull(type, parameterName);
|
||||
// if (!type.IsAssignableTo<TBaseType>())
|
||||
// {
|
||||
// throw new ArgumentException(parameterName + " (type of " + type.AssemblyQualifiedName + ") should be assignable to the " + typeof(TBaseType).GetFullNameWithAssemblyName() + "!");
|
||||
// }
|
||||
|
||||
// return type;
|
||||
//}
|
||||
|
||||
public static short OutOfRange(short value, string parameterName, short minimumValue, short maximumValue = short.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int OutOfRange(int value, string parameterName, int minimumValue, int maximumValue = int.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long OutOfRange(long value, string parameterName, long minimumValue, long maximumValue = long.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float OutOfRange(float value, string parameterName, float minimumValue, float maximumValue = float.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double OutOfRange(double value, string parameterName, double minimumValue, double maximumValue = double.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static decimal OutOfRange(decimal value, string parameterName, decimal minimumValue, decimal maximumValue = decimal.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
200
visualdev/Tnb.Vmodel/VmAppService.cs
Normal file
200
visualdev/Tnb.Vmodel/VmAppService.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.DataAccess;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 增删改查基类
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 10, KeepVerb = true)]
|
||||
[Route("api")]
|
||||
public class VmAppService : BaseAppService
|
||||
{
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly ISqlSugarClient _db;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VmAppService(IDataAccess da)
|
||||
{
|
||||
_dataAccess = da;
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
#region 根据vmodel id进行增删改查接口
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
[HttpGet("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpGet("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(input.q))
|
||||
{
|
||||
arg.q = input.q.ToObject<DObject>();
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpPost("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<VmPagedOutput> QueryAsync(string vmid, [FromBody] VmQueryInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
[HttpPost("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<dynamic> CreateAsync(string vmid, VmCreateInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
[HttpPut("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<dynamic> UpdateAsync(string vmid, VmUpdateInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
[HttpDelete("[area]/[controller]/{vmid}/[action]")]
|
||||
public async Task<dynamic> DeleteAsync(string vmid, [FromQuery] VmDeleteInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private async Task<Vmodel> GetVmodelAsync(string area, string vmCode)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(area.SnakeToPascalCase(), vmCode.SnakeToPascalCase(), true);
|
||||
return vm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 根据vmode的area和code进行增删改查接口
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
[HttpGet("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpGet("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(input.q))
|
||||
{
|
||||
arg.q = input.q.ToObject<DObject>();
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpPost("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<VmPagedOutput> QueryAsync(string areaCode, string vmCode, [FromBody] VmQueryInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
[HttpPost("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<dynamic> CreateAsync(string areaCode, string vmCode, VmCreateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
[HttpPut("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<dynamic> UpdateAsync(string areaCode, string vmCode, VmUpdateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
[HttpDelete("{areaCode}/{vmCode}/[action]")]
|
||||
public async Task<dynamic> DeleteAsync(string areaCode, string vmCode, [FromQuery] VmDeleteInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
119
visualdev/Tnb.Vmodel/VmAppServiceT.cs
Normal file
119
visualdev/Tnb.Vmodel/VmAppServiceT.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.DataAccess;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 增删改查基类
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Area = ModuleConst.Area, Order = 10, KeepVerb = true)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class VmAppService<TEntity> : BaseAppService where TEntity : IEntity
|
||||
{
|
||||
protected readonly IDataAccess _dataAccess;
|
||||
protected readonly ISqlSugarClient _db;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VmAppService(IDataAccess dataAccess)
|
||||
{
|
||||
_dataAccess = dataAccess;
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
protected async Task<Vmodel> GetVmodelAsync()
|
||||
{
|
||||
var tp = typeof(TEntity);
|
||||
if (string.IsNullOrEmpty(tp?.Namespace))
|
||||
{
|
||||
throw new ArgumentNullException($"类型 {nameof(tp)} 的命名空间不可为空");
|
||||
}
|
||||
var area = tp.Namespace.Split('.').Last().ToKebabCase();
|
||||
var vm = await _dataAccess.GetVmodelAsync(area, tp.Name, true);
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
public virtual async Task<dynamic> GetAsync([FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls.items.FirstOrDefault()!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public virtual async Task<VmPagedOutput> GetListAsync([FromQuery] VmGetListInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(input.q))
|
||||
{
|
||||
arg.q = input.q.ToObject<DObject>();
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public virtual async Task<VmPagedOutput> QueryAsync([FromBody] VmQueryInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||
return ls;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
public virtual async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
public virtual async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
public virtual async Task<dynamic> DeleteAsync([FromQuery] VmDeleteInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
150
visualdev/Tnb.Vmodel/VmodelAppService.cs
Normal file
150
visualdev/Tnb.Vmodel/VmodelAppService.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.DataAccess;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型服务类
|
||||
/// </summary>
|
||||
public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VmodelAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
public override async Task<dynamic> GetAsync(VmGetInput input)
|
||||
{
|
||||
//return await _dataAccess.GetVmodelAsync(input.id);
|
||||
var query = _db.Queryable<Vmodel>().Where(a => a.deleted == 0);
|
||||
Vmodel vm;
|
||||
if (long.TryParse(input.id, out long id))
|
||||
{
|
||||
vm = await query.FirstAsync(a => a.id == input.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm = await query.FirstAsync(a => a.vmCode == input.id);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
||||
{
|
||||
VmPagedOutput ret = new();
|
||||
var q = _db.Queryable<Vmodel>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.vmCode.Contains(input.k!) || a.vmName.Contains(input.k!));
|
||||
RefAsync<int> total = 0;
|
||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||
ret.total = total;
|
||||
ret.items = data.ConvertAll<dynamic>(a => a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public override Task<VmPagedOutput> QueryAsync(VmQueryInput input)
|
||||
{
|
||||
return base.QueryAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 模型
|
||||
/// </summary>
|
||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
{
|
||||
//ThrowIf.IsNull(input.data, nameof(input));
|
||||
ArgumentNullException.ThrowIfNull(input.data);
|
||||
Vmodel vm = input.data.Adapt<Vmodel>();
|
||||
await _db.Insertable(vm).ExecuteCommandAsync();
|
||||
return input;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input.data);
|
||||
Vmodel vm = input.data.Adapt<Vmodel>();
|
||||
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||
return input;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||
{
|
||||
var ret = await _db.Deleteable<Vmodel>(input.id).ExecuteCommandAsync();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据表创建模型
|
||||
/// </summary>
|
||||
public async Task<List<Vmodel>> CreateFromTable(VmodelCreateFromTableInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.tableName, nameof(input.tableName));
|
||||
var sugar = _dataAccess.GetSqlSugar(input.dbCode);
|
||||
var lsTable = sugar.DbMaintenance.GetTableInfoList().WhereIF(input.tableName != "ALL", a => a.Name == input.tableName);
|
||||
|
||||
List<Vmodel> lsToAdd = new List<Vmodel>();
|
||||
List<Vmodel> lsToUpdate = new List<Vmodel>();
|
||||
foreach (var tb in lsTable)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(input.removePrefix) && !tb.Name.StartsWith(input.removePrefix)) continue;
|
||||
var colInfo = sugar.DbMaintenance.GetColumnInfosByTableName(tb.Name);
|
||||
Vmodel model = new() { dbCode = input.dbCode, vmName = tb.Description, tableName = tb.Name };
|
||||
model.area = input.area;
|
||||
model.vmCode = (string.IsNullOrEmpty(input.removePrefix) ? tb.Name : tb.Name.RemovePreFix(input.removePrefix)).SnakeToPascalCase();
|
||||
//model.createId = CurrentUser.Id;
|
||||
int n = 1;
|
||||
foreach (var p in colInfo)
|
||||
{
|
||||
var prop = p.Adapt<VmDbProp>();
|
||||
prop.ordinal = n++;
|
||||
prop.csType = sugar.Ado.DbBind.GetPropertyTypeName(p.DataType);
|
||||
model.dbProps.Add(prop);
|
||||
}
|
||||
var exist = await _db.Queryable<Vmodel>().FirstAsync(a => a.dbCode == input.dbCode && a.tableName == tb.Name);
|
||||
if (exist == null)
|
||||
{
|
||||
lsToAdd.Add(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist.area = model.area;
|
||||
model.dbProps.Adapt(exist.dbProps);
|
||||
//exist.dbProps.Clear();
|
||||
//exist.dbProps.AddRange(model.dbProps.OrderBy(a => a.ordinal));
|
||||
lsToUpdate.Add(exist);
|
||||
}
|
||||
}
|
||||
if (lsToAdd.Count > 0)
|
||||
{
|
||||
await _db.Insertable(lsToAdd).ExecuteCommandAsync();
|
||||
}
|
||||
if (lsToUpdate.Count > 0)
|
||||
{
|
||||
await _db.Updateable(lsToUpdate).ExecuteCommandAsync();
|
||||
}
|
||||
return lsToAdd.Union(lsToUpdate).ToList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
166
visualdev/Tnb.Vmodel/VmodelPageAppService.cs
Normal file
166
visualdev/Tnb.Vmodel/VmodelPageAppService.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System.Text;
|
||||
using JNPF.Common.Security;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using Tnb.DataAccess;
|
||||
|
||||
namespace Tnb.VmodelEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型服务类
|
||||
/// </summary>
|
||||
public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppService
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VmodelPageAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
public override async Task<dynamic> GetAsync(VmGetInput input)
|
||||
{
|
||||
var query = _db.Queryable<VmodelPage>().Where(a => a.deleted == 0);
|
||||
VmodelPage vm = await query.FirstAsync(a => a.id == input.id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
||||
{
|
||||
VmPagedOutput ret = new();
|
||||
var q = _db.Queryable<VmodelPage>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.code.Contains(input.k!) || a.name.Contains(input.k!));
|
||||
RefAsync<int> total = 0;
|
||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||
ret.total = total;
|
||||
ret.items = data.ConvertAll<dynamic>(a => a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 模型
|
||||
/// </summary>
|
||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input.data);
|
||||
VmodelPage vpage = input.data.Adapt<VmodelPage>();
|
||||
await _db.Insertable(vpage).ExecuteCommandAsync();
|
||||
return vpage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input.data);
|
||||
if (!input.data.ContainsKey(nameof(VmodelPage.id)))
|
||||
{
|
||||
throw new Exception($"更新数据时主键({nameof(VmodelPage.id)})不可为空");
|
||||
}
|
||||
var id = input.data[nameof(VmodelPage.id)].ToString();
|
||||
var model = await _db.Queryable<VmodelPage>().FirstAsync(a => a.id == id);
|
||||
ArgumentNullException.ThrowIfNull(model);
|
||||
input.data.Adapt(model, TypeAdapter.IgnoreNull);
|
||||
await _db.Updateable(model).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||
{
|
||||
var ret = await _db.Deleteable<VmodelPage>(input.id).ExecuteCommandAsync();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据表创建模型
|
||||
/// </summary>
|
||||
public async Task<VmodelPage> CreateByVmodel(CreatePageFromVmodelInput input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input.vmid);
|
||||
var vm = await _dataAccess.GetVmodelAsync(input.vmid);
|
||||
ArgumentNullException.ThrowIfNull(vm);
|
||||
|
||||
var page = await _db.Queryable<VmodelPage>().FirstAsync(a => a.vmid == vm.id);
|
||||
if (page == null)
|
||||
{
|
||||
page = new VmodelPage { vmid = vm.id, code = vm.vmCode, name = vm.vmName };
|
||||
page.pageSchema = CreatePageSchema(vm, page.id);
|
||||
await _db.Insertable(page).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
page.pageSchema = CreatePageSchema(vm, page.id);
|
||||
await _db.Updateable(page).ExecuteCommandAsync();
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private JObject CreatePageSchema(Vmodel vm, string pageid)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendLine("{");
|
||||
str.AppendLine($"\"page\": {{ \"loadList\": true, \"watchClient\": false }},");
|
||||
str.AppendLine($"\"queryData\": {{ }},");
|
||||
str.AppendLine($"\"queryForm\": {{");
|
||||
str.AppendLine($"\"show\": false,");
|
||||
str.AppendLine($"\"attr\": {{ \"labelWidth\": \"106px\", \"hasKeyword\":false }},");
|
||||
str.AppendLine($"\"cols\": {{");
|
||||
var pQuery = vm.dbProps.Skip(1).Take(1).FirstOrDefault();
|
||||
if (pQuery != null)
|
||||
{
|
||||
str.AppendLine($"\"{pQuery.code}\": {{ \"label\": \"{pQuery.name}\", \"span\": 8, \"qtype\": 2, \"isQuick\": true, \"comp\": {{ \"type\": \"el-input\", \"attr\": {{ \"placeholder\": \"{pQuery.name}\", \"clearable\": true, \"maxlength\": 20 }} }} }}");
|
||||
}
|
||||
str.AppendLine($"}}");
|
||||
str.AppendLine($"}},");
|
||||
str.AppendLine($"\"list\": {{");
|
||||
str.AppendLine($"\"opt\": {{ \"isPage\": true, \"isCheck\": true, \"sortBy\": \"\", \"pkey\": \"{vm.GetPrimary().code}\" }},");
|
||||
str.AppendLine($"\"attr\": {{ \"border\": false }},");
|
||||
str.AppendLine($"\"cols\": {{");
|
||||
foreach (var p in vm.dbProps)
|
||||
{
|
||||
str.AppendLine($"\"{p.code}\":{{ \"label\": \"{p.name}\", \"show\": true, \"attr\": {{ {p.GetDefaultWidth()} }}, \"comp\": {{}} }},");
|
||||
}
|
||||
str.AppendLine($"}}");
|
||||
str.AppendLine($"}},");
|
||||
str.AppendLine($"\"editData\": {vm.GetDefaultDObject().ToJsonString()},");
|
||||
str.AppendLine($"\"editDlg\": {{ \"isAdd\": true, \"tabHeight\": 300, \"name\": \"{vm.vmName}\" }},");
|
||||
str.AppendLine($"\"editForm\": {{");
|
||||
str.AppendLine($"\"attr\": {{ \"labelWidth\": \"106px\" }},");
|
||||
str.AppendLine($"\"rules\": {{");
|
||||
foreach (var p in vm.dbProps.Where(a => a.required && !a.pkey))
|
||||
{
|
||||
str.AppendLine($"\"{p.code}\": [{{ \"required\": true, \"message\": \"必填项不能为空\", \"trigger\": \"blur\" }}],");
|
||||
}
|
||||
str.AppendLine($"}},");
|
||||
str.AppendLine($"\"cols\": {{");
|
||||
foreach (var p in vm.dbProps)
|
||||
{
|
||||
str.AppendLine($"\"{p.code}\": {{ \"label\": \"{p.name}\", \"show\": true, \"comp\": {p.GetDefaultComp().ToJsonString()} }},");
|
||||
}
|
||||
str.AppendLine($"}}");
|
||||
str.AppendLine($"}},");
|
||||
str.AppendLine($"\"tree\": {{ \"key\": \"id\", \"height\": 300, \"props\": {{ \"label\": \"enumName\" }}, \"data\": [] }}");
|
||||
str.AppendLine($"}}");
|
||||
var s = str.ToString();
|
||||
Console.WriteLine(s);
|
||||
return JObject.Parse(s);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user