213 lines
6.7 KiB
C#
213 lines
6.7 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using DevExpress.PivotGrid.OLAP.Mdx;
|
|
using DevExpress.XtraRichEdit.Commands;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
|
|
namespace BeWo.Service.ServiceUtils
|
|
{
|
|
public static class AiSystemBuilder
|
|
{
|
|
public static string CreateSystemInstructions(int uicontext, Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
var system_prompt = getSystemPrompt(2);
|
|
|
|
var data = getContextData(uicontext, bewoobjects);
|
|
|
|
var text = JsonConvert.SerializeObject(data);
|
|
|
|
var result = system_prompt + text;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// SupportConcept = 0,
|
|
/// Customer = 1,
|
|
/// Person = 2,
|
|
/// Employee = 3,
|
|
/// Organisation = 4,
|
|
/// Team = 5,
|
|
/// Dokumente = 6,
|
|
/// User = 7,
|
|
/// UserGroup = 8,
|
|
/// Report = 9,
|
|
/// Scheduler = 10,
|
|
/// Wohnheim = 11,
|
|
/// Vertretungen = 12,
|
|
/// CustomerTeam = 13,
|
|
/// Scheduling = 14,
|
|
/// Finance = 15,
|
|
/// Administration = 16,
|
|
/// AiConversation = 17,
|
|
/// AiConversationPopup = 18,
|
|
/// // Nur für AI Conversation Zuweisung
|
|
/// ServiceRecord = 19,
|
|
/// CustomerSingle = 20,
|
|
/// PersonSingle = 21,
|
|
/// EmployeeSingle = 22,
|
|
/// </summary>
|
|
/// <param name="uicontext"></param>
|
|
/// <param name="bewoobjects"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private static Dictionary<string, object> getContextData(int uicontext, Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
switch (uicontext)
|
|
{
|
|
case 0: break;
|
|
case 1: return createCustomerNavigationContext(bewoobjects);
|
|
case 2: return createPersonNavigationContext(bewoobjects);
|
|
case 3: return createEmployeeNavigationContext(bewoobjects);
|
|
case 4: break;
|
|
case 5: break;
|
|
case 6: break;
|
|
case 7: break;
|
|
case 8: break;
|
|
case 9: break;
|
|
case 10: break;
|
|
case 11: break;
|
|
case 12: break;
|
|
case 13: break;
|
|
case 14: break;
|
|
case 15: break;
|
|
case 16: break;
|
|
case 17: break;
|
|
case 18: break;
|
|
case 19: return createServiceRecordContext(bewoobjects);
|
|
}
|
|
|
|
throw new NotImplementedException("UI Context unknown");
|
|
}
|
|
|
|
private static Dictionary<string, object> createCustomerNavigationContext(Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
var klienten = LoadEntities(bewoobjects, TableID.Customer, MapperFactory.CompactCustomerDC_Customer);
|
|
|
|
var dict = new Dictionary<string, object>
|
|
{
|
|
{ "Aktuelle Ansicht", "Klienten Navigation" },
|
|
{ "Aktueller Ansichtsfilter", "Funktion noch nicht verfügbar" },
|
|
{ "Klientenliste", (object)klienten ?? "keine Klienten sichtbar" }
|
|
};
|
|
|
|
return dict;
|
|
}
|
|
private static Dictionary<string, object> createPersonNavigationContext(Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
var personen = LoadEntities(bewoobjects, TableID.Person, MapperFactory.CompactPersonDC_Person);
|
|
|
|
var dict = new Dictionary<string, object>
|
|
{
|
|
{ "Aktuelle Ansicht", "Personen Navigation" },
|
|
{ "Aktueller Ansichtsfilter", "Funktion noch nicht verfügbar" },
|
|
{ "Personenliste", (object)personen ?? "keine Personen sichtbar" }
|
|
};
|
|
|
|
return dict;
|
|
}
|
|
private static Dictionary<string, object> createEmployeeNavigationContext(Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
var mitarbeiter = LoadEntities(bewoobjects, TableID.Employee, MapperFactory.CompactEmployeeDC_Employee);
|
|
|
|
var dict = new Dictionary<string, object>
|
|
{
|
|
{ "Aktuelle Ansicht", "Mitarbeiter Navigation" },
|
|
{ "Aktueller Ansichtsfilter", "Funktion noch nicht verfügbar" },
|
|
{ "Mitarbeiterliste", (object)mitarbeiter ?? "keine Mitarbeiter sichtbar" }
|
|
};
|
|
|
|
return dict;
|
|
}
|
|
private static Dictionary<string, object> createServiceRecordContext(Dictionary<TableID, long[]> bewoobjects)
|
|
{
|
|
var customer = LoadEntity(bewoobjects, TableID.Customer, MapperFactory.CompactCustomerDC_Customer);
|
|
var costbearer = LoadProperty(bewoobjects, TableID.CostBearer, MapperFactory.CompactOrganisationDC_Organisation, dc => dc.Name);
|
|
var supportconcept = LoadProperty(bewoobjects, TableID.SupportConcept, MapperFactory.CompactSupportConceptDC_SupportConcept, dc => $"{dc.StartDate?.Date} - {dc.EndDate?.Date}");
|
|
var records = LoadEntities(bewoobjects, TableID.ServiceRecord, MapperFactory.ServiceRecordDC_ServiceRecord);
|
|
|
|
var sub_dict = new Dictionary<string, object>()
|
|
{
|
|
{ "CustomerName Ansicht", customer },
|
|
{ "CostBearerName", costbearer },
|
|
{ "SupportConceptDuration", supportconcept }
|
|
};
|
|
|
|
var dict = new Dictionary<string, object>
|
|
{
|
|
{ "Aktuelle Ansicht", "Zeiterfassung" },
|
|
{ "Aktueller Ansichtsfilter", "Funktion noch nicht verfügbar" },
|
|
{ "Selected", sub_dict},
|
|
{ "Zeiterfassungen", records }
|
|
};
|
|
|
|
return dict;
|
|
}
|
|
|
|
private static object LoadProperty<TEntity, TDC>
|
|
(Dictionary<TableID, long[]> bewoobjects, TableID tid, IDCEntityMapper<TEntity, TDC> mapper, Func<TDC, object> getPropertyFunc)
|
|
where TDC : new() where TEntity : BeWoEntityBase, new()
|
|
{
|
|
if (!bewoobjects.TryGetValue(tid, out long[] oids) || (oids?.Length ?? 0) == 0)
|
|
return null;
|
|
|
|
var entity = DAOFactory.GenericDAO.GetByID<TEntity>(oids[0]);
|
|
var dc = mapper.MapToNewDC(entity);
|
|
var property = getPropertyFunc(dc);
|
|
|
|
return property;
|
|
}
|
|
|
|
private static Dictionary<string, object> LoadEntity<TEntity, TDC>
|
|
(Dictionary<TableID, long[]> bewoobjects, TableID tid, IDCEntityMapper<TEntity, TDC> mapper)
|
|
where TDC : new() where TEntity : BeWoEntityBase, new()
|
|
{
|
|
if (!bewoobjects.TryGetValue(tid, out long[] oids) || (oids?.Length ?? 0) == 0)
|
|
return null;
|
|
|
|
var entity = DAOFactory.GenericDAO.GetByID<TEntity>(oids[0]);
|
|
var dict = mapper.ToJsonDictionary(entity);
|
|
|
|
return dict;
|
|
}
|
|
|
|
private static IList<Dictionary<string, object>> LoadEntities<TEntity, TDC>
|
|
(Dictionary<TableID, long[]> bewoobjects, TableID tid, IDCEntityMapper<TEntity, TDC> mapper)
|
|
where TDC : new() where TEntity : BeWoEntityBase, new()
|
|
{
|
|
if (!bewoobjects.TryGetValue(tid, out long[] oids) || (oids?.Length ?? 0) == 0)
|
|
return null;
|
|
|
|
var entities = DAOFactory.GenericDAO.GetByIDs<TEntity>(oids);
|
|
var dict = mapper.ToJsonDictionary(entities);
|
|
|
|
return dict;
|
|
}
|
|
|
|
private static string getSystemPrompt(int i)
|
|
{
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
var resourceName = $"BeWo.Service.AI.system_prompt{i}.txt";
|
|
|
|
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
{
|
|
string result = reader.ReadToEnd();
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|