添加Tnb.Vengine
This commit is contained in:
30
visualdev/Tnb.Vengine/Domain/Entity.cs
Normal file
30
visualdev/Tnb.Vengine/Domain/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.Vengine.Domain;
|
||||
|
||||
[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);
|
||||
//}
|
||||
}
|
||||
36
visualdev/Tnb.Vengine/Domain/VmBaseProp.cs
Normal file
36
visualdev/Tnb.Vengine/Domain/VmBaseProp.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型属性
|
||||
/// </summary>
|
||||
public class VmBaseProp
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性代码
|
||||
/// </summary>
|
||||
public string code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string name { 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();
|
||||
}
|
||||
12
visualdev/Tnb.Vengine/Domain/VmCalcProp.cs
Normal file
12
visualdev/Tnb.Vengine/Domain/VmCalcProp.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
|
||||
public class VmCalProp : VmBaseProp
|
||||
{
|
||||
public string calculate { get; set; } = string.Empty;
|
||||
}
|
||||
149
visualdev/Tnb.Vengine/Domain/VmDbProp.cs
Normal file
149
visualdev/Tnb.Vengine/Domain/VmDbProp.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// 字段属性
|
||||
/// </summary>
|
||||
public class VmDbProp : VmBaseProp
|
||||
{
|
||||
#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;
|
||||
}
|
||||
}
|
||||
198
visualdev/Tnb.Vengine/Domain/VmDto.cs
Normal file
198
visualdev/Tnb.Vengine/Domain/VmDto.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
54
visualdev/Tnb.Vengine/Domain/VmNavProp.cs
Normal file
54
visualdev/Tnb.Vengine/Domain/VmNavProp.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性
|
||||
/// </summary>
|
||||
public class VmNavProp : VmBaseProp
|
||||
{
|
||||
/// <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; }
|
||||
}
|
||||
443
visualdev/Tnb.Vengine/Domain/Vmodel.cs
Normal file
443
visualdev/Tnb.Vengine/Domain/Vmodel.cs
Normal file
@@ -0,0 +1,443 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通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 Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
34
visualdev/Tnb.Vengine/Domain/VmodelDto.cs
Normal file
34
visualdev/Tnb.Vengine/Domain/VmodelDto.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
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; }
|
||||
|
||||
}
|
||||
|
||||
49
visualdev/Tnb.Vengine/Domain/VmodelLink.cs
Normal file
49
visualdev/Tnb.Vengine/Domain/VmodelLink.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
|
||||
/// <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.Vengine/Domain/VmodelPage.cs
Normal file
107
visualdev/Tnb.Vengine/Domain/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.Vengine.Domain;
|
||||
|
||||
/// <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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user