109 lines
3.2 KiB
C#
109 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Feature.AI;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Service.DCEntityMapper
|
|
{
|
|
public class AiConversationDC_AiConversation : AbstractIDCEntityMapper<AiConversation, AiConversationDC>
|
|
{
|
|
public override AiConversationDC MergeWithDC(AiConversation pEntity, AiConversationDC pDataContract)
|
|
{
|
|
pDataContract.Oid = pEntity.Oid;
|
|
pDataContract.Version = pEntity.Version;
|
|
pDataContract.Notice = pEntity.Notice;
|
|
pDataContract.Displayname = pEntity.Displayname;
|
|
pDataContract.Created = pEntity.Created;
|
|
pDataContract.Updated = pEntity.Updated;
|
|
pDataContract.Context = pEntity.Context;
|
|
pDataContract.ContextBeWoObjects = Parse(pEntity.ContextBeWoObjects);
|
|
pDataContract.UIContext = pEntity.UIContext;
|
|
pDataContract.ContextType = pEntity.ContextType;
|
|
|
|
if (pEntity.Messages is IList<AiConversationMessage> list && list.Any())
|
|
pDataContract.Messages = MapperFactory.AiConversationMessage.MapToNewDCs(list);
|
|
|
|
if (pEntity.Modell is AiModel model)
|
|
pDataContract.Modell = MapperFactory.AiModel.MapToNewDC(model);
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override AiConversation MergeWithEntity(AiConversationDC pDataContract, AiConversation pEntity)
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
ConcurrencyCheck(pDataContract.Version, pEntity);
|
|
|
|
//pEntity.Oid = pDataContract.Oid;
|
|
//pEntity.Version = pDataContract.Version;
|
|
pEntity.Notice = pDataContract.Notice;
|
|
pEntity.Displayname = pDataContract.Displayname;
|
|
pEntity.Created = pDataContract.Created;
|
|
pEntity.Updated = pDataContract.Updated;
|
|
pEntity.Context = pDataContract.Context;
|
|
pEntity.UIContext = pDataContract.UIContext;
|
|
pEntity.ContextBeWoObjects = Parse(pDataContract.ContextBeWoObjects);
|
|
pEntity.ContextType = pDataContract.ContextType;
|
|
|
|
MapperFactory.AiConversationMessage.MergeWithEntitys(pDataContract.Messages, pEntity.Messages);
|
|
|
|
if (pDataContract.Modell?.Oid is long oid)
|
|
pEntity.Modell = DAOFactory.GenericDAO.LoadByID<AiModel>(oid);
|
|
|
|
return pEntity;
|
|
}
|
|
|
|
protected override bool AreDCAndEntityEqual(AiConversationDC pDC, AiConversation pEntity)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Dictionary<TableID, long[]> Parse(IEnumerable<BeWoEntityReference> beWoEntities)
|
|
{
|
|
if (beWoEntities is null)
|
|
return null;
|
|
|
|
var tables = beWoEntities.Select(x => x.Tid).Distinct();
|
|
|
|
var rtn = new Dictionary<TableID, List<long>>();
|
|
foreach (var table in tables)
|
|
{
|
|
rtn.Add(table, new List<long>());
|
|
}
|
|
|
|
beWoEntities.DoForEach(x => rtn[x.Tid].Add(x.Oid));
|
|
|
|
return rtn.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToArray());
|
|
}
|
|
|
|
public IList<BeWoEntityReference> Parse(Dictionary<TableID, long[]> input)
|
|
{
|
|
if (input is null)
|
|
return null;
|
|
|
|
var rtn = new List<BeWoEntityReference>();
|
|
|
|
foreach (var kvp in input)
|
|
{
|
|
var table = kvp.Key;
|
|
for (var i = 0; i < kvp.Value.Length; i++)
|
|
{
|
|
var oid = kvp.Value[i];
|
|
rtn.Add(new BeWoEntityReference() { Tid = table, Oid = oid });
|
|
}
|
|
}
|
|
|
|
return rtn;
|
|
}
|
|
}
|
|
}
|