Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
d6af566601
91 files changed
+3869
-3097
No files matched your search
@@ -0,0 +1,105 @@
|
||||
"""
|
||||
services/agent_category.py
|
||||
|
||||
用途:从 Agent.extra_config 解析 P1 分类字段(category / sub_category / sort_order),并提供排序与序列化。
|
||||
依赖:无外部服务;由 api/agents、api/user 在返回列表时调用。
|
||||
逻辑:分类信息暂存 extra_config,P2 可迁移至独立 agent_categories 表。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def parse_agent_category_meta(extra_config: dict | None) -> dict[str, Any]:
|
||||
"""
|
||||
从 extra_config 解析 Agent 分类元数据。
|
||||
核心逻辑:category / sub_category 去首尾空白;sort_order 非法值回退为 0。
|
||||
|
||||
Args:
|
||||
extra_config: Agent.extra_config JSON 字典,可为 None。
|
||||
|
||||
Returns:
|
||||
含 category (str)、sub_category (str)、sort_order (int) 的字典。
|
||||
"""
|
||||
extra = extra_config if isinstance(extra_config, dict) else {}
|
||||
category = str(extra.get('category') or '').strip()
|
||||
sub_category = str(extra.get('sub_category') or '').strip()
|
||||
sort_raw = extra.get('sort_order')
|
||||
try:
|
||||
sort_order = int(sort_raw) if sort_raw is not None and sort_raw != '' else 0
|
||||
except (TypeError, ValueError):
|
||||
sort_order = 0
|
||||
return {
|
||||
'category': category,
|
||||
'sub_category': sub_category,
|
||||
'sort_order': sort_order,
|
||||
}
|
||||
|
||||
|
||||
def _row_extra_config(row: Any) -> dict | None:
|
||||
"""从 ORM 行或 dict 行读取 extra_config。"""
|
||||
if hasattr(row, 'extra_config'):
|
||||
return row.extra_config
|
||||
if isinstance(row, dict):
|
||||
return row.get('extra_config')
|
||||
return None
|
||||
|
||||
|
||||
def _row_id(row: Any) -> int:
|
||||
"""从 ORM 行或 dict 行读取主键 id。"""
|
||||
if hasattr(row, 'id'):
|
||||
return int(row.id)
|
||||
if isinstance(row, dict):
|
||||
return int(row.get('id') or 0)
|
||||
return 0
|
||||
|
||||
|
||||
def agent_category_sort_key(row: Any) -> tuple:
|
||||
"""
|
||||
生成分类排序键:sort_order → category → sub_category → id。
|
||||
核心逻辑:未配置 category 的 Agent 排在同 sort_order 下的末尾(用 \\uffff 占位)。
|
||||
"""
|
||||
meta = parse_agent_category_meta(_row_extra_config(row))
|
||||
category_key = meta['category'] or '\uffff'
|
||||
sub_key = meta['sub_category'] or '\uffff'
|
||||
return (meta['sort_order'], category_key, sub_key, _row_id(row))
|
||||
|
||||
|
||||
def sort_agent_rows(rows: list) -> list:
|
||||
"""
|
||||
按分类元数据对 Agent 行列表原地排序并返回。
|
||||
"""
|
||||
return sorted(rows, key=agent_category_sort_key)
|
||||
|
||||
|
||||
def serialize_agent_category_fields(row: Any) -> dict[str, Any]:
|
||||
"""
|
||||
序列化分类相关 API 字段。
|
||||
空字符串 category / sub_category 输出为 None,便于前端区分「未配置」。
|
||||
"""
|
||||
meta = parse_agent_category_meta(_row_extra_config(row))
|
||||
return {
|
||||
'category': meta['category'] or None,
|
||||
'sub_category': meta['sub_category'] or None,
|
||||
'sort_order': meta['sort_order'],
|
||||
}
|
||||
|
||||
|
||||
def serialize_agent_list_item(row: Any) -> dict[str, Any]:
|
||||
"""
|
||||
序列化用户可见 Agent 列表项(聊天侧栏、工作台首页共用)。
|
||||
核心逻辑:合并基础字段、dify_app_type 与分类元数据。
|
||||
"""
|
||||
extra = _row_extra_config(row) or {}
|
||||
name = row.name if hasattr(row, 'name') else row.get('name')
|
||||
description = row.description if hasattr(row, 'description') else row.get('description')
|
||||
icon_url = row.icon_url if hasattr(row, 'icon_url') else row.get('icon_url')
|
||||
return {
|
||||
'id': _row_id(row),
|
||||
'name': name,
|
||||
'description': description,
|
||||
'icon_url': icon_url,
|
||||
'dify_app_type': extra.get('dify_app_type') or 'chatflow',
|
||||
**serialize_agent_category_fields(row),
|
||||
}
|
||||
@@ -34,8 +34,9 @@ from typing import Any, List, Optional
|
||||
import requests
|
||||
from flask import current_app
|
||||
|
||||
from app.config import Config
|
||||
from app.models import ChatLog, db
|
||||
from app.core.config.settings import Config
|
||||
from app import db
|
||||
from app.models import ChatLog
|
||||
from app.services.chat_perf import ChatPerfTracker, chat_perf_enabled
|
||||
from app.services.integration_api import IntegrationApiService
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ from typing import Any, Optional
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.models import ChatLog, QuickQuestion, db
|
||||
from app import db
|
||||
from app.models import ChatLog, QuickQuestion
|
||||
from app.services.faq_text_utils import normalize_faq_query
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ from typing import Any, Optional
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.models import KbDifySyncRecord, QuickQuestion, db
|
||||
from app import db
|
||||
from app.models import KbDifySyncRecord, QuickQuestion
|
||||
from app.services.dify import DifyService
|
||||
from app.services.integration_api import IntegrationApiService
|
||||
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
"""␍
|
||||
services/file_check_tools/dify_inputs.py␍
|
||||
␍
|
||||
用途:构建文件检核 Chatflow 的 Dify chat inputs,并在 task_id 缺失时快速失败。␍
|
||||
依赖:task_resolver、agent_resolver、errors.ValidationError。␍
|
||||
逻辑:chat.py 在调 Dify 前调用本模块;缺失 schedule_task_id 时抛 ValidationError,避免 Dify 长连接挂死。␍
|
||||
"""␍
|
||||
from __future__ import annotations␍
|
||||
␍
|
||||
from app.errors import ValidationError␍
|
||||
from app.services.file_check_tools.task_resolver import resolve_schedule_task_id_from_agent␍
|
||||
␍
|
||||
# Dify Chatflow「用户输入」变量名 — 须与画布 Start 节点配置一致␍
|
||||
FILE_CHECK_TASK_ID_INPUT = "task_id"␍
|
||||
FILE_CHECK_TASK_ID_MISSING_CODE = "file_check_task_id_required"␍
|
||||
␍
|
||||
␍
|
||||
def _missing_task_id_error(agent) -> ValidationError:␍
|
||||
"""␍
|
||||
构造 task_id 未配置时的业务异常。␍
|
||||
␍
|
||||
核心逻辑:返回可操作的配置提示,供管理后台与前端直接展示。␍
|
||||
"""␍
|
||||
return ValidationError(␍
|
||||
"文件检核 Agent 未配置有效的 schedule_task_id,无法调用 Dify Chatflow。"␍
|
||||
"请在管理后台编辑该 Agent,于 extra_config 中设置 "␍
|
||||
"tool_run_progress.schedule_task_id(绑定排程任务 ID)。",␍
|
||||
details={␍
|
||||
"error_code": FILE_CHECK_TASK_ID_MISSING_CODE,␍
|
||||
"agent_id": getattr(agent, "id", None),␍
|
||||
"agent_name": getattr(agent, "name", None) or "",␍
|
||||
"config_hint": {␍
|
||||
"capabilities": ["tool_run_progress"],␍
|
||||
"tool_run_progress": {␍
|
||||
"type": "file_check",␍
|
||||
"schedule_task_id": "<ScheduleTask.id>",␍
|
||||
},␍
|
||||
},␍
|
||||
},␍
|
||||
)␍
|
||||
␍
|
||||
␍
|
||||
def ensure_file_check_task_id_configured(agent) -> int:␍
|
||||
"""␍
|
||||
解析并校验文件检核 Agent 绑定的 schedule_task_id。␍
|
||||
␍
|
||||
Args:␍
|
||||
agent: 当前对话 Agent。␍
|
||||
␍
|
||||
Returns:␍
|
||||
有效的 ScheduleTask.id。␍
|
||||
␍
|
||||
Raises:␍
|
||||
ValidationError: extra_config 未配置或 schedule_task_id 非法。␍
|
||||
"""␍
|
||||
task_id = resolve_schedule_task_id_from_agent(agent)␍
|
||||
if not task_id:␍
|
||||
raise _missing_task_id_error(agent)␍
|
||||
return task_id␍
|
||||
␍
|
||||
␍
|
||||
def build_file_check_dify_inputs(agent, *, required: bool = False) -> dict[str, str]:␍
|
||||
"""␍
|
||||
构建文件检核 Chatflow 的 Dify chat inputs。␍
|
||||
␍
|
||||
仅注入 task_id。hxops_session_id / hxops_turn_id 由 chat.py 登记 turn 注册表,␍
|
||||
Tool API 启动时通过 user_message 推断,无需传入 Dify 画布。␍
|
||||
␍
|
||||
Args:␍
|
||||
agent: 当前对话 Agent;task_id 从其 extra_config 解析。␍
|
||||
required: 为 True 时若 task_id 缺失立即抛 ValidationError,避免 Dify 流式挂死。␍
|
||||
␍
|
||||
Returns:␍
|
||||
含 task_id 的 inputs 字典;required=False 且未配置时返回空 dict。␍
|
||||
␍
|
||||
Raises:␍
|
||||
ValidationError: required=True 且 schedule_task_id 未配置。␍
|
||||
"""␍
|
||||
task_id = resolve_schedule_task_id_from_agent(agent)␍
|
||||
if not task_id:␍
|
||||
if required:␍
|
||||
raise _missing_task_id_error(agent)␍
|
||||
return {}␍
|
||||
return {FILE_CHECK_TASK_ID_INPUT: str(task_id)}␍
|
||||
␍
|
||||
␍
|
||||
__all__ = [␍
|
||||
"FILE_CHECK_TASK_ID_INPUT",␍
|
||||
"FILE_CHECK_TASK_ID_MISSING_CODE",␍
|
||||
"build_file_check_dify_inputs",␍
|
||||
"ensure_file_check_task_id_configured",␍
|
||||
]␍
|
||||
"""
|
||||
services/file_check_tools/dify_inputs.py
|
||||
|
||||
用途:构建文件检核 Chatflow 的 Dify chat inputs,并在 task_id 缺失时快速失败。
|
||||
依赖:task_resolver、agent_resolver、errors.ValidationError。
|
||||
逻辑:chat.py 在调 Dify 前调用本模块;缺失 schedule_task_id 时抛 ValidationError,避免 Dify 长连接挂死。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.file_check_tools.task_resolver import resolve_schedule_task_id_from_agent
|
||||
|
||||
# Dify Chatflow「用户输入」变量名 — 须与画布 Start 节点配置一致
|
||||
FILE_CHECK_TASK_ID_INPUT = "task_id"
|
||||
FILE_CHECK_TASK_ID_MISSING_CODE = "file_check_task_id_required"
|
||||
|
||||
|
||||
def _missing_task_id_error(agent) -> ValidationError:
|
||||
"""
|
||||
构造 task_id 未配置时的业务异常。
|
||||
|
||||
核心逻辑:返回可操作的配置提示,供管理后台与前端直接展示。
|
||||
"""
|
||||
return ValidationError(
|
||||
"文件检核 Agent 未配置有效的 schedule_task_id,无法调用 Dify Chatflow。"
|
||||
"请在管理后台编辑该 Agent,于 extra_config 中设置 "
|
||||
"tool_run_progress.schedule_task_id(绑定排程任务 ID)。",
|
||||
details={
|
||||
"error_code": FILE_CHECK_TASK_ID_MISSING_CODE,
|
||||
"agent_id": getattr(agent, "id", None),
|
||||
"agent_name": getattr(agent, "name", None) or "",
|
||||
"config_hint": {
|
||||
"capabilities": ["tool_run_progress"],
|
||||
"tool_run_progress": {
|
||||
"type": "file_check",
|
||||
"schedule_task_id": "<ScheduleTask.id>",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def ensure_file_check_task_id_configured(agent) -> int:
|
||||
"""
|
||||
解析并校验文件检核 Agent 绑定的 schedule_task_id。
|
||||
|
||||
Args:
|
||||
agent: 当前对话 Agent。
|
||||
|
||||
Returns:
|
||||
有效的 ScheduleTask.id。
|
||||
|
||||
Raises:
|
||||
ValidationError: extra_config 未配置或 schedule_task_id 非法。
|
||||
"""
|
||||
task_id = resolve_schedule_task_id_from_agent(agent)
|
||||
if not task_id:
|
||||
raise _missing_task_id_error(agent)
|
||||
return task_id
|
||||
|
||||
|
||||
def build_file_check_dify_inputs(agent, *, required: bool = False) -> dict[str, str]:
|
||||
"""
|
||||
构建文件检核 Chatflow 的 Dify chat inputs。
|
||||
|
||||
仅注入 task_id。hxops_session_id / hxops_turn_id 由 chat.py 登记 turn 注册表,
|
||||
Tool API 启动时通过 user_message 推断,无需传入 Dify 画布。
|
||||
|
||||
Args:
|
||||
agent: 当前对话 Agent;task_id 从其 extra_config 解析。
|
||||
required: 为 True 时若 task_id 缺失立即抛 ValidationError,避免 Dify 流式挂死。
|
||||
|
||||
Returns:
|
||||
含 task_id 的 inputs 字典;required=False 且未配置时返回空 dict。
|
||||
|
||||
Raises:
|
||||
ValidationError: required=True 且 schedule_task_id 未配置。
|
||||
"""
|
||||
task_id = resolve_schedule_task_id_from_agent(agent)
|
||||
if not task_id:
|
||||
if required:
|
||||
raise _missing_task_id_error(agent)
|
||||
return {}
|
||||
return {FILE_CHECK_TASK_ID_INPUT: str(task_id)}
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FILE_CHECK_TASK_ID_INPUT",
|
||||
"FILE_CHECK_TASK_ID_MISSING_CODE",
|
||||
"build_file_check_dify_inputs",
|
||||
"ensure_file_check_task_id_configured",
|
||||
]
|
||||
␍
|
||||
@@ -11,7 +11,7 @@ import re
|
||||
from typing import Any
|
||||
|
||||
from app import db
|
||||
from app.errors import NotFoundError, ServiceUnavailableError, ValidationError
|
||||
from app.core.errors import NotFoundError, ServiceUnavailableError, ValidationError
|
||||
from app.models import KbGroup, ScheduleTask
|
||||
from app.services.knowledge_cleaning.dify_sync_service import KbDifySyncError, KbDifySyncService
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class FixedAssetsSnapshotService:
|
||||
"资产编号",
|
||||
"资产名称",
|
||||
"规格型号",
|
||||
"账套",
|
||||
"保管人姓名",
|
||||
"保管部门名称",
|
||||
"存放位置名称",
|
||||
@@ -74,6 +75,11 @@ class FixedAssetsSnapshotService:
|
||||
"X": "被资本",
|
||||
"Z": "停用",
|
||||
}
|
||||
ACCOUNT_BOOK_MAP = {
|
||||
"HXJM": "和信精密",
|
||||
"HTT": "和泰科技",
|
||||
"HTE": "和泰电子",
|
||||
}
|
||||
STOPWORDS_PATTERN = re.compile(
|
||||
r"(固定资产|固资|资产编号|财产编号|资产编码|编号|资产名称|设备名称|资产|设备|请问|帮我|看下|查下|查询|统计|核对|看看|我想知道|有多少台?|有多少|多少台?|多少|明细|列表|数据|结果|并且|以及|还有|和|按|根据|生成图表|生成excel|生成表单|导出excel|导出表单|导出)",
|
||||
re.IGNORECASE,
|
||||
@@ -132,6 +138,7 @@ class FixedAssetsSnapshotService:
|
||||
f"资产编号:{row.get('资产编号', '')}",
|
||||
f"资产名称:{row.get('资产名称', '')}",
|
||||
f"规格型号:{row.get('规格型号', '')}",
|
||||
f"账套:{row.get('账套', '')}({row.get('营运中心代码', '')})",
|
||||
f"保管人姓名:{row.get('保管人姓名', '')}",
|
||||
f"保管部门名称:{row.get('保管部门名称', '')}",
|
||||
f"存放位置名称:{row.get('存放位置名称', '')}",
|
||||
@@ -257,6 +264,10 @@ ORDER BY faj.faj02
|
||||
columns[idx]: cls._stringify(value)
|
||||
for idx, value in enumerate(raw_row)
|
||||
}
|
||||
item["账套"] = cls.ACCOUNT_BOOK_MAP.get(
|
||||
item.get("营运中心代码", "").strip().upper(),
|
||||
item.get("营运中心代码", ""),
|
||||
)
|
||||
item["资产状态"] = cls.STATUS_MAP.get(item.get("资产状态代码", "").upper(), item.get("资产状态代码", ""))
|
||||
item["资产性质"] = cls.NATURE_MAP.get(item.get("资产性质代码", ""), item.get("资产性质代码", ""))
|
||||
item["备注"] = cls._build_remark(item)
|
||||
@@ -391,6 +402,7 @@ INSERT INTO fixed_assets (
|
||||
item.get("资产编号", ""),
|
||||
item.get("资产名称", ""),
|
||||
item.get("规格型号", ""),
|
||||
item.get("账套", ""),
|
||||
item.get("保管人姓名", ""),
|
||||
item.get("保管部门名称", ""),
|
||||
item.get("存放位置名称", ""),
|
||||
@@ -460,23 +472,29 @@ INSERT INTO fixed_assets (
|
||||
cls._log("warning", f"Failed to remove temp snapshot file {temp_file}: {exc}")
|
||||
|
||||
@classmethod
|
||||
def _cleanup_history_snapshots(cls, keep_count: int | None = None) -> None:
|
||||
"""仅保留最新 N 份历史快照,额外旧文件自动清理。"""
|
||||
cls._ensure_storage_dirs()
|
||||
snapshots_dir = cls._snapshots_dir()
|
||||
cls._cleanup_temp_snapshot_files(snapshots_dir)
|
||||
def _cleanup_versioned_files(
|
||||
cls,
|
||||
directory: Path,
|
||||
*,
|
||||
patterns: tuple[str, ...],
|
||||
keep_count: int,
|
||||
) -> None:
|
||||
"""按版本号仅保留最近 N 份历史文件,跳过 latest 固定别名文件。"""
|
||||
if not directory.exists():
|
||||
return
|
||||
|
||||
safe_keep_count = max(1, int(keep_count or current_app.config.get("FIXED_ASSETS_HISTORY_KEEP_COUNT", 3) or 3))
|
||||
version_files: dict[str, list[Path]] = {}
|
||||
for pattern in ("FixedAssets_*.db", "FixedAssets_*.xlsx"):
|
||||
for file_path in snapshots_dir.glob(pattern):
|
||||
for pattern in patterns:
|
||||
for file_path in directory.glob(pattern):
|
||||
if file_path.name.startswith("~$"):
|
||||
continue
|
||||
version_key = file_path.stem
|
||||
version_files.setdefault(version_key, []).append(file_path)
|
||||
match = re.fullmatch(r"FixedAssets_(\d{8}_\d{6})", file_path.stem)
|
||||
if not match:
|
||||
continue
|
||||
version_files.setdefault(match.group(1), []).append(file_path)
|
||||
|
||||
version_keys = sorted(version_files.keys(), reverse=True)
|
||||
obsolete_keys = version_keys[safe_keep_count:]
|
||||
obsolete_keys = version_keys[keep_count:]
|
||||
for version_key in obsolete_keys:
|
||||
for file_path in version_files.get(version_key, []):
|
||||
try:
|
||||
@@ -484,6 +502,28 @@ INSERT INTO fixed_assets (
|
||||
except OSError as exc:
|
||||
cls._log("warning", f"Failed to remove obsolete snapshot file {file_path}: {exc}")
|
||||
|
||||
@classmethod
|
||||
def _cleanup_history_snapshots(cls, keep_count: int | None = None) -> None:
|
||||
"""仅保留最新 N 份历史快照,额外旧文件自动清理。"""
|
||||
cls._ensure_storage_dirs()
|
||||
snapshots_dir = cls._snapshots_dir()
|
||||
cls._cleanup_temp_snapshot_files(snapshots_dir)
|
||||
safe_keep_count = max(1, int(keep_count or current_app.config.get("FIXED_ASSETS_HISTORY_KEEP_COUNT", 3) or 3))
|
||||
cls._cleanup_versioned_files(
|
||||
snapshots_dir,
|
||||
patterns=("FixedAssets_*.db", "FixedAssets_*.xlsx"),
|
||||
keep_count=safe_keep_count,
|
||||
)
|
||||
|
||||
if current_app.config.get("FIXED_ASSETS_EXPORT_TO_DOCS", True):
|
||||
docs_root = cls._docs_export_root()
|
||||
cls._cleanup_temp_snapshot_files(docs_root)
|
||||
cls._cleanup_versioned_files(
|
||||
docs_root,
|
||||
patterns=("FixedAssets_*.xlsx",),
|
||||
keep_count=safe_keep_count,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_snapshot_available(cls) -> bool:
|
||||
return cls._latest_db_path().exists()
|
||||
@@ -728,6 +768,7 @@ WITH deduped_assets AS (
|
||||
asset_no AS "资产编号",
|
||||
asset_name AS "资产名称",
|
||||
specification AS "规格型号",
|
||||
operating_center_code AS "账套",
|
||||
custodian_name AS "保管人姓名",
|
||||
department_name AS "保管部门名称",
|
||||
location_name AS "存放位置名称",
|
||||
|
||||
@@ -40,7 +40,8 @@ from typing import Any, Optional
|
||||
from flask import current_app
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from app.models import Agent, ChatLog, QuickQuestion, db
|
||||
from app import db
|
||||
from app.models import Agent, ChatLog, QuickQuestion
|
||||
from app.services.faq_hot_settings import read_faq_hot_env
|
||||
from app.services.faq_text_utils import normalize_faq_query
|
||||
from app.services.hot_faq_candidate_store import HotFaqCandidateStore
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
backend/app/services/hot_faq_candidate_store.py
|
||||
|
||||
用途:热点 FAQ 候选池 PostgreSQL 读写(离线聚合结果,不含在线命中)。
|
||||
依赖:models.FaqHotCandidate、Agent、faq_hot_settings、SQLAlchemy db。
|
||||
依赖:models.FaqHotCandidate、Agent、faq_hot_settings、app.extensions.db。
|
||||
逻辑:HotFaqAggregator 写入;管理端 API 读取 / 晋升 / 忽略。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -13,7 +13,8 @@ from typing import Any, Optional
|
||||
from flask import current_app
|
||||
from sqlalchemy import desc, or_
|
||||
|
||||
from app.models import Agent, FaqHotCandidate, db
|
||||
from app import db
|
||||
from app.models import Agent, FaqHotCandidate
|
||||
from app.services.faq_hot_settings import read_faq_hot_env
|
||||
|
||||
|
||||
|
||||
@@ -445,7 +445,8 @@ WHERE c002001 = ?
|
||||
latency,
|
||||
)
|
||||
|
||||
from app.models import ChatLog, db
|
||||
from app import db
|
||||
from app.models import ChatLog
|
||||
|
||||
chat_log_id = None
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,7 @@ from urllib.parse import urlparse
|
||||
import requests
|
||||
from flask import current_app, has_app_context, has_request_context, request
|
||||
|
||||
from app.config import Config
|
||||
from app.core.config.settings import Config
|
||||
|
||||
|
||||
class IntegrationApiService:
|
||||
|
||||
@@ -9,7 +9,7 @@ import os
|
||||
from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.env_persistence import persist_env_settings
|
||||
from app.core.config.env_persistence import persist_env_settings
|
||||
from app.models import AppSetting, KbDifySyncRecord, KbGroup, KbJob, KbDocumentVersion
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import BinaryIO
|
||||
from minio import Minio
|
||||
from minio.error import S3Error
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.config import config, ACTIVE_ENV_NAME
|
||||
from app.core.config.settings import config, ACTIVE_ENV_NAME
|
||||
|
||||
cfg = config[ACTIVE_ENV_NAME]
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ from urllib.parse import quote
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.models import ChatLog, db
|
||||
from app import db
|
||||
from app.models import ChatLog
|
||||
from app.services.text2sql import Text2SQLService
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from sqlalchemy.orm import joinedload
|
||||
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.response_utils import utc_iso
|
||||
from app.core.response import utc_iso
|
||||
from app.services.schedule.timezone_util import (
|
||||
DEFAULT_SCHEDULE_TIMEZONE,
|
||||
compute_next_run_at,
|
||||
|
||||
@@ -25,6 +25,7 @@ class Text2SQLService:
|
||||
"ASSET_NO": "资产编号",
|
||||
"ASSET_NAME": "资产名称",
|
||||
"SPECIFICATION": "规格型号",
|
||||
"ACCOUNT_BOOK": "账套",
|
||||
"UNIT_PRICE": "本币单价",
|
||||
"QUANTITY": "数量",
|
||||
"UNIT": "计量单位",
|
||||
@@ -43,6 +44,7 @@ class Text2SQLService:
|
||||
"LOCATION_NAME": "存放位置名称",
|
||||
"SITE": "营运中心代码",
|
||||
"SITE_DESC": "营运中心名称",
|
||||
"OPERATING_CENTER_CODE": "账套",
|
||||
"PMC03": "供应厂商",
|
||||
"FAJ01": "序号",
|
||||
"FAJ02": "资产编号",
|
||||
@@ -64,7 +66,7 @@ class Text2SQLService:
|
||||
"FAJ19": "保管人姓名",
|
||||
"FAJ20": "保管部门名称",
|
||||
"FAJ21": "存放位置名称",
|
||||
"FAJ22": "存放营运中心",
|
||||
"FAJ22": "账套",
|
||||
"FAJ25": "取得日期",
|
||||
"FAJ26": "入账日期",
|
||||
"FAJ31": "预留残值",
|
||||
@@ -80,6 +82,7 @@ class Text2SQLService:
|
||||
"资产编号",
|
||||
"资产名称",
|
||||
"规格型号",
|
||||
"账套",
|
||||
"保管人姓名",
|
||||
"保管部门名称",
|
||||
"存放位置名称",
|
||||
@@ -115,6 +118,11 @@ class Text2SQLService:
|
||||
"X": "被资本",
|
||||
"Z": "停用",
|
||||
},
|
||||
"账套": {
|
||||
"HXJM": "和信精密",
|
||||
"HTT": "和泰科技",
|
||||
"HTE": "和泰电子",
|
||||
},
|
||||
}
|
||||
_ASSET_FALLBACK_NAME_COLUMNS = {
|
||||
"保管人": ("保管人姓名", "员工姓名"),
|
||||
@@ -973,6 +981,7 @@ SELECT DISTINCT
|
||||
faj.faj02 AS "资产编号",
|
||||
faj.faj06 AS "资产名称",
|
||||
faj.faj08 AS "规格型号",
|
||||
TRIM(NVL(faj.faj22, '')) AS "账套",
|
||||
faj.faj09 AS "资产性质",
|
||||
faj.faj13 AS "本币单价",
|
||||
faj.faj17 AS "数量",
|
||||
@@ -1013,6 +1022,7 @@ SELECT DISTINCT
|
||||
faj.faj02 AS "资产编号",
|
||||
faj.faj06 AS "资产名称",
|
||||
faj.faj08 AS "规格型号",
|
||||
TRIM(NVL(faj.faj22, '')) AS "账套",
|
||||
faj.faj09 AS "资产性质",
|
||||
faj.faj13 AS "本币单价",
|
||||
faj.faj17 AS "数量",
|
||||
@@ -1074,6 +1084,7 @@ SELECT DISTINCT
|
||||
faj.faj02 AS "资产编号",
|
||||
faj.faj06 AS "资产名称",
|
||||
faj.faj08 AS "规格型号",
|
||||
TRIM(NVL(faj.faj22, '')) AS "账套",
|
||||
faj.faj09 AS "资产性质",
|
||||
faj.faj13 AS "本币单价",
|
||||
faj.faj17 AS "数量",
|
||||
@@ -1159,6 +1170,7 @@ SELECT DISTINCT
|
||||
faj.faj02 AS "资产编号",
|
||||
faj.faj06 AS "资产名称",
|
||||
faj.faj08 AS "规格型号",
|
||||
TRIM(NVL(faj.faj22, '')) AS "账套",
|
||||
faj.faj09 AS "资产性质",
|
||||
faj.faj13 AS "本币单价",
|
||||
faj.faj17 AS "数量",
|
||||
@@ -1259,7 +1271,7 @@ ORDER BY faj.faj02
|
||||
"- 固资相关联表必须同时补齐 `site` 条件,例如 `gen.site = faj.site`、`gem.site = faj.site`、`faf.site = faj.site`、`fab.site = faj.site`、`pmc.site = faj.site`,避免同编码跨营运中心造成重复记录。",
|
||||
"- 固资数据只允许保留 `faj22`(存放营运中心)属于 `HXJM`、`HTT`、`HTE` 的记录;生成 SQL 时必须显式加上 `UPPER(TRIM(NVL(faj.faj22, ''))) IN ('HXJM', 'HTT', 'HTE')` 过滤。",
|
||||
"- 查询固定资产明细列表时优先使用 `SELECT DISTINCT`;如果是统计资产数量,优先使用 `COUNT(DISTINCT faj.faj02)`。",
|
||||
"- 当查询固定资产明细时,返回结果必须且只能包含以下列并使用严格对应的中文别名,顺序必须为:faj.faj02 AS \"资产编号\"、faj.faj06 AS \"资产名称\"、faj.faj08 AS \"规格型号\"、gen.gen02 AS \"保管人姓名\"、gem.gem02 AS \"保管部门名称\"、faf.faf02 AS \"存放位置名称\"、faj.faj43 AS \"资产状态\"、faj.faj31 AS \"预留残值\"、pmc.pmc03 AS \"供应厂商\"、faj.faj09 AS \"资产性质\"、faj.faj13 AS \"本币单价\"、faj.faj17 AS \"数量\"、faj.faj18 AS \"计量单位\"、TO_CHAR(faj.faj25, YYYY-MM-DD HH24:MI:SS) AS \"取得日期\"、TO_CHAR(faj.faj26, YYYY-MM-DD HH24:MI:SS) AS \"入账日期\"。",
|
||||
"- 当查询固定资产明细时,返回结果必须且只能包含以下列并使用严格对应的中文别名,顺序必须为:faj.faj02 AS \"资产编号\"、faj.faj06 AS \"资产名称\"、faj.faj08 AS \"规格型号\"、TRIM(NVL(faj.faj22, '')) AS \"账套\"、gen.gen02 AS \"保管人姓名\"、gem.gem02 AS \"保管部门名称\"、faf.faf02 AS \"存放位置名称\"、faj.faj43 AS \"资产状态\"、faj.faj31 AS \"预留残值\"、pmc.pmc03 AS \"供应厂商\"、faj.faj09 AS \"资产性质\"、faj.faj13 AS \"本币单价\"、faj.faj17 AS \"数量\"、faj.faj18 AS \"计量单位\"、TO_CHAR(faj.faj25, YYYY-MM-DD HH24:MI:SS) AS \"取得日期\"、TO_CHAR(faj.faj26, YYYY-MM-DD HH24:MI:SS) AS \"入账日期\"。",
|
||||
"- 日期时间字段展示时不要去掉时分秒;若使用 TO_CHAR 格式化,必须保留为 `YYYY-MM-DD HH24:MI:SS`,不能只输出日期。",
|
||||
*filters,
|
||||
]
|
||||
@@ -2164,7 +2176,8 @@ ORDER BY faj.faj02
|
||||
return
|
||||
|
||||
# Create ChatLog
|
||||
from app.models import ChatLog, db
|
||||
from app import db
|
||||
from app.models import ChatLog
|
||||
chat_log_id = None
|
||||
try:
|
||||
chat_log = ChatLog(
|
||||
|
||||
Reference in new issue
Block a user