Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -1,105 +1,83 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
using Tnb.Common.Contracts;
|
||||
|
||||
namespace Tnb.BasicData.Entities
|
||||
namespace Tnb.BasicData.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 次品项
|
||||
/// </summary>
|
||||
[SugarTable("bas_defect")]
|
||||
public partial class BasDefect : BaseEntity<string>
|
||||
{
|
||||
///<summary>
|
||||
///次品项
|
||||
///</summary>
|
||||
[SugarTable("bas_defect")]
|
||||
public partial class BasDefect
|
||||
public BasDefect()
|
||||
{
|
||||
public BasDefect(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true)]
|
||||
public string id {get;set;} = SnowflakeIdHelper.NextId();
|
||||
|
||||
/// <summary>
|
||||
/// Desc:排序
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public long? ordinal {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建用户
|
||||
/// Default:NULL::character varying
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? create_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime? create_time {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:修改用户
|
||||
/// Default:NULL::character varying
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? modify_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:修改时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime? modify_time {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:扩展字段
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? extras {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:备注
|
||||
/// Default:NULL::character varying
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? remark {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:次品类型
|
||||
/// Default:NULL::character varying
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? defect_type_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:缺陷代码
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? defect_code {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:缺陷名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string? defect_name {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:是否启用
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public short enabled {get;set;}
|
||||
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扩展字段
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? extras { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 次品类型
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? defect_type_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缺陷代码
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? defect_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缺陷名称
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? defect_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public short enabled { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.EquipMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 保养规则关联模具列表输出参数
|
||||
/// </summary>
|
||||
public class MaintainRuleMoldListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模具Id
|
||||
/// </summary>
|
||||
public string mold_id { get; set; }
|
||||
/// <summary>
|
||||
/// 模具编码
|
||||
/// </summary>
|
||||
public string mold_code { get; set; }
|
||||
/// <summary>
|
||||
/// 模具名称
|
||||
/// </summary>
|
||||
public string mold_name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Tnb.EquipMgr.Entities
|
||||
///<summary>
|
||||
///模具保养
|
||||
///</summary>
|
||||
[SugarTable("tool_mold_maintenance")]
|
||||
[SugarTable("tool_mold_maintain_item")]
|
||||
public partial class MoldMaintenance
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -12,6 +12,7 @@ using Tnb.Common.Contracts;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Utils;
|
||||
using Mapster;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
{
|
||||
@@ -22,13 +23,21 @@ namespace Tnb.EquipMgr
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
protected async Task Relevance<TSrc, TDest>(TSrc input,string masterTableName, string name, Expression<Func<TDest, bool>> deleleExp) where TDest : BaseEntity<string>, new()
|
||||
/// <summary>
|
||||
/// 关联
|
||||
/// </summary>
|
||||
/// <typeparam name="TSrc">输入参数类型</typeparam>
|
||||
/// <typeparam name="TDest">目标数据库表类型</typeparam>
|
||||
/// <param name="input">输入参数</param>
|
||||
/// <param name="mColumnName">主表属性名称</param>
|
||||
/// <param name="name">次表属性名称</param>
|
||||
/// <param name="deleleExp">删除条件</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
protected async Task Relevance<TSrc, TDest>(TSrc input, string mColumnName, string name, Expression<Func<TDest, bool>> deleleExp) where TDest : BaseEntity<string>, new()
|
||||
where TSrc : BaseMoldMaintainInput
|
||||
{
|
||||
|
||||
await _db.Deleteable<TDest>().Where(deleleExp).ExecuteCommandAsync();
|
||||
//var itemGroupId = nameof(ToolMoldMaintainGroupRelation.item_group_id);
|
||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||
var entities = new List<TDest>();
|
||||
if (input.ids?.Count > 0)
|
||||
@@ -38,10 +47,10 @@ namespace Tnb.EquipMgr
|
||||
var pk = id;
|
||||
TDest entity = new();
|
||||
entity.id = SnowflakeIdHelper.NextId();
|
||||
if (!PropertySet<TDest>.ValueFactories.TryGetValue(masterTableName, out Action<object, object>? setGroupIdAction))
|
||||
if (!PropertySet<TDest>.ValueFactories.TryGetValue(mColumnName, out Action<object, object>? setGroupIdAction))
|
||||
{
|
||||
setGroupIdAction = PropertySet<TDest>.CreateSetPropertyValueAction(masterTableName);
|
||||
PropertySet<TDest>.ValueFactories.Add(masterTableName, setGroupIdAction);
|
||||
setGroupIdAction = PropertySet<TDest>.CreateSetPropertyValueAction(mColumnName);
|
||||
PropertySet<TDest>.ValueFactories.Add(mColumnName, setGroupIdAction);
|
||||
}
|
||||
setGroupIdAction(entity, input.item_group_id);
|
||||
if (!PropertySet<TDest>.ValueFactories.TryGetValue(name, out Action<object, object>? setAction))
|
||||
@@ -56,5 +65,24 @@ namespace Tnb.EquipMgr
|
||||
var row = await _db.Insertable(entities).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
||||
}
|
||||
|
||||
|
||||
protected async Task<dynamic> GetListByMasterId<TRelaction, TDest, TOutput>(string masterId,
|
||||
Expression<Func<TRelaction, bool>> masterFilterExp,
|
||||
Expression<Func<TRelaction, string>> masterSelector,
|
||||
Expression<Func<TDest, bool>> relactionFilterExp)
|
||||
{
|
||||
var config = new TypeAdapterConfig();
|
||||
config.ForType<TDest, TOutput>();
|
||||
var list = new List<TOutput>();
|
||||
var itemIds = await _db.Queryable<TRelaction>().Where(masterFilterExp).Select(masterSelector).ToListAsync();
|
||||
if (itemIds?.Count > 0)
|
||||
{
|
||||
var items = await _db.Queryable<TDest>().Where(relactionFilterExp).ToListAsync();
|
||||
list = items.Adapt<List<TOutput>>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,29 @@ namespace Tnb.EquipMgr
|
||||
public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager) : base(repository.AsSugarClient())
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository) : base(repository.AsSugarClient())
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据规则Id获取匹配的模具列表
|
||||
/// </summary>
|
||||
/// <param name="ruleId">规则Id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetListById([FromRoute] string ruleId)
|
||||
{
|
||||
var result = new List<MaintainRuleMoldListOutput>();
|
||||
var list = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == ruleId).ToListAsync();
|
||||
if (list?.Count > 0)
|
||||
{
|
||||
var ids = list.Select(it => it.mold_id).ToList();
|
||||
result = await _db.Queryable<ToolMolds>().Where(it => ids.Contains(it.id))
|
||||
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id }, true).ToListAsync();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联模具
|
||||
/// </summary>
|
||||
@@ -39,6 +58,16 @@ namespace Tnb.EquipMgr
|
||||
[HttpPost]
|
||||
public async Task RelevanceMold(RelevanceMoldInput input) =>
|
||||
await Relevance<RelevanceMoldInput, ToolMoldMaintainRuleRelation>(input, nameof(ToolMoldMaintainRuleRelation.rule_id), nameof(ToolMoldMaintainRuleRelation.mold_id), it => it.rule_id == input.rule_id);
|
||||
|
||||
/// <summary>
|
||||
/// 删除模具信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task DeleteMoldRelevance(RelevanceMoldInput input)
|
||||
{
|
||||
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace @Model.nsName;
|
||||
|
||||
/// <summary>
|
||||
/// @Model.table.Description
|
||||
/// @Model.descrip
|
||||
/// </summary>
|
||||
[SugarTable("@Model.table.Name")]
|
||||
public partial class @Model.clsName : BaseEntity<@Model.pkType>
|
||||
[SugarTable("@Model.tableName")]
|
||||
public partial class @Model.clsName : @Model.GetInherit()
|
||||
{
|
||||
public @Model.clsName()
|
||||
public @(Model.clsName)()
|
||||
{
|
||||
@Model.GetConstruct()
|
||||
}
|
||||
@foreach(var col in Model.columns)
|
||||
{
|
||||
/// <summary>
|
||||
/// col.Descrip
|
||||
/// </summary>
|
||||
@Model.GetColumnAttrib(col.DbColumnName)
|
||||
public col.PropertyType.Name col.PropertyName {get;set;}@Model.GetColumnDefaultValue(col.DbColumnName)
|
||||
}
|
||||
if(!Model.ignoreCols.Contains(col.colName)){
|
||||
@:/// <summary>
|
||||
@:/// @col.descrip
|
||||
@:/// </summary>
|
||||
@col.GetPropAttr()
|
||||
@:public @col.GetPropType() @col.propName { get; set; }@col.GetDefaultValue()
|
||||
@:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,17 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.Common.Contracts
|
||||
namespace Tnb.Common.Contracts;
|
||||
|
||||
public class BaseEntity<TKey> : IEntity where TKey : IEquatable<TKey>
|
||||
{
|
||||
public class BaseEntity<TKey> : IEntity where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置 编号.
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true)]
|
||||
public TKey id { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取或设置 编号.
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true)]
|
||||
public TKey id { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,25 @@ public class SystemMapper : IRegister
|
||||
.Map(dest => dest.IsPrimarykey, src => src.primaryKey)
|
||||
.Map(dest => dest.IsNullable, src => src.allowNull == 1)
|
||||
.Map(dest => dest.DefaultValue, src => src.defaults);
|
||||
config.ForType<DbTableInfo, DbEntityInfo>()
|
||||
.Map(dest => dest.tableName, src => src.Name)
|
||||
.Map(dest => dest.descrip, src => src.Description);
|
||||
config.ForType<DbColumnInfo, DbEntityPropInfo>()
|
||||
.Map(dest => dest.colName, src => src.DbColumnName)
|
||||
.Map(dest => dest.dataType, src => src.DataType)
|
||||
.Map(dest => dest.propName, src => src.PropertyName)
|
||||
.Map(dest => dest.propType, src => src.PropertyType)
|
||||
.Map(dest => dest.length, src => src.Length)
|
||||
.Map(dest => dest.descrip, src => src.ColumnDescription)
|
||||
.Map(dest => dest.defaultValue, src => src.DefaultValue)
|
||||
.Map(dest => dest.allowNull, src => src.IsNullable)
|
||||
.Map(dest => dest.identity, src => src.IsIdentity)
|
||||
.Map(dest => dest.primaryKey, src => src.IsPrimarykey)
|
||||
.Map(dest => dest.isArray, src => src.IsArray)
|
||||
.Map(dest => dest.isJson, src => src.IsJson)
|
||||
.Map(dest => dest.value, src => src.Value)
|
||||
.Map(dest => dest.scale, src => src.Scale)
|
||||
.Map(dest => dest.digits, src => src.DecimalDigits);
|
||||
//config.ForType<DynamicDbTableModel, DbTableModel>()
|
||||
// .Map(dest => dest.table, src => src.F_TABLE)
|
||||
// .Map(dest => dest.tableName, src => src.F_TABLENAME)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Systems.Entitys.Dto.Database;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表列表输出.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DatabaseTableInfo
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
DbTableInfo table { get; set; }
|
||||
|
||||
List<DbColumnInfo> columns { get; set; }
|
||||
|
||||
public string clsName { get; set; } = string.Empty;
|
||||
|
||||
public string nsName { get; set; } = "Tnb.Entities";
|
||||
|
||||
public string pkType { get; set; } = "string";
|
||||
|
||||
public string pkName { get; set; } = "id";
|
||||
|
||||
public string GetColumnDefaultValue(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnCsType(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnCsName(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnAttrib(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
124
system/Tnb.Systems.Entitys/Model/System/DataBase/DbEntityInfo.cs
Normal file
124
system/Tnb.Systems.Entitys/Model/System/DataBase/DbEntityInfo.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Systems.Entitys.Dto.Database;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表映射实体信息.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DbEntityInfo
|
||||
{
|
||||
public string tableName { get; set; } = string.Empty;
|
||||
|
||||
public string descrip { get; set; } = string.Empty;
|
||||
|
||||
public string clsName { get; set; } = string.Empty;
|
||||
|
||||
public string nsName { get; set; } = "Tnb.Entities";
|
||||
|
||||
public string pkType { get; set; } = "string";
|
||||
|
||||
public string pkName { get; set; } = "id";
|
||||
|
||||
public List<DbEntityPropInfo> columns { get; set; } = new List<DbEntityPropInfo>();
|
||||
public List<string> ignoreCols { get; set; } = new List<string>();
|
||||
|
||||
public string GetInherit()
|
||||
{
|
||||
return pkName == "id" ? $"BaseEntity<{pkType}>" : "IEntity";
|
||||
}
|
||||
public string GetConstruct()
|
||||
{
|
||||
if (pkName == "id")
|
||||
{
|
||||
string str = pkType switch
|
||||
{
|
||||
"string" => "id = SnowflakeIdHelper.NextId();",
|
||||
"long" => "id = YitIdHelper.NextId();",
|
||||
_ => string.Empty
|
||||
};
|
||||
return str;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表映射实体属性信息.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DbEntityPropInfo
|
||||
{
|
||||
public string colName { get; set; }
|
||||
|
||||
public string dataType { get; set; }
|
||||
|
||||
public string csType { get; set; }
|
||||
|
||||
public string propName { get; set; }
|
||||
|
||||
public Type propType { get; set; }
|
||||
|
||||
public int length { get; set; }
|
||||
|
||||
public string descrip { get; set; }
|
||||
|
||||
public string defaultValue { get; set; }
|
||||
|
||||
public bool allowNull { get; set; }
|
||||
|
||||
public bool identity { get; set; }
|
||||
|
||||
public bool primaryKey { get; set; }
|
||||
|
||||
public bool isArray { get; set; }
|
||||
|
||||
public bool isJson { get; set; }
|
||||
|
||||
public object value { get; set; }
|
||||
|
||||
public int digits { get; set; }
|
||||
|
||||
public int scale { get; set; }
|
||||
|
||||
public string GetPropType()
|
||||
{
|
||||
string propType = csType;
|
||||
if (allowNull)
|
||||
propType = csType + "?";
|
||||
return propType;
|
||||
}
|
||||
public virtual string GetPropAttr()
|
||||
{
|
||||
List<string> sugarAttrs = new List<string>();
|
||||
if (primaryKey)
|
||||
sugarAttrs.Add("IsPrimaryKey = true");
|
||||
if (identity)
|
||||
sugarAttrs.Add("IsIdentity = true");
|
||||
//if (allowNull)
|
||||
// sugarAttrs.Add("IsNullable = true");
|
||||
if (colName != propName)
|
||||
sugarAttrs.Add($"ColumnName = \"{colName}\"");
|
||||
if (sugarAttrs.Count > 0)
|
||||
return $" [SugarColumn({string.Join(", ", sugarAttrs)})]\n";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
public string GetDefaultValue()
|
||||
{
|
||||
if (allowNull) return string.Empty;
|
||||
|
||||
string str = csType switch
|
||||
{
|
||||
"string" => " = string.Empty;",
|
||||
"DateTime" => " = DateTime.Now;",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ using JNPF.Systems.Entitys.Dto.Database;
|
||||
using JNPF.Systems.Entitys.Model.DataBase;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.ViewEngine;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -51,6 +52,12 @@ public class DataBaseService : IDynamicApiController, ITransient
|
||||
/// </summary>
|
||||
private readonly IDbLinkService _dbLinkService;
|
||||
|
||||
/// <summary>
|
||||
/// 视图引擎.
|
||||
/// </summary>
|
||||
private readonly IViewEngine _viewEngine;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 文件服务.
|
||||
/// </summary>
|
||||
@@ -74,13 +81,15 @@ public class DataBaseService : IDynamicApiController, ITransient
|
||||
IDbLinkService dbLinkService,
|
||||
IFileManager fileManager,
|
||||
IDataBaseManager dataBaseManager,
|
||||
IUserManager userManager)
|
||||
IUserManager userManager,
|
||||
IViewEngine viewEngine)
|
||||
{
|
||||
_repository = repository;
|
||||
_dbLinkService = dbLinkService;
|
||||
_fileManager = fileManager;
|
||||
_dataBaseManager = dataBaseManager;
|
||||
_userManager = userManager;
|
||||
_viewEngine = viewEngine;
|
||||
}
|
||||
|
||||
#region GET
|
||||
@@ -386,17 +395,47 @@ public class DataBaseService : IDynamicApiController, ITransient
|
||||
var link = await _dbLinkService.GetInfo(linkId);
|
||||
sugarClient = _dataBaseManager.ChangeDataBase(link);
|
||||
}
|
||||
foreach (var item in sugarClient.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
||||
{
|
||||
var entityName = string.Join("", input.TableName.Split('_').Select(a => a.ToPascalCase()));
|
||||
sugarClient.MappingTables.Add(entityName, item.Name);
|
||||
//foreach (var col in sugarClient.DbMaintenance.GetColumnInfosByTableName(item.Name))
|
||||
//{
|
||||
// //var colName = CustomFormatName(col.DbColumnName);
|
||||
// sugarClient.MappingColumns.Add(col.DbColumnName /*类的属性首字母大写*/, col.DbColumnName, entityName);
|
||||
//}
|
||||
}
|
||||
List<DbEntityInfo> entities = new();
|
||||
Dictionary<string, string> nsMapper = GetNsMapper();
|
||||
foreach (var tbl in sugarClient.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
||||
{
|
||||
var entityName = string.Join("", tbl.Name.Split('_').Select(a => a.ToPascalCase()));
|
||||
sugarClient.MappingTables.Add(entityName, tbl.Name);
|
||||
DbEntityInfo model = new() { tableName = tbl.Name, descrip = tbl.Description, clsName = entityName };
|
||||
var key = tbl.Name.Split('_')[0] + "_";
|
||||
if (nsMapper.ContainsKey(key)) model.nsName = nsMapper[key];
|
||||
foreach (var field in sugarClient.DbMaintenance.GetColumnInfosByTableName(tbl.Name))
|
||||
{
|
||||
DbEntityPropInfo col = field.Adapt<DbEntityPropInfo>();
|
||||
col.csType = sugarClient.Ado.DbBind.GetPropertyTypeName(field.DataType);
|
||||
col.propName = field.DbColumnName;
|
||||
model.columns.Add(col);
|
||||
}
|
||||
var primaryKey = model.columns.FirstOrDefault(a => a.primaryKey);
|
||||
if (primaryKey != null)
|
||||
{
|
||||
model.pkType = primaryKey.csType;
|
||||
model.pkName = primaryKey.propName;
|
||||
}
|
||||
if (model.pkName == "id") model.ignoreCols.Add(model.pkName);
|
||||
entities.Add(model);
|
||||
}
|
||||
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template", "Entity.vue.vm");
|
||||
string tContent = File.ReadAllText(templatePath);
|
||||
foreach (var item in entities)
|
||||
{
|
||||
var tResult = _viewEngine.RunCompileFromCached(tContent, item, builderAction: builder =>
|
||||
{
|
||||
builder.AddUsing("System.Collections.Generic");
|
||||
builder.AddAssemblyReferenceByName("System.Collections");
|
||||
});
|
||||
var dir = Path.Combine(FileVariable.GenerateCodePath, item.nsName);
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(Path.Combine(dir, item.clsName + ".cs"), tResult);
|
||||
|
||||
return tResult;
|
||||
}
|
||||
|
||||
var prefix = input.TableName.Split('_')[0];
|
||||
var nsName = nsMapper.ContainsKey(prefix) ? nsMapper[prefix] : "Tnb.Entities";
|
||||
var dict = GenerateEntityConfig(sugarClient.DbFirst.Where(input.TableName)).ToClassStringList(nsName);
|
||||
@@ -664,8 +703,8 @@ public class DataBaseService : IDynamicApiController, ITransient
|
||||
var txt = tpl.Replace("{PropertyType}", type).Replace("{PropertyName}", col.DbColumnName).Replace("{SugarColumn}", sugarColumnStr);
|
||||
if (col.DbColumnName == "id")
|
||||
{
|
||||
if(type == "string") txt = txt.TrimEnd('\n', '\r') + " = SnowflakeIdHelper.NextId();\r\n";
|
||||
else if(type == "long") txt = txt.TrimEnd('\n', '\r') + " = YitIdHelper.NextId();\r\n";
|
||||
if (type == "string") txt = txt.TrimEnd('\n', '\r') + " = SnowflakeIdHelper.NextId();\r\n";
|
||||
else if (type == "long") txt = txt.TrimEnd('\n', '\r') + " = YitIdHelper.NextId();\r\n";
|
||||
}
|
||||
else if (type == "string") txt = txt.TrimEnd('\n', '\r') + " = string.Empty;\r\n";
|
||||
return txt;
|
||||
|
||||
@@ -857,7 +857,7 @@ public class RunService : IRunService, ITransient
|
||||
if (!templateInfo.VerifyTemplate()) throw Oops.Oh(ErrorCode.D1401); // 验证模板
|
||||
|
||||
// 处理系统控件(模板开启行编辑)
|
||||
if (_userManager.UserOrigin.Equals("pc") && templateInfo.ColumnData.type.Equals(4))
|
||||
if (_userManager.UserOrigin?.Equals("pc") == true && templateInfo.ColumnData.type.Equals(4))
|
||||
{
|
||||
// 处理显示列和提交的表单数据匹配(行编辑空数据 前端会过滤该控件)
|
||||
templateInfo.ColumnData.columnList.Where(x => !allDataMap.ContainsKey(x.prop) && x.__config__.visibility.Equals("pc")).ToList()
|
||||
|
||||
Reference in New Issue
Block a user