日常修复内容20260422
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -15,7 +15,7 @@ from pathlib import Path
|
||||
from utils.chen_response import ChenResponse
|
||||
# 导入数据库ORM
|
||||
from apps.project.models import Project, Contact, Abbreviation, ProjectSoftSummary, StuctSortData, StaticSoftItem, StaticSoftHardware, \
|
||||
DynamicSoftTable, DynamicHardwareTable, ProjectDynamicDescription, EvaluateData, EnvAnalysis
|
||||
DynamicSoftTable, DynamicHardwareTable, ProjectDynamicDescription, EvaluateData, EnvAnalysis, Design
|
||||
from apps.dict.models import Dict
|
||||
# 导入工具函数
|
||||
from utils.util import get_str_dict, get_list_dict, get_testType, get_ident, get_str_abbr
|
||||
@@ -91,12 +91,23 @@ class GenerateControllerDG(ControllerBase, FragementToolsMixin):
|
||||
html_parser = RichParser(single_qs.design.description)
|
||||
desc_list = html_parser.get_final_list(doc)
|
||||
# 查询关联design以及普通design
|
||||
doc_list = [{'dut_name': single_qs.dut.name, 'design_chapter': single_qs.design.chapter,
|
||||
'design_name': single_qs.design.name}]
|
||||
for relate_design in single_qs.otherDesign.all():
|
||||
ddict = {'dut_name': relate_design.dut.name, 'design_chapter': relate_design.chapter,
|
||||
'design_name': relate_design.name}
|
||||
doc_list = [{
|
||||
'dut_name': single_qs.dut.name,
|
||||
'design_chapter': single_qs.design.chapter,
|
||||
'design_name': single_qs.design.name,
|
||||
'dut_type': single_qs.dut.type # 添加 type 字段用于排序
|
||||
}]
|
||||
for relate_design in single_qs.otherDesign.all(): # type: Design
|
||||
ddict = {
|
||||
'dut_name': relate_design.dut.name,
|
||||
'design_chapter': relate_design.chapter,
|
||||
'design_name': relate_design.name,
|
||||
'dut_type': relate_design.dut.type # 添加 type 字段用于排序
|
||||
}
|
||||
doc_list.append(ddict)
|
||||
# 定义排序顺序映射
|
||||
TYPE_ORDER = {'YZ': 0, 'XQ': 1, 'XY': 2, 'SJ': 3, None: 99, '': 999}
|
||||
doc_list.sort(key=lambda x: TYPE_ORDER.get(x.get('dut_type'), 999))
|
||||
|
||||
# 组装单个测试项
|
||||
## 打印本项目是FPGA还是CPU
|
||||
@@ -403,10 +414,13 @@ class GenerateControllerDG(ControllerBase, FragementToolsMixin):
|
||||
interface_dict = {
|
||||
'name': interface.name,
|
||||
'ident': interface.ident,
|
||||
'source': interface.source,
|
||||
'to': interface.to,
|
||||
'type': interface.type,
|
||||
'protocal': interface.protocal,
|
||||
'is_bidirectional': interface.is_bidirectional, # 是否有反向
|
||||
'jk_info_list': [{
|
||||
'source': item.source,
|
||||
'destination': item.destination,
|
||||
'description': item.description,
|
||||
} for item in interface.jkField.all()]
|
||||
}
|
||||
interface_list.append(interface_dict)
|
||||
# 项目接口图处理 - 2026/2/4
|
||||
@@ -423,7 +437,7 @@ class GenerateControllerDG(ControllerBase, FragementToolsMixin):
|
||||
'iters': interfaceNameList,
|
||||
'iter_list': interface_list,
|
||||
'image_render': image_render if image_render else "",
|
||||
'fontnote': fontnote if fontnote else "".join([project_name, '接口示意图'])
|
||||
'fontnote': fontnote if fontnote else "".join([project_name, '接口示意图']),
|
||||
}
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
@@ -469,7 +483,7 @@ class GenerateControllerDG(ControllerBase, FragementToolsMixin):
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
# 通用生成静态软件项、静态硬件项、动态软件项、动态硬件信息的context,包含fontnote和table
|
||||
# 通用生成静态软件项、静态硬件项、动态软件项、动态硬件信息、测评数据的context,包含fontnote和table
|
||||
@classmethod
|
||||
def create_table_context(cls, table_data: list[list[str]], doc: DocxTemplate):
|
||||
"""注意:该函数会增加一列序号列,并且支持单元格内回车换行(段落换行)"""
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.db.models import QuerySet, Q
|
||||
from docxtpl import DocxTemplate
|
||||
from docx import Document
|
||||
# 导入模型
|
||||
from apps.project.models import Project, Round, Dut, InfluenceArea
|
||||
from apps.project.models import Project, Round, Dut
|
||||
from apps.dict.models import Dict
|
||||
# 导入项目工具
|
||||
from utils.util import get_list_dict, get_str_dict, get_ident, get_case_ident, get_testType
|
||||
@@ -19,7 +19,6 @@ from utils.path_utils import project_path
|
||||
from apps.createDocument.extensions.util import delete_dir_files
|
||||
from apps.createDocument.extensions.parse_rich_text import RichParser
|
||||
from apps.createDocument.extensions.documentTime import DocTime
|
||||
from utils.util import get_str_abbr
|
||||
from apps.createDocument.extensions.content_result_tool import create_influence_context
|
||||
# 导入生成日志记录模块
|
||||
from apps.createSeiTaiDocument.extensions.logger import GenerateLogger
|
||||
@@ -234,7 +233,7 @@ class GenerateControllerHSM(ControllerBase):
|
||||
xq_dut: Dut = hround.rdField.filter(type='XQ').first()
|
||||
# 处理代码版本
|
||||
last_round_key = str(int(hround.key) - 1)
|
||||
last_round: Round = project_obj.pField.filter(key=last_round_key).first()
|
||||
last_round: Round | None = project_obj.pField.filter(key=last_round_key).first()
|
||||
last_round_so_dut = last_round.rdField.filter(type='SO').first()
|
||||
if not last_round_so_dut:
|
||||
return ChenResponse(code=400, status=400,
|
||||
|
||||
Binary file not shown.
@@ -1,98 +1,109 @@
|
||||
from pathlib import Path
|
||||
from docxtpl import DocxTemplate
|
||||
from docx.table import Table
|
||||
from utils.chen_response import ChenResponse
|
||||
from typing import Any
|
||||
from apps.project.models import Project
|
||||
from utils.path_utils import project_path
|
||||
|
||||
def merge_all_cell(table: Table) -> None:
|
||||
"""生成需求研总对照表工具:逐个找第二列和第三列单元格的text,如果一致则合并"""
|
||||
col_list = [table.columns[1], table.columns[2]]
|
||||
# 合并第二列相同的单元格
|
||||
for col_right in col_list:
|
||||
index = 0
|
||||
temp_text = ""
|
||||
for cell in col_right.cells:
|
||||
if index == 0:
|
||||
temp_text = cell.text
|
||||
else:
|
||||
if cell.text == temp_text:
|
||||
if cell.text == '': # 不知道什么原因必须这样判断下
|
||||
cell.text = '/'
|
||||
text_temp = cell.text
|
||||
ce = cell.merge(col_right.cells[index - 1])
|
||||
ce.text = text_temp
|
||||
else:
|
||||
temp_text = cell.text
|
||||
index += 1
|
||||
|
||||
def create_sm_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终说明文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'sm' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/sm" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_dg_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终大纲文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'dg' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_bg_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终报告文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'bg' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/bg" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_wtd_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终问题单文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'wtd' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/wtd" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def get_round1_problem(project: Project) -> Any:
|
||||
"""
|
||||
从项目返回第一轮问题单
|
||||
:param project: Project项目Model对象
|
||||
:return: 问题单的列表
|
||||
"""
|
||||
all_problem_qs = project.projField.all()
|
||||
# 遍历每个问题,找出第一轮的问题
|
||||
problem_set = set()
|
||||
for problem in all_problem_qs:
|
||||
flag = False
|
||||
for case in problem.case.all():
|
||||
if case.round.key == '0':
|
||||
flag = True
|
||||
if flag:
|
||||
problem_set.add(problem)
|
||||
return list(problem_set)
|
||||
|
||||
def delete_dir_files(path: Path) -> Any:
|
||||
"""传入一个Path对象,如果是文件夹则删除里面所有的文件(不删除文件夹)"""
|
||||
if path.is_dir():
|
||||
for file in path.iterdir():
|
||||
if file.is_file():
|
||||
file.unlink()
|
||||
|
||||
from pathlib import Path
|
||||
from docxtpl import DocxTemplate
|
||||
from docx.table import Table
|
||||
from utils.chen_response import ChenResponse
|
||||
from typing import Any
|
||||
from apps.project.models import Project
|
||||
from utils.path_utils import project_path
|
||||
|
||||
def merge_all_cell(table: Table) -> None:
|
||||
"""生成需求研总对照表工具:逐个找第二列和第三列单元格的text,如果一致则合并"""
|
||||
col_list = [table.columns[1], table.columns[2]]
|
||||
# 合并第二列相同的单元格
|
||||
for col_right in col_list:
|
||||
index = 0
|
||||
temp_text = ""
|
||||
for cell in col_right.cells:
|
||||
if index == 0:
|
||||
temp_text = cell.text
|
||||
else:
|
||||
if cell.text == temp_text:
|
||||
if cell.text == '': # 不知道什么原因必须这样判断下
|
||||
cell.text = '/'
|
||||
text_temp = cell.text
|
||||
ce = cell.merge(col_right.cells[index - 1])
|
||||
ce.text = text_temp
|
||||
else:
|
||||
temp_text = cell.text
|
||||
index += 1
|
||||
|
||||
def create_sm_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终说明文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'sm' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/sm" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_hsm_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终回归测试说明文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'hsm' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/hsm" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_dg_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终大纲文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'dg' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_bg_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终报告文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'bg' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/bg" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def create_wtd_docx(template_name: str, context: dict, id: int) -> ChenResponse:
|
||||
"""生成最终问题单文档工具函数"""
|
||||
input_path = Path.cwd() / 'media' / project_path(id) / 'form_template' / 'wtd' / template_name
|
||||
doc = DocxTemplate(input_path)
|
||||
doc.render(context, autoescape=True)
|
||||
try:
|
||||
doc.save(Path.cwd() / "media" / project_path(id) / "output_dir/wtd" / template_name)
|
||||
return ChenResponse(status=200, code=200, message="文档生成成功!")
|
||||
except PermissionError as e:
|
||||
return ChenResponse(status=400, code=400, message="模版文件已打开,请关闭后再试,{0}".format(e))
|
||||
|
||||
def get_round1_problem(project: Project) -> Any:
|
||||
"""
|
||||
从项目返回第一轮问题单
|
||||
:param project: Project项目Model对象
|
||||
:return: 问题单的列表
|
||||
"""
|
||||
all_problem_qs = project.projField.all()
|
||||
# 遍历每个问题,找出第一轮的问题
|
||||
problem_set = set()
|
||||
for problem in all_problem_qs:
|
||||
flag = False
|
||||
for case in problem.case.all():
|
||||
if case.round.key == '0':
|
||||
flag = True
|
||||
if flag:
|
||||
problem_set.add(problem)
|
||||
return list(problem_set)
|
||||
|
||||
def delete_dir_files(path: Path) -> Any:
|
||||
"""传入一个Path对象,如果是文件夹则删除里面所有的文件(不删除文件夹)"""
|
||||
if path.is_dir():
|
||||
for file in path.iterdir():
|
||||
if file.is_file():
|
||||
file.unlink()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user