fix(固资): 固资查询erp报错问题修复
This commit is contained in:
1 parent
d039fc255c
commit
4ce4d75524
2 files changed
+55
-13
No files matched your search
@@ -7,6 +7,7 @@ from flask import current_app, has_app_context
|
|||||||
class Text2SQLService:
|
class Text2SQLService:
|
||||||
_schema_text = None
|
_schema_text = None
|
||||||
_oracle_client_initialized = False
|
_oracle_client_initialized = False
|
||||||
|
_oracle_dll_handles = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _backend_dir() -> str:
|
def _backend_dir() -> str:
|
||||||
@@ -86,6 +87,9 @@ class Text2SQLService:
|
|||||||
cls._prepend_env_path("DYLD_LIBRARY_PATH", target_lib_dir)
|
cls._prepend_env_path("DYLD_LIBRARY_PATH", target_lib_dir)
|
||||||
elif system_name == "Windows":
|
elif system_name == "Windows":
|
||||||
cls._prepend_env_path("PATH", target_lib_dir)
|
cls._prepend_env_path("PATH", target_lib_dir)
|
||||||
|
if hasattr(os, "add_dll_directory"):
|
||||||
|
handle = os.add_dll_directory(target_lib_dir)
|
||||||
|
cls._oracle_dll_handles.append(handle)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
cls._log("warning", f"Failed to prepare Oracle runtime env: {exc}")
|
cls._log("warning", f"Failed to prepare Oracle runtime env: {exc}")
|
||||||
|
|
||||||
@@ -108,9 +112,9 @@ class Text2SQLService:
|
|||||||
if platform.system() == 'Windows' and target_lib_dir and not target_lib_dir.isascii():
|
if platform.system() == 'Windows' and target_lib_dir and not target_lib_dir.isascii():
|
||||||
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
||||||
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
||||||
if not os.path.exists(safe_lib_dir) and os.path.exists(target_lib_dir):
|
if os.path.exists(target_lib_dir):
|
||||||
os.makedirs(temp_dir, exist_ok=True)
|
os.makedirs(temp_dir, exist_ok=True)
|
||||||
shutil.copytree(target_lib_dir, safe_lib_dir)
|
shutil.copytree(target_lib_dir, safe_lib_dir, dirs_exist_ok=True)
|
||||||
target_lib_dir = safe_lib_dir
|
target_lib_dir = safe_lib_dir
|
||||||
|
|
||||||
cls._prepare_oracle_runtime_env(target_lib_dir)
|
cls._prepare_oracle_runtime_env(target_lib_dir)
|
||||||
@@ -185,16 +189,18 @@ class Text2SQLService:
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
target_lib_dir = cls._get_oracle_client_dir()
|
target_lib_dir = cls._get_oracle_client_dir()
|
||||||
|
cls._prepare_oracle_runtime_env(target_lib_dir)
|
||||||
|
|
||||||
if platform.system() == 'Windows' and target_lib_dir:
|
if platform.system() == 'Windows' and target_lib_dir:
|
||||||
# OCI C-library fails to load if path contains non-ASCII.
|
# OCI C-library fails to load if path contains non-ASCII.
|
||||||
if not target_lib_dir.isascii():
|
if not target_lib_dir.isascii():
|
||||||
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
||||||
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
||||||
if not os.path.exists(safe_lib_dir) and os.path.exists(target_lib_dir):
|
if os.path.exists(target_lib_dir):
|
||||||
os.makedirs(temp_dir, exist_ok=True)
|
os.makedirs(temp_dir, exist_ok=True)
|
||||||
shutil.copytree(target_lib_dir, safe_lib_dir)
|
shutil.copytree(target_lib_dir, safe_lib_dir, dirs_exist_ok=True)
|
||||||
target_lib_dir = safe_lib_dir
|
target_lib_dir = safe_lib_dir
|
||||||
|
cls._prepare_oracle_runtime_env(target_lib_dir)
|
||||||
|
|
||||||
if target_lib_dir:
|
if target_lib_dir:
|
||||||
oracledb.init_oracle_client(lib_dir=target_lib_dir)
|
oracledb.init_oracle_client(lib_dir=target_lib_dir)
|
||||||
|
|||||||
@@ -71,13 +71,17 @@ const currentUser = ref(getStoredAuthUser());
|
|||||||
const showUserDropdown = ref(false);
|
const showUserDropdown = ref(false);
|
||||||
const userMenuRef = ref<HTMLElement | null>(null);
|
const userMenuRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
const selectedKb = ref('企业知识库');
|
const DEFAULT_KB = '企业知识库';
|
||||||
|
const ERP_KB = 'ERP知识库';
|
||||||
|
const ERP_KB_ENABLED_AGENT_NAMES = new Set(['固资管理']);
|
||||||
|
|
||||||
|
const selectedKb = ref(DEFAULT_KB);
|
||||||
const showKbDropdown = ref(false);
|
const showKbDropdown = ref(false);
|
||||||
const kbMenuRef = ref<HTMLElement | null>(null);
|
const kbMenuRef = ref<HTMLElement | null>(null);
|
||||||
const kbOptions = ['企业知识库', 'ERP知识库'];
|
const kbOptions = [DEFAULT_KB, ERP_KB];
|
||||||
const getKbLabel = (kb: string) => {
|
const getKbLabel = (kb: string) => {
|
||||||
if (kb === '企业知识库') return t('chat.kb.enterprise');
|
if (kb === DEFAULT_KB) return t('chat.kb.enterprise');
|
||||||
if (kb === 'ERP知识库') return t('chat.kb.erp');
|
if (kb === ERP_KB) return t('chat.kb.erp');
|
||||||
return kb;
|
return kb;
|
||||||
};
|
};
|
||||||
const chatScrollContainer = ref<HTMLElement | null>(null);
|
const chatScrollContainer = ref<HTMLElement | null>(null);
|
||||||
@@ -782,6 +786,37 @@ const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestio
|
|||||||
};
|
};
|
||||||
|
|
||||||
const currentAgentName = computed(() => String(currentAgent.value?.name || '').trim());
|
const currentAgentName = computed(() => String(currentAgent.value?.name || '').trim());
|
||||||
|
const canSelectErpKnowledgeBase = computed(() => ERP_KB_ENABLED_AGENT_NAMES.has(currentAgentName.value));
|
||||||
|
const availableKbOptions = computed(() => (
|
||||||
|
canSelectErpKnowledgeBase.value
|
||||||
|
? kbOptions
|
||||||
|
: kbOptions.filter((option) => option !== ERP_KB)
|
||||||
|
));
|
||||||
|
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
|
||||||
|
|
||||||
|
const toggleKbDropdown = () => {
|
||||||
|
if (kbDropdownDisabled.value) {
|
||||||
|
showKbDropdown.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showKbDropdown.value = !showKbDropdown.value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectKb = (option: string) => {
|
||||||
|
if (!availableKbOptions.value.includes(option)) return;
|
||||||
|
selectedKb.value = option;
|
||||||
|
showKbDropdown.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(canSelectErpKnowledgeBase, (allowed) => {
|
||||||
|
if (!allowed && selectedKb.value === ERP_KB) {
|
||||||
|
selectedKb.value = DEFAULT_KB;
|
||||||
|
}
|
||||||
|
if (!allowed) {
|
||||||
|
showKbDropdown.value = false;
|
||||||
|
}
|
||||||
|
}, { immediate: true });
|
||||||
|
|
||||||
const agentDescription = computed(() => {
|
const agentDescription = computed(() => {
|
||||||
const text = String(currentAgent.value?.description || '').trim();
|
const text = String(currentAgent.value?.description || '').trim();
|
||||||
return text || DEFAULT_AGENT_DESCRIPTIONS[currentAgentName.value] || '';
|
return text || DEFAULT_AGENT_DESCRIPTIONS[currentAgentName.value] || '';
|
||||||
@@ -3567,20 +3602,21 @@ const showChatRating = ref(false);
|
|||||||
</div>
|
</div>
|
||||||
<div class="relative" ref="kbMenuRef">
|
<div class="relative" ref="kbMenuRef">
|
||||||
<button
|
<button
|
||||||
@click="showKbDropdown = !showKbDropdown"
|
@click="toggleKbDropdown"
|
||||||
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
:disabled="kbDropdownDisabled"
|
||||||
|
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
>
|
>
|
||||||
<Database class="h-3.5 w-3.5 text-brand-500" />
|
<Database class="h-3.5 w-3.5 text-brand-500" />
|
||||||
{{ getKbLabel(selectedKb) }} <ChevronDown class="h-3 w-3" />
|
{{ getKbLabel(selectedKb) }} <ChevronDown class="h-3 w-3" />
|
||||||
</button>
|
</button>
|
||||||
<div
|
<div
|
||||||
v-if="showKbDropdown"
|
v-if="showKbDropdown && !kbDropdownDisabled"
|
||||||
class="absolute bottom-full left-0 mb-2 w-36 overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl animate-fade-in"
|
class="absolute bottom-full left-0 mb-2 w-36 overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl animate-fade-in"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
v-for="option in kbOptions"
|
v-for="option in availableKbOptions"
|
||||||
:key="option"
|
:key="option"
|
||||||
@click="selectedKb = option; showKbDropdown = false"
|
@click="selectKb(option)"
|
||||||
class="flex w-full items-center justify-between px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
class="flex w-full items-center justify-between px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||||||
:class="{ 'font-bold text-brand-700': selectedKb === option }"
|
:class="{ 'font-bold text-brand-700': selectedKb === option }"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user