EchoTex_Payroll/HRM.DA/Service/OpenAIService/OpenAIQueryLogService.cs

148 lines
3.7 KiB
C#
Raw Permalink Normal View History

2026-07-12 18:07:59 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HRM.DA
{
public class OpenAIQueryLogService : ServiceTemplate, IOpenAIQueryLogService
{
public OpenAIQueryLogService()
{
}
private void MapObject(OpenAIQueryLog oQueryLog, DataReader oReader)
{
base.SetObjectID(oQueryLog, (oReader.GetInt32("QueryLogID").Value));
oQueryLog.UserId = oReader.GetInt32("UserId").Value;
oQueryLog.UserPrompt = oReader.GetString("UserPrompt");
oQueryLog.GeneratedQuery = oReader.GetString("GeneratedQuery", "");
oQueryLog.ExecutedAt = oReader.GetDateTime("ExecutedAt").HasValue
? oReader.GetDateTime("ExecutedAt").Value
: DateTime.MinValue;
oQueryLog.TotalExecution = oReader.GetInt32("TotalExecution", 0);
oQueryLog.ReportGroup = (EnumReportGroupType)oReader.GetInt32("ReportGroup").Value;
oQueryLog.IsChart = oReader.GetBoolean("IsChart", false);
oQueryLog.ChartType = (EnumAIChartType)oReader.GetInt32("ChartType").Value;
oQueryLog.Title = oReader.GetString("Title", "");
oQueryLog.IsCommon = oReader.GetBoolean("IsCommon", false);
this.SetObjectState(oQueryLog, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OpenAIQueryLog oQueryLog = new OpenAIQueryLog();
MapObject(oQueryLog, oReader);
return oQueryLog as T;
}
protected OpenAIQueryLog CreateObject(DataReader oReader)
{
OpenAIQueryLog oQueryLog = new OpenAIQueryLog();
MapObject(oQueryLog, oReader);
return oQueryLog;
}
public void Save(OpenAIQueryLog oQueryLog)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oQueryLog.IsNew)
{
int id = tc.GenerateID("OpenAIQueryLog", "QueryLogID");
base.SetObjectID(oQueryLog, (id));
OpenAIDA.Insert(tc, oQueryLog);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateQueryLogTotalExecution(OpenAIQueryLog oQueryLog)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!oQueryLog.IsNew)
{
OpenAIDA.UpdateQueryLogTotalExecution(tc, oQueryLog);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void ChatShareWithOthers(OpenAIQueryLog oQueryLog)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!oQueryLog.IsNew)
{
OpenAIDA.ChatShareWithOthers(tc, oQueryLog);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<OpenAIQueryLog> GetAllQueryLogByUserID(int userID, EnumReportGroupType reportGroup)
{
List<OpenAIQueryLog> allQueryLog = new List<OpenAIQueryLog>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpenAIDA.GetAllQueryLogByUserID(tc, userID, reportGroup));
allQueryLog = this.CreateObjects<OpenAIQueryLog>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return allQueryLog;
}
}
}