1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user