132 lines
4.0 KiB
C#
132 lines
4.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Configuration;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Net.Http.Headers;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using AutoMapper.Configuration;
|
|||
|
|
using Ease.Core;
|
|||
|
|
using HRM.BO;
|
|||
|
|
using HRM.DA;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using Payroll.BO;
|
|||
|
|
using Payroll.Service;
|
|||
|
|
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
|
|||
|
|
|
|||
|
|
namespace HRM.UI.Controllers
|
|||
|
|
{
|
|||
|
|
[ApiController]
|
|||
|
|
[Route("api/HRMApenAPIAI")]
|
|||
|
|
[Authorize]
|
|||
|
|
public class OpenAIController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly OpenAIService _openAIService;
|
|||
|
|
private readonly IOpenAIQueryLogService _openAIQueryLogService;
|
|||
|
|
|
|||
|
|
public OpenAIController(OpenAIService openAIService, IOpenAIQueryLogService openAIQueryLogService)
|
|||
|
|
{
|
|||
|
|
_openAIService = openAIService;
|
|||
|
|
_openAIQueryLogService = openAIQueryLogService;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
[Route("AskOpenAI")]
|
|||
|
|
public async Task<IActionResult> AskOpenAI(dynamic data)
|
|||
|
|
{
|
|||
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|||
|
|
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|||
|
|
string userCommand = (string)item["userPrompt"].ToObject<string>();
|
|||
|
|
EnumReportGroupType reportGroupType = (EnumReportGroupType)item["reportGroup"].ToObject<EnumReportGroupType>();
|
|||
|
|
DataSet oEmpBasicInfos = new DataSet();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
var response = await _openAIService.AskOpenAISqlQueryWithChartAsync(userCommand, (int)currentUser.UserID, reportGroupType,
|
|||
|
|
currentUser.NextPayProcessDate ?? DateTime.Now);
|
|||
|
|
return Ok(response);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
[Route("GetReportColumnDefinition/{reportGroupType}")]
|
|||
|
|
public async Task<IActionResult> GetReportColumnDefinition(EnumReportGroupType reportGroupType)
|
|||
|
|
{
|
|||
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var response = await _openAIService.GetColumnDefinitions(reportGroupType);
|
|||
|
|
return Ok(response);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
[Route("GetCurrentUserAllQueryLog/{reportGroupType}")]
|
|||
|
|
public ActionResult GetCurrentUserAllQueryLog(EnumReportGroupType reportGroupType)
|
|||
|
|
{
|
|||
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|||
|
|
List<OpenAIQueryLog> queryLogs = new List<OpenAIQueryLog>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
queryLogs = _openAIQueryLogService.GetAllQueryLogByUserID((int)currentUser.UserID, reportGroupType);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|||
|
|
}
|
|||
|
|
return Ok(queryLogs);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
[Route("OpenAIPreviousQueryExecution")]
|
|||
|
|
public async Task<IActionResult> OpenAIPreviousQueryExecution(dynamic data)
|
|||
|
|
{
|
|||
|
|
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|||
|
|
OpenAIQueryLog userCommand = (OpenAIQueryLog)item["oQueryLog"].ToObject<OpenAIQueryLog>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var response = await _openAIService.OpenAIPreviousQueryExecution(userCommand);
|
|||
|
|
return Ok(response);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
[Route("ChatShareWithOthers")]
|
|||
|
|
public async Task<IActionResult> ChatShareWithOthers(dynamic data)
|
|||
|
|
{
|
|||
|
|
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|||
|
|
OpenAIQueryLog userCommand = (OpenAIQueryLog)item["oQueryLog"].ToObject<OpenAIQueryLog>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
_openAIQueryLogService.ChatShareWithOthers(userCommand);
|
|||
|
|
return Ok();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|