Merge branch 'dev' into test
This commit is contained in:
commit
10ececfd91
23 files changed
+3115
-436
No files matched your search
@@ -64,3 +64,6 @@ Thumbs.db
|
|||||||
.npm-cache2
|
.npm-cache2
|
||||||
.pip-cache
|
.pip-cache
|
||||||
|
|
||||||
|
|
||||||
|
# 忽略Oracle Instant Client本地目录
|
||||||
|
oracle_client/
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# hxops
|
||||||
|
|
||||||
|
#### 介绍
|
||||||
|
hxops
|
||||||
|
|
||||||
|
#### 软件架构
|
||||||
|
软件架构说明
|
||||||
|
|
||||||
|
|
||||||
|
#### 安装教程
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### 使用说明
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### 参与贡献
|
||||||
|
|
||||||
|
1. Fork 本仓库
|
||||||
|
2. 新建 Feat_xxx 分支
|
||||||
|
3. 提交代码
|
||||||
|
4. 新建 Pull Request
|
||||||
|
|
||||||
|
|
||||||
|
#### 特技
|
||||||
|
|
||||||
|
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||||
|
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||||
|
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||||
|
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||||
|
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||||
|
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||||
|
## 环境配置
|
||||||
|
|
||||||
|
本项目依赖 Oracle Instant Client 19.30。
|
||||||
|
|
||||||
|
### 安装步骤:
|
||||||
|
1. 访问 [Oracle Instant Client 下载页面](官方链接),并接受许可协议。
|
||||||
|
2. 根据你的操作系统,下载对应的 **Basic Lite** 版本安装包。
|
||||||
|
3. 将下载的压缩包解压到本地目录。
|
||||||
|
4. 在项目根目录下创建名为 `oracle_client` 的文件夹,并将解压后的所有文件(`adrci.exe` 等)放入其中。
|
||||||
|
|
||||||
|
 *(可在此处放置一个目录结构截图,清晰地展示 `oracle_client` 文件夹的位置和内部文件)*
|
||||||
+12
-2
@@ -1,10 +1,15 @@
|
|||||||
INTEGRATION_API_BASE=http://192.168.100.230:8891
|
# 数据库连接
|
||||||
|
DATABASE_URL=postgresql://postgres:1qaz%40WSX@localhost:5432/hxops
|
||||||
|
|
||||||
|
INTEGRATION_API_BASE=http://192.168.100.230:8891
|
||||||
INTEGRATION_API_KEY=I76mSQZQEPYU6TubMhjh-xLsCgWC0gSIg5MncJFHFCvqvVlg-gZ_BvwO_UEL2nh
|
INTEGRATION_API_KEY=I76mSQZQEPYU6TubMhjh-xLsCgWC0gSIg5MncJFHFCvqvVlg-gZ_BvwO_UEL2nh
|
||||||
|
|
||||||
|
|
||||||
# 是否启用 JWT 认证
|
# 是否启用 JWT 认证
|
||||||
AUTH_JWT_REQUIRED=true
|
AUTH_JWT_REQUIRED=true
|
||||||
|
|
||||||
|
AUTH_LOGIN_MODE=casdoor
|
||||||
|
|
||||||
# Casdoor JWT 验签三件套
|
# Casdoor JWT 验签三件套
|
||||||
AUTH_JWT_ISSUER=http://192.168.100.230:8088
|
AUTH_JWT_ISSUER=http://192.168.100.230:8088
|
||||||
AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4
|
AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4
|
||||||
@@ -23,4 +28,9 @@ AUTH_ALLOW_LOCAL_PASSWORD_LOGIN=true
|
|||||||
AUTH_ALLOW_LOCAL_JWT=true
|
AUTH_ALLOW_LOCAL_JWT=true
|
||||||
AUTH_LOCAL_JWT_ISSUER=hxops-backend
|
AUTH_LOCAL_JWT_ISSUER=hxops-backend
|
||||||
AUTH_LOCAL_JWT_AUDIENCE=hxops-frontend
|
AUTH_LOCAL_JWT_AUDIENCE=hxops-frontend
|
||||||
AUTH_LOCAL_JWT_EXPIRES_HOURS=12
|
AUTH_LOCAL_JWT_EXPIRES_HOURS=12
|
||||||
|
|
||||||
|
# SiliconFlow API Configuration
|
||||||
|
GJL_API_KEY=sk-umfzicwjcvwampzblqczckkqojiscyybtaljzbsvpdwdvxlu
|
||||||
|
GJL_API_BASE=https://api.siliconflow.cn/v1
|
||||||
|
GJL_MODEL=deepseek-ai/DeepSeek-V3
|
||||||
+206
-45
@@ -7,6 +7,9 @@ backend/app/api/chat.py
|
|||||||
"""
|
"""
|
||||||
import io
|
import io
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -66,69 +69,111 @@ def _fetch_preview_source_bytes(file_url: str):
|
|||||||
返回: (content_bytes, content_type, error_tuple)
|
返回: (content_bytes, content_type, error_tuple)
|
||||||
其中 error_tuple = (message, status_code);成功时为 None。
|
其中 error_tuple = (message, status_code);成功时为 None。
|
||||||
"""
|
"""
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
base_url = current_app.config.get('INTEGRATION_API_BASE', '')
|
base_url = current_app.config.get('INTEGRATION_API_BASE', '')
|
||||||
api_key = current_app.config.get('INTEGRATION_API_KEY', '')
|
api_key = current_app.config.get('INTEGRATION_API_KEY', '')
|
||||||
|
|
||||||
# 尝试解析 token 并续期
|
def _resolve_latest_integration_url(raw_url: str):
|
||||||
if base_url and file_url.startswith(base_url) and 'token=' in file_url:
|
dataset_id = ''
|
||||||
|
remote_document_id = ''
|
||||||
try:
|
try:
|
||||||
import base64
|
parsed = urlparse(raw_url)
|
||||||
import json
|
|
||||||
from urllib.parse import urlparse, parse_qs
|
|
||||||
parsed = urlparse(file_url)
|
|
||||||
qs = parse_qs(parsed.query)
|
qs = parse_qs(parsed.query)
|
||||||
if 'token' in qs:
|
token = (qs.get('token') or [''])[0]
|
||||||
token = qs['token'][0]
|
if token:
|
||||||
parts = token.split('.')
|
parts = token.split('.')
|
||||||
if len(parts) >= 2:
|
if len(parts) >= 2:
|
||||||
payload_b64 = parts[1]
|
payload_b64 = parts[1]
|
||||||
payload_b64 += '=' * (-len(payload_b64) % 4)
|
payload_b64 += '=' * (-len(payload_b64) % 4)
|
||||||
payload_str = base64.urlsafe_b64decode(payload_b64).decode('utf-8')
|
payload_data = json.loads(base64.urlsafe_b64decode(payload_b64).decode('utf-8'))
|
||||||
payload_data = json.loads(payload_str)
|
dataset_id = str(payload_data.get('dataset_id') or '').strip()
|
||||||
|
remote_document_id = str(payload_data.get('remote_document_id') or '').strip()
|
||||||
# 检查是否过期,或者直接重新获取
|
except Exception:
|
||||||
import time
|
pass
|
||||||
|
|
||||||
|
if not dataset_id or not remote_document_id:
|
||||||
|
try:
|
||||||
|
stmt = sa.text("CAST(retriever_resources AS TEXT) LIKE :url")
|
||||||
|
log = db.session.query(ChatLog).filter(stmt).params(url=f'%{raw_url}%').order_by(ChatLog.created_at.desc()).first()
|
||||||
|
if log and log.retriever_resources:
|
||||||
|
for r in log.retriever_resources:
|
||||||
|
source_url = str(r.get('source_download_url') or '')
|
||||||
|
if source_url == raw_url or (source_url and source_url.split('&token=')[0] == raw_url.split('&token=')[0]):
|
||||||
|
dataset_id = dataset_id or str(r.get('dataset_id') or r.get('metadata', {}).get('dataset_id') or '').strip()
|
||||||
|
remote_document_id = remote_document_id or str(
|
||||||
|
r.get('remote_document_id') or r.get('metadata', {}).get('remote_document_id') or r.get('document_id') or ''
|
||||||
|
).strip()
|
||||||
|
if dataset_id and remote_document_id:
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning("[file-preview] failed to find IDs in ChatLog: %s", e)
|
||||||
|
|
||||||
|
if dataset_id and remote_document_id:
|
||||||
|
new_info = IntegrationApiService.lookup_file_by_dify(dataset_id, remote_document_id)
|
||||||
|
if new_info and new_info.get('source_download_url'):
|
||||||
|
current_app.logger.info("[file-preview] refreshed integration url for dataset=%s doc=%s", dataset_id, remote_document_id)
|
||||||
|
return new_info['source_download_url']
|
||||||
|
return raw_url
|
||||||
|
|
||||||
|
def _build_headers(raw_url: str):
|
||||||
|
next_headers = {}
|
||||||
|
if base_url and raw_url.startswith(base_url) and api_key:
|
||||||
|
next_headers['X-Integration-Key'] = api_key
|
||||||
|
return next_headers
|
||||||
|
|
||||||
|
def _should_refresh_from_response(resp) -> bool:
|
||||||
|
ctype = (resp.headers.get('content-type') or '').split(';')[0].strip().lower()
|
||||||
|
if resp.status_code == 401:
|
||||||
|
return True
|
||||||
|
if ctype == 'application/json':
|
||||||
|
body = (resp.content or b'')[:512].decode('utf-8', errors='ignore').lower()
|
||||||
|
if 'unauthorized' in body or '"error"' in body:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
if base_url and file_url.startswith(base_url) and 'token=' in file_url:
|
||||||
|
try:
|
||||||
|
parsed = urlparse(file_url)
|
||||||
|
qs = parse_qs(parsed.query)
|
||||||
|
token = (qs.get('token') or [''])[0]
|
||||||
|
if token:
|
||||||
|
parts = token.split('.')
|
||||||
|
if len(parts) >= 2:
|
||||||
|
payload_b64 = parts[1]
|
||||||
|
payload_b64 += '=' * (-len(payload_b64) % 4)
|
||||||
|
payload_data = json.loads(base64.urlsafe_b64decode(payload_b64).decode('utf-8'))
|
||||||
exp = payload_data.get('exp', 0)
|
exp = payload_data.get('exp', 0)
|
||||||
if exp and exp < time.time() + 300: # 如果已经过期或者即将在 5 分钟内过期
|
if exp and exp < time.time() + 300:
|
||||||
dataset_id = payload_data.get('dataset_id')
|
file_url = _resolve_latest_integration_url(file_url)
|
||||||
remote_document_id = payload_data.get('remote_document_id')
|
|
||||||
|
|
||||||
# 如果旧版本的 token 里没有这俩 ID,尝试从聊天记录反查
|
|
||||||
if not dataset_id or not remote_document_id:
|
|
||||||
from app.models import ChatLog
|
|
||||||
from app import db
|
|
||||||
import sqlalchemy as sa
|
|
||||||
try:
|
|
||||||
stmt = sa.text("CAST(retriever_resources AS TEXT) LIKE :url")
|
|
||||||
log = db.session.query(ChatLog).filter(stmt).params(url=f'%{file_url}%').order_by(ChatLog.created_at.desc()).first()
|
|
||||||
if log and log.retriever_resources:
|
|
||||||
for r in log.retriever_resources:
|
|
||||||
if r.get('source_download_url') == file_url:
|
|
||||||
dataset_id = dataset_id or r.get('dataset_id') or r.get('metadata', {}).get('dataset_id')
|
|
||||||
remote_document_id = remote_document_id or r.get('remote_document_id') or r.get('metadata', {}).get('remote_document_id') or r.get('document_id')
|
|
||||||
if dataset_id and remote_document_id:
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning("[file-preview] failed to find IDs in ChatLog: %s", e)
|
|
||||||
|
|
||||||
if dataset_id and remote_document_id:
|
|
||||||
new_info = IntegrationApiService.lookup_file_by_dify(dataset_id, remote_document_id)
|
|
||||||
if new_info and new_info.get('source_download_url'):
|
|
||||||
file_url = new_info['source_download_url']
|
|
||||||
current_app.logger.info("[file-preview] refreshed expired integration url for dataset=%s doc=%s", dataset_id, remote_document_id)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning("[file-preview] failed to refresh expired integration token: %s", e)
|
current_app.logger.warning("[file-preview] failed to refresh expired integration token: %s", e)
|
||||||
|
|
||||||
if base_url and file_url.startswith(base_url) and api_key:
|
headers = _build_headers(file_url)
|
||||||
headers['X-Integration-Key'] = api_key
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
upstream = requests.get(file_url, headers=headers, timeout=(5, 20))
|
upstream = requests.get(file_url, headers=headers, timeout=(5, 20))
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
current_app.logger.warning("[file-preview] upstream request failed: %s", e)
|
current_app.logger.warning("[file-preview] upstream request failed: %s", e)
|
||||||
return None, None, ('failed to fetch source file', 502)
|
return None, None, ('failed to fetch source file', 502)
|
||||||
|
|
||||||
|
# 某些旧历史记录中的 source_download_url 已过期,但上游可能返回 200 + JSON 错误体。
|
||||||
|
# 这里统一视为“坏链接”,刷新最新下载地址后重试一次。
|
||||||
|
if base_url and file_url.startswith(base_url) and 'token=' in file_url and _should_refresh_from_response(upstream):
|
||||||
|
refreshed_url = _resolve_latest_integration_url(file_url)
|
||||||
|
if refreshed_url != file_url:
|
||||||
|
headers = _build_headers(refreshed_url)
|
||||||
|
try:
|
||||||
|
upstream = requests.get(refreshed_url, headers=headers, timeout=(5, 20))
|
||||||
|
file_url = refreshed_url
|
||||||
|
except requests.RequestException as e:
|
||||||
|
current_app.logger.warning("[file-preview] refreshed upstream request failed: %s", e)
|
||||||
|
return None, None, ('failed to fetch source file', 502)
|
||||||
|
|
||||||
if upstream.status_code != 200:
|
if upstream.status_code != 200:
|
||||||
return None, None, (f'upstream returned status {upstream.status_code}', 502)
|
return None, None, (f'upstream returned status {upstream.status_code}', 502)
|
||||||
|
|
||||||
@@ -138,8 +183,103 @@ def _fetch_preview_source_bytes(file_url: str):
|
|||||||
return None, None, ('file too large for online preview', 413)
|
return None, None, ('file too large for online preview', 413)
|
||||||
|
|
||||||
content_type = (upstream.headers.get('content-type') or '').split(';')[0].strip().lower()
|
content_type = (upstream.headers.get('content-type') or '').split(';')[0].strip().lower()
|
||||||
|
if content_type == 'application/json':
|
||||||
|
body = content[:512].decode('utf-8', errors='ignore')
|
||||||
|
current_app.logger.warning("[file-preview] upstream returned json instead of binary url=%s body=%s", file_url, body)
|
||||||
|
return None, None, ('upstream returned invalid preview payload', 502)
|
||||||
return content, content_type, None
|
return content, content_type, None
|
||||||
|
|
||||||
|
def _convert_office_to_pdf(content: bytes, ext: str) -> bytes:
|
||||||
|
"""
|
||||||
|
使用 LibreOffice 将 office 文件转为 PDF
|
||||||
|
"""
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
input_path = os.path.join(temp_dir, f"input.{ext}")
|
||||||
|
with open(input_path, 'wb') as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
commands = [
|
||||||
|
'soffice',
|
||||||
|
'libreoffice',
|
||||||
|
r'C:\Program Files\LibreOffice\program\soffice.exe',
|
||||||
|
r'C:\Program Files (x86)\LibreOffice\program\soffice.exe'
|
||||||
|
]
|
||||||
|
|
||||||
|
success = False
|
||||||
|
for cmd in commands:
|
||||||
|
try:
|
||||||
|
process = subprocess.run(
|
||||||
|
[cmd, '--headless', '--convert-to', 'pdf', '--outdir', temp_dir, input_path],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
timeout=60
|
||||||
|
)
|
||||||
|
if process.returncode == 0:
|
||||||
|
success = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
current_app.logger.warning(f"LibreOffice command {cmd} failed: {process.stderr.decode('utf-8', errors='ignore')}")
|
||||||
|
except (FileNotFoundError, subprocess.TimeoutExpired):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 如果 LibreOffice 失败,且是在 Windows 系统下,尝试调用本地安装的 WPS 或 MS Office
|
||||||
|
if not success and os.name == 'nt':
|
||||||
|
try:
|
||||||
|
import win32com.client
|
||||||
|
import pythoncom
|
||||||
|
pythoncom.CoInitialize()
|
||||||
|
output_path = os.path.join(temp_dir, "input.pdf")
|
||||||
|
|
||||||
|
if ext in ('doc', 'docx'):
|
||||||
|
try:
|
||||||
|
app = win32com.client.Dispatch("KWPS.Application") # 尝试 WPS Word
|
||||||
|
except Exception:
|
||||||
|
app = win32com.client.Dispatch("Word.Application") # 回退 MS Word
|
||||||
|
app.Visible = False
|
||||||
|
doc = app.Documents.Open(os.path.abspath(input_path))
|
||||||
|
doc.SaveAs(os.path.abspath(output_path), FileFormat=17) # 17 = wdFormatPDF
|
||||||
|
doc.Close()
|
||||||
|
app.Quit()
|
||||||
|
success = True
|
||||||
|
|
||||||
|
elif ext in ('ppt', 'pptx'):
|
||||||
|
try:
|
||||||
|
app = win32com.client.Dispatch("KWPP.Application") # 尝试 WPS PPT
|
||||||
|
except Exception:
|
||||||
|
app = win32com.client.Dispatch("PowerPoint.Application") # 回退 MS PPT
|
||||||
|
app.Visible = False
|
||||||
|
presentation = app.Presentations.Open(os.path.abspath(input_path), WithWindow=False)
|
||||||
|
presentation.SaveAs(os.path.abspath(output_path), 32) # 32 = ppSaveAsPDF
|
||||||
|
presentation.Close()
|
||||||
|
app.Quit()
|
||||||
|
success = True
|
||||||
|
|
||||||
|
elif ext in ('xls', 'xlsx'):
|
||||||
|
try:
|
||||||
|
app = win32com.client.Dispatch("KET.Application") # 尝试 WPS Excel
|
||||||
|
except Exception:
|
||||||
|
app = win32com.client.Dispatch("Excel.Application") # 回退 MS Excel
|
||||||
|
app.Visible = False
|
||||||
|
wb = app.Workbooks.Open(os.path.abspath(input_path))
|
||||||
|
wb.ExportAsFixedFormat(0, os.path.abspath(output_path)) # 0 = xlTypePDF
|
||||||
|
wb.Close(False)
|
||||||
|
app.Quit()
|
||||||
|
success = True
|
||||||
|
except ImportError:
|
||||||
|
current_app.logger.warning("pywin32 not installed, cannot fallback to WPS/MS Office COM API.")
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning(f"WPS/MS Office COM conversion failed: {e}")
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
raise Exception("Failed to convert document to PDF using LibreOffice or WPS/MS Office")
|
||||||
|
|
||||||
|
output_path = os.path.join(temp_dir, "input.pdf")
|
||||||
|
if os.path.exists(output_path):
|
||||||
|
with open(output_path, 'rb') as f:
|
||||||
|
return f.read()
|
||||||
|
else:
|
||||||
|
raise Exception("PDF output not found after conversion")
|
||||||
|
|
||||||
|
|
||||||
@chat_bp.route('/sessions', methods=['GET'])
|
@chat_bp.route('/sessions', methods=['GET'])
|
||||||
@require_agent_permission
|
@require_agent_permission
|
||||||
@@ -295,17 +435,20 @@ def chat_completions():
|
|||||||
query = data.get('query')
|
query = data.get('query')
|
||||||
# 提取会话 ID(可选)
|
# 提取会话 ID(可选)
|
||||||
conversation_id = data.get('conversation_id')
|
conversation_id = data.get('conversation_id')
|
||||||
|
# 知识库类型
|
||||||
|
kb_type = data.get('kb_type', '企业知识库')
|
||||||
|
|
||||||
# 从全局 g 中获取装饰器注入的用户和 Agent 对象
|
# 从全局 g 中获取装饰器注入的用户和 Agent 对象
|
||||||
user = getattr(g, 'current_user', None)
|
user = getattr(g, 'current_user', None)
|
||||||
agent = getattr(g, 'current_agent', None)
|
agent = getattr(g, 'current_agent', None)
|
||||||
|
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"[chat-api] /completions request user_id=%s agent_id=%s query_len=%s conversation_id=%s",
|
"[chat-api] /completions request user_id=%s agent_id=%s query_len=%s conversation_id=%s kb_type=%s",
|
||||||
getattr(user, 'id', None),
|
getattr(user, 'id', None),
|
||||||
getattr(agent, 'id', None),
|
getattr(agent, 'id', None),
|
||||||
len(query or ''),
|
len(query or ''),
|
||||||
conversation_id,
|
conversation_id,
|
||||||
|
kb_type
|
||||||
)
|
)
|
||||||
|
|
||||||
# 安全兜底:如果装饰器未正确注入,返回错误
|
# 安全兜底:如果装饰器未正确注入,返回错误
|
||||||
@@ -313,10 +456,18 @@ def chat_completions():
|
|||||||
current_app.logger.error("[chat-api] missing user/agent context user=%s agent=%s", bool(user), bool(agent))
|
current_app.logger.error("[chat-api] missing user/agent context user=%s agent=%s", bool(user), bool(agent))
|
||||||
return jsonify({'error': 'Missing user or agent context'}), 500
|
return jsonify({'error': 'Missing user or agent context'}), 500
|
||||||
|
|
||||||
|
from app.services.dify import DifyService
|
||||||
|
|
||||||
|
if kb_type == 'ERP知识库':
|
||||||
|
from app.services.text2sql import Text2SQLService
|
||||||
|
generator = Text2SQLService.stream_chat(query, user.id, agent, conversation_id)
|
||||||
|
else:
|
||||||
|
generator = DifyService.stream_chat(query, user.id, agent, conversation_id)
|
||||||
|
|
||||||
# 返回 SSE 响应,mimetype 设为 text/event-stream
|
# 返回 SSE 响应,mimetype 设为 text/event-stream
|
||||||
return Response(
|
return Response(
|
||||||
stream_with_context(
|
stream_with_context(
|
||||||
DifyService.stream_chat(query, user.id, agent, conversation_id)
|
generator
|
||||||
),
|
),
|
||||||
mimetype='text/event-stream',
|
mimetype='text/event-stream',
|
||||||
headers={
|
headers={
|
||||||
@@ -571,6 +722,16 @@ def preview_file_raw():
|
|||||||
msg, code = err
|
msg, code = err
|
||||||
return jsonify({'error': msg}), code
|
return jsonify({'error': msg}), code
|
||||||
|
|
||||||
|
# 如果是无法纯前端渲染的旧版 Office 或 PPT 格式,尝试转为 PDF 供前端统一渲染
|
||||||
|
if ext in ('doc', 'ppt', 'pptx') and request.args.get('download') != '1':
|
||||||
|
try:
|
||||||
|
content = _convert_office_to_pdf(content, ext)
|
||||||
|
ext = 'pdf'
|
||||||
|
content_type = 'application/pdf'
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error("[file-preview] LibreOffice conversion failed: %s", e)
|
||||||
|
# 转换失败则回退到原始格式
|
||||||
|
|
||||||
fallback_types = {
|
fallback_types = {
|
||||||
'pdf': 'application/pdf',
|
'pdf': 'application/pdf',
|
||||||
'doc': 'application/msword',
|
'doc': 'application/msword',
|
||||||
|
|||||||
+81
-1
@@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, request, jsonify, current_app
|
from flask import Blueprint, request, jsonify, current_app
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, Announcement, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
|
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, Announcement, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
|
||||||
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
|
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
|
||||||
@@ -308,6 +308,30 @@ def _casdoor_userinfo(access_token: str):
|
|||||||
raise RuntimeError(f'Casdoor userinfo failed: {data}')
|
raise RuntimeError(f'Casdoor userinfo failed: {data}')
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def _casdoor_password_login(username: str, password: str):
|
||||||
|
"""
|
||||||
|
Resource-owner password login against Casdoor token endpoint.
|
||||||
|
Requires the Casdoor application to enable password grant.
|
||||||
|
"""
|
||||||
|
meta = _get_casdoor_oidc_metadata()
|
||||||
|
token_endpoint = meta.get('token_endpoint')
|
||||||
|
if not token_endpoint:
|
||||||
|
raise RuntimeError('Casdoor token endpoint missing')
|
||||||
|
payload = {
|
||||||
|
'grant_type': 'password',
|
||||||
|
'username': username,
|
||||||
|
'password': password,
|
||||||
|
'client_id': current_app.config.get('CASDOOR_CLIENT_ID') or '',
|
||||||
|
'client_secret': current_app.config.get('CASDOOR_CLIENT_SECRET') or '',
|
||||||
|
'scope': current_app.config.get('CASDOOR_SCOPE') or 'openid profile email',
|
||||||
|
}
|
||||||
|
resp = requests.post(token_endpoint, data=payload, timeout=8)
|
||||||
|
data = resp.json() or {}
|
||||||
|
if not resp.ok or not data.get('access_token'):
|
||||||
|
raise RuntimeError(f'Casdoor password login failed: {data}')
|
||||||
|
return data
|
||||||
|
|
||||||
def _cleanup_wecom_state_cache():
|
def _cleanup_wecom_state_cache():
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
expired = [k for k, v in _WECOM_STATE_CACHE.items() if not v or v < now]
|
expired = [k for k, v in _WECOM_STATE_CACHE.items() if not v or v < now]
|
||||||
@@ -904,6 +928,62 @@ def login():
|
|||||||
return jsonify({'error': 'Internal server error'}), 500
|
return jsonify({'error': 'Internal server error'}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@user_bp.route('/casdoor/password-login', methods=['POST'])
|
||||||
|
def casdoor_password_login():
|
||||||
|
"""
|
||||||
|
Direct login with username/password against Casdoor (no browser redirect).
|
||||||
|
"""
|
||||||
|
if (current_app.config.get('AUTH_LOGIN_MODE') or 'casdoor').lower() != 'casdoor':
|
||||||
|
return jsonify({
|
||||||
|
'error': 'Casdoor password login is disabled by AUTH_LOGIN_MODE',
|
||||||
|
'error_code': 'CASDOOR_PASSWORD_LOGIN_DISABLED',
|
||||||
|
}), 403
|
||||||
|
data = request.get_json() or {}
|
||||||
|
username = _clean_str(data.get('username'))
|
||||||
|
password = data.get('password') or ''
|
||||||
|
if not username or not password:
|
||||||
|
return jsonify({'error': 'Username and password are required'}), 400
|
||||||
|
try:
|
||||||
|
token_data = _casdoor_password_login(username, password)
|
||||||
|
access_token = token_data.get('access_token')
|
||||||
|
refresh_token = token_data.get('refresh_token')
|
||||||
|
id_token = token_data.get('id_token')
|
||||||
|
expires_in = int(token_data.get('expires_in') or 3600)
|
||||||
|
|
||||||
|
claims = None
|
||||||
|
if id_token:
|
||||||
|
try:
|
||||||
|
claims = _decode_jwt(id_token)
|
||||||
|
except Exception:
|
||||||
|
claims = None
|
||||||
|
if claims is None:
|
||||||
|
claims = _casdoor_userinfo(access_token)
|
||||||
|
|
||||||
|
user = _resolve_user_from_casdoor_claims(claims)
|
||||||
|
_write_login_audit('casdoor', 'success', user=user)
|
||||||
|
db.session.commit()
|
||||||
|
api_bearer_token = id_token or access_token
|
||||||
|
return jsonify({
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username,
|
||||||
|
'role': user.role,
|
||||||
|
'default_agent_id': user.default_agent_id,
|
||||||
|
'source': 'casdoor',
|
||||||
|
'access_token': api_bearer_token,
|
||||||
|
'refresh_token': refresh_token,
|
||||||
|
'id_token': id_token,
|
||||||
|
'token_type': token_data.get('token_type') or 'Bearer',
|
||||||
|
'expires_in': expires_in,
|
||||||
|
})
|
||||||
|
except WeComLoginError as e:
|
||||||
|
db.session.rollback()
|
||||||
|
payload, status = e.to_response()
|
||||||
|
return jsonify(payload), status
|
||||||
|
except Exception as e:
|
||||||
|
db.session.rollback()
|
||||||
|
return jsonify({'error': f'Casdoor password login failed: {str(e)}'}), 401
|
||||||
|
|
||||||
|
|
||||||
@user_bp.route('/casdoor/authorize-url', methods=['GET'])
|
@user_bp.route('/casdoor/authorize-url', methods=['GET'])
|
||||||
def casdoor_authorize_url():
|
def casdoor_authorize_url():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ class Config:
|
|||||||
AUTH_LEGACY_HEADER_ENABLED = os.getenv('AUTH_LEGACY_HEADER_ENABLED', 'true').lower() == 'true'
|
AUTH_LEGACY_HEADER_ENABLED = os.getenv('AUTH_LEGACY_HEADER_ENABLED', 'true').lower() == 'true'
|
||||||
AUTH_JWT_REQUIRED = os.getenv('AUTH_JWT_REQUIRED', 'true').lower() == 'true'
|
AUTH_JWT_REQUIRED = os.getenv('AUTH_JWT_REQUIRED', 'true').lower() == 'true'
|
||||||
AUTH_ALLOW_LOCAL_PASSWORD_LOGIN = os.getenv('AUTH_ALLOW_LOCAL_PASSWORD_LOGIN', 'true').lower() == 'true'
|
AUTH_ALLOW_LOCAL_PASSWORD_LOGIN = os.getenv('AUTH_ALLOW_LOCAL_PASSWORD_LOGIN', 'true').lower() == 'true'
|
||||||
|
# Login mode switch: "casdoor" (default) or "password".
|
||||||
|
# casdoor: login form credentials are sent to Casdoor token endpoint (no redirect page for users).
|
||||||
|
# password: keep legacy local username/password login.
|
||||||
|
AUTH_LOGIN_MODE = os.getenv('AUTH_LOGIN_MODE', 'casdoor').strip().lower()
|
||||||
AUTH_ALLOW_LOCAL_JWT = os.getenv('AUTH_ALLOW_LOCAL_JWT', 'true').lower() == 'true'
|
AUTH_ALLOW_LOCAL_JWT = os.getenv('AUTH_ALLOW_LOCAL_JWT', 'true').lower() == 'true'
|
||||||
# JWT 的签发者(iss)校验值,后端用它确认“这个 token 是谁发的”
|
# JWT 的签发者(iss)校验值,后端用它确认“这个 token 是谁发的”
|
||||||
AUTH_JWT_ISSUER = os.getenv('AUTH_JWT_ISSUER', 'http://192.168.100.230:8088')
|
AUTH_JWT_ISSUER = os.getenv('AUTH_JWT_ISSUER', 'http://192.168.100.230:8088')
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class DifyService:
|
|||||||
# Prefer agent-specific base URL; fallback to global config.
|
# Prefer agent-specific base URL; fallback to global config.
|
||||||
base_url = agent.api_base_url if agent.api_base_url else Config.DIFY_API_BASE
|
base_url = agent.api_base_url if agent.api_base_url else Config.DIFY_API_BASE
|
||||||
base_url = base_url.rstrip('/')
|
base_url = base_url.rstrip('/')
|
||||||
url = f"{base_url}/chat-messages"
|
url = f"{base_url}/v1/chat-messages"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': f'Bearer {agent.dify_api_key}',
|
'Authorization': f'Bearer {agent.dify_api_key}',
|
||||||
|
|||||||
@@ -0,0 +1,314 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
class Text2SQLService:
|
||||||
|
_schema_text = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_schema(cls):
|
||||||
|
if cls._schema_text is None:
|
||||||
|
try:
|
||||||
|
# docs is at the project root: c:\Users\PC\Desktop\HX工作目录\hxops\hxops\docs
|
||||||
|
# This file is in backend/app/services/text2sql.py
|
||||||
|
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||||
|
doc_path = os.path.join(base_dir, 'docs', '(表+字段).md')
|
||||||
|
with open(doc_path, 'r', encoding='utf-8') as f:
|
||||||
|
cls._schema_text = f.read()
|
||||||
|
except Exception as e:
|
||||||
|
cls._schema_text = f"Failed to load schema: {e}"
|
||||||
|
return cls._schema_text
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _clean_llm_output(content: str) -> str:
|
||||||
|
cleaned = (content or "").strip()
|
||||||
|
cleaned = re.sub(r"^```(?:sql|json)?\s*", "", cleaned, flags=re.IGNORECASE)
|
||||||
|
cleaned = re.sub(r"\s*```$", "", cleaned)
|
||||||
|
return cleaned.strip()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_llm_client(cls):
|
||||||
|
try:
|
||||||
|
from openai import OpenAI
|
||||||
|
except ImportError:
|
||||||
|
return None, "OpenAI SDK not installed"
|
||||||
|
|
||||||
|
api_key = os.getenv("GJL_API_KEY", "")
|
||||||
|
base_url = os.getenv("GJL_API_BASE", "https://api.siliconflow.cn/v1")
|
||||||
|
|
||||||
|
if not api_key:
|
||||||
|
return None, "Missing GJL_API_KEY. Please configure it in .env to enable Text-to-SQL"
|
||||||
|
|
||||||
|
return OpenAI(api_key=api_key, base_url=base_url), None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _chat_completion(cls, system_prompt: str, user_prompt: str, temperature: float = 0):
|
||||||
|
client, error = cls._get_llm_client()
|
||||||
|
if error:
|
||||||
|
raise RuntimeError(error)
|
||||||
|
|
||||||
|
response = client.chat.completions.create(
|
||||||
|
model=os.getenv("GJL_MODEL", "deepseek-ai/DeepSeek-V3"),
|
||||||
|
messages=[
|
||||||
|
{"role": "system", "content": system_prompt},
|
||||||
|
{"role": "user", "content": user_prompt},
|
||||||
|
],
|
||||||
|
temperature=temperature,
|
||||||
|
)
|
||||||
|
content = response.choices[0].message.content or ""
|
||||||
|
return cls._clean_llm_output(content)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _escape_sql_message(message: str) -> str:
|
||||||
|
safe = (message or "").replace("'", "''").replace("\n", " ").strip()
|
||||||
|
return safe or "Unknown error"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _is_safe_query(sql: str) -> bool:
|
||||||
|
sql = (sql or "").strip()
|
||||||
|
if not re.match(r"(?is)^(select|with)\b", sql):
|
||||||
|
return False
|
||||||
|
return not re.search(r"(?is)\b(insert|update|delete|merge|alter|drop|truncate|create|grant|revoke)\b", sql)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _stringify_value(value):
|
||||||
|
if value is None:
|
||||||
|
return "NULL"
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _serialize_results_for_llm(cls, columns, rows, max_rows: int = 30) -> str:
|
||||||
|
preview_rows = rows[:max_rows]
|
||||||
|
preview = []
|
||||||
|
for row in preview_rows:
|
||||||
|
preview.append({columns[idx]: cls._stringify_value(value) for idx, value in enumerate(row)})
|
||||||
|
payload = {
|
||||||
|
"columns": columns,
|
||||||
|
"row_count": len(rows),
|
||||||
|
"preview_row_count": len(preview_rows),
|
||||||
|
"truncated": len(rows) > max_rows,
|
||||||
|
"rows": preview,
|
||||||
|
}
|
||||||
|
return json.dumps(payload, ensure_ascii=False)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def summarize_result(cls, query: str, columns, rows) -> str:
|
||||||
|
if columns == ["Error"]:
|
||||||
|
error_message = rows[0][0] if rows and rows[0] else "未知错误"
|
||||||
|
return f"- 直击答案:查询执行失败,当前无法返回结果。\n- 异常提醒:数据库返回错误 `{error_message}`,请检查筛选条件、表名或字段名。"
|
||||||
|
|
||||||
|
if not rows:
|
||||||
|
return "- 直击答案:当前未查询到符合条件的数据。\n- 趋势发现:当前结果未体现明显趋势。\n- 异常提醒:当前结果未体现明显异常,建议调整筛选条件后重试。"
|
||||||
|
|
||||||
|
system_prompt = f"""你是一位资深的业务分析师。
|
||||||
|
任务:根据下方的数据库查询结果,为用户提供一份简洁、直观的分析汇总。
|
||||||
|
|
||||||
|
汇总要求:
|
||||||
|
- 直击答案:第一句话直接回答用户的核心问题。
|
||||||
|
- 趋势发现:如果有时间维度,请指出增长或下降趋势。
|
||||||
|
- 异常提醒:如果数据中有显著的极值或异常,请标注。
|
||||||
|
- 语言风格:专业且易懂,避免直接念数字,要讲出数字背后的业务含义。
|
||||||
|
- 格式:使用 Markdown 列表。
|
||||||
|
- 如果查询结果没有体现明显趋势或异常,请明确写出“当前结果未体现明显趋势”或“当前结果未体现明显异常”,不要编造。
|
||||||
|
- 结合用户原始问题组织语言,不要重复输出 SQL,也不要复述字段名清单。"""
|
||||||
|
|
||||||
|
user_prompt = f"""原始问题:{query}
|
||||||
|
查询数据:{cls._serialize_results_for_llm(columns, rows)}"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
summary = cls._chat_completion(system_prompt, user_prompt, temperature=0.2)
|
||||||
|
return summary or cls._fallback_summary(columns, rows)
|
||||||
|
except Exception:
|
||||||
|
return cls._fallback_summary(columns, rows)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _fallback_summary(cls, columns, rows) -> str:
|
||||||
|
if not rows:
|
||||||
|
return "- 直击答案:当前未查询到符合条件的数据。\n- 趋势发现:当前结果未体现明显趋势。\n- 异常提醒:当前结果未体现明显异常。"
|
||||||
|
|
||||||
|
if len(rows) == 1 and len(columns) == 1:
|
||||||
|
return (
|
||||||
|
f"- 直击答案:{columns[0]} 为 {cls._stringify_value(rows[0][0])}。\n"
|
||||||
|
"- 趋势发现:当前结果未体现明显趋势。\n"
|
||||||
|
"- 异常提醒:当前结果未体现明显异常。"
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
f"- 直击答案:本次共返回 {len(rows)} 条记录,可结合下方明细进一步查看。\n"
|
||||||
|
"- 趋势发现:当前结果未体现明显趋势。\n"
|
||||||
|
"- 异常提醒:当前结果未体现明显异常。"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def generate_sql(cls, query: str) -> str:
|
||||||
|
schema = cls.get_schema()
|
||||||
|
|
||||||
|
try:
|
||||||
|
system_prompt = f"""你是一个专业的 Oracle SQL 专家和数据分析助手。你的任务是将用户的自然语言转换为准确的 Oracle 查询语句。
|
||||||
|
|
||||||
|
数据库结构 (Schema):
|
||||||
|
{schema}
|
||||||
|
|
||||||
|
约束要求:
|
||||||
|
- 只输出 SQL,不要解释。
|
||||||
|
- 日期查询请优先使用 CURRENT_DATE 进行计算。
|
||||||
|
- 如果用户问题模糊,请选择最合理的关联方式,优先使用 LEFT JOIN 补充维度信息。
|
||||||
|
- 严禁生成任何 INSERT、UPDATE、DELETE、MERGE、ALTER、DROP、TRUNCATE、CREATE 语句。
|
||||||
|
- 仅允许输出单条 SELECT 或 WITH 开头的查询。
|
||||||
|
- 必须使用 Schema 中出现的精确表名,包含完整前缀,如 ERP_VIEW_USER.ERP_FAJ_FILE_V。
|
||||||
|
- 优先选择最相关字段,避免 SELECT *。
|
||||||
|
- 当问题涉及“多少、总额、平均值、数量、占比、排名”时,请使用清晰的聚合逻辑与英文别名。
|
||||||
|
- 如果问题无法仅依据当前 Schema 回答,请输出安全的 SELECT 语句说明原因,例如 SELECT '无法根据当前表结构回答该问题' AS message FROM DUAL。"""
|
||||||
|
|
||||||
|
user_prompt = f"用户问题:{query}"
|
||||||
|
sql = cls._chat_completion(system_prompt, user_prompt, temperature=0)
|
||||||
|
sql = sql.rstrip(";")
|
||||||
|
|
||||||
|
if not cls._is_safe_query(sql):
|
||||||
|
return "SELECT 'Generated SQL was blocked because it is not a safe read-only SELECT query' AS error FROM DUAL"
|
||||||
|
|
||||||
|
return sql
|
||||||
|
except Exception as e:
|
||||||
|
return f"SELECT '{cls._escape_sql_message(f'LLM Error: {e}')}' AS error FROM DUAL"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def execute_sql(cls, sql: str):
|
||||||
|
try:
|
||||||
|
import oracledb
|
||||||
|
except ImportError:
|
||||||
|
return ["Error"], [["oracledb is not installed"]]
|
||||||
|
|
||||||
|
user = "EXT_VIEW_USER"
|
||||||
|
password = "extviewuser"
|
||||||
|
dsn = os.getenv("ERP_DB_DSN", "192.168.8.24:1521/topprod")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Enable thick mode to support older Oracle versions
|
||||||
|
import platform
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
oracle_client_dir = os.path.join(base_dir, 'oracle_client')
|
||||||
|
|
||||||
|
# Dynamically find the instantclient folder
|
||||||
|
client_dirs = []
|
||||||
|
if os.path.exists(oracle_client_dir):
|
||||||
|
client_dirs = [
|
||||||
|
os.path.join(oracle_client_dir, d)
|
||||||
|
for d in os.listdir(oracle_client_dir)
|
||||||
|
if d.startswith('instantclient_') and os.path.isdir(os.path.join(oracle_client_dir, d))
|
||||||
|
]
|
||||||
|
|
||||||
|
target_lib_dir = None
|
||||||
|
if client_dirs:
|
||||||
|
target_lib_dir = client_dirs[0]
|
||||||
|
else:
|
||||||
|
target_lib_dir = os.path.join(oracle_client_dir, 'instantclient_19_24')
|
||||||
|
|
||||||
|
# Fix for OCI path issue with Chinese characters (like "HX工作目录")
|
||||||
|
# OCI C-library fails to load if path contains non-ASCII
|
||||||
|
if not target_lib_dir.isascii():
|
||||||
|
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
||||||
|
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):
|
||||||
|
os.makedirs(temp_dir, exist_ok=True)
|
||||||
|
shutil.copytree(target_lib_dir, safe_lib_dir)
|
||||||
|
target_lib_dir = safe_lib_dir
|
||||||
|
|
||||||
|
oracledb.init_oracle_client(lib_dir=target_lib_dir)
|
||||||
|
else:
|
||||||
|
oracledb.init_oracle_client()
|
||||||
|
except Exception as e:
|
||||||
|
if current_app:
|
||||||
|
current_app.logger.warning(f"Failed to init thick mode: {e}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
connection = oracledb.connect(user=user, password=password, dsn=dsn)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(sql)
|
||||||
|
|
||||||
|
columns = [col[0] for col in cursor.description]
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
return columns, rows
|
||||||
|
except Exception as e:
|
||||||
|
return ["Error"], [[str(e)]]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def format_result(cls, columns, rows, sql, original_query):
|
||||||
|
summary_text = cls.summarize_result(original_query, columns, rows)
|
||||||
|
sql_details = f"<details>\n<summary class=\"cursor-pointer text-xs font-semibold uppercase tracking-wide text-slate-600 dark:text-slate-300 mb-2\">执行的SQL</summary>\n\n```sql\n{sql}\n```\n</details>"
|
||||||
|
|
||||||
|
if columns == ["Error"]:
|
||||||
|
error_message = rows[0][0] if rows and rows[0] else "未知错误"
|
||||||
|
return f"{summary_text}\n\n**错误详情**\n\n`{error_message}`\n\n{sql_details}"
|
||||||
|
|
||||||
|
if not columns or not rows:
|
||||||
|
return f"{summary_text}\n\n{sql_details}"
|
||||||
|
|
||||||
|
header = "| " + " | ".join(columns) + " |"
|
||||||
|
separator = "| " + " | ".join(["---"] * len(columns)) + " |"
|
||||||
|
|
||||||
|
body = []
|
||||||
|
for row in rows:
|
||||||
|
body.append("| " + " | ".join([cls._stringify_value(val) for val in row]) + " |")
|
||||||
|
|
||||||
|
table_str = "\n".join([header, separator] + body)
|
||||||
|
|
||||||
|
return f"{summary_text}\n\n**查询结果如下:**\n\n{table_str}\n\n{sql_details}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def stream_chat(query: str, user_id: int, agent, conversation_id: str = None):
|
||||||
|
"""Yields SSE events to frontend just like DifyService"""
|
||||||
|
start_time = time.time()
|
||||||
|
final_conversation_id = conversation_id or f"erp_{int(time.time())}"
|
||||||
|
|
||||||
|
# 1. Generate SQL
|
||||||
|
yield f"data: {json.dumps({'event': 'message', 'answer': '正在分析问题并生成 SQL...\n'})}\n\n"
|
||||||
|
sql = Text2SQLService.generate_sql(query)
|
||||||
|
yield f"data: {json.dumps({'event': 'message', 'answer': '已完成查询口径分析,正在查询数据库...\n'})}\n\n"
|
||||||
|
|
||||||
|
# 2. Execute SQL
|
||||||
|
columns, rows = Text2SQLService.execute_sql(sql)
|
||||||
|
|
||||||
|
# 3. Format result
|
||||||
|
yield f"data: {json.dumps({'event': 'message', 'answer': '正在整理结果并生成业务汇总...\n'})}\n\n"
|
||||||
|
result_text = Text2SQLService.format_result(columns, rows, sql, query)
|
||||||
|
|
||||||
|
latency = int((time.time() - start_time) * 1000)
|
||||||
|
|
||||||
|
# Create ChatLog
|
||||||
|
from app.models import ChatLog, db
|
||||||
|
chat_log_id = None
|
||||||
|
try:
|
||||||
|
chat_log = ChatLog(
|
||||||
|
user_id=user_id,
|
||||||
|
agent_id=agent.id,
|
||||||
|
conversation_id=final_conversation_id,
|
||||||
|
query=query,
|
||||||
|
answer=result_text,
|
||||||
|
tokens_used=0,
|
||||||
|
latency=latency,
|
||||||
|
)
|
||||||
|
db.session.add(chat_log)
|
||||||
|
db.session.commit()
|
||||||
|
chat_log_id = chat_log.id
|
||||||
|
except Exception as e:
|
||||||
|
if current_app:
|
||||||
|
current_app.logger.error(f'Failed to log text2sql chat: {e}')
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
|
end_data = {
|
||||||
|
'event': 'message_end',
|
||||||
|
'answer': result_text,
|
||||||
|
'replace_answer': True,
|
||||||
|
'chat_log_id': chat_log_id,
|
||||||
|
'conversation_id': final_conversation_id
|
||||||
|
}
|
||||||
|
yield f"data: {json.dumps(end_data)}\n\n"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import urllib.request
|
||||||
|
import zipfile
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
url = "https://download.oracle.com/otn_software/nt/instantclient/1924000/instantclient-basiclite-windows.x64-19.24.0.0.0dbru.zip"
|
||||||
|
zip_path = "instantclient.zip"
|
||||||
|
extract_dir = "oracle_client"
|
||||||
|
|
||||||
|
print("Downloading...")
|
||||||
|
urllib.request.urlretrieve(url, zip_path)
|
||||||
|
print("Downloaded. Extracting...")
|
||||||
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||||
|
zip_ref.extractall(extract_dir)
|
||||||
|
print("Done. Content:")
|
||||||
|
print(os.listdir(extract_dir))
|
||||||
@@ -14,3 +14,4 @@ openpyxl
|
|||||||
pycryptodome
|
pycryptodome
|
||||||
PyJWT
|
PyJWT
|
||||||
cryptography
|
cryptography
|
||||||
|
pywin32
|
||||||
+913
@@ -0,0 +1,913 @@
|
|||||||
|
<br />
|
||||||
|
|
||||||
|
营运中心主档 ERP\_VIEW\_USER.ERP\_AZP\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
azp01 varchar2 10 营运中心代码,关联各视图site
|
||||||
|
|
||||||
|
azp02 varchar2 80 营运中心名称,关联各视图site\_desc
|
||||||
|
|
||||||
|
azp03 varchar2 20 数据库代码
|
||||||
|
|
||||||
|
azp04 varchar2 10 服务器(SERVER)编号
|
||||||
|
|
||||||
|
azp051 varchar2 255 地址-1
|
||||||
|
|
||||||
|
azp052 varchar2 80 时区
|
||||||
|
|
||||||
|
azp053 varchar2 1 ERP 数据库否
|
||||||
|
|
||||||
|
azp06 varchar2 40 营运中心电话
|
||||||
|
|
||||||
|
azp07 varchar2 40 营运中心传真
|
||||||
|
|
||||||
|
azp08 varchar2 1 No Use
|
||||||
|
|
||||||
|
azp09 varchar2 1 是否限制上线人数
|
||||||
|
|
||||||
|
azp10 number 10 可上线人数
|
||||||
|
|
||||||
|
azp20 varchar2 20
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
部门名称资料档 ERP\_VIEW\_USER.ERP\_GEM\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
gem01 varchar2 10 部门编号
|
||||||
|
|
||||||
|
gem02 varchar2 80 部门名称
|
||||||
|
|
||||||
|
gem03 varchar2 80 部门全称
|
||||||
|
|
||||||
|
gem04 varchar2 6 No Use
|
||||||
|
|
||||||
|
gem05 varchar2 1 是否为会计部门
|
||||||
|
|
||||||
|
gem06 varchar2 1 No Use
|
||||||
|
|
||||||
|
gem07 varchar2 1 费用类型
|
||||||
|
|
||||||
|
gem08 varchar2 1 No Use
|
||||||
|
|
||||||
|
gemacti varchar2 1 资料有效码
|
||||||
|
|
||||||
|
gemuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
gemgrup varchar2 10 资料所有部门
|
||||||
|
|
||||||
|
gemmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
gemdate date 最近更改日
|
||||||
|
|
||||||
|
gem09 varchar2 1 管理类型 1.成本中心 2.利润中心 3.其它
|
||||||
|
|
||||||
|
gem10 varchar2 10 对应成本中心
|
||||||
|
|
||||||
|
gem11 varchar2 10 no use
|
||||||
|
|
||||||
|
gemorig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
gemoriu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
员工姓名档案 ERP\_VIEW\_USER.ERP\_GEN\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
gen01 varchar2 10 员工编号
|
||||||
|
|
||||||
|
gen02 varchar2 40 员工姓名
|
||||||
|
|
||||||
|
gen03 varchar2 10 所属部门编号
|
||||||
|
|
||||||
|
gen04 varchar2 80 职称
|
||||||
|
|
||||||
|
gen05 varchar2 5 分机
|
||||||
|
|
||||||
|
gen06 varchar2 80 E-mail
|
||||||
|
|
||||||
|
genacti varchar2 1 资料有效码
|
||||||
|
|
||||||
|
genuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
gengrup varchar2 10 资料所有部门
|
||||||
|
|
||||||
|
genmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
genorig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
genoriu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
genpos varchar2 1 已传POS否
|
||||||
|
|
||||||
|
gen07 varchar2 10 归属营运中心
|
||||||
|
|
||||||
|
gen08 varchar2 20 行动电话
|
||||||
|
|
||||||
|
gendate date 最近更改日
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
供应商基础资料档 ERP\_VIEW\_USER.ERP\_PMC\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
pmc01 varchar2 10 供应厂商编号
|
||||||
|
|
||||||
|
pmc02 varchar2 10 厂商分类
|
||||||
|
|
||||||
|
pmc03 varchar2 40 简称
|
||||||
|
|
||||||
|
pmc04 varchar2 10 付款厂商编号
|
||||||
|
|
||||||
|
pmc05 varchar2 1 交易状况
|
||||||
|
|
||||||
|
pmc06 varchar2 10 区域编号
|
||||||
|
|
||||||
|
pmc07 varchar2 10 国家编号
|
||||||
|
|
||||||
|
pmc081 varchar2 80 全名 (第一行)
|
||||||
|
|
||||||
|
pmc082 varchar2 80 全名 (第二行)
|
||||||
|
|
||||||
|
pmc091 varchar2 255 地址(第一行)
|
||||||
|
|
||||||
|
pmc092 varchar2 255 地址(第二行)
|
||||||
|
|
||||||
|
pmc093 varchar2 255 地址(第三行)
|
||||||
|
|
||||||
|
pmc094 varchar2 255 地址(第四行)
|
||||||
|
|
||||||
|
pmc095 varchar2 255 地址(第五行)
|
||||||
|
|
||||||
|
pmc10 varchar2 40 电话号码
|
||||||
|
|
||||||
|
pmc11 varchar2 40 传真号码
|
||||||
|
|
||||||
|
pmc12 varchar2 40 电传号码
|
||||||
|
|
||||||
|
pmc13 varchar2 1 VAT Feature
|
||||||
|
|
||||||
|
pmc14 varchar2 1 资料性质
|
||||||
|
|
||||||
|
pmc15 varchar2 10 送货地址
|
||||||
|
|
||||||
|
pmc16 varchar2 10 帐单地址
|
||||||
|
|
||||||
|
pmc17 varchar2 10 付款方式
|
||||||
|
|
||||||
|
pmc18 varchar2 1 厂商评鉴/ABC 等级
|
||||||
|
|
||||||
|
pmc19 varchar2 1 厂商评鉴/交货等级
|
||||||
|
|
||||||
|
pmc20 varchar2 1 厂商评鉴/质量等级
|
||||||
|
|
||||||
|
pmc21 varchar2 1 厂商评鉴/价格等级
|
||||||
|
|
||||||
|
pmc22 varchar2 4 采购币种
|
||||||
|
|
||||||
|
pmc23 varchar2 1 No Use
|
||||||
|
|
||||||
|
pmc24 varchar2 20 税号
|
||||||
|
|
||||||
|
pmc25 varchar2 2 付款行事历别
|
||||||
|
|
||||||
|
pmc26 varchar2 24 应付帐款会计科目
|
||||||
|
|
||||||
|
pmc27 varchar2 1 票据寄领方式
|
||||||
|
|
||||||
|
pmc28 number 5 邮资/手续费
|
||||||
|
|
||||||
|
pmc30 varchar2 1 厂商性质
|
||||||
|
|
||||||
|
pmc40 date 最近采购日期
|
||||||
|
|
||||||
|
pmc41 date 最近退货日期
|
||||||
|
|
||||||
|
pmc42 date 最近交货日期
|
||||||
|
|
||||||
|
pmc43 date 最近凭证日期
|
||||||
|
|
||||||
|
pmc44 date 最近付款日期
|
||||||
|
|
||||||
|
pmc45 number 13,2 No Use
|
||||||
|
|
||||||
|
pmc46 number 13,2 No Use
|
||||||
|
|
||||||
|
pmc47 varchar2 4 惯用税种
|
||||||
|
|
||||||
|
pmc48 varchar2 1 付款票据是否禁止背书
|
||||||
|
|
||||||
|
pmc49 varchar2 20 惯用价格条件
|
||||||
|
|
||||||
|
pmc50 number 5 现金票据到期日为每月的第几日
|
||||||
|
|
||||||
|
pmc51 number 5 远期票据到期日为每月的第几日
|
||||||
|
|
||||||
|
pmc52 varchar2 255 发票地址
|
||||||
|
|
||||||
|
pmc53 varchar2 255 寄票地址
|
||||||
|
|
||||||
|
pmc54 varchar2 10 惯用佣金编号
|
||||||
|
|
||||||
|
pmc55 varchar2 20 汇款银行编号
|
||||||
|
|
||||||
|
pmc56 varchar2 30 银行帐号
|
||||||
|
|
||||||
|
pmc901 varchar2 10 出货厂商
|
||||||
|
|
||||||
|
pmc902 varchar2 1 是否缴交切结书
|
||||||
|
|
||||||
|
pmc903 varchar2 1 是否为关系人
|
||||||
|
|
||||||
|
pmc904 varchar2 10 邮递区号
|
||||||
|
|
||||||
|
pmc905 varchar2 1 检验水准
|
||||||
|
|
||||||
|
pmc906 varchar2 1 检验程度
|
||||||
|
|
||||||
|
pmc907 varchar2 1 级数
|
||||||
|
|
||||||
|
pmc908 varchar2 10 地区别
|
||||||
|
|
||||||
|
pmc909 varchar2 30 用户自行定义
|
||||||
|
|
||||||
|
pmc910 varchar2 30 用户自行定义
|
||||||
|
|
||||||
|
pmc911 varchar2 1 惯用语言别
|
||||||
|
|
||||||
|
pmcacti varchar2 1 资料有效码
|
||||||
|
|
||||||
|
pmcuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
pmcgrup varchar2 10 资料所有部门
|
||||||
|
|
||||||
|
pmcmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
pmcdate date 最近更改日
|
||||||
|
|
||||||
|
pmcud01 varchar2 255 用户自订字段
|
||||||
|
|
||||||
|
pmcud02 varchar2 40 SCM厂商否
|
||||||
|
|
||||||
|
pmcud03 varchar2 40 SCM资料抛转否
|
||||||
|
|
||||||
|
pmcud04 varchar2 40 推送第一次来料否
|
||||||
|
|
||||||
|
pmcud05 varchar2 40 SRM供应商编码
|
||||||
|
|
||||||
|
pmcud06 varchar2 40 用户自订字段
|
||||||
|
|
||||||
|
pmcud07 number 15,3 用户自订字段
|
||||||
|
|
||||||
|
pmcud08 number 15,3 用户自订字段
|
||||||
|
|
||||||
|
pmcud09 number 15,3 用户自订字段
|
||||||
|
|
||||||
|
pmcud10 number 10 用户自订字段
|
||||||
|
|
||||||
|
pmcud11 number 10 用户自订字段
|
||||||
|
|
||||||
|
pmcud12 number 10 用户自订字段
|
||||||
|
|
||||||
|
pmcud13 date 用户自订字段
|
||||||
|
|
||||||
|
pmcud14 date 用户自订字段
|
||||||
|
|
||||||
|
pmcud15 date 用户自订字段
|
||||||
|
|
||||||
|
pmc912 varchar2 1 采购发出/采购变更是否以e-mail通知厂商?
|
||||||
|
|
||||||
|
pmc1912 varchar2 10 保税入库异动原因代码
|
||||||
|
|
||||||
|
pmc1913 varchar2 10 保税仓退异动原因代码
|
||||||
|
|
||||||
|
pmc1914 varchar2 10 保税海关监管编号
|
||||||
|
|
||||||
|
pmc1915 varchar2 10 保税业务人员
|
||||||
|
|
||||||
|
pmc1916 varchar2 10 负责人
|
||||||
|
|
||||||
|
pmc1917 varchar2 6 评核年月
|
||||||
|
|
||||||
|
pmc1918 number 15,3 评核分数
|
||||||
|
|
||||||
|
pmc1919 varchar2 1 评核等级
|
||||||
|
|
||||||
|
pmc1920 varchar2 10 资料来源
|
||||||
|
|
||||||
|
pmc1921 number 10 抛转次数
|
||||||
|
|
||||||
|
pmc913 varchar2 1 预付金额是否与采购单勾稽
|
||||||
|
|
||||||
|
pmc281 varchar2 1 手续费内扣/外加
|
||||||
|
|
||||||
|
pmc914 varchar2 1 VMI管理否
|
||||||
|
|
||||||
|
pmc915 varchar2 10 VMI库存仓库
|
||||||
|
|
||||||
|
pmc916 varchar2 10 VMI库存储位
|
||||||
|
|
||||||
|
pmc917 varchar2 10 VMI结算仓库
|
||||||
|
|
||||||
|
pmc918 varchar2 10 VMI结算储位
|
||||||
|
|
||||||
|
pmc919 varchar2 5 VMI结算收货单别
|
||||||
|
|
||||||
|
pmc920 varchar2 5 VMI结算入库单别
|
||||||
|
|
||||||
|
pmc921 varchar2 5 VMI结算退货单别
|
||||||
|
|
||||||
|
pmc922 varchar2 5 VMI库存杂发单别
|
||||||
|
|
||||||
|
pmc923 varchar2 5 VMI库存杂收单别
|
||||||
|
|
||||||
|
pmc57 varchar2 2 通知书传送方式
|
||||||
|
|
||||||
|
pmc58 number 5 送货天数
|
||||||
|
|
||||||
|
pmc59 varchar2 2 采购间隔
|
||||||
|
|
||||||
|
pmc60 varchar2 8 采购星期
|
||||||
|
|
||||||
|
pmc930 varchar2 10 对应营运中心编号
|
||||||
|
|
||||||
|
pmccrat date
|
||||||
|
|
||||||
|
pmcoriu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
pmcorig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
pmc29 number 5 结帐日
|
||||||
|
|
||||||
|
pmc61 varchar2 1 代印条码
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
固定资产主要类型档 ERP\_VIEW\_USER.ERP\_FAB\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
fab01 varchar2 10 资产主要类型
|
||||||
|
|
||||||
|
fab02 varchar2 80 类型名称
|
||||||
|
|
||||||
|
fab03 varchar2 1 资产性质
|
||||||
|
|
||||||
|
fab04 varchar2 1 折旧方法
|
||||||
|
|
||||||
|
fab05 number 5 耐用年限(月数)
|
||||||
|
|
||||||
|
fab06 varchar2 1 税签折旧方法
|
||||||
|
|
||||||
|
fab07 number 5 税签耐用年限
|
||||||
|
|
||||||
|
fab08 varchar2 1 折毕再提否
|
||||||
|
|
||||||
|
fab09 number 11 No Use
|
||||||
|
|
||||||
|
fab10 number 5 折毕再提年限
|
||||||
|
|
||||||
|
fab11 varchar2 24 资产会计科目
|
||||||
|
|
||||||
|
fab12 varchar2 24 累计折旧会计科目
|
||||||
|
|
||||||
|
fab13 varchar2 24 折旧费用会计科目
|
||||||
|
|
||||||
|
fab14 varchar2 1 是否直接资本化
|
||||||
|
|
||||||
|
fab15 varchar2 1 保税否
|
||||||
|
|
||||||
|
fab16 varchar2 1 保险否
|
||||||
|
|
||||||
|
fab17 varchar2 1 免税否
|
||||||
|
|
||||||
|
fab18 varchar2 1 抵押否
|
||||||
|
|
||||||
|
fab19 varchar2 1 投资抵减否
|
||||||
|
|
||||||
|
fab20 number 5 本币投资抵减比率
|
||||||
|
|
||||||
|
fab21 number 5 外币投资抵减比率
|
||||||
|
|
||||||
|
fab22 number 5 投资抵减补税年限
|
||||||
|
|
||||||
|
fab23 number 5 残值率
|
||||||
|
|
||||||
|
fabacti varchar2 1 资料有效码
|
||||||
|
|
||||||
|
fabuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
fabgrup varchar2 10 资料所有群
|
||||||
|
|
||||||
|
fabmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
fabdate date 最近更改日
|
||||||
|
|
||||||
|
fab24 varchar2 24 减值准备科目
|
||||||
|
|
||||||
|
fab25 varchar2 1 No Use
|
||||||
|
|
||||||
|
fab26 varchar2 1 No Use
|
||||||
|
|
||||||
|
fab27 varchar2 1 No Use
|
||||||
|
|
||||||
|
fab28 number 5 No Use
|
||||||
|
|
||||||
|
fab29 number 5 No Use
|
||||||
|
|
||||||
|
fab111 varchar2 24 资产会计科目二
|
||||||
|
|
||||||
|
fab121 varchar2 24 累计折旧会计科目二
|
||||||
|
|
||||||
|
fab131 varchar2 24 折旧费用会计科目二
|
||||||
|
|
||||||
|
fab241 varchar2 24 减值准备科目二
|
||||||
|
|
||||||
|
fabud01 varchar2 255 自订字段-Textedit
|
||||||
|
|
||||||
|
fabud02 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fabud03 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fabud04 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fabud05 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fabud06 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fabud07 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fabud08 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fabud09 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fabud10 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fabud11 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fabud12 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fabud13 date 自订字段-日期
|
||||||
|
|
||||||
|
fabud14 date 自订字段-日期
|
||||||
|
|
||||||
|
fabud15 date 自订字段-日期
|
||||||
|
|
||||||
|
faboriu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
faborig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
fab042 varchar2 1 折旧方法(财签二)
|
||||||
|
|
||||||
|
fab052 number 5 耐用年限(月数)(财签二)
|
||||||
|
|
||||||
|
fab082 varchar2 1 折毕再提否(财签二)
|
||||||
|
|
||||||
|
fab232 number 5 残值率(财签二)
|
||||||
|
|
||||||
|
fab102 number 5 折毕再提年限(财签二)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
固定资产存放位置档 ERP\_VIEW\_USER.ERP\_FAF\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
faf01 varchar2 10 存放位置代码
|
||||||
|
|
||||||
|
faf02 varchar2 80 存放位置名称
|
||||||
|
|
||||||
|
faf03 varchar2 10 存放营运中心
|
||||||
|
|
||||||
|
fafacti varchar2 1 资料有效码
|
||||||
|
|
||||||
|
fafuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
fafgrup varchar2 10 资料所有群
|
||||||
|
|
||||||
|
fafmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
fafdate date 最近更改日
|
||||||
|
|
||||||
|
faforig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
faforiu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
固定资产资料档 ERP\_VIEW\_USER.ERP\_FAJ\_FILE\_V
|
||||||
|
|
||||||
|
字段名称 类型 长度 字段说明
|
||||||
|
|
||||||
|
site varchar2 10 营运中心代码
|
||||||
|
|
||||||
|
site\_desc varchar2 80 营运中心名称
|
||||||
|
|
||||||
|
faj01 varchar2 10 序号
|
||||||
|
|
||||||
|
faj02 varchar2 10 财产编号
|
||||||
|
|
||||||
|
faj021 varchar2 1 类型 DECODE(faj021,''1'',''主件'',''2'',''附属配件'',''3'',''附加费用'')
|
||||||
|
|
||||||
|
faj022 varchar2 4 附号
|
||||||
|
|
||||||
|
faj03 varchar2 1 取得方式DECODE(faj03,''1'',''购入'',''2'',''盘点'',''3'',''其他方式'')
|
||||||
|
|
||||||
|
faj04 varchar2 10 资产类型 关联 fab02
|
||||||
|
|
||||||
|
faj05 varchar2 10 资产次类型
|
||||||
|
|
||||||
|
faj06 varchar2 80 中文名称-1
|
||||||
|
|
||||||
|
faj061 varchar2 80 中文名称-2
|
||||||
|
|
||||||
|
faj07 varchar2 80 英文名称-1
|
||||||
|
|
||||||
|
faj071 varchar2 80 英文名称-2
|
||||||
|
|
||||||
|
faj08 varchar2 30 规格型号
|
||||||
|
|
||||||
|
faj09 varchar2 1 资产性质 DECODE(faj09,''1'',''有形资产'',''2'',''无形资产'',''3'',''土地'',''4'',''递耗资产'',''5'',''费用'')
|
||||||
|
|
||||||
|
faj10 varchar2 10 供应商编号 关联pmc01
|
||||||
|
|
||||||
|
faj11 varchar2 10 制造厂商编号 关联pmc01
|
||||||
|
|
||||||
|
faj12 varchar2 10 原产地
|
||||||
|
|
||||||
|
faj13 number 20,6 本币单价
|
||||||
|
|
||||||
|
faj14 number 20,6 本币成本
|
||||||
|
|
||||||
|
faj141 number 20,6 调整成本
|
||||||
|
|
||||||
|
faj15 varchar2 4 原币币种
|
||||||
|
|
||||||
|
faj16 number 20,6 原币成本
|
||||||
|
|
||||||
|
faj17 number 5 数量
|
||||||
|
|
||||||
|
faj171 number 5 在外数量
|
||||||
|
|
||||||
|
faj18 varchar2 4 计量单位
|
||||||
|
|
||||||
|
faj19 varchar2 10 保管人 关联gen01
|
||||||
|
|
||||||
|
faj20 varchar2 10 保管部门 关联gem02
|
||||||
|
|
||||||
|
faj21 varchar2 10 存放位置 关联faf01
|
||||||
|
|
||||||
|
faj22 varchar2 10 存放营运中心 关联azp01
|
||||||
|
|
||||||
|
faj23 varchar2 1 分摊方式 DECODE(faj23,''1'',''单一部门分摊'',''2'',''多部门分摊'')
|
||||||
|
|
||||||
|
faj24 varchar2 10 分摊部门/分摊类型
|
||||||
|
|
||||||
|
faj25 date 取得日期
|
||||||
|
|
||||||
|
faj26 date 入帐日期
|
||||||
|
|
||||||
|
faj27 varchar2 6 折旧年月
|
||||||
|
|
||||||
|
faj28 varchar2 1 折旧方法
|
||||||
|
|
||||||
|
faj29 number 5 耐用年限(月数)
|
||||||
|
|
||||||
|
faj30 number 5 未使用年限(月数)
|
||||||
|
|
||||||
|
faj31 number 20,6 预留残值
|
||||||
|
|
||||||
|
faj32 number 20,6 累积折旧
|
||||||
|
|
||||||
|
faj33 number 20,6 未折减额
|
||||||
|
|
||||||
|
faj34 varchar2 1 折毕再提否
|
||||||
|
|
||||||
|
faj35 number 20,6 折毕再提预留残值
|
||||||
|
|
||||||
|
faj36 number 5 折毕再提年限
|
||||||
|
|
||||||
|
faj37 varchar2 1 是否直接资本化
|
||||||
|
|
||||||
|
faj38 varchar2 1 保税否
|
||||||
|
|
||||||
|
faj39 varchar2 1 保险否
|
||||||
|
|
||||||
|
faj40 varchar2 1 免税否
|
||||||
|
|
||||||
|
faj41 varchar2 1 抵押否
|
||||||
|
|
||||||
|
faj42 varchar2 1 投资抵减否
|
||||||
|
|
||||||
|
faj421 number 5 本币投资抵减比率
|
||||||
|
|
||||||
|
faj422 number 5 外币投资抵减比率
|
||||||
|
|
||||||
|
faj423 number 5 投资抵减补税年限
|
||||||
|
|
||||||
|
faj43 varchar2 1 资产状态 DECODE(faj43,''0'',''取得'',''1'',''资本化'',''2'',''折旧中'',''3'',''外送'',''4'',''折毕'',''5'',''出售'',''6'',''销账'',''7'',''折旧再提'',''8'',''改良'',''9'',''重估'',''X'',''被资本'',''Z'',''停用'')
|
||||||
|
|
||||||
|
faj44 varchar2 10 进货营运中心
|
||||||
|
|
||||||
|
faj45 varchar2 20 帐款编号
|
||||||
|
|
||||||
|
faj451 number 5 帐款编号项次
|
||||||
|
|
||||||
|
faj46 varchar2 20 收料单号
|
||||||
|
|
||||||
|
faj461 number 5 收料单项次
|
||||||
|
|
||||||
|
faj462 date 收料日期
|
||||||
|
|
||||||
|
faj47 varchar2 20 采购单号
|
||||||
|
|
||||||
|
faj471 number 5 采购单项次
|
||||||
|
|
||||||
|
faj48 varchar2 30 进口报单
|
||||||
|
|
||||||
|
faj49 varchar2 10 进口编号
|
||||||
|
|
||||||
|
faj491 date 交货日期
|
||||||
|
|
||||||
|
faj50 varchar2 12 预算编号
|
||||||
|
|
||||||
|
faj51 varchar2 20 发票号码
|
||||||
|
|
||||||
|
faj511 date 发票日期
|
||||||
|
|
||||||
|
faj52 varchar2 20 凭证号码
|
||||||
|
|
||||||
|
faj53 varchar2 24 资产科目
|
||||||
|
|
||||||
|
faj54 varchar2 24 累折科目
|
||||||
|
|
||||||
|
faj55 varchar2 24 折旧科目
|
||||||
|
|
||||||
|
faj56 varchar2 80 用途
|
||||||
|
|
||||||
|
faj57 number 5 最近折旧年度
|
||||||
|
|
||||||
|
faj571 number 5 最近折旧期别
|
||||||
|
|
||||||
|
faj58 number 5 销帐数量
|
||||||
|
|
||||||
|
faj59 number 20,6 销帐成本
|
||||||
|
|
||||||
|
faj60 number 20,6 销帐累折
|
||||||
|
|
||||||
|
faj61 varchar2 1 税签折旧方法
|
||||||
|
|
||||||
|
faj62 number 20,6 税签成本
|
||||||
|
|
||||||
|
faj63 number 20,6 税签调整成本
|
||||||
|
|
||||||
|
faj64 number 5 税签耐用年限
|
||||||
|
|
||||||
|
faj65 number 5 税签未使用年限(月数)
|
||||||
|
|
||||||
|
faj66 number 20,6 税签预留残值
|
||||||
|
|
||||||
|
faj67 number 20,6 税签累积折旧
|
||||||
|
|
||||||
|
faj68 number 20,6 税签未折减额
|
||||||
|
|
||||||
|
faj69 number 20,6 税签销帐成本
|
||||||
|
|
||||||
|
faj70 number 20,6 税签销帐累折
|
||||||
|
|
||||||
|
faj71 varchar2 1 税签折毕再提否
|
||||||
|
|
||||||
|
faj72 number 20,6 税签再提预留残值
|
||||||
|
|
||||||
|
faj73 number 5 税签折毕再提年限
|
||||||
|
|
||||||
|
faj74 number 5 最近税签折旧年度
|
||||||
|
|
||||||
|
faj741 number 5 最近折旧期别
|
||||||
|
|
||||||
|
faj80 number 5 抵减率
|
||||||
|
|
||||||
|
faj81 number 20,6 抵减金额
|
||||||
|
|
||||||
|
faj811 number 20,6 已抵减金额
|
||||||
|
|
||||||
|
faj812 number 5 已抵减的年度
|
||||||
|
|
||||||
|
faj813 varchar2 80 不可抵减原因
|
||||||
|
|
||||||
|
faj82 date 管理局核准日期
|
||||||
|
|
||||||
|
faj83 varchar2 30 管理局核准文号
|
||||||
|
|
||||||
|
faj84 date 国税局核准日期
|
||||||
|
|
||||||
|
faj85 varchar2 30 国税局核准文号
|
||||||
|
|
||||||
|
faj851 varchar2 1 抵减的合并码
|
||||||
|
|
||||||
|
faj86 number 20,6 申请抵押金额
|
||||||
|
|
||||||
|
faj87 number 20,6 设置抵押金额
|
||||||
|
|
||||||
|
faj88 date 抵押日期
|
||||||
|
|
||||||
|
faj89 varchar2 30 抵押文号
|
||||||
|
|
||||||
|
faj90 varchar2 20 抵押银行
|
||||||
|
|
||||||
|
faj91 date 解除日期
|
||||||
|
|
||||||
|
faj92 varchar2 10 底稿财产编号
|
||||||
|
|
||||||
|
faj921 varchar2 4 底稿财产附号
|
||||||
|
|
||||||
|
faj100 date 最近异动日期
|
||||||
|
|
||||||
|
faj201 varchar2 1 税签资产状态 DECODE(faj201,''0'',''取得'',''1'',''资本化'',''2'',''折旧中'',''3'',''外送'',''4'',''折毕'',''5'',''出售'',''6'',''销账'',''7'',''折旧再提'',''8'',''改良'',''9'',''重估'',''X'',''被资本'',''Z'',''停用'')
|
||||||
|
|
||||||
|
faj202 number 5 No Use
|
||||||
|
|
||||||
|
faj203 number 20,6 本期累折(财签)
|
||||||
|
|
||||||
|
faj204 number 20,6 本期销帐累折(财签)
|
||||||
|
|
||||||
|
faj205 number 20,6 本期累折(税签)
|
||||||
|
|
||||||
|
faj206 number 20,6 本期销帐累折(税签)
|
||||||
|
|
||||||
|
faj207 varchar2 1 资产列管/列帐
|
||||||
|
|
||||||
|
fajconf varchar2 1 审核否
|
||||||
|
|
||||||
|
fajuser varchar2 10 资料所有者
|
||||||
|
|
||||||
|
fajgrup varchar2 10 资料所有部门
|
||||||
|
|
||||||
|
fajmodu varchar2 10 资料更改者
|
||||||
|
|
||||||
|
fajdate date 最近更改日
|
||||||
|
|
||||||
|
faj101 number 20,6 已计提减值准备
|
||||||
|
|
||||||
|
faj102 number 20,6 销帐减值准备
|
||||||
|
|
||||||
|
faj103 number 20,6 税签减值准备
|
||||||
|
|
||||||
|
faj104 number 20,6 税签销帐减值
|
||||||
|
|
||||||
|
faj105 varchar2 1 资产停用否
|
||||||
|
|
||||||
|
faj106 number 15,2 预计总工作量
|
||||||
|
|
||||||
|
faj107 number 15,2 已使用工作量
|
||||||
|
|
||||||
|
faj108 number 20,6 年折旧额
|
||||||
|
|
||||||
|
faj109 number 20,6 税签年折旧额
|
||||||
|
|
||||||
|
faj110 number 15,2 税签预计总工作量
|
||||||
|
|
||||||
|
faj111 number 15,2 税签已使用工作量
|
||||||
|
|
||||||
|
faj112 number 15,2 No Use
|
||||||
|
|
||||||
|
faj113 number 15,2 No Use
|
||||||
|
|
||||||
|
faj114 number 5 No Use
|
||||||
|
|
||||||
|
faj115 varchar2 1 保税机器设备撷取否
|
||||||
|
|
||||||
|
faj531 varchar2 24 资产科目二
|
||||||
|
|
||||||
|
faj541 varchar2 24 累折科目二
|
||||||
|
|
||||||
|
faj551 varchar2 24 折旧科目二
|
||||||
|
|
||||||
|
fajud01 varchar2 255 老供应商
|
||||||
|
|
||||||
|
fajud02 varchar2 40 送签状态
|
||||||
|
|
||||||
|
fajud03 varchar2 40 OA单号
|
||||||
|
|
||||||
|
fajud04 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fajud05 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fajud06 varchar2 40 自订字段-文字
|
||||||
|
|
||||||
|
fajud07 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fajud08 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fajud09 number 15,3 自订字段-数值
|
||||||
|
|
||||||
|
fajud10 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fajud11 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fajud12 number 10 自订字段-整数
|
||||||
|
|
||||||
|
fajud13 date 自订字段-日期
|
||||||
|
|
||||||
|
fajud14 date 自订字段-日期
|
||||||
|
|
||||||
|
fajud15 date 自订字段-日期
|
||||||
|
|
||||||
|
faj331 number 20,6 第一个月未折减额
|
||||||
|
|
||||||
|
faj681 number 20,6 税签第一个月未折减额
|
||||||
|
|
||||||
|
fajoriu varchar2 10 资料建立者
|
||||||
|
|
||||||
|
fajorig varchar2 10 资料建立部门
|
||||||
|
|
||||||
|
faj93 varchar2 10 族群编号
|
||||||
|
|
||||||
|
faj1012 number 20,6 已堤列减值准备(财签二)
|
||||||
|
|
||||||
|
faj1022 number 20,6 销帐减值准备(财签二)
|
||||||
|
|
||||||
|
faj1062 number 15,3 预计总工作量(财签二)
|
||||||
|
|
||||||
|
faj1072 number 15,3 已使用工作量(财签二)
|
||||||
|
|
||||||
|
faj1082 number 20,6 年折旧额(财签二)
|
||||||
|
|
||||||
|
faj1412 number 20,6 调整成本(财签二)
|
||||||
|
|
||||||
|
faj142 number 20,6 取得成本(财签二)
|
||||||
|
|
||||||
|
faj143 varchar2 4 币别(财签二)
|
||||||
|
|
||||||
|
faj144 number 20,10 取得汇率(财签二)
|
||||||
|
|
||||||
|
faj2032 number 20,6 本期累折(财签二)
|
||||||
|
|
||||||
|
faj2042 number 20,6 本期销账累折(财签二)
|
||||||
|
|
||||||
|
faj232 varchar2 1 分摊方式(财签二)
|
||||||
|
|
||||||
|
faj242 varchar2 10 分摊部门/分摊类型(财签二)
|
||||||
|
|
||||||
|
faj262 date 入账日期(财签二)
|
||||||
|
|
||||||
|
faj272 varchar2 6 折旧年月(财签二)
|
||||||
|
|
||||||
|
faj282 varchar2 1 折旧方法(财签二)
|
||||||
|
|
||||||
|
faj292 number 5 耐用年限(月数)(财签二)
|
||||||
|
|
||||||
|
faj302 number 5 未使用年限(月数)(财签二)
|
||||||
|
|
||||||
|
faj312 number 20,6 预留残值(财签二)
|
||||||
|
|
||||||
|
faj322 number 20,6 累积折旧(财签二)
|
||||||
|
|
||||||
|
faj3312 number 20,6 第一个月未折减额(财签二)
|
||||||
|
|
||||||
|
faj332 number 20,6 未折减额(财签二)
|
||||||
|
|
||||||
|
faj342 varchar2 1 折毕再提否(财签二)
|
||||||
|
|
||||||
|
faj352 number 20,6 折毕再提预留残值(财签二)
|
||||||
|
|
||||||
|
faj362 number 5 折毕再提年限(财签二)
|
||||||
|
|
||||||
|
faj432 varchar2 1 资产状态(财签二)
|
||||||
|
|
||||||
|
faj5712 number 5
|
||||||
|
|
||||||
|
faj572 number 5 最近折旧年度(财签二)
|
||||||
|
|
||||||
|
faj582 number 5 销账数量(财签二)
|
||||||
|
|
||||||
|
faj592 number 20,6 销账成本(财签二)
|
||||||
|
|
||||||
|
faj602 number 20,6 销账累折(财签二)
|
||||||
|
|
||||||
|
faj922 varchar2 10 序号
|
||||||
Binary file not shown.
+1
-1
@@ -170,7 +170,7 @@ docker compose up -d --build
|
|||||||
| 本地 | `http://localhost:8881` | `http://localhost:5002` | 密码/企业微信(按配置) | |
|
| 本地 | `http://localhost:8881` | `http://localhost:5002` | 密码/企业微信(按配置) | |
|
||||||
| 测试 | `待定` | `待定` | 密码/企业微信(按配置) | |
|
| 测试 | `待定` | `待定` | 密码/企业微信(按配置) | |
|
||||||
| 生产 | `http://192.168.100.230:8881/` | | 密码/企业微信(按配置) | |
|
| 生产 | `http://192.168.100.230:8881/` | | 密码/企业微信(按配置) | |
|
||||||
| Jenkins | `http://8.152.207.171:10240/` | `` | 密码 | |
|
| Jenkins | `http://8.152.207.171:10240/` | | 密码 | |
|
||||||
| Casdoor | `http://192.168.100.230:8088` | | 密码 | |
|
| Casdoor | `http://192.168.100.230:8088` | | 密码 | |
|
||||||
|
|
||||||
### 6.3 默认测试账号(仅本地初始化脚本场景)
|
### 6.3 默认测试账号(仅本地初始化脚本场景)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
ERP\_VIEW\_USER.ERP\_AZP\_FILE\_V - 营运中心主档
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_GEM\_FILE\_V - 部门名称资料档
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_GEN\_FILE\_V - 员工姓名档案
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_PMC\_FILE\_V - 供应商基础资料档
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_FAB\_FILE\_V - 固定资产主要类型档
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_FAF\_FILE\_V - 固定资产存放位置档
|
||||||
|
|
||||||
|
ERP\_VIEW\_USER.ERP\_FAJ\_FILE\_V - 固定资产资料档
|
||||||
Vendored
+19
-20
@@ -1,20 +1,19 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||||
<meta name="theme-color" content="#0284c7" />
|
<meta name="theme-color" content="#0284c7" />
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
<meta name="apple-mobile-web-app-title" content="AI工作台" />
|
<meta name="apple-mobile-web-app-title" content="AI工作台" />
|
||||||
<link rel="manifest" href="/manifest.webmanifest" />
|
<link rel="manifest" href="/manifest.webmanifest" />
|
||||||
<title>AI工作台</title>
|
<title>AI工作台</title>
|
||||||
<script type="module" crossorigin src="/assets/index-DNiQ9nKy.js"></script>
|
<script type="module" crossorigin src="/assets/index-B0RZ7Ems.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-DDtKBb2t.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-Ck6nsfgg.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>␍
|
||||||
|
</body>
|
||||||
</body>
|
</html>
|
||||||
</html>
|
|
||||||
@@ -64,67 +64,26 @@ const getExt = (raw: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ext = computed(() => {
|
const ext = computed(() => {
|
||||||
// URL extension has higher priority than display name.
|
// Display name extension has higher priority than URL.
|
||||||
const byUrl = getExt(props.file?.url || '');
|
const byName = getExt(props.file?.name || '');
|
||||||
if (byUrl) return byUrl;
|
if (byName) return byName;
|
||||||
return getExt(props.file?.name || '');
|
return getExt(props.file?.url || '');
|
||||||
});
|
});
|
||||||
|
|
||||||
const preferredMode = computed<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>(() => {
|
const preferredMode = computed<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>(() => {
|
||||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'].includes(ext.value)) return 'image';
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'].includes(ext.value)) return 'image';
|
||||||
if (['md', 'markdown', 'txt', 'csv', 'vtt', 'properties', 'html', 'htm'].includes(ext.value)) return 'markdown';
|
if (['md', 'markdown', 'txt', 'csv', 'vtt', 'properties', 'html', 'htm'].includes(ext.value)) return 'markdown';
|
||||||
if (['xlsx', 'xls'].includes(ext.value)) return 'office';
|
if (['xlsx', 'xls'].includes(ext.value)) return 'sheet';
|
||||||
if (['docx', 'doc', 'pdf'].includes(ext.value)) return 'iframe';
|
if (['docx'].includes(ext.value)) return 'office';
|
||||||
|
if (['doc', 'ppt', 'pptx', 'pdf'].includes(ext.value)) return 'iframe';
|
||||||
return 'iframe';
|
return 'iframe';
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolvedMode = ref<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>('iframe');
|
const resolvedMode = ref<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>('iframe');
|
||||||
|
|
||||||
const isOfficeDoc = computed(() => ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'].includes(ext.value));
|
const needsOfficeFallback = computed(() => {
|
||||||
|
// We no longer need fallback for doc/ppt/pptx because they are converted to PDF by the backend
|
||||||
/**
|
return false;
|
||||||
* 判断当前文件是否可使用微软 Office 在线预览。
|
|
||||||
* 实际条件:
|
|
||||||
* - 必须是 Office 文档类型;
|
|
||||||
* - 必须是 HTTPS;
|
|
||||||
* - 主机必须公网可达(非 localhost/私网网段)。
|
|
||||||
*/
|
|
||||||
const canUseOfficeOnlineViewer = computed(() => {
|
|
||||||
const raw = props.file?.url || '';
|
|
||||||
if (!raw || !isOfficeDoc.value) return false;
|
|
||||||
try {
|
|
||||||
const u = new URL(raw, window.location.origin);
|
|
||||||
// Office online viewer usually requires a publicly reachable HTTPS URL.
|
|
||||||
// Private-network or local addresses typically render as blank pages.
|
|
||||||
if (u.protocol !== 'https:') return false;
|
|
||||||
const host = u.hostname;
|
|
||||||
if (
|
|
||||||
host === 'localhost' ||
|
|
||||||
host === '127.0.0.1' ||
|
|
||||||
host === '::1' ||
|
|
||||||
/^10\./.test(host) ||
|
|
||||||
/^192\.168\./.test(host) ||
|
|
||||||
/^172\.(1[6-9]|2\d|3[0-1])\./.test(host)
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const needsOfficeFallback = computed(
|
|
||||||
() => ['ppt', 'pptx'].includes(ext.value) && !canUseOfficeOnlineViewer.value
|
|
||||||
);
|
|
||||||
|
|
||||||
const previewRawUrl = computed(() => {
|
|
||||||
if (!props.file?.url || !props.agentId) return '';
|
|
||||||
const params = new URLSearchParams({
|
|
||||||
agent_id: String(props.agentId),
|
|
||||||
url: props.file.url,
|
|
||||||
name: props.file.name || '',
|
|
||||||
});
|
|
||||||
return `/api/chat/preview-file-raw?${params.toString()}`;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,16 +94,11 @@ const previewRawUrl = computed(() => {
|
|||||||
*/
|
*/
|
||||||
const iframeSrc = computed(() => {
|
const iframeSrc = computed(() => {
|
||||||
if (!props.file?.url || !props.agentId) return '';
|
if (!props.file?.url || !props.agentId) return '';
|
||||||
if (ext.value === 'pdf') {
|
if (['pdf', 'doc', 'ppt', 'pptx'].includes(ext.value)) {
|
||||||
// PDF must use authenticated fetched blob URL; do not fallback to raw URL.
|
// These formats must use the authenticated fetch -> blob flow only.
|
||||||
|
// Never fallback to a protected iframe URL, otherwise it returns Unauthorized.
|
||||||
return officeObjectUrl.value;
|
return officeObjectUrl.value;
|
||||||
}
|
}
|
||||||
if (isOfficeDoc.value && canUseOfficeOnlineViewer.value) {
|
|
||||||
return `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(previewRawUrl.value)}`;
|
|
||||||
}
|
|
||||||
if (['doc', 'docx'].includes(ext.value)) {
|
|
||||||
return previewRawUrl.value;
|
|
||||||
}
|
|
||||||
return props.file.url;
|
return props.file.url;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -244,13 +198,18 @@ const loadPdfContent = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const buf = await res.arrayBuffer();
|
const buf = await res.arrayBuffer();
|
||||||
const head = new TextDecoder().decode(buf.slice(0, 5));
|
// const head = new TextDecoder().decode(buf.slice(0, 5));
|
||||||
if (head !== '%PDF-') {
|
// 暂时取消对 PDF header 的强校验,因为 docx 等文件也会调用该函数生成 Blob 并渲染在 iframe 或下载中
|
||||||
throw new Error('Invalid PDF binary from preview API');
|
// if (head !== '%PDF-') {
|
||||||
}
|
// throw new Error('Invalid PDF binary from preview API');
|
||||||
|
// }
|
||||||
|
|
||||||
clearOfficeObjectUrl();
|
clearOfficeObjectUrl();
|
||||||
const blob = new Blob([buf], { type: 'application/pdf' });
|
let type = 'application/octet-stream';
|
||||||
|
if (ext.value === 'pdf' || ['doc', 'ppt', 'pptx'].includes(ext.value)) type = 'application/pdf';
|
||||||
|
else if (ext.value === 'docx') type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
||||||
|
|
||||||
|
const blob = new Blob([buf], { type });
|
||||||
officeObjectUrl.value = URL.createObjectURL(blob);
|
officeObjectUrl.value = URL.createObjectURL(blob);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -272,13 +231,17 @@ const loadContent = async () => {
|
|||||||
if (!props.file?.url) return;
|
if (!props.file?.url) return;
|
||||||
resolvedMode.value = preferredMode.value;
|
resolvedMode.value = preferredMode.value;
|
||||||
|
|
||||||
if (ext.value === 'pdf') {
|
if (['pdf', 'doc', 'docx', 'ppt', 'pptx'].includes(ext.value) && preferredMode.value === 'iframe') {
|
||||||
|
if (needsOfficeFallback.value) {
|
||||||
|
resolvedMode.value = 'iframe';
|
||||||
|
return;
|
||||||
|
}
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
try {
|
try {
|
||||||
await loadPdfContent();
|
await loadPdfContent(); // This fetches as Blob, and sets officeObjectUrl which will be used in iframeSrc
|
||||||
resolvedMode.value = 'iframe';
|
resolvedMode.value = 'iframe';
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e?.message || 'Failed to preview pdf';
|
error.value = e?.message || `Failed to preview ${ext.value}`;
|
||||||
resolvedMode.value = 'iframe';
|
resolvedMode.value = 'iframe';
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
@@ -286,7 +249,7 @@ const loadContent = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferredMode.value === 'office') {
|
if (preferredMode.value === 'office' && !needsOfficeFallback.value) {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
try {
|
try {
|
||||||
await loadOfficeContent();
|
await loadOfficeContent();
|
||||||
@@ -469,14 +432,14 @@ watch(
|
|||||||
<img :src="file.url" :alt="file.name" class="max-w-full max-h-full object-contain" />
|
<img :src="file.url" :alt="file.name" class="max-w-full max-h-full object-contain" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="ext === 'pdf' && officeObjectUrl"
|
v-else-if="['pdf', 'doc', 'ppt', 'pptx'].includes(ext) && officeObjectUrl"
|
||||||
class="h-full rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 overflow-hidden"
|
class="h-full rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 overflow-hidden"
|
||||||
>
|
>
|
||||||
<embed
|
<iframe
|
||||||
:src="officeObjectUrl"
|
:src="officeObjectUrl"
|
||||||
type="application/pdf"
|
class="w-full h-full min-h-[480px] border-0"
|
||||||
class="w-full h-full min-h-[480px]"
|
allow="clipboard-read; clipboard-write"
|
||||||
/>
|
></iframe>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="needsOfficeFallback"
|
v-else-if="needsOfficeFallback"
|
||||||
@@ -489,20 +452,18 @@ watch(
|
|||||||
This Office file uses a private or non-HTTPS link, so online preview cannot render it.
|
This Office file uses a private or non-HTTPS link, so online preview cannot render it.
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4 flex gap-3">
|
<div class="mt-4 flex gap-3">
|
||||||
<a
|
<button
|
||||||
:href="previewRawUrl || file.url"
|
type="button"
|
||||||
target="_blank"
|
@click="downloadFile"
|
||||||
class="px-3 py-2 rounded-lg bg-brand-600 text-white text-sm hover:bg-brand-700"
|
:disabled="isDownloading"
|
||||||
|
class="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm hover:bg-brand-700 disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center"
|
||||||
>
|
>
|
||||||
Open in new tab
|
<svg v-if="isDownloading" class="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||||
</a>
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||||
<a
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||||
:href="previewRawUrl || file.url"
|
</svg>
|
||||||
download
|
{{ isDownloading ? '下载中...' : '下载文件' }}
|
||||||
class="px-3 py-2 rounded-lg border border-slate-300 dark:border-slate-600 text-sm text-slate-700 dark:text-slate-200 hover:bg-slate-50 dark:hover:bg-slate-800"
|
</button>
|
||||||
>
|
|
||||||
Download file
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<iframe
|
<iframe
|
||||||
|
|||||||
@@ -22,9 +22,14 @@ interface ChatMessage {
|
|||||||
// 对话消息结构:用户/助手文本 + 可选的来源与归因信息
|
// 对话消息结构:用户/助手文本 + 可选的来源与归因信息
|
||||||
role: 'user' | 'assistant';
|
role: 'user' | 'assistant';
|
||||||
content: string;
|
content: string;
|
||||||
|
type?: 'text' | 'leave-form' | 'leave-confirmation' | 'leave-result';
|
||||||
retriever_resources?: RetrieverResource[];
|
retriever_resources?: RetrieverResource[];
|
||||||
attribution_parts?: string[];
|
attribution_parts?: string[];
|
||||||
chat_log_id?: number;
|
chat_log_id?: number;
|
||||||
|
payload?: any;
|
||||||
|
local_id?: string;
|
||||||
|
local_only?: boolean;
|
||||||
|
rated?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一资源格式为数组,兼容 list 或 { data: list } 两种结构
|
// 统一资源格式为数组,兼容 list 或 { data: list } 两种结构
|
||||||
@@ -133,9 +138,10 @@ export function useChat() {
|
|||||||
* query: 用户输入文本
|
* query: 用户输入文本
|
||||||
* agentId: 目标 Agent ID
|
* agentId: 目标 Agent ID
|
||||||
*/
|
*/
|
||||||
const sendMessage = async (query: string, agentId: number) => {
|
const sendMessage = async (query: string, agentId: number, kbType: string = '企业知识库') => {
|
||||||
console.info('[chat][send] start', {
|
console.info('[chat][send] start', {
|
||||||
agentId,
|
agentId,
|
||||||
|
kbType,
|
||||||
queryLength: query.length,
|
queryLength: query.length,
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
});
|
});
|
||||||
@@ -154,7 +160,7 @@ export function useChat() {
|
|||||||
}
|
}
|
||||||
return messages.value[botMsgIndex] || null;
|
return messages.value[botMsgIndex] || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
isThinking.value = true;
|
isThinking.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -166,6 +172,7 @@ export function useChat() {
|
|||||||
query,
|
query,
|
||||||
agent_id: agentId,
|
agent_id: agentId,
|
||||||
conversation_id: conversationId.value,
|
conversation_id: conversationId.value,
|
||||||
|
kb_type: kbType
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -225,7 +232,7 @@ export function useChat() {
|
|||||||
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||||
const botMsg = ensureBotMessage();
|
const botMsg = ensureBotMessage();
|
||||||
if (!botMsg) continue;
|
if (!botMsg) continue;
|
||||||
botMsg.content += data.answer;
|
botMsg.content += normalizeStreamText(data.answer);
|
||||||
console.debug('[chat][sse] append answer chunk', {
|
console.debug('[chat][sse] append answer chunk', {
|
||||||
event: data.event,
|
event: data.event,
|
||||||
appended: data.answer.length,
|
appended: data.answer.length,
|
||||||
@@ -251,9 +258,15 @@ export function useChat() {
|
|||||||
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||||
const botMsg = ensureBotMessage();
|
const botMsg = ensureBotMessage();
|
||||||
if (!botMsg) continue;
|
if (!botMsg) continue;
|
||||||
botMsg.content += data.answer;
|
const normalizedAnswer = normalizeStreamText(data.answer);
|
||||||
console.debug('[chat][sse] append final answer', {
|
if (data.replace_answer) {
|
||||||
|
botMsg.content = normalizedAnswer;
|
||||||
|
} else {
|
||||||
|
botMsg.content += normalizedAnswer;
|
||||||
|
}
|
||||||
|
console.debug('[chat][sse] apply final answer', {
|
||||||
event: data.event,
|
event: data.event,
|
||||||
|
replace: Boolean(data.replace_answer),
|
||||||
appended: data.answer.length,
|
appended: data.answer.length,
|
||||||
total: botMsg.content.length,
|
total: botMsg.content.length,
|
||||||
});
|
});
|
||||||
@@ -291,5 +304,10 @@ export function useChat() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeStreamText = (text: string) => {
|
||||||
|
if (!text) return '';
|
||||||
|
return text.replace(/\\n/g, '\n');
|
||||||
|
};
|
||||||
|
|
||||||
return { messages, isThinking, conversationId, sendMessage };
|
return { messages, isThinking, conversationId, sendMessage };
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
export const config = {
|
export const config = {
|
||||||
appTitle: 'AI工作台',
|
appTitle: 'AI工作台',
|
||||||
auth: {
|
auth: {
|
||||||
|
// Login mode switch:
|
||||||
|
// - 'casdoor': submit username/password to backend Casdoor password-login API.
|
||||||
|
// - 'password': submit to legacy local /api/user/login.
|
||||||
|
loginMode: 'casdoor',
|
||||||
casdoor: {
|
casdoor: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
authorizeApi: '/api/user/casdoor/authorize-url',
|
authorizeApi: '/api/user/casdoor/authorize-url',
|
||||||
loginApi: '/api/user/casdoor/login',
|
loginApi: '/api/user/casdoor/login',
|
||||||
|
passwordLoginApi: '/api/user/casdoor/password-login',
|
||||||
refreshApi: '/api/user/casdoor/refresh',
|
refreshApi: '/api/user/casdoor/refresh',
|
||||||
callbackPath: '/casdoor-callback',
|
callbackPath: '/casdoor-callback',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export interface AuthUser {
|
export interface AuthUser {
|
||||||
id?: number;
|
id?: number;
|
||||||
username?: string;
|
username?: string;
|
||||||
|
real_name?: string;
|
||||||
|
employee_id?: string;
|
||||||
role?: string;
|
role?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
|
|||||||
+951
-233
File diff suppressed because it is too large.
Load diff
@@ -385,6 +385,8 @@ const persistLoginUser = (user: any) => {
|
|||||||
saveAuthUser({ ...(user || {}) }, rememberMe.value);
|
saveAuthUser({ ...(user || {}) }, rememberMe.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEFAULT_POST_LOGIN_AGENT_ID = 16;
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
if (!loginUsername.value.trim()) {
|
if (!loginUsername.value.trim()) {
|
||||||
showMessageDialog('warning', t('login.usernameRequired'));
|
showMessageDialog('warning', t('login.usernameRequired'));
|
||||||
@@ -392,7 +394,12 @@ const handleLogin = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/user/login', {
|
const loginMode = String(config.auth?.loginMode || 'casdoor').toLowerCase();
|
||||||
|
const isCasdoorMode = loginMode === 'casdoor';
|
||||||
|
const loginApi = isCasdoorMode
|
||||||
|
? (config.auth?.casdoor?.passwordLoginApi || '/api/user/casdoor/password-login')
|
||||||
|
: '/api/user/login';
|
||||||
|
const res = await fetch(loginApi, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -405,6 +412,15 @@ const handleLogin = async () => {
|
|||||||
const err = await res.json();
|
const err = await res.json();
|
||||||
// Handle specific error messages if needed, or just alert
|
// Handle specific error messages if needed, or just alert
|
||||||
let msg = err.error || t('login.failed');
|
let msg = err.error || t('login.failed');
|
||||||
|
if (isCasdoorMode) {
|
||||||
|
if (err.error_code === 'CASDOOR_USER_NOT_FOUND') {
|
||||||
|
msg = 'Casdoor 登录成功,但未匹配到本地账号,请联系管理员。';
|
||||||
|
} else if (err.error_code === 'ACCOUNT_DISABLED') {
|
||||||
|
msg = t('login.accountDisabled');
|
||||||
|
} else if (String(err.error || '').includes('invalid_grant')) {
|
||||||
|
msg = t('login.incorrectPassword');
|
||||||
|
}
|
||||||
|
}
|
||||||
if (err.error === 'User not found') msg = t('login.userNotFound');
|
if (err.error === 'User not found') msg = t('login.userNotFound');
|
||||||
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword');
|
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword');
|
||||||
if (err.error === 'Account is disabled') msg = t('login.accountDisabled');
|
if (err.error === 'Account is disabled') msg = t('login.accountDisabled');
|
||||||
@@ -420,39 +436,9 @@ const handleLogin = async () => {
|
|||||||
persistLoginUser(user);
|
persistLoginUser(user);
|
||||||
|
|
||||||
await fetchHome();
|
await fetchHome();
|
||||||
|
|
||||||
if (pendingAgentId.value) {
|
|
||||||
const targetId = pendingAgentId.value;
|
|
||||||
pendingAgentId.value = null;
|
|
||||||
if (agents.value.some(a => a.id === targetId)) {
|
|
||||||
navigateToChat(targetId);
|
|
||||||
} else {
|
|
||||||
showMessageDialog('error', t('workspace.permission.denied'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
showMessageDialog('error', t('login.requestFailed'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCasdoorLogin = async () => {
|
pendingAgentId.value = null;
|
||||||
if (!config.auth?.casdoor?.enabled) return;
|
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||||
try {
|
|
||||||
// Ask backend to build a server-side-tracked authorize URL (includes state).
|
|
||||||
const api = config.auth.casdoor.authorizeApi || '/api/user/casdoor/authorize-url';
|
|
||||||
const callbackPath = config.auth.casdoor.callbackPath || '/casdoor-callback';
|
|
||||||
const redirectUri = `${window.location.origin}${callbackPath}`;
|
|
||||||
const res = await fetch(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
|
|
||||||
const data = await res.json();
|
|
||||||
if (!res.ok || !data.url) {
|
|
||||||
showMessageDialog('error', data.error || t('login.requestFailed'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (data.state) {
|
|
||||||
sessionStorage.setItem('hxops_casdoor_state', data.state);
|
|
||||||
}
|
|
||||||
window.location.href = data.url;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
showMessageDialog('error', t('login.requestFailed'));
|
showMessageDialog('error', t('login.requestFailed'));
|
||||||
@@ -1144,14 +1130,6 @@ onBeforeUnmount(() => {
|
|||||||
{{ $t('login.submit') }}
|
{{ $t('login.submit') }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
|
||||||
v-if="config.auth?.casdoor?.enabled"
|
|
||||||
@click="handleCasdoorLogin"
|
|
||||||
class="btn-secondary w-full py-3 text-base mt-3"
|
|
||||||
>
|
|
||||||
{{ $t('login.casdoorLogin') }}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-if="config.auth?.wecom?.enabled"
|
v-if="config.auth?.wecom?.enabled"
|
||||||
@click="handleWecomLogin"
|
@click="handleWecomLogin"
|
||||||
|
|||||||
@@ -0,0 +1,253 @@
|
|||||||
|
</td>␍
|
||||||
|
</tr>␍
|
||||||
|
<tr height="42px">␍
|
||||||
|
<td align="right" valign="middle" style="padding-right: 12px">␍
|
||||||
|
<span class="STYLE6" id="result0"></span>␍
|
||||||
|
</td>␍
|
||||||
|
</tr>␍
|
||||||
|
</table>␍
|
||||||
|
</td>␍
|
||||||
|
</tr>␍
|
||||||
|
</table>␍
|
||||||
|
</div>␍
|
||||||
|
␍
|
||||||
|
␍
|
||||||
|
<div id="zDialog_div_bottom" class="zDialog_div_bottom">␍
|
||||||
|
<input type="button" style="display:none;" class=zd_btn_submit accessKey=S id=btnsearch value="S-搜索"></input>␍
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- 鎵�鏈夋病鏈夊唴瀹圭殑鏍囩璇峰鍔犱竴涓┖鏍� -->
|
||||||
|
<!-- 瀹氫箟琛ㄨ揪寮忔墍浣跨敤鐨勫彉閲� -->
|
||||||
|
|
||||||
|
<table class="LayoutTable" id="" style="display:;width:100%;">
|
||||||
|
<colgroup>
|
||||||
|
<col width="20%"/>
|
||||||
|
<col width="80%"/>
|
||||||
|
</colgroup>
|
||||||
|
<tbody>
|
||||||
|
<!-- 鍒嗙粍寰幆 -->
|
||||||
|
|
||||||
|
|
||||||
|
<tr class="intervalTR">
|
||||||
|
<td class="interval" colspan="2" style="text-align:center;">␍
|
||||||
|
<input type="button" class=zd_btn_submit accessKey=2 id=btnclear value="清除" onclick='onClear();'></input>␍
|
||||||
|
<span class="e8_sep_line">|</span>
|
||||||
|
<input type="button" class=zd_btn_cancle accessKey=T id=btncancel value="取消" onclick='onClose();'></input>␍
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
␍
|
||||||
|
<script type="text/javascript">␍
|
||||||
|
jQuery(document).ready(function(){␍
|
||||||
|
resizeDialog(document);␍
|
||||||
|
});␍
|
||||||
|
</script>␍
|
||||||
|
</div>␍
|
||||||
|
</div>␍
|
||||||
|
</BODY></HTML>␍
|
||||||
|
␍
|
||||||
|
␍
|
||||||
|
<script type="text/javascript">␍
|
||||||
|
//<!--␍
|
||||||
|
␍
|
||||||
|
␍
|
||||||
|
//-->␍
|
||||||
|
</script>␍
|
||||||
|
<!-- ␍
|
||||||
|
<SCRIPT LANGUAGE=VBS>␍
|
||||||
|
Sub btnclear_onclick()␍
|
||||||
|
window.parent.returnvalue = Array(0,"")␍
|
||||||
|
window.parent.close␍
|
||||||
|
End Sub␍
|
||||||
|
Sub BrowseTable_onclick()␍
|
||||||
|
Set e = window.event.srcElement␍
|
||||||
|
If e.TagName = "TD" Then ␍
|
||||||
|
window.parent.returnvalue = Array(e.parentelement.cells(0).innerText,e.parentelement.cells(1).innerText,e.parentelement.cells(2).innerText)␍
|
||||||
|
// window.parent.returnvalue = e.parentelement.cells(0).innerText␍
|
||||||
|
window.parent.Close␍
|
||||||
|
ElseIf e.TagName = "A" Then␍
|
||||||
|
window.parent.returnvalue = Array(e.parentelement.parentelement.cells(0).innerText,e.parentelement.parentelement.cells(1).innerText,e.parentelement.parentelement.cells(2).innerText)␍
|
||||||
|
// window.parent.returnvalue = e.parentelement.parentelement.cells(0).innerText␍
|
||||||
|
window.parent.Close␍
|
||||||
|
End If␍
|
||||||
|
␍
|
||||||
|
End Sub␍
|
||||||
|
Sub BrowseTable_onmouseover()␍
|
||||||
|
Set e = window.event.srcElement␍
|
||||||
|
If e.TagName = "TD" Then␍
|
||||||
|
e.parentelement.className = "Selected"␍
|
||||||
|
ElseIf e.TagName = "A" Then␍
|
||||||
|
e.parentelement.parentelement.className = "Selected"␍
|
||||||
|
End If␍
|
||||||
|
End Sub␍
|
||||||
|
Sub BrowseTable_onmouseout()␍
|
||||||
|
Set e = window.event.srcElement␍
|
||||||
|
If e.TagName = "TD" Or e.TagName = "A" Then␍
|
||||||
|
If e.TagName = "TD" Then␍
|
||||||
|
Set p = e.parentelement␍
|
||||||
|
Else␍
|
||||||
|
Set p = e.parentelement.parentelement␍
|
||||||
|
End If␍
|
||||||
|
If p.RowIndex Mod 2 Then␍
|
||||||
|
p.className = "DataLight"␍
|
||||||
|
Else␍
|
||||||
|
p.className = "DataDark"␍
|
||||||
|
End If␍
|
||||||
|
End If␍
|
||||||
|
End Sub␍
|
||||||
|
␍
|
||||||
|
</SCRIPT>␍
|
||||||
|
␍
|
||||||
|
-->␍
|
||||||
|
<SCRIPT LANGUAGE=VBS>␍
|
||||||
|
Sub returnData(returnstr)␍
|
||||||
|
window.parent.returnvalue = returnstr␍
|
||||||
|
window.parent.Close␍
|
||||||
|
End Sub␍
|
||||||
|
</SCRIPT>␍
|
||||||
|
<script language="javascript">␍
|
||||||
|
$(function(){␍
|
||||||
|
try{␍
|
||||||
|
window.parent.setTabObjName("请假类型");␍
|
||||||
|
}catch(e){␍
|
||||||
|
//alert("ddddddddddddd");␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
var parentWin = window.parent.parent.getParentWindow(parent);␍
|
||||||
|
var dialog = window.parent.parent.getDialog(parent);␍
|
||||||
|
function onClear()␍
|
||||||
|
{␍
|
||||||
|
var returnjson = {id:"",name:""};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
}else{␍
|
||||||
|
␍
|
||||||
|
window.parent.returnValue=returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
function onSubmit()␍
|
||||||
|
{␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
function onPage(index)␍
|
||||||
|
{␍
|
||||||
|
changeCurpage(index);//TD34490 lv 修改当前页␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
function onClose()␍
|
||||||
|
{␍
|
||||||
|
if(dialog){␍
|
||||||
|
dialog.close();␍
|
||||||
|
}else{ ␍
|
||||||
|
window.parent.close();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
//TD196207 回车即搜索␍
|
||||||
|
function enterSearch(){␍
|
||||||
|
var event = arguments.callee.caller.arguments[0] || window.event;␍
|
||||||
|
if(event.keyCode == 13){␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
//TD34490 lv 修改当前页␍
|
||||||
|
function changeCurpage(index){␍
|
||||||
|
//document.SearchForm.curpage.value = index;␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
function BrowseTable_onclick(e){␍
|
||||||
|
var e=e||event;␍
|
||||||
|
var target=e.srcElement||e.target;␍
|
||||||
|
␍
|
||||||
|
if( target.nodeName =="TD"||target.nodeName =="A" ){␍
|
||||||
|
var pNode = target.parentNode;␍
|
||||||
|
if(pNode.nodeName!="TR"){␍
|
||||||
|
pNode = pNode.parentNode;␍
|
||||||
|
}␍
|
||||||
|
var returnjson = {␍
|
||||||
|
id:jQuery(jQuery(target).parents("tr")[0].cells[0]).text(),␍
|
||||||
|
name:jQuery(jQuery(target).parents("tr")[0].cells[1]).text(),␍
|
||||||
|
desc:jQuery(jQuery(target).parents("tr")[0].cells[2]).text()␍
|
||||||
|
};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
}else{ ␍
|
||||||
|
window.parent.returnValue=returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
function afterDoWhenLoaded(){␍
|
||||||
|
␍
|
||||||
|
$("#_xTable").find("table.ListStyle tbody").children("tr[class!='Spacing']").each(function(){␍
|
||||||
|
var tr = jQuery(this);␍
|
||||||
|
tr.bind("click",function(){␍
|
||||||
|
var id = tr.children("td:first").next().attr("spacevalue");␍
|
||||||
|
var name = tr.children("td:first").next().next().text();␍
|
||||||
|
␍
|
||||||
|
var desc = "";␍
|
||||||
|
try␍
|
||||||
|
{␍
|
||||||
|
desc = tr.children("td:first").next().next().next().text();␍
|
||||||
|
}␍
|
||||||
|
catch(e)␍
|
||||||
|
{␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
␍
|
||||||
|
var returnjson = {'id':id,'name':name,'desc':desc,'href':''};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
}else{␍
|
||||||
|
␍
|
||||||
|
window.parent.returnValue = returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
});␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
jQuery(function(){␍
|
||||||
|
if(dialog){␍
|
||||||
|
jQuery("#BrowseTable").bind("click",BrowseTable_onclick);␍
|
||||||
|
}else{␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("click",function(){␍
|
||||||
|
window.parent.returnValue = {id:$(this).find("td:first").text(),name:$(this).find("td:first").next().text(),desc:$(this).find("td:first").next().next().text(),href:''};␍
|
||||||
|
window.parent.close();␍
|
||||||
|
});␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("mouseover",function(){␍
|
||||||
|
$(this).addClass("Selected");␍
|
||||||
|
});␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("mouseout",function(){␍
|
||||||
|
$(this).removeClass("Selected");␍
|
||||||
|
});␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
␍
|
||||||
|
</script>␍
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
urnvalue = Array(e.parentelement.parentelement.cells(0).innerText,e.parentelement.parentelement.cells(1).innerText,e.parentelement.parentelement.cells(2).innerText)␍
|
||||||
|
// window.parent.returnvalue = e.parentelement.parentelement.cells(0).innerText␍
|
||||||
|
window.parent.Close␍
|
||||||
|
End If␍
|
||||||
|
␍
|
||||||
|
End Sub␍
|
||||||
|
Sub BrowseTable_onmouseover()␍
|
||||||
|
Set e = window.event.srcElement␍
|
||||||
|
If e.TagName = "TD" Then␍
|
||||||
|
e.parentelement.className = "Selected"␍
|
||||||
|
ElseIf e.TagName = "A" Then␍
|
||||||
|
e.parentelement.parentelement.className = "Selected"␍
|
||||||
|
End If␍
|
||||||
|
End Sub␍
|
||||||
|
Sub BrowseTable_onmouseout()␍
|
||||||
|
Set e = window.event.srcElement␍
|
||||||
|
If e.TagName = "TD" Or e.TagName = "A" Then␍
|
||||||
|
If e.TagName = "TD" Then␍
|
||||||
|
Set p = e.parentelement␍
|
||||||
|
Else␍
|
||||||
|
Set p = e.parentelement.parentelement␍
|
||||||
|
End If␍
|
||||||
|
If p.RowIndex Mod 2 Then␍
|
||||||
|
p.className = "DataLight"␍
|
||||||
|
Else␍
|
||||||
|
p.className = "DataDark"␍
|
||||||
|
End If␍
|
||||||
|
End If␍
|
||||||
|
End Sub␍
|
||||||
|
␍
|
||||||
|
</SCRIPT>␍
|
||||||
|
␍
|
||||||
|
-->␍
|
||||||
|
<SCRIPT LANGUAGE=VBS>␍
|
||||||
|
Sub returnData(returnstr)␍
|
||||||
|
window.parent.returnvalue = returnstr␍
|
||||||
|
window.parent.Close␍
|
||||||
|
End Sub␍
|
||||||
|
</SCRIPT>␍
|
||||||
|
<script language="javascript">␍
|
||||||
|
$(function(){␍
|
||||||
|
try{␍
|
||||||
|
window.parent.setTabObjName("请假类型");␍
|
||||||
|
}catch(e){␍
|
||||||
|
//alert("ddddddddddddd");␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
var parentWin = window.parent.parent.getParentWindow(parent);␍
|
||||||
|
var dialog = window.parent.parent.getDialog(parent);␍
|
||||||
|
function onClear()␍
|
||||||
|
{␍
|
||||||
|
var returnjson = {id:"",name:""};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
}else{␍
|
||||||
|
␍
|
||||||
|
window.parent.returnValue=returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
function onSubmit()␍
|
||||||
|
{␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
function onPage(index)␍
|
||||||
|
{␍
|
||||||
|
changeCurpage(index);//TD34490 lv 修改当前页␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
function onClose()␍
|
||||||
|
{␍
|
||||||
|
if(dialog){␍
|
||||||
|
dialog.close();␍
|
||||||
|
}else{ ␍
|
||||||
|
window.parent.close();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
//TD196207 回车即搜索␍
|
||||||
|
function enterSearch(){␍
|
||||||
|
var event = arguments.callee.caller.arguments[0] || window.event;␍
|
||||||
|
if(event.keyCode == 13){␍
|
||||||
|
SearchForm.submit();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
//TD34490 lv 修改当前页␍
|
||||||
|
function changeCurpage(index){␍
|
||||||
|
//document.SearchForm.curpage.value = index;␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
function BrowseTable_onclick(e){␍
|
||||||
|
var e=e||event;␍
|
||||||
|
var target=e.srcElement||e.target;␍
|
||||||
|
␍
|
||||||
|
if( target.nodeName =="TD"||target.nodeName =="A" ){␍
|
||||||
|
var pNode = target.parentNode;␍
|
||||||
|
if(pNode.nodeName!="TR"){␍
|
||||||
|
pNode = pNode.parentNode;␍
|
||||||
|
}␍
|
||||||
|
var returnjson = {␍
|
||||||
|
id:jQuery(jQuery(target).parents("tr")[0].cells[0]).text(),␍
|
||||||
|
name:jQuery(jQuery(target).parents("tr")[0].cells[1]).text(),␍
|
||||||
|
desc:jQuery(jQuery(target).parents("tr")[0].cells[2]).text()␍
|
||||||
|
};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
}else{ ␍
|
||||||
|
window.parent.returnValue=returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
}␍
|
||||||
|
function afterDoWhenLoaded(){␍
|
||||||
|
␍
|
||||||
|
$("#_xTable").find("table.ListStyle tbody").children("tr[class!='Spacing']").each(function(){␍
|
||||||
|
var tr = jQuery(this);␍
|
||||||
|
tr.bind("click",function(){␍
|
||||||
|
var id = tr.children("td:first").next().attr("spacevalue");␍
|
||||||
|
var name = tr.children("td:first").next().next().text();␍
|
||||||
|
␍
|
||||||
|
var desc = "";␍
|
||||||
|
try␍
|
||||||
|
{␍
|
||||||
|
desc = tr.children("td:first").next().next().next().text();␍
|
||||||
|
}␍
|
||||||
|
catch(e)␍
|
||||||
|
{␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
␍
|
||||||
|
var returnjson = {'id':id,'name':name,'desc':desc,'href':''};␍
|
||||||
|
if(dialog){␍
|
||||||
|
try{␍
|
||||||
|
dialog.callback(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
␍
|
||||||
|
try{␍
|
||||||
|
dialog.close(returnjson);␍
|
||||||
|
}catch(e){}␍
|
||||||
|
}else{␍
|
||||||
|
␍
|
||||||
|
window.parent.returnValue = returnjson;␍
|
||||||
|
window.parent.close();␍
|
||||||
|
␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
});␍
|
||||||
|
}␍
|
||||||
|
␍
|
||||||
|
jQuery(function(){␍
|
||||||
|
if(dialog){␍
|
||||||
|
jQuery("#BrowseTable").bind("click",BrowseTable_onclick);␍
|
||||||
|
}else{␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("click",function(){␍
|
||||||
|
window.parent.returnValue = {id:$(this).find("td:first").text(),name:$(this).find("td:first").next().text(),desc:$(this).find("td:first").next().next().text(),href:''};␍
|
||||||
|
window.parent.close();␍
|
||||||
|
});␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("mouseover",function(){␍
|
||||||
|
$(this).addClass("Selected");␍
|
||||||
|
});␍
|
||||||
|
jQuery("#BrowseTable").find("tr[class^='Data'][class!='DataHeader']").bind("mouseout",function(){␍
|
||||||
|
$(this).removeClass("Selected");␍
|
||||||
|
});␍
|
||||||
|
}␍
|
||||||
|
});␍
|
||||||
|
␍
|
||||||
|
</script>␍
|
||||||
Reference in new issue
Block a user