- Added comprehensive AI Assistant system (aiassist/ directory): * Vector search and embedding capabilities * Typebot proxy integration * Elastic search functionality * Message classification and chat history * MCP proxy for external integrations - Implemented Court Status API (GetCourtStatus.php): * Real-time court document status checking * Integration with external court systems * Comprehensive error handling and logging - Enhanced S3 integration: * Improved file backup system with metadata * Batch processing capabilities * Enhanced error logging and recovery * Copy operations with URL fixing - Added Telegram contact creation API - Improved error logging across all modules - Enhanced callback system for AI responses - Extensive backup file storage with timestamps - Updated documentation and README files - File storage improvements: * Thousands of backup files with proper metadata * Fix operations for broken file references * Project-specific backup and recovery systems * Comprehensive file integrity checking Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
155 lines
6.7 KiB
PHP
155 lines
6.7 KiB
PHP
<?php
|
||
/*********************************************************************************
|
||
* API-интерфейс для изменения любой записи
|
||
* All Rights Reserved.
|
||
* Contributor(s): Илья Руденко itsaturn@yandex.ru
|
||
********************************************************************************/
|
||
|
||
include_once 'include/Webservices/Query.php';
|
||
include_once 'modules/Users/Users.php';
|
||
require_once('include/Webservices/Utils.php');
|
||
require_once 'include/Webservices/Revise.php';
|
||
require_once 'includes/Loader.php';
|
||
vimport ('includes.runtime.Globals');
|
||
vimport ('includes.runtime.BaseModel');
|
||
vimport ('includes.runtime.LanguageHandler');
|
||
|
||
function vtws_updateentity($crmid, $element, $user = false) {
|
||
$logstring = date("Y-m-d H:i:s").' '.$crmid.'; '.$element;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
|
||
if(empty($crmid) or empty($element)){
|
||
$logstring = date("Y-m-d H:i:s").' Не указано одно из обязательных полей: ID изменяеммой записи или массив полей';
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не заполнены обязательные поля");
|
||
}
|
||
|
||
global $adb, $current_user;
|
||
|
||
// Устанавливаем правильную кодировку для соединения с базой данных
|
||
$adb->database->query("SET NAMES utf8");
|
||
|
||
$query = "select w.id
|
||
from vtiger_crmentity e
|
||
left join vtiger_ws_entity w on w.name = e.setype
|
||
where e.deleted = 0 and e.crmid = ?";
|
||
$result = $adb->pquery($query, array($crmid));
|
||
|
||
if ($adb->num_rows($result) == 0) {
|
||
$output = 'Запись с id = '.$crmid.' не найдена';
|
||
$logstring = date("Y-m-d H:i:s").' '.$output;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, $output);
|
||
}
|
||
|
||
$prefix = $adb->query_result($result, 0, 'id');
|
||
$element = json_decode($element, true);
|
||
|
||
// Проверяем, что переданы данные для обновления
|
||
if (empty($element) || count($element) == 0) {
|
||
$logstring = date("Y-m-d H:i:s").' Пустой массив полей для записи '.$crmid.', обновление пропущено'.PHP_EOL;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
return 'NO_CHANGES';
|
||
}
|
||
|
||
// Добавляем ID записи
|
||
$element['id'] = $prefix.'x'.$crmid;
|
||
|
||
try {
|
||
$entity = vtws_revise($element, $current_user);
|
||
$logstring = date('Y-m-d H:i:s').' Запись обновлена'.PHP_EOL;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring, FILE_APPEND);
|
||
$output = 'YES';
|
||
} catch (WebServiceException $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' '.$output.PHP_EOL;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, 'Ошибка при сохранении изменений в базе - см. журнал ошибок');
|
||
}
|
||
|
||
return $output;
|
||
}
|
||
|
||
/**
|
||
* Обновление заявки ответом от RAG системы
|
||
* @param int $ticketid - ID заявки в CRM
|
||
* @param string $rag_response - ответ от RAG системы
|
||
* @param string $status - новый статус заявки (опционально)
|
||
* @param object $user - пользователь CRM (опционально)
|
||
* @return string - результат обновления
|
||
*/
|
||
function vtws_updateRAGTicket($ticketid, $rag_response, $status = null, $user = false) {
|
||
|
||
$logstring = date("Y-m-d H:i:s").' Обновление RAG заявки '.$ticketid.' ответом: '.substr($rag_response, 0, 100).'...';
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
|
||
if(empty($ticketid) or empty($rag_response)){
|
||
$logstring = date("Y-m-d H:i:s").' Не указано одно из обязательных полей: ID заявки или ответ RAG';
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не заполнены обязательные поля");
|
||
}
|
||
|
||
global $adb, $current_user;
|
||
|
||
// Устанавливаем правильную кодировку для соединения с базой данных
|
||
$adb->database->query("SET NAMES utf8");
|
||
|
||
// Проверяем существование заявки
|
||
$query = "select w.id
|
||
from vtiger_crmentity e
|
||
left join vtiger_ws_entity w on w.name = e.setype
|
||
where e.deleted = 0 and e.crmid = ? and e.setype = 'HelpDesk'";
|
||
$result = $adb->pquery($query, array($ticketid));
|
||
|
||
if ($adb->num_rows($result) == 0) {
|
||
$output = 'Заявка с id = '.$ticketid.' не найдена';
|
||
$logstring = date("Y-m-d H:i:s").' '.$output;
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, $output);
|
||
}
|
||
|
||
$prefix = $adb->query_result($result, 0, 'id');
|
||
|
||
// Подготавливаем данные для обновления
|
||
$element = array(
|
||
'solution' => $rag_response, // Записываем ответ RAG в поле solution
|
||
'update_log' => 'Ответ получен от RAG системы: ' . date('Y-m-d H:i:s')
|
||
);
|
||
|
||
// Если указан статус, обновляем его
|
||
if (!empty($status)) {
|
||
$element['status'] = $status;
|
||
}
|
||
|
||
$element['id'] = $prefix.'x'.$ticketid;
|
||
|
||
try {
|
||
$logstring = date('Y-m-d H:i:s').' Пытаемся обновить заявку с данными: '.json_encode($element).PHP_EOL;
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring, FILE_APPEND);
|
||
|
||
// Обновляем заявку напрямую через SQL
|
||
$update_query = "UPDATE vtiger_troubletickets SET solution = ?, update_log = ?";
|
||
$update_params = array($rag_response, $element['update_log']);
|
||
|
||
if (!empty($status)) {
|
||
$update_query .= ", status = ?";
|
||
$update_params[] = $status;
|
||
}
|
||
|
||
$update_query .= " WHERE ticketid = ?";
|
||
$update_params[] = $ticketid;
|
||
|
||
$adb->pquery($update_query, $update_params);
|
||
|
||
$logstring = date('Y-m-d H:i:s').' RAG заявка обновлена через SQL'.PHP_EOL;
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring, FILE_APPEND);
|
||
$output = 'YES';
|
||
} catch (Exception $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' Exception: '.$output.PHP_EOL;
|
||
file_put_contents('logs/UpdateRAGTicket.log', $logstring, FILE_APPEND);
|
||
throw new Exception('Ошибка при обновлении RAG заявки: '.$output);
|
||
}
|
||
|
||
return $output;
|
||
} |