导出功能再切割subject的时候直接标题中的【】去掉了,导致主题显示不完全,有什么办法优化吗 ,完整主题如下 # 构建完整主题
complete_subject = (
f"【{data['ISP名称'][index].strip()}】"
f"【{data['区域'][index].strip()}】"
f"【{data['机型'][index].strip()}】"
f"{data['主题'][index].strip()}"
) ,但是现在光主题中的【】也被过滤,例如【ITWIND3】【意大利】【XB432v 1.0】【定制】收到486 SIP消息播忙音,导出变成【ITWIND3】【意大利】【XB432v 1.0】定制 实现如下
def export_data(self):
def async_export():
try:
self.progress.start()
# 获取用户自定义文件名
filename = filedialog.asksaveasfilename(
defaultextension=".xlsx",
filetypes=[("Excel文件", "*.xlsx")],
initialfile="redmine.xlsx"
)
if not filename:
return
# 初始化Excel
wb = op.Workbook()
ws = wb.active
#ws.title = "Function"
total_rows = 0
# 添加表头(带错误处理)
try:
head1 = ['任务id','ISP名称','区域','机型','跟踪','主题','描述','状态','优先级','指派给','功能类别','目标版本','父任务','开始日期','计划完成日期','预期时间','%完成','源头团队','需求组评估工作量','项目组评估工作量','实际执行工作量','源头状态','源头机型','业务模块','任务类别','备注','文件','跟踪者','是否推送平台','验收平台版本']
head2 = ['(必填)','(必填)','(必填)','(必填)','(必填)','(必填)','(必填)','(默认值)','(必填)','(不填)','(必填)','(不填)','(必填)','(不填)','(不填)','(不填)','(不填)','(默认值)','(选填)','(必填)','(选值)','(不填)','(不填)','(不填)','(默认值)','(不填)','(不填)','(不填)','(必填)','(必填)']
ws.append(head1)
ws.append(head2)
except Exception as e:
self.append_output(f"表头创建失败:{str(e)}")
return
# 获取项目数据(带进度更新)
try:
project = self.controller.redmine.project.get(defaultProjectName)
self.append_output(f"正在获取项目数据:{project.name}")
issues = self.controller.redmine.issue.filter(project_id=project.id)
except Exception as e:
self.append_output(f"获取项目数据失败:{str(e)}")
return
#分割subject
def split_subject(str):
result= re.split(r'[【](.*?)[】]', str.strip())
result=list(filter(None,result))
return result
# 新增getd函数定义
def getd(issue_id):
try:
issue = self.controller.redmine.issue.get(issue_id, include=['children'])#预加载子任务
res = split_subject(issue.subject)
# 获取并补充缺失的字段
req_workload = issue.custom_fields.get(31).value if issue.custom_fields.get(31) else None
proj_workload = issue.custom_fields.get(32).value if issue.custom_fields.get(32) else None
act_workload = issue.custom_fields.get(33).value if issue.custom_fields.get(33) else None
push_platform_workload = issue.custom_fields.get(23).value if issue.custom_fields.get(23) else None
platform_pass_workload = issue.custom_fields.get(37).value if issue.custom_fields.get(37) else None
return [
issue.id,
res[0], # ISP名称
res[1], # 区域
res[2], # 机型
issue.tracker.name, # 跟踪类型
res[3], # 主题
issue.description or '', # 空值处理
issue.status.name, # 状态
issue.priority.name, # 优先级
issue.author.name,
issue.custom_fields.get(24).value if issue.custom_fields.get(24) else '', # 功能类别
None, # 目标版本
issue.parent.id if issue.parent else '',
issue.start_date.strftime('%Y-%m-%d') if issue.start_date else '',
None, # 计划完成日期
None, # 预期时间
issue.done_ratio,
issue.custom_fields.get(8).value, # 源头团队
req_workload, # 需求组评估工作量
proj_workload, # 项目组评估工作量
act_workload, # 实际执行工作量
None, # 源头状态
None, # 源头机型
None, # 业务模块
None, # 任务类别
None, # 备注
None, # 文件
None, # 跟踪者
push_platform_workload,
platform_pass_workload
]
except Exception as e:
self.append_output(f"任务{issue_id}数据处理异常:{str(e)}")
return []
# 处理数据(带进度显示)
total = len(issues)
for i, issue in enumerate(issues):
try:
# 更新进度
self.after(0, lambda: self.progress.configure(value=(i+1)/total*100))
# 处理子任务
if self.id_entry.get().strip() == str(issue.id):
for c in issue.children:# 在处理数据处增加计数
ws.append(getd(c.id))
total_rows +=1
for cc in c.children:
ws.append(getd(cc.id))
total_rows +=1
except (ResourceNotFoundError, ResourceAttrError) as e:
self.append_output(f"处理任务{issue.id}时出错:{str(e)}")
except Exception as e:
self.append_output(f"未知错误:{str(e)}")
# 在循环外输出统计信息(避免每次循环都输出)
self.append_output(f"成功写入{total_rows}行数据")
# 保存文件
try:
wb.save(filename)
self.append_output(f"文件已保存至:{filename}")
except Exception as e:
self.append_output(f"保存文件失败:{str(e)}")
# Excel导出时及时释放资源
wb.close()
del wb
finally:
self.progress.stop()
self.progress["value"] = 0
# 在子线程中执行导出操作
Thread(target=async_export).start()
最新发布