namespace IStation.DAL
|
{
|
/// <summary>
|
/// 业务清单
|
/// </summary>
|
public partial class LogicTree : Yw.DAL.BaseDAL_TreeSorter<Entity.LogicTree>
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConfigHelper.DefaultConnectionConfig; }
|
}
|
|
/// <summary>
|
/// 通过 PolicyID 获取
|
/// </summary>
|
public List<Entity.LogicTree> GetByPolicyID(long PolicyID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.LogicTree>()
|
.Where(x => x.PolicyID == PolicyID)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
public bool Save(long PolicyID, List<Entity.LogicTreeSaveTree> treeList)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
if (treeList == null || treeList.Count < 1)
|
{
|
return db.Deleteable<Entity.LogicTree>()
|
.Where(x => x.PolicyID == PolicyID)
|
.ExecuteCommandHasChange();
|
}
|
db.BeginTran();
|
|
var idList = new List<long>();
|
|
#region 迭代函数
|
|
long Append(Entity.LogicTreeSaveTree tree, List<long> parentIds, int sortCode)
|
{
|
if (parentIds == null)
|
parentIds = new List<long>();
|
sortCode++;
|
|
//构造
|
var entity = new Entity.LogicTree()
|
{
|
ID = tree.ID,
|
PolicyID = PolicyID,
|
ParentIds = TreeParentIdsHelper.ToString(parentIds),
|
LogicType = tree.LogicType,
|
LogicID = tree.LogicID,
|
SortCode = sortCode
|
};
|
|
if (entity.ID < 1)
|
{
|
entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
|
if (entity.ID < 1)
|
{
|
return default;
|
}
|
}
|
else
|
{
|
var bol = db.Updateable(entity).ExecuteCommandHasChange();
|
if (!bol)
|
{
|
return default;
|
}
|
}
|
|
idList.Add(entity.ID);
|
|
if (tree.Children != null && tree.Children.Count > 0)
|
{
|
var childParentIds = parentIds.Append(entity.ID).ToList();
|
var childSortCode = 0;
|
foreach (var child in tree.Children)
|
{
|
var id = Append(child, childParentIds, childSortCode);
|
if (id < 1)
|
return default;
|
}
|
}
|
|
return entity.ID;
|
}
|
|
#endregion
|
|
#region 遍历处理
|
|
foreach (var tree in treeList)
|
{
|
var id = Append(tree, null, 0);
|
if (id < 1)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region 清理目录
|
|
if (idList.Count > 0)
|
{
|
db.Deleteable<Entity.LogicTree>()
|
.Where(x => x.PolicyID == PolicyID && !idList.Contains(x.ID))
|
.ExecuteCommandHasChange();
|
}
|
else
|
{
|
db.Deleteable<Entity.LogicTree>()
|
.Where(x => x.PolicyID == PolicyID)
|
.ExecuteCommandHasChange();
|
}
|
|
#endregion
|
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|