feat: 增强规则资产管理与审计页面运行时调试

后端新增规则资产版本管理和规则文件 CRUD 接口,优化风险
规则生成模板执行和员工数据模型字段,知识库 RAG 增强本
地回退和文档提取能力,清理旧风险规则文件统一由生成引擎
管理,前端审计页面增加运行时调试面板和规则资产编辑交互,
补充单元测试覆盖。
This commit is contained in:
caoxiaozhu
2026-05-24 21:44:17 +08:00
parent 575f093c74
commit 50b1c3f9a9
113 changed files with 13896 additions and 5044 deletions

View File

@@ -5,6 +5,38 @@ from zipfile import ZipFile
from app.services.knowledge_document_extractors import _extract_document_text_from_path
def test_extract_docx_document_text_preserves_tables_as_markdown(tmp_path) -> None:
file_path = tmp_path / "financial-basic.docx"
_write_minimal_docx_with_table(
file_path,
paragraphs=[
"远光软件股份有限公司",
"财务基础知识手册",
"二、常用会计科目",
],
table=[
["科目类别", "科目名称", "说明"],
["资产类", "库存现金", "公司持有的现金"],
["负债类", "应付账款", "因购买商品或接受劳务应付的款项"],
["损益类", "销售费用", "为销售产品发生的费用"],
],
)
text = _extract_document_text_from_path(
file_path=file_path,
original_name="远光软件财务基础知识手册.docx",
mime_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
)
assert "二、常用会计科目" in text
assert "| 科目类别 | 科目名称 | 说明 |" in text
assert "| 资产类 | 库存现金 | 公司持有的现金 |" in text
assert "| 负债类 | 应付账款 | 因购买商品或接受劳务应付的款项 |" in text
assert "| 损益类 | 销售费用 | 为销售产品发生的费用 |" in text
assert "表格第 2 行:科目类别=资产类;科目名称=库存现金;说明=公司持有的现金" in text
assert "科目类别\n科目名称\n说明" not in text
def test_extract_xlsx_document_text_builds_markdown_with_row_clues(tmp_path) -> None:
file_path = tmp_path / "company-expense-rules.xlsx"
_write_minimal_xlsx(
@@ -58,6 +90,39 @@ def test_extract_pptx_document_text_builds_markdown_slides(tmp_path) -> None:
assert "- 发票、审批、预算三项要素必须齐全" in text
def _write_minimal_docx_with_table(
file_path,
*,
paragraphs: list[str],
table: list[list[str]],
) -> None:
paragraph_xml = "\n".join(f"<w:p>{_docx_text_run(text)}</w:p>" for text in paragraphs)
table_xml = (
"<w:tbl>"
+ "".join(
"<w:tr>"
+ "".join(f"<w:tc><w:p>{_docx_text_run(cell)}</w:p></w:tc>" for cell in row)
+ "</w:tr>"
for row in table
)
+ "</w:tbl>"
)
document_xml = f"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
{paragraph_xml}
{table_xml}
</w:body>
</w:document>
"""
with ZipFile(file_path, "w") as archive:
archive.writestr("word/document.xml", document_xml)
def _docx_text_run(text: str) -> str:
return f"<w:r><w:t>{text}</w:t></w:r>"
def _write_minimal_xlsx(file_path, *, sheet_name: str, rows: list[list[str]]) -> None:
workbook_xml = f"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"